#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(DisplayDriver::LIGHT); 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" };