From e43d8a12a75da876cea3ef249c6244410d83d08a Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 9 Jun 2025 20:10:27 -0500 Subject: [PATCH] Optionally set the initial selection for the chooser popup --- src/graphics/Screen.cpp | 32 +++++++++++++++++++------------- src/graphics/Screen.h | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 0fa3674cd..731c7ea1b 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -134,7 +134,8 @@ extern bool hasUnreadMessage; // 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 -void Screen::showOverlayBanner(const char *message, uint32_t durationMs, uint8_t options, std::function bannerCallback) +void Screen::showOverlayBanner(const char *message, uint32_t durationMs, uint8_t options, std::function bannerCallback, + int8_t InitialSelected) { // Store the message and set the expiration timestamp 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::alertBannerOptions = options; NotificationRenderer::alertBannerCallback = bannerCallback; - NotificationRenderer::curSelected = 0; + NotificationRenderer::curSelected = InitialSelected; } 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) { LOG_WARN("event %u", event->inputEvent); + if (!screenOn) + return 0; if (NotificationRenderer::isOverlayBannerShowing()) { NotificationRenderer::inEvent = event->inputEvent; @@ -1375,17 +1378,20 @@ int Screen::handleInputEvent(const InputEvent *event) #endif #if HAS_GPS } else if (this->ui->getUiState()->currentFrame == framesetInfo.positions.gps && gps) { - showOverlayBanner("Toggle GPS\nENABLED\nDISABLED", 30000, 2, [](int selected) -> void { - if (selected == 0) { - config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED; - playGPSEnableBeep(); - gps->enable(); - } else if (selected == 1) { - config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_DISABLED; - playGPSDisableBeep(); - gps->disable(); - } - }); + showOverlayBanner( + "Toggle GPS\nENABLED\nDISABLED", 30000, 2, + [](int selected) -> void { + if (selected == 0) { + config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED; + playGPSEnableBeep(); + gps->enable(); + } else if (selected == 1) { + config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_DISABLED; + playGPSDisableBeep(); + gps->disable(); + } + }, + config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_ENABLED ? 0 : 1); #endif } else if (this->ui->getUiState()->currentFrame == framesetInfo.positions.clock) { showOverlayBanner( diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 7cebf5026..b845af1d4 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -285,7 +285,7 @@ class Screen : public concurrency::OSThread } void showOverlayBanner(const char *message, uint32_t durationMs = 3000, uint8_t options = 0, - std::function bannerCallback = NULL); + std::function bannerCallback = NULL, int8_t InitialSelected = 0); void startFirmwareUpdateScreen() {