diff --git a/radio/src/gui/colorlcd/popups.cpp b/radio/src/gui/colorlcd/popups.cpp index 8671b62d44f..202149f8705 100644 --- a/radio/src/gui/colorlcd/popups.cpp +++ b/radio/src/gui/colorlcd/popups.cpp @@ -21,17 +21,36 @@ #include "popups.h" #include "libopenui.h" +#include "pwr.h" static void _run_popup_dialog(const char* title, const char* msg, const char* info = nullptr) { bool running = true; + + // reset input devices to avoid + // RELEASED/CLICKED to be called in a loop + lv_indev_reset(nullptr, nullptr); + auto md = new MessageDialog(MainWindow::instance(), title, msg); md->setCloseHandler([&]() { running = false; }); if (info) { 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(); @@ -48,3 +67,40 @@ 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, bool waitForClose) +{ + // if already in a popup, and we don't want to wait, ignore call + if (!waitForClose && ui_popup_active) + return; + + // 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 + if (waitForClose) { + while (ui_popup_active) { + RTOS_WAIT_MS(20); + } + } +} \ No newline at end of file diff --git a/radio/src/gui/colorlcd/popups.h b/radio/src/gui/colorlcd/popups.h index 2b4cd5cbce2..9d85008a112 100644 --- a/radio/src/gui/colorlcd/popups.h +++ b/radio/src/gui/colorlcd/popups.h @@ -27,3 +27,6 @@ typedef std::function 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, bool waitForClose = true); + +void show_ui_popup(); \ No newline at end of file diff --git a/radio/src/gui/common/stdlcd/popups.h b/radio/src/gui/common/stdlcd/popups.h index dbcea388a37..980a1d7e80f 100644 --- a/radio/src/gui/common/stdlcd/popups.h +++ b/radio/src/gui/common/stdlcd/popups.h @@ -74,7 +74,7 @@ enum #if !defined(GUI) #define DISPLAY_WARNING(...) inline void POPUP_WAIT(const char * s) { } - inline void POPUP_WARNING(const char *, const char * = nullptr) { } + inline void POPUP_WARNING(const char *, const char * = nullptr, bool waitForClose) { } inline void POPUP_CONFIRMATION(const char * s, PopupMenuHandler handler) { } inline void POPUP_INPUT(const char * s, PopupFunc func) { } inline void SET_WARNING_INFO(const char * info, uint8_t length, uint8_t flags) { } @@ -105,8 +105,10 @@ enum popupFunc = runPopupWarning; } - inline void POPUP_WARNING(const char * message, const char * info = nullptr) + inline void POPUP_WARNING(const char * message, const char * info = nullptr, bool waitForClose = true) { + (void)waitForClose; + warningText = message; warningInfoText = info; warningInfoLength = info ? strlen(info) : 0; @@ -187,4 +189,7 @@ inline void POPUP_MENU_START(PopupMenuHandler handler) } } -#endif // _STDLCD_POPUPS_H_ +// 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_ \ No newline at end of file diff --git a/radio/src/gui/screenshot.cpp b/radio/src/gui/screenshot.cpp index c0cb50373bb..a2726086d72 100644 --- a/radio/src/gui/screenshot.cpp +++ b/radio/src/gui/screenshot.cpp @@ -56,6 +56,11 @@ const char * writeScreenshot() UINT written; char filename[42]; // /SCREENSHOTS/screen-2013-01-01-123540.bmp + if (IS_SDCARD_FULL()) { + POPUP_WARNING(STR_SDCARD_FULL_EXT); + return STR_SDCARD_FULL_EXT; + } + // check and create folder here strcpy(filename, SCREENSHOTS_PATH); const char * error = sdCheckAndCreateDirectory(filename); @@ -88,7 +93,7 @@ const char * writeScreenshot() auto h = snapshot->header.h; for (int y = h - 1; y >= 0; y--) { - for (int x = 0; x < w; x++) { + for (uint32_t x = 0; x < w; x++) { lv_color_t pixel = lv_img_buf_get_px_color(snapshot, x, y, {}); @@ -123,4 +128,4 @@ const char * writeScreenshot() f_close(&bmpFile); return nullptr; -} +} \ No newline at end of file diff --git a/radio/src/logs.cpp b/radio/src/logs.cpp index 23f32ab3f33..b580af424e3 100644 --- a/radio/src/logs.cpp +++ b/radio/src/logs.cpp @@ -121,9 +121,6 @@ const char * logsOpen() if (!sdMounted()) return STR_NO_SDCARD; - if (sdGetFreeSectors() == 0) - return STR_SDCARD_FULL; - // check and create folder here strcpy(filename, STR_LOGS_PATH); const char * error = sdCheckAndCreateDirectory(filename); @@ -189,9 +186,7 @@ void logsClose() } lastLogTime = 0; } - #if !defined(SIMU) - loggingTimerStop(); - #endif + } void writeHeader() @@ -283,17 +278,34 @@ void logsWrite() { #endif + static int lines = 0; + lines++; if(lines > 30) lines = 30; + bool sdCardFull = IS_SDCARD_FULL() || lines == 30; + //bool sdCardFull = IS_SDCARD_FULL(); + + // check if file needs to be opened if (!g_oLogFile.obj.fs) { - const char * result = logsOpen(); + const char *result = sdCardFull ? STR_SDCARD_FULL_EXT : logsOpen(); + + // SD card is full or file open failed if (result) { if (result != error_displayed) { error_displayed = result; - POPUP_WARNING(result); + POPUP_WARNING_ON_UI_TASK(result, nullptr, false); } return; } } + // check at every write cycle + if (sdCardFull) { + logsClose(); // timer is still running and code above will try to + // open the file again but will fail with error + // which will trigger the warning popup + return; + } + + #if defined(RTCLOCK) { static struct gtm utm; @@ -380,15 +392,17 @@ void logsWrite() if (result<0 && !error_displayed) { error_displayed = STR_SDCARD_ERROR; - POPUP_WARNING(STR_SDCARD_ERROR); + POPUP_WARNING_ON_UI_TASK(STR_SDCARD_ERROR, nullptr, false); logsClose(); } } } else { error_displayed = nullptr; - if (g_oLogFile.obj.fs) { - logsClose(); - } + logsClose(); + + #if !defined(SIMU) + loggingTimerStop(); + #endif } } diff --git a/radio/src/main.cpp b/radio/src/main.cpp index 96dfb255fa7..a019e184c94 100644 --- a/radio/src/main.cpp +++ b/radio/src/main.cpp @@ -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 diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index eed5658512f..7cd7b976d45 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -695,6 +695,11 @@ static void checkRTCBattery() } } +void checkSDfreeStorage() { + if(IS_SDCARD_FULL()) + ALERT(STR_SD_CARD, STR_SDCARD_FULL, AU_ERROR); +} + #if defined(PCBFRSKY) || defined(PCBFLYSKY) static void checkFailsafe() { @@ -722,6 +727,8 @@ void checkAll() #if defined(EEPROM_RLC) && !defined(SDCARD_RAW) && !defined(SDCARD_YAML) checkLowEEPROM(); #endif + + checkSDfreeStorage(); // we don't check the throttle stick if the radio is not calibrated if (g_eeGeneral.chkSum == evalChkSum()) { diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 7a27dbcd187..bd202b6bc71 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -1105,6 +1105,10 @@ inline getvalue_t convertTelemValue(source_t channel, ls_telemetry_value_t value return convert16bitsTelemValue(channel, value); } +inline bool IS_SDCARD_FULL() { + return sdGetFreeSectors() < ((50 *1024*1024) / BLOCK_SIZE); // 50MB safety margin +} + extern uint8_t g_vbat100mV; inline uint8_t GET_TXBATT_BARS(uint8_t barsMax) diff --git a/radio/src/sdcard.cpp b/radio/src/sdcard.cpp index 5f39af548a6..ccab049bc2e 100644 --- a/radio/src/sdcard.cpp +++ b/radio/src/sdcard.cpp @@ -463,7 +463,7 @@ uint32_t sdGetSize() uint32_t sdGetFreeSectors() { - return 10; + return ((50 *1024*1024)/BLOCK_SIZE)+1; // SIMU SD card is always above threshold } #endif // #if !defined(SIMU) || defined(SIMU_DISKIO) diff --git a/radio/src/targets/horus/diskio.cpp b/radio/src/targets/horus/diskio.cpp index b9c677cfc5f..6150453b642 100644 --- a/radio/src/targets/horus/diskio.cpp +++ b/radio/src/targets/horus/diskio.cpp @@ -177,7 +177,7 @@ DRESULT __disk_read(BYTE drv, BYTE * buff, DWORD sector, UINT count) if ((DWORD)buff < 0x20000000 || ((DWORD)buff & 3)) { // buffer is not aligned, use scratch buffer that is aligned - TRACE("disk_read bad alignment (%p)", buff); + //TRACE("disk_read bad alignment (%p)", buff); while (count--) { res = disk_read_dma(drv, (BYTE *)scratch, sector++, 1); if (res != RES_OK) break; diff --git a/radio/src/targets/horus/lcd_driver.cpp b/radio/src/targets/horus/lcd_driver.cpp index 1176a872ba1..5e4b7ff9b06 100644 --- a/radio/src/targets/horus/lcd_driver.cpp +++ b/radio/src/targets/horus/lcd_driver.cpp @@ -153,8 +153,8 @@ static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer, lv_area_t refr_area; lv_area_copy(&refr_area, &disp->inv_areas[i]); - TRACE("{%d,%d,%d,%d}", refr_area.x1, - refr_area.y1, refr_area.x2, refr_area.y2); + //TRACE("{%d,%d,%d,%d}", refr_area.x1, + // refr_area.y1, refr_area.x2, refr_area.y2); _rotate_area_180(refr_area); diff --git a/radio/src/translations.cpp b/radio/src/translations.cpp index 8de353bad28..053330b6672 100644 --- a/radio/src/translations.cpp +++ b/radio/src/translations.cpp @@ -949,6 +949,7 @@ const char STR_SDCARD_ERROR[] = TR_SDCARD_ERROR; #define STR_CLEAR TR_CLEAR const char STR_NO_SDCARD[] = TR_NO_SDCARD; const char STR_SDCARD_FULL[] = TR_SDCARD_FULL; +const char STR_SDCARD_FULL_EXT[] = TR_SDCARD_FULL_EXT; const char STR_INCOMPATIBLE[] = TR_INCOMPATIBLE; const char STR_LOGS_PATH[] = LOGS_PATH; const char STR_LOGS_EXT[] = LOGS_EXT; diff --git a/radio/src/translations.h b/radio/src/translations.h index 21f14db33f8..91f488e18c6 100644 --- a/radio/src/translations.h +++ b/radio/src/translations.h @@ -626,6 +626,7 @@ extern const char STR_DELETE_ERROR[]; extern const char STR_SDCARD_ERROR[]; extern const char STR_NO_SDCARD[]; extern const char STR_SDCARD_FULL[]; +extern const char STR_SDCARD_FULL_EXT[]; extern const char STR_INCOMPATIBLE[]; extern const char STR_LOGS_PATH[]; extern const char STR_LOGS_EXT[]; diff --git a/radio/src/translations/cn.h b/radio/src/translations/cn.h index 3668ba05b4d..a3063c6e6c4 100644 --- a/radio/src/translations/cn.h +++ b/radio/src/translations/cn.h @@ -686,6 +686,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "频谱仪 (外置)" #define TR_SPECTRUM_ANALYSER_INT "频谱仪 (内置)" #define TR_SDCARD_FULL "存储卡已满" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "需要文件名包含" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/cz.h b/radio/src/translations/cz.h index 2ec4616537c..f85f3b052e1 100644 --- a/radio/src/translations/cz.h +++ b/radio/src/translations/cz.h @@ -704,6 +704,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spektální an. (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Spektální an. (INT)" #define TR_SDCARD_FULL "Plná SD karta" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "Vyžadován soubor" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/da.h b/radio/src/translations/da.h index 5fcf8d3bd83..fbe1267b18a 100644 --- a/radio/src/translations/da.h +++ b/radio/src/translations/da.h @@ -691,6 +691,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spectrum (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Spectrum (INT)" #define TR_SDCARD_FULL "SD kort fuldt" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "MANGLER FIL" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/de.h b/radio/src/translations/de.h index 132cf558250..e8ca100a648 100644 --- a/radio/src/translations/de.h +++ b/radio/src/translations/de.h @@ -686,6 +686,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spectrum (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Spectrum (INT)" #define TR_SDCARD_FULL "SD-Karte voll" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "Datei benötigt" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/en.h b/radio/src/translations/en.h index ab2d074fa3f..5c8042616bf 100644 --- a/radio/src/translations/en.h +++ b/radio/src/translations/en.h @@ -686,6 +686,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spectrum (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Spectrum (INT)" #define TR_SDCARD_FULL "SD card full" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "NEEDS FILE" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/es.h b/radio/src/translations/es.h index 32664545027..46729ecbd54 100644 --- a/radio/src/translations/es.h +++ b/radio/src/translations/es.h @@ -687,6 +687,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Espectro (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Espectro (INT)" #define TR_SDCARD_FULL "SD Card llena" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "NECESITA ARCHIVO" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/fi.h b/radio/src/translations/fi.h index ceae6c0eb95..af322d0d104 100644 --- a/radio/src/translations/fi.h +++ b/radio/src/translations/fi.h @@ -713,6 +713,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spectrum (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Spectrum (INT)" #define TR_SDCARD_FULL "SD Card Full" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "NEEDS FILE" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/fr.h b/radio/src/translations/fr.h index 57999cfb372..5bd28012644 100644 --- a/radio/src/translations/fr.h +++ b/radio/src/translations/fr.h @@ -707,6 +707,7 @@ #define TR_SPECTRUM_ANALYSER_EXT TR("Spectre (EXT)", "Analyseur spectre (EXT)") #define TR_SPECTRUM_ANALYSER_INT TR("Spectre (INT)", "Analyseur spectre (INT)") #define TR_SDCARD_FULL "Carte SD pleine" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "NEEDS FILE" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/it.h b/radio/src/translations/it.h index b0a40abafe8..610b4f1acea 100644 --- a/radio/src/translations/it.h +++ b/radio/src/translations/it.h @@ -687,6 +687,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spettro (EST)" #define TR_SPECTRUM_ANALYSER_INT "Spettro (INT)" #define TR_SDCARD_FULL "SDCard Piena" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "RICHIEDE FILE" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/jp.h b/radio/src/translations/jp.h index b14b6ef9c25..a4d0e1dba0f 100644 --- a/radio/src/translations/jp.h +++ b/radio/src/translations/jp.h @@ -698,6 +698,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "スペクトラム (外部)" #define TR_SPECTRUM_ANALYSER_INT "スペクトラム (内部)" #define TR_SDCARD_FULL "SDカード空き容量なし" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "を含むファイルが必要です" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/nl.h b/radio/src/translations/nl.h index 3055d2e82d2..2b15192f305 100644 --- a/radio/src/translations/nl.h +++ b/radio/src/translations/nl.h @@ -692,6 +692,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spectrum (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Spectrum (INT)" #define TR_SDCARD_FULL "SD-Kaart vol" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "NEEDS FILE" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/pl.h b/radio/src/translations/pl.h index fab367b86cd..1530acad8bd 100644 --- a/radio/src/translations/pl.h +++ b/radio/src/translations/pl.h @@ -683,6 +683,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spectrum (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Spectrum (INT)" #define TR_SDCARD_FULL "Karta Pełna " +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "NEEDS FILE" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/pt.h b/radio/src/translations/pt.h index 57aaec26fa6..0ce6ccc1817 100644 --- a/radio/src/translations/pt.h +++ b/radio/src/translations/pt.h @@ -689,6 +689,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spectrum (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Spectrum (INT)" #define TR_SDCARD_FULL "SD Card Full" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "NEEDS FILE" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/se.h b/radio/src/translations/se.h index 3554007def9..ba96cec40aa 100644 --- a/radio/src/translations/se.h +++ b/radio/src/translations/se.h @@ -726,6 +726,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "Spektrum (EXT)" #define TR_SPECTRUM_ANALYSER_INT "Spektrum (INT)" #define TR_SDCARD_FULL "SD-kort fullt" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "BEHÖVER FIL" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv" diff --git a/radio/src/translations/tw.h b/radio/src/translations/tw.h index ab3c1ec4e7d..aafae94964a 100644 --- a/radio/src/translations/tw.h +++ b/radio/src/translations/tw.h @@ -686,6 +686,7 @@ #define TR_SPECTRUM_ANALYSER_EXT "頻譜儀 (外置)" #define TR_SPECTRUM_ANALYSER_INT "頻譜儀 (內置)" #define TR_SDCARD_FULL "存儲卡已滿" +#define TR_SDCARD_FULL_EXT "SD card full\nLogs and Screenshots disabled" #define TR_NEEDS_FILE "需要文件名包含" #define TR_EXT_MULTI_SPEC "opentx-inv" #define TR_INT_MULTI_SPEC "stm-opentx-noinv"