From 9a5663e6114e3b954e7207cdf074d9cac517aada Mon Sep 17 00:00:00 2001 From: Malte Langermann <54738901+gagarinlg@users.noreply.github.com> Date: Sun, 28 Nov 2021 02:39:40 +0100 Subject: [PATCH] Fix colorlcd auto power off on cleared shutdown warning trigger (#1164) --- radio/src/gui/colorlcd/fullscreen_dialog.cpp | 14 ++++++++++- radio/src/opentx.cpp | 25 +++++++++++++++++--- radio/src/opentx.h | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/radio/src/gui/colorlcd/fullscreen_dialog.cpp b/radio/src/gui/colorlcd/fullscreen_dialog.cpp index a53a669d5..0c5767561 100644 --- a/radio/src/gui/colorlcd/fullscreen_dialog.cpp +++ b/radio/src/gui/colorlcd/fullscreen_dialog.cpp @@ -201,12 +201,24 @@ void raiseAlert(const char * title, const char * msg, const char * action, uint8 } // POPUP_CONFIRMATION -bool confirmationDialog(const char* title, const char* msg, bool checkPwr) +bool confirmationDialog(const char* title, const char* msg, bool checkPwr, const std::function& closeCondition) { bool confirmed = false; auto dialog = new FullScreenDialog(WARNING_TYPE_CONFIRM, title ? title : "", msg ? msg : "", "", [&confirmed]() { confirmed = true; }); + if(closeCondition) + { + dialog->setCloseCondition([&confirmed,&closeCondition]() { + if(closeCondition()) + { + confirmed=true; + return true; + } else { + return false; + }}); + } + if (checkPwr) { dialog->runForever(); } else { diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index e80205742..fda896810 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2044,6 +2044,10 @@ uint32_t pwrCheck() BACKLIGHT_ENABLE(); } if (get_tmr10ms() - pwr_press_time > PWR_PRESS_SHUTDOWN_DELAY()) { +#if defined(COLORLCD) + bool usbConfirmed = !usbPlugged() || getSelectedUsbMode() == USB_UNSELECTED_MODE; + bool modelConnectedConfirmed = !TELEMETRY_STREAMING() || g_eeGeneral.disableRssiPoweroffAlarm; +#endif #if defined(SHUTDOWN_CONFIRMATION) while (1) #else @@ -2087,15 +2091,30 @@ uint32_t pwrCheck() #else // COLORLCD const char* message = nullptr; - if (usbPlugged()) { + std::function closeCondition = nullptr; + if (!usbConfirmed) { message = STR_USB_STILL_CONNECTED; + closeCondition = [](){ + return !usbPlugged(); + }; } - else { + else if (!modelConnectedConfirmed) { message = STR_MODEL_STILL_POWERED; + closeCondition = [](){ + return !TELEMETRY_STREAMING() || g_eeGeneral.disableRssiPoweroffAlarm; + }; } // TODO: abort dialog condition (here, RSSI lost / USB connected) - if (confirmationDialog(STR_MODEL_SHUTDOWN, message, false)) { + if (confirmationDialog(STR_MODEL_SHUTDOWN, message, false, closeCondition)) { + if( message == STR_USB_STILL_CONNECTED) + usbConfirmed=true; + if( message == STR_MODEL_STILL_POWERED) + modelConnectedConfirmed = true; + + if(!usbConfirmed || !modelConnectedConfirmed) + continue; + pwr_check_state = PWR_CHECK_OFF; return e_power_off; } else { diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 68eb3924b..5fc09b7ab 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -471,7 +471,7 @@ void alert(const char * title, const char * msg, uint8_t sound); #elif defined(COLORLCD) -bool confirmationDialog(const char *title, const char *msg, bool checkPwr = true); +bool confirmationDialog(const char *title, const char *msg, bool checkPwr = true, const std::function& closeCondition = nullptr); void raiseAlert(const char *title, const char *msg, const char *info, uint8_t sound);