Optionally set the initial selection for the chooser popup

This commit is contained in:
Jonathan Bennett 2025-06-09 20:10:27 -05:00
parent 1d60769f64
commit e43d8a12a7
2 changed files with 20 additions and 14 deletions

View File

@ -134,7 +134,8 @@ extern bool hasUnreadMessage;
// The banner appears in the center of the screen and disappears after the specified duration // The banner appears in the center of the screen and disappears after the specified duration
// Called to trigger a banner with custom message and duration // Called to trigger a banner with custom message and duration
void Screen::showOverlayBanner(const char *message, uint32_t durationMs, uint8_t options, std::function<void(int)> bannerCallback) void Screen::showOverlayBanner(const char *message, uint32_t durationMs, uint8_t options, std::function<void(int)> bannerCallback,
int8_t InitialSelected)
{ {
// Store the message and set the expiration timestamp // Store the message and set the expiration timestamp
strncpy(NotificationRenderer::alertBannerMessage, message, 255); strncpy(NotificationRenderer::alertBannerMessage, message, 255);
@ -142,7 +143,7 @@ void Screen::showOverlayBanner(const char *message, uint32_t durationMs, uint8_t
NotificationRenderer::alertBannerUntil = (durationMs == 0) ? 0 : millis() + durationMs; NotificationRenderer::alertBannerUntil = (durationMs == 0) ? 0 : millis() + durationMs;
NotificationRenderer::alertBannerOptions = options; NotificationRenderer::alertBannerOptions = options;
NotificationRenderer::alertBannerCallback = bannerCallback; NotificationRenderer::alertBannerCallback = bannerCallback;
NotificationRenderer::curSelected = 0; NotificationRenderer::curSelected = InitialSelected;
} }
static void drawModuleFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) static void drawModuleFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
@ -1316,6 +1317,8 @@ int Screen::handleUIFrameEvent(const UIFrameEvent *event)
int Screen::handleInputEvent(const InputEvent *event) int Screen::handleInputEvent(const InputEvent *event)
{ {
LOG_WARN("event %u", event->inputEvent); LOG_WARN("event %u", event->inputEvent);
if (!screenOn)
return 0;
if (NotificationRenderer::isOverlayBannerShowing()) { if (NotificationRenderer::isOverlayBannerShowing()) {
NotificationRenderer::inEvent = event->inputEvent; NotificationRenderer::inEvent = event->inputEvent;
@ -1375,7 +1378,9 @@ int Screen::handleInputEvent(const InputEvent *event)
#endif #endif
#if HAS_GPS #if HAS_GPS
} else if (this->ui->getUiState()->currentFrame == framesetInfo.positions.gps && gps) { } else if (this->ui->getUiState()->currentFrame == framesetInfo.positions.gps && gps) {
showOverlayBanner("Toggle GPS\nENABLED\nDISABLED", 30000, 2, [](int selected) -> void { showOverlayBanner(
"Toggle GPS\nENABLED\nDISABLED", 30000, 2,
[](int selected) -> void {
if (selected == 0) { if (selected == 0) {
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED; config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED;
playGPSEnableBeep(); playGPSEnableBeep();
@ -1385,7 +1390,8 @@ int Screen::handleInputEvent(const InputEvent *event)
playGPSDisableBeep(); playGPSDisableBeep();
gps->disable(); gps->disable();
} }
}); },
config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED ? 0 : 1);
#endif #endif
} else if (this->ui->getUiState()->currentFrame == framesetInfo.positions.clock) { } else if (this->ui->getUiState()->currentFrame == framesetInfo.positions.clock) {
showOverlayBanner( showOverlayBanner(

View File

@ -285,7 +285,7 @@ class Screen : public concurrency::OSThread
} }
void showOverlayBanner(const char *message, uint32_t durationMs = 3000, uint8_t options = 0, void showOverlayBanner(const char *message, uint32_t durationMs = 3000, uint8_t options = 0,
std::function<void(int)> bannerCallback = NULL); std::function<void(int)> bannerCallback = NULL, int8_t InitialSelected = 0);
void startFirmwareUpdateScreen() void startFirmwareUpdateScreen()
{ {