From d8d6f671c215f53bb9dbbb7a084d146b0be973a5 Mon Sep 17 00:00:00 2001 From: philmoz Date: Sun, 30 Jun 2024 11:55:09 +1000 Subject: [PATCH] fix(color): block radio startup until checklist is closed (#5227) Which includes preventing internal and external RF from being active --- radio/src/gui/colorlcd/view_text.cpp | 113 ++++++++++++++++++++------- radio/src/gui/colorlcd/view_text.h | 1 + radio/src/opentx.cpp | 4 + 3 files changed, 88 insertions(+), 30 deletions(-) diff --git a/radio/src/gui/colorlcd/view_text.cpp b/radio/src/gui/colorlcd/view_text.cpp index 5b2d84fcd..93f02d37d 100644 --- a/radio/src/gui/colorlcd/view_text.cpp +++ b/radio/src/gui/colorlcd/view_text.cpp @@ -24,6 +24,10 @@ #include "opentx.h" #include "sdcard.h" #include "themes/etx_lv_theme.h" +#include "fullscreen_dialog.h" + +// Used on startup to block until checlist is closed. +static bool checkListOpen = false; // Check Box const lv_style_const_prop_t cb_marker_checked_props[] = { @@ -84,7 +88,11 @@ void ViewTextWindow::on_draw(lv_event_t* e) } } -void ViewTextWindow::onCancel() { Page::onCancel(); } +void ViewTextWindow::onCancel() +{ + Page::onCancel(); + checkListOpen = false; +} void ViewTextWindow::extractNameSansExt() { @@ -423,16 +431,51 @@ static void replaceSpaceWithUnderscore(std::string& name) #define MODEL_FILE_EXT MODELS_EXT #endif -static bool openNotes(const char buf[], std::string modelNotesName, +static bool checkNotesFile(std::string modelNotesName) +{ + std::string fullPath = std::string(MODELS_PATH) + PATH_SEPARATOR + modelNotesName; + return isFileAvailable(fullPath.c_str()); +} + +static std::string getModelNotesFile() +{ + std::string modelNotesName(g_model.header.name); + modelNotesName.append(TEXT_EXT); + + if (checkNotesFile(modelNotesName)) + return modelNotesName; + + replaceSpaceWithUnderscore(modelNotesName); + if (checkNotesFile(modelNotesName)) + return modelNotesName; + +#if !defined(EEPROM) + modelNotesName.assign(g_eeGeneral.currModelFilename); + size_t index = modelNotesName.find(MODEL_FILE_EXT); + if (index != std::string::npos) { + modelNotesName.erase(index); + modelNotesName.append(TEXT_EXT); + if (checkNotesFile(modelNotesName)) + return modelNotesName; + } + replaceSpaceWithUnderscore(modelNotesName); + if (checkNotesFile(modelNotesName)) + return modelNotesName; +#endif + + return std::string(""); +} + +static bool openNotes(std::string modelNotesName, bool fromMenu = false) { - std::string fullPath = std::string(buf) + PATH_SEPARATOR + modelNotesName; + std::string fullPath = std::string(MODELS_PATH) + PATH_SEPARATOR + modelNotesName; if (isFileAvailable(fullPath.c_str())) { if (fromMenu || !g_model.checklistInteractive) - new ViewTextWindow(std::string(buf), modelNotesName, ICON_MODEL); + new ViewTextWindow(std::string(MODELS_PATH), modelNotesName, ICON_MODEL); else - new ViewChecklistWindow(std::string(buf), modelNotesName, ICON_MODEL); + new ViewChecklistWindow(std::string(MODELS_PATH), modelNotesName, ICON_MODEL); return true; } else { return false; @@ -441,34 +484,44 @@ static bool openNotes(const char buf[], std::string modelNotesName, void readModelNotes(bool fromMenu) { - bool notesFound = false; - LED_ERROR_BEGIN(); + std::string modelNotesName = getModelNotesFile(); + if (!modelNotesName.empty()) { + openNotes(modelNotesName, fromMenu); + } +} - std::string modelNotesName(g_model.header.name); - modelNotesName.append(TEXT_EXT); - const char buf[] = {MODELS_PATH}; - - notesFound = openNotes(buf, modelNotesName, fromMenu); - if (!notesFound) { - replaceSpaceWithUnderscore(modelNotesName); - notesFound = openNotes(buf, modelNotesName, fromMenu); +class CheckListDialog : public FullScreenDialog +{ + public: + CheckListDialog() : + FullScreenDialog(WARNING_TYPE_ALERT, "", "", "") + { + LED_ERROR_BEGIN(); + checkListOpen = true; + setCloseCondition(std::bind(&CheckListDialog::warningInactive, this)); + readModelNotes(); } -#if !defined(EEPROM) - if (!notesFound) { - modelNotesName.assign(g_eeGeneral.currModelFilename); - size_t index = modelNotesName.find(MODEL_FILE_EXT); - if (index != std::string::npos) { - modelNotesName.erase(index); - modelNotesName.append(TEXT_EXT); - notesFound = openNotes(buf, modelNotesName, fromMenu); - } - if (!notesFound) { - replaceSpaceWithUnderscore(modelNotesName); - notesFound = openNotes(buf, modelNotesName, fromMenu); - } - } +#if defined(DEBUG_WINDOWS) + std::string getName() const override { return "CheckListDialog"; } #endif - LED_ERROR_END(); + protected: + + bool warningInactive() + { + if (!checkListOpen) + LED_ERROR_END(); + return !checkListOpen; + } +}; + +// Blocking version of readModelNotes. +void readChecklist() +{ + std::string s = getModelNotesFile(); + if (!s.empty()) { + auto dialog = new CheckListDialog(); + dialog->runForever(); + } } diff --git a/radio/src/gui/colorlcd/view_text.h b/radio/src/gui/colorlcd/view_text.h index d4f26a45e..5a0cccbc2 100644 --- a/radio/src/gui/colorlcd/view_text.h +++ b/radio/src/gui/colorlcd/view_text.h @@ -71,3 +71,4 @@ class ViewTextWindow : public Page }; void readModelNotes(bool fromMenu = false); +void readChecklist(); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index a4a72daaf..53c218099 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -649,7 +649,11 @@ void checkAll(bool isBootCheck) if (g_model.displayChecklist && modelHasNotes()) { cancelSplash(); +#if defined(COLORLCD) + readChecklist(); +#else readModelNotes(); +#endif } #if defined(MULTIMODULE)