Files
MeshCore-Solo/examples/companion_radio/ui-new/AutoAdvertScreen.h
T
JakubandClaude Opus 5.5 8c20914689 refactor(ui): upstream's UIColor palette in place of the DARK/LIGHT enum
- DisplayDriver takes ColorVal; each driver's .cpp defines the UIColor roles
  (window_bkg, primary_txt, ...) in its own values. ui-new draws in two:
  window_bkg and primary_txt. OLED and e-ink look as before (sim screens
  pixel-identical).
- E213, E290, LGFX, Null, ST7735, ST7789LCD, U8g2 taken whole from upstream
  (with them the rewritten ST7735 driver and the Heltec V4 R8 TFT display).
- SH1106, SSD1306, ST7789, EinkGfxDisplay and the sim drivers converted.
- ui-orig, ui-tiny, simple_* get upstream's colour roles; the repeater's UI
  taken from upstream (its power-off screen).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 14:42:04 +02:00

65 lines
2.1 KiB
C++

#pragma once
#include "InfoKit.h"
// Configures periodic automatic 0-hop advert with GPS position.
// Included by UITask.cpp after DashboardConfigScreen.h.
class AutoAdvertScreen : public UIScreen {
UITask* _task;
NodePrefs* _prefs;
bool _dirty;
public:
// The intervals on offer, shared with the Home Advert panel.
static const int OPT_COUNT = 8;
static const uint32_t OPTS[OPT_COUNT];
static const char* OPT_LABELS[OPT_COUNT];
static int indexOf(uint32_t sec) {
for (int i = 0; i < OPT_COUNT; i++)
if (OPTS[i] == sec) return i;
return 0;
}
private:
int currentIdx() const { return indexOf(_prefs->advert_auto_interval_sec); }
public:
AutoAdvertScreen(UITask* task, NodePrefs* prefs) : _task(task), _prefs(prefs) {}
void onShow() override { _dirty = false; }
// One value row, drawn like every other settings list (LEFT/RIGHT or Enter
// cycles, Back saves) instead of a screen of its own with typed hints.
int render(DisplayDriver& display) override {
display.setTextSize(1);
display.setColor(UIColor::primary_txt);
drawScreenHeader(display, "Auto-advert");
int sel = 0, scroll = 0;
drawList(display, 1, sel, scroll, [&](int, int y, bool is_sel, int reserve) {
drawRowSelection(display, y, is_sel, reserve);
info::valueRow(display, y, "Interval", OPT_LABELS[currentIdx()], is_sel, reserve);
});
return 5000;
}
bool handleInput(char c) override {
if (c == KEY_CANCEL) {
_task->savePrefsIfDirty(_dirty);
_task->leaveTool();
return true;
}
bool right = keyIsNext(c) || c == KEY_ENTER;
bool left = keyIsPrev(c);
if (right || left) {
int idx = currentIdx();
idx = right ? (idx + 1) % OPT_COUNT : (idx + OPT_COUNT - 1) % OPT_COUNT;
_prefs->advert_auto_interval_sec = OPTS[idx];
_dirty = true;
return true;
}
return false;
}
};
const uint32_t AutoAdvertScreen::OPTS[AutoAdvertScreen::OPT_COUNT] = { 0, 30, 60, 120, 300, 600, 1800, 3600 };
const char* AutoAdvertScreen::OPT_LABELS[AutoAdvertScreen::OPT_COUNT] = { "Off", "30 s", "1 min", "2 min", "5 min", "10 min", "30 min", "1 h" };