diff --git a/radio/src/gui/colorlcd/model_select.cpp b/radio/src/gui/colorlcd/model_select.cpp index fb83be8a8..58b97b568 100644 --- a/radio/src/gui/colorlcd/model_select.cpp +++ b/radio/src/gui/colorlcd/model_select.cpp @@ -42,6 +42,7 @@ constexpr coord_t MODEL_SELECT_CELL_HEIGHT = 92; constexpr coord_t MODEL_IMAGE_WIDTH = MODEL_SELECT_CELL_WIDTH; constexpr coord_t MODEL_IMAGE_HEIGHT = 72; +inline tmr10ms_t getTicks() { return g_tmr10ms; } class ModelButton : public Button { @@ -208,11 +209,30 @@ class ModelCategoryPageBody : public FormWindow Menu *menu = new Menu(parent); if (model != modelslist.getCurrentModel()) { menu->addLine(STR_SELECT_MODEL, [=]() { - // we store the latest changes if any + bool modelConnected = TELEMETRY_STREAMING() && + !g_eeGeneral.disableRssiPoweroffAlarm; + if (modelConnected) { + AUDIO_ERROR_MESSAGE(AU_MODEL_STILL_POWERED); + if (!confirmationDialog( + STR_MODEL_STILL_POWERED, nullptr, false, []() { + tmr10ms_t startTime = getTicks(); + while (!TELEMETRY_STREAMING()) { + if (getTicks() - startTime > TELEMETRY_CHECK_DELAY10ms) + break; + } + return !TELEMETRY_STREAMING() || + g_eeGeneral.disableRssiPoweroffAlarm; + })) { + return; // stop if connected but not confirmed + } + } + + // store changes (if any) and load selected model storageFlushCurrentModel(); storageCheck(true); memcpy(g_eeGeneral.currModelFilename, model->modelFilename, LEN_MODEL_FILENAME); + loadModel(g_eeGeneral.currModelFilename, false); storageDirty(EE_GENERAL); storageCheck(true); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 9a66bc08d..60682e62e 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2048,6 +2048,10 @@ uint32_t pwrPressedDuration() } } +#if defined(COLORLCD) +inline tmr10ms_t getTicks() { return g_tmr10ms; } +#endif + uint32_t pwrCheck() { const char * message = nullptr; @@ -2138,7 +2142,11 @@ uint32_t pwrCheck() } else if (!modelConnectedConfirmed) { message = STR_MODEL_STILL_POWERED; - closeCondition = [](){ + closeCondition = []() { + tmr10ms_t startTime = getTicks(); + while (!TELEMETRY_STREAMING()) { + if (getTicks() - startTime > TELEMETRY_CHECK_DELAY10ms) break; + } return !TELEMETRY_STREAMING() || g_eeGeneral.disableRssiPoweroffAlarm; }; } diff --git a/radio/src/opentx.h b/radio/src/opentx.h index d659b1208..47d0de997 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -471,6 +471,8 @@ void alert(const char * title, const char * msg, uint8_t sound); #elif defined(COLORLCD) +#define TELEMETRY_CHECK_DELAY10ms 150 + 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,