From 22470bca9a5d7f1883bcfa9ad40637ca3e5a1702 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 30 Jul 2025 19:54:39 -0500 Subject: [PATCH] Move bluetooth to system menu and add confirmation for canned messages --- src/graphics/draw/MenuHandler.cpp | 42 +++++++++++++++---- src/graphics/draw/MenuHandler.h | 1 + src/modules/CannedMessageModule.cpp | 8 +++- .../nrf52840/seeed_wio_tracker_L1/variant.h | 2 + 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/graphics/draw/MenuHandler.cpp b/src/graphics/draw/MenuHandler.cpp index cf19c4825..c6b0d5416 100644 --- a/src/graphics/draw/MenuHandler.cpp +++ b/src/graphics/draw/MenuHandler.cpp @@ -14,7 +14,9 @@ #include "modules/AdminModule.h" #include "modules/CannedMessageModule.h" #include "modules/KeyVerificationModule.h" + #include "modules/TraceRouteModule.h" +#include extern uint16_t TFT_MESH; @@ -25,6 +27,7 @@ bool test_enabled = false; uint8_t test_count = 0; void menuHandler::LoraRegionPicker(uint32_t duration) +// ...existing code... { static const char *optionsArray[] = {"Back", "US", @@ -118,6 +121,22 @@ void menuHandler::TwelveHourPicker() screen->showOverlayBanner(bannerOptions); } +// Reusable confirmation prompt function +void menuHandler::showConfirmationBanner(const char *message, std::function onConfirm) +{ + static const char *confirmOptions[] = {"No", "Yes"}; + BannerOverlayOptions confirmBanner; + confirmBanner.message = message; + confirmBanner.optionsArrayPtr = confirmOptions; + confirmBanner.optionsCount = 2; + confirmBanner.bannerCallback = [onConfirm](int confirmSelected) -> void { + if (confirmSelected == 1) { + onConfirm(); + } + }; + screen->showOverlayBanner(confirmBanner); +} + void menuHandler::ClockFacePicker() { static const char *optionsArray[] = {"Back", "Digital", "Analog"}; @@ -294,7 +313,7 @@ void menuHandler::messageResponseMenu() void menuHandler::homeBaseMenu() { - enum optionsNumbers { Back, Backlight, Position, Preset, Freetext, Bluetooth, Sleep, enumEnd }; + enum optionsNumbers { Back, Backlight, Position, Preset, Freetext, Sleep, enumEnd }; static const char *optionsArray[enumEnd] = {"Back"}; static int optionsEnumArray[enumEnd] = {Back}; @@ -316,8 +335,6 @@ void menuHandler::homeBaseMenu() optionsArray[options] = "New Freetext Msg"; optionsEnumArray[options++] = Freetext; } - optionsArray[options] = "Bluetooth Toggle"; - optionsEnumArray[options++] = Bluetooth; BannerOverlayOptions bannerOptions; bannerOptions.message = "Home Action"; @@ -339,12 +356,13 @@ void menuHandler::homeBaseMenu() InputEvent event = {.inputEvent = (input_broker_event)INPUT_BROKER_SEND_PING, .kbchar = 0, .touchX = 0, .touchY = 0}; inputBroker->injectInputEvent(&event); } else if (selected == Preset) { +#if CANNED_MESSAGE_ADD_CONFIRMATION + showConfirmationBanner("Send message?", [] { cannedMessageModule->LaunchWithDestination(NODENUM_BROADCAST); }); +#else cannedMessageModule->LaunchWithDestination(NODENUM_BROADCAST); +#endif } else if (selected == Freetext) { cannedMessageModule->LaunchFreetextWithDestination(NODENUM_BROADCAST); - } else if (selected == Bluetooth) { - menuQueue = bluetooth_toggle_menu; - screen->runNow(); } }; screen->showOverlayBanner(bannerOptions); @@ -371,7 +389,11 @@ void menuHandler::textMessageBaseMenu() bannerOptions.optionsCount = options; bannerOptions.bannerCallback = [](int selected) -> void { if (selected == Preset) { +#if CANNED_MESSAGE_ADD_CONFIRMATION + showConfirmationBanner("Send message?", [] { cannedMessageModule->LaunchWithDestination(NODENUM_BROADCAST); }); +#else cannedMessageModule->LaunchWithDestination(NODENUM_BROADCAST); +#endif } else if (selected == Freetext) { cannedMessageModule->LaunchFreetextWithDestination(NODENUM_BROADCAST); } @@ -381,7 +403,7 @@ void menuHandler::textMessageBaseMenu() void menuHandler::systemBaseMenu() { - enum optionsNumbers { Back, Notifications, ScreenOptions, PowerMenu, Test, enumEnd }; + enum optionsNumbers { Back, Notifications, ScreenOptions, Bluetooth, PowerMenu, Test, enumEnd }; static const char *optionsArray[enumEnd] = {"Back"}; static int optionsEnumArray[enumEnd] = {Back}; int options = 1; @@ -394,6 +416,9 @@ void menuHandler::systemBaseMenu() optionsEnumArray[options++] = ScreenOptions; #endif + optionsArray[options] = "Bluetooth Toggle"; + optionsEnumArray[options++] = Bluetooth; + optionsArray[options] = "Reboot/Shutdown"; optionsEnumArray[options++] = PowerMenu; @@ -420,6 +445,9 @@ void menuHandler::systemBaseMenu() } else if (selected == Test) { menuHandler::menuQueue = menuHandler::test_menu; screen->runNow(); + } else if (selected == Bluetooth) { + menuQueue = bluetooth_toggle_menu; + screen->runNow(); } else if (selected == Back && !test_enabled) { test_count++; if (test_count > 4) { diff --git a/src/graphics/draw/MenuHandler.h b/src/graphics/draw/MenuHandler.h index 2e4923241..87a0b055e 100644 --- a/src/graphics/draw/MenuHandler.h +++ b/src/graphics/draw/MenuHandler.h @@ -43,6 +43,7 @@ class menuHandler static void LoraRegionPicker(uint32_t duration = 30000); static void handleMenuSwitch(OLEDDisplay *display); + static void showConfirmationBanner(const char *message, std::function onConfirm); static void clockMenu(); static void TZPicker(); static void TwelveHourPicker(); diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index ed930db41..7221721ea 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -595,8 +595,12 @@ bool CannedMessageModule::handleMessageSelectorInput(const InputEvent *event, bo // Normal canned message selection if (runState == CANNED_MESSAGE_RUN_STATE_INACTIVE || runState == CANNED_MESSAGE_RUN_STATE_DISABLED) { } else { - payload = runState; - runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT; + // Show confirmation dialog before sending canned message + NodeNum destNode = dest; + ChannelIndex chan = channel; + graphics::menuHandler::showConfirmationBanner( + "Send preset message?", [this, destNode, chan, current]() { this->sendText(destNode, chan, current, false); }); + // Do not immediately set runState; wait for confirmation handled = true; } } diff --git a/variants/nrf52840/seeed_wio_tracker_L1/variant.h b/variants/nrf52840/seeed_wio_tracker_L1/variant.h index 0c5964c5a..c5647caa8 100644 --- a/variants/nrf52840/seeed_wio_tracker_L1/variant.h +++ b/variants/nrf52840/seeed_wio_tracker_L1/variant.h @@ -162,6 +162,8 @@ static const uint8_t SCL = PIN_WIRE_SCL; #define CANNED_MESSAGE_MODULE_ENABLE 1 +#define CANNED_MESSAGE_ADD_CONFIRMATION 1 + // trackball #define HAS_TRACKBALL 1 #define TB_UP 25