Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/cms/cms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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...");

Expand Down
29 changes: 22 additions & 7 deletions src/main/fc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/fc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions src/main/fc/fc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/fc/fc_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 30 additions & 9 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -486,6 +487,8 @@ int32_t osdGetAltitude(void);

bool osdUsingScaledThrottle(void);

void osdSaveProcessAborted(void);
void osdSaveWaitingProcess(void);
void osdStartedSaveProcess(void);
void osdShowEEPROMSavedNotification(void);

Expand Down