fix(color): Popup telemetry warning can crash radio (#3439)

Also fixes issue where simulator does not close cleanly if popup showing.
This commit is contained in:
philmoz
2023-04-16 18:25:29 +10:00
committed by GitHub
parent b3c7a95aa2
commit e0fad3d122
5 changed files with 53 additions and 1 deletions
+44
View File
@@ -21,6 +21,7 @@
#include "popups.h"
#include "libopenui.h"
#include "pwr.h"
static void _run_popup_dialog(const char* title, const char* msg,
const char* info = nullptr)
@@ -37,6 +38,19 @@ static void _run_popup_dialog(const char* title, const char* msg,
md->setInfoText(std::string(info));
}
while (running) {
// Allow power off while showing popup
auto check = pwrCheck();
if (check == e_power_off) {
boardOff();
#if defined(SIMU)
// Required so simulator exits cleanly when window closed
return;
#endif
} else if (check == e_power_press) {
WDG_RESET();
RTOS_WAIT_MS(1);
continue;
}
WDG_RESET();
MainWindow::instance()->run();
LvglWrapper::runNested();
@@ -53,3 +67,33 @@ void POPUP_WARNING(const char * message, const char * info)
{
_run_popup_dialog("Warning", message, info);
}
static const char* ui_popup_title = nullptr;
static const char* ui_popup_msg = nullptr;
static const char* ui_popup_info = nullptr;
static bool ui_popup_active = false;
// Allow UI task to show a popup deferred from another task.
void show_ui_popup()
{
if (ui_popup_active) {
_run_popup_dialog(ui_popup_title, ui_popup_msg, ui_popup_info);
ui_popup_active = false;
}
}
void POPUP_WARNING_ON_UI_TASK(const char * message, const char * info)
{
// Wait in case already in popup.
while (ui_popup_active) {
RTOS_WAIT_MS(20);
}
ui_popup_title = "Warning";
ui_popup_msg = message;
ui_popup_info = info;
ui_popup_active = true;
// Wait until closed
while (ui_popup_active) {
RTOS_WAIT_MS(20);
}
}
+3
View File
@@ -27,3 +27,6 @@ typedef std::function<void(const char *, const char *, int, int)> ProgressHandle
void POPUP_INFORMATION(const char * message);
void POPUP_WARNING(const char * message, const char * info = nullptr);
void POPUP_WARNING_ON_UI_TASK(const char * message, const char * info = nullptr);
void show_ui_popup();
+3
View File
@@ -187,4 +187,7 @@ inline void POPUP_MENU_START(PopupMenuHandler handler)
}
}
// For compatability with color LCD code base, not (currently) required for B&W
#define POPUP_WARNING_ON_UI_TASK POPUP_WARNING
#endif // _STDLCD_POPUPS_H_
+2
View File
@@ -580,6 +580,8 @@ void perMain()
DEBUG_TIMER_START(debugTimerGuiMain);
#if defined(LIBOPENUI)
guiMain(0);
// For color screens show a popup deferred from another task
show_ui_popup();
#else
guiMain(evt);
#endif
+1 -1
View File
@@ -269,7 +269,7 @@ void telemetryWakeup()
#if defined(PCBFRSKY)
if (isBadAntennaDetected()) {
AUDIO_RAS_RED();
POPUP_WARNING(STR_WARNING, STR_ANTENNAPROBLEM);
POPUP_WARNING_ON_UI_TASK(STR_WARNING, STR_ANTENNAPROBLEM);
SCHEDULE_NEXT_ALARMS_CHECK(10/*seconds*/);
}
#endif