diff --git a/src/main/cms/cms.c b/src/main/cms/cms.c index a32ab0af886..f2f66476e4d 100644 --- a/src/main/cms/cms.c +++ b/src/main/cms/cms.c @@ -902,7 +902,7 @@ long cmsMenuExit(displayPort_t *pDisplay, const void *ptr) setServoOutputEnabled(true); if ((exitType == CMS_EXIT_SAVEREBOOT) || (exitType == CMS_POPUP_SAVEREBOOT)) { - processDelayedSave(); + processDelayedSave(true); displayClearScreen(pDisplay); displayWrite(pDisplay, 5, 3, "REBOOTING..."); diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 52cb06f81a6..ea8e0d509d4 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -68,6 +68,7 @@ #include "fc/config.h" #include "fc/controlrate_profile.h" +#include "fc/fc_core.h" #include "fc/rc_adjustments.h" #include "fc/rc_controls.h" #include "fc/rc_curves.h" @@ -396,16 +397,30 @@ void saveConfig(void) } } -void processDelayedSave(void) +void processDelayedSave(bool readyToSave) { if (saveState == SAVESTATE_SAVEANDNOTIFY) { - processSaveConfigAndNotify(); - saveState = SAVESTATE_NONE; + if (emergInflightRearmEnabled() || !readyToSave) { + // Do not process save if we are potentially still flying. Once armed, this function will not be called until the next disarm. +#ifdef USE_OSD + osdSaveWaitingProcess(); +#endif + } else { +#ifdef USE_OSD + osdStartedSaveProcess(); +#endif + if (readyToSave) { + processSaveConfigAndNotify(); + saveState = SAVESTATE_NONE; + } + } } else if (saveState == SAVESTATE_SAVEONLY) { - suspendRxSignal(); - writeEEPROM(); - resumeRxSignal(); - saveState = SAVESTATE_NONE; + if (readyToSave) { + suspendRxSignal(); + writeEEPROM(); + resumeRxSignal(); + saveState = SAVESTATE_NONE; + } } } diff --git a/src/main/fc/config.h b/src/main/fc/config.h index bafa5c0cbe0..00ffe36e044 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -124,7 +124,7 @@ void resetEEPROM(void); void readEEPROM(void); void writeEEPROM(void); void ensureEEPROMContainsValidData(void); -void processDelayedSave(void); +void processDelayedSave(bool readyToSave); void saveConfig(void); void saveConfigAndNotify(void); diff --git a/src/main/fc/fc_core.c b/src/main/fc/fc_core.c index a61204dee90..470d9c11aae 100644 --- a/src/main/fc/fc_core.c +++ b/src/main/fc/fc_core.c @@ -65,6 +65,7 @@ #include "io/beeper.h" #include "io/dashboard.h" #include "io/gps.h" +#include "io/osd.h" #include "io/serial.h" #include "io/statusindicator.h" #include "io/asyncfatfs/asyncfatfs.h" @@ -894,13 +895,15 @@ void taskMainPidLoop(timeUs_t currentTimeUs) if (!ARMING_FLAG(ARMED)) { armTime = 0; - // Delay saving for 0.5s to allow other functions to process save actions on disarm - if (currentTimeUs - lastDisarmTimeUs > USECS_PER_SEC / 2) { - processDelayedSave(); - } + // Delay saving for 0.5s to allow other functions to finish processing data to be stored on disarm + processDelayedSave((currentTimeUs - lastDisarmTimeUs > USECS_PER_SEC / 2)); } if (armTime > 1 * USECS_PER_SEC) { // reset in flight emerg rearm flag 1 sec after arming once it's served its purpose +#ifdef USE_OSD + if (STATE(IN_FLIGHT_EMERG_REARM)) + osdSaveProcessAborted(); +#endif DISABLE_STATE(IN_FLIGHT_EMERG_REARM); } diff --git a/src/main/fc/fc_core.h b/src/main/fc/fc_core.h index c66a0050ba2..573ae31bc4d 100644 --- a/src/main/fc/fc_core.h +++ b/src/main/fc/fc_core.h @@ -43,6 +43,7 @@ void tryArm(void); disarmReason_t getDisarmReason(void); bool emergencyArmingUpdate(bool armingSwitchIsOn, bool forceArm); +bool emergInflightRearmEnabled(void); bool areSensorsCalibrating(void); float getFlightTime(void); diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 02d0e02a803..70e8f524456 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -155,8 +155,16 @@ #define OSD_MIN_FONT_VERSION 3 static timeMs_t linearDescentMessageMs = 0; + +typedef enum { + OSD_SAVE_MESSAGE_NONE, + OSD_SAVE_MESSAGE_WAITING, + OSD_SAVE_MESSAGE_SAVING, + OSD_SAVE_MESSAGE_SAVED +} osd_saveMessage_e; + static timeMs_t notify_settings_saved = 0; -static bool savingSettings = false; +static uint8_t savingSettings = OSD_SAVE_MESSAGE_NONE; static unsigned currentLayout = 0; static int layoutOverride = -1; @@ -212,17 +220,24 @@ static bool osdDisplayHasCanvas; PG_REGISTER_WITH_RESET_TEMPLATE(osdConfig_t, osdConfig, PG_OSD_CONFIG, 9); PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t, osdLayoutsConfig, PG_OSD_LAYOUTS_CONFIG, 1); +void osdSaveProcessAborted(void) { + notify_settings_saved = 0; + savingSettings = OSD_SAVE_MESSAGE_NONE; +} + +void osdSaveWaitingProcess(void) { + savingSettings = OSD_SAVE_MESSAGE_WAITING; +} + void osdStartedSaveProcess(void) { - savingSettings = true; + savingSettings = OSD_SAVE_MESSAGE_SAVING; } void osdShowEEPROMSavedNotification(void) { - savingSettings = false; + savingSettings = OSD_SAVE_MESSAGE_SAVED; notify_settings_saved = millis() + 5000; } - - bool osdDisplayIsPAL(void) { return displayScreenSize(osdDisplayPort) == VIDEO_BUFFER_CHARS_PAL; @@ -4534,12 +4549,15 @@ static void osdShowStats(bool isSinglePageStatsCompatible, uint8_t page) displayWrite(osdDisplayPort, statValuesX + multiValueLengthOffset, top++, buff); } - if (savingSettings == true) { + if (savingSettings == OSD_SAVE_MESSAGE_SAVING) { displayWrite(osdDisplayPort, statNameX, top++, OSD_MESSAGE_STR(OSD_MSG_SAVING_SETTNGS)); + } else if (savingSettings == OSD_SAVE_MESSAGE_WAITING) { + displayWrite(osdDisplayPort, statNameX, top++, OSD_MESSAGE_STR(OSD_MSG_WAITING_TO_SAVE)); } else if (notify_settings_saved > 0) { if (millis() > notify_settings_saved) { notify_settings_saved = 0; - } else { + savingSettings = OSD_SAVE_MESSAGE_NONE; + } else if (savingSettings == OSD_SAVE_MESSAGE_SAVED) { displayWrite(osdDisplayPort, statNameX, top++, OSD_MESSAGE_STR(OSD_MSG_SETTINGS_SAVED)); } } @@ -5265,12 +5283,15 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter /* Messages that are shown regardless of Arming state */ - if (savingSettings == true) { + if (savingSettings == OSD_SAVE_MESSAGE_SAVING) { messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_SAVING_SETTNGS); + } else if (savingSettings == OSD_SAVE_MESSAGE_WAITING) { + messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_WAITING_TO_SAVE); } else if (notify_settings_saved > 0) { if (millis() > notify_settings_saved) { notify_settings_saved = 0; - } else { + savingSettings = OSD_SAVE_MESSAGE_NONE; + } else if (savingSettings == OSD_SAVE_MESSAGE_SAVED) { messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_SETTINGS_SAVED); } } diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 5bcf6d34740..5f444ad4543 100644 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -119,6 +119,7 @@ #define OSD_MSG_UNABLE_ARM "UNABLE TO ARM" #define OSD_MSG_SAVING_SETTNGS "** SAVING SETTINGS **" #define OSD_MSG_SETTINGS_SAVED "** SETTINGS SAVED **" +#define OSD_MSG_WAITING_TO_SAVE "** WAITING TO SAVE **" #define OSD_MSG_ANGLEHOLD_ROLL "(ANGLEHOLD ROLL)" #define OSD_MSG_ANGLEHOLD_PITCH "(ANGLEHOLD PITCH)" #define OSD_MSG_ANGLEHOLD_LEVEL "(ANGLEHOLD LEVEL)" @@ -486,6 +487,8 @@ int32_t osdGetAltitude(void); bool osdUsingScaledThrottle(void); +void osdSaveProcessAborted(void); +void osdSaveWaitingProcess(void); void osdStartedSaveProcess(void); void osdShowEEPROMSavedNotification(void);