2026-05-14 16:08:33 +02:00
|
|
|
#pragma once
|
|
|
|
|
// 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;
|
|
|
|
|
|
2026-05-17 14:33:58 +02:00
|
|
|
static const int OPT_COUNT = 8;
|
2026-05-14 16:08:33 +02:00
|
|
|
static const uint32_t OPTS[OPT_COUNT];
|
|
|
|
|
static const char* OPT_LABELS[OPT_COUNT];
|
|
|
|
|
|
|
|
|
|
int currentIdx() const {
|
|
|
|
|
for (int i = 0; i < OPT_COUNT; i++)
|
|
|
|
|
if (OPTS[i] == _prefs->advert_auto_interval_sec) return i;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
AutoAdvertScreen(UITask* task, NodePrefs* prefs) : _task(task), _prefs(prefs) {}
|
|
|
|
|
|
2026-06-29 18:37:04 +02:00
|
|
|
void onShow() override { _dirty = false; }
|
2026-05-14 16:08:33 +02:00
|
|
|
|
|
|
|
|
int render(DisplayDriver& display) override {
|
|
|
|
|
display.setTextSize(1);
|
|
|
|
|
display.setColor(DisplayDriver::LIGHT);
|
2026-05-22 18:05:09 +02:00
|
|
|
int label_y = display.listStart();
|
|
|
|
|
int bar_y = label_y + display.lineStep();
|
|
|
|
|
int bar_h = display.lineStep();
|
2026-05-22 19:11:25 +02:00
|
|
|
int tip_y = bar_y + bar_h + 4;
|
2026-05-14 16:08:33 +02:00
|
|
|
|
2026-06-15 21:23:00 +02:00
|
|
|
display.drawCenteredHeader("AUTO-ADVERT");
|
2026-05-22 18:05:09 +02:00
|
|
|
|
|
|
|
|
display.setCursor(2, label_y);
|
2026-05-14 16:08:33 +02:00
|
|
|
display.print("Interval:");
|
|
|
|
|
|
|
|
|
|
int idx = currentIdx();
|
|
|
|
|
display.setColor(DisplayDriver::LIGHT);
|
2026-05-22 18:05:09 +02:00
|
|
|
display.fillRect(0, bar_y, display.width(), bar_h);
|
2026-05-14 16:08:33 +02:00
|
|
|
display.setColor(DisplayDriver::DARK);
|
2026-05-22 18:05:09 +02:00
|
|
|
display.drawTextCentered(display.width() / 2, bar_y + 1, OPT_LABELS[idx]);
|
2026-05-14 16:08:33 +02:00
|
|
|
display.setColor(DisplayDriver::LIGHT);
|
|
|
|
|
|
2026-05-22 18:05:09 +02:00
|
|
|
display.setCursor(2, tip_y);
|
2026-05-14 16:08:33 +02:00
|
|
|
display.print("< > to change");
|
2026-05-22 18:05:09 +02:00
|
|
|
display.setCursor(2, tip_y + display.lineStep());
|
2026-05-14 16:08:33 +02:00
|
|
|
display.print("[Esc] to save");
|
|
|
|
|
return 500;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool handleInput(char c) override {
|
|
|
|
|
if (c == KEY_CANCEL || c == KEY_CONTEXT_MENU) {
|
2026-06-29 18:47:51 +02:00
|
|
|
_task->savePrefsIfDirty(_dirty);
|
2026-05-14 16:08:33 +02:00
|
|
|
_task->gotoToolsScreen();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-06-15 21:23:00 +02:00
|
|
|
bool right = keyIsNext(c) || c == KEY_ENTER;
|
|
|
|
|
bool left = keyIsPrev(c);
|
2026-05-14 16:08:33 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-17 14:33:58 +02:00
|
|
|
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", "30s", "1min", "2min", "5min", "10min", "30min", "1h" };
|