mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-26 17:55:28 +03:00
Reduce post flight and non-essential saves
This PR reduces the number of non-essential saves processed by the flight controller. Currently, all calls to `saveConfigAndNotify()` are processed immediately. This means that multiple saves can be processed in the same loop. This PR changes that function to set a flag, to process the save in the next loop. Meaning multiple save calls are now consolidated in to a single call. For example, continuous servo trim and stats would both call save. Now, there would be a single save for both features. Saving stats and continuous servo trim have been moved over to `saveConfigAndNotify()`. Also, messages has been added to the OSD. A `** SAVING SETTINGS ** messages appears when the save is requested. Then a `** SETTINGS SAVED **` message takes over for 5 seconds; once the save command has completed. These are shown with both standard `SYSTEM MESSAGES` and on the stats screen.
This commit is contained in:
parent
234454afa5
commit
df8c451c28
8 changed files with 116 additions and 58 deletions
|
@ -142,8 +142,13 @@ PG_RESET_TEMPLATE(adcChannelConfig_t, adcChannelConfig,
|
|||
}
|
||||
);
|
||||
|
||||
void validateNavConfig(void)
|
||||
{
|
||||
#define SAVESTATE_NONE 0
|
||||
#define SAVESTATE_SAVEONLY 1
|
||||
#define SAVESTATE_SAVEANDNOTIFY 2
|
||||
|
||||
static uint8_t saveState = SAVESTATE_NONE;
|
||||
|
||||
void validateNavConfig(void) {
|
||||
// Make sure minAlt is not more than maxAlt, maxAlt cannot be set lower than 500.
|
||||
navConfigMutable()->general.land_slowdown_minalt = MIN(navConfig()->general.land_slowdown_minalt, navConfig()->general.land_slowdown_maxalt - 100);
|
||||
}
|
||||
|
@ -160,7 +165,6 @@ __attribute__((weak)) void targetConfiguration(void)
|
|||
__NOP();
|
||||
}
|
||||
|
||||
|
||||
#ifdef SWAP_SERIAL_PORT_0_AND_1_DEFAULTS
|
||||
#define FIRST_PORT_INDEX 1
|
||||
#define SECOND_PORT_INDEX 0
|
||||
|
@ -177,8 +181,7 @@ uint32_t getGyroLooptime(void) {
|
|||
return gyro.targetLooptime;
|
||||
}
|
||||
|
||||
void validateAndFixConfig(void)
|
||||
{
|
||||
void validateAndFixConfig(void) {
|
||||
if (accelerometerConfig()->acc_notch_cutoff >= accelerometerConfig()->acc_notch_hz) {
|
||||
accelerometerConfigMutable()->acc_notch_hz = 0;
|
||||
}
|
||||
|
@ -248,15 +251,13 @@ void validateAndFixConfig(void)
|
|||
}
|
||||
}
|
||||
|
||||
void applyAndSaveBoardAlignmentDelta(int16_t roll, int16_t pitch)
|
||||
{
|
||||
void applyAndSaveBoardAlignmentDelta(int16_t roll, int16_t pitch) {
|
||||
updateBoardAlignment(roll, pitch);
|
||||
saveConfigAndNotify();
|
||||
}
|
||||
|
||||
// Default settings
|
||||
void createDefaultConfig(void)
|
||||
{
|
||||
void createDefaultConfig(void) {
|
||||
// Radio
|
||||
#ifdef RX_CHANNELS_TAER
|
||||
parseRcChannels("TAER1234");
|
||||
|
@ -275,8 +276,7 @@ void createDefaultConfig(void)
|
|||
targetConfiguration();
|
||||
}
|
||||
|
||||
void resetConfigs(void)
|
||||
{
|
||||
void resetConfigs(void) {
|
||||
pgResetAll(MAX_PROFILE_COUNT);
|
||||
pgActivateProfile(0);
|
||||
|
||||
|
@ -288,8 +288,7 @@ void resetConfigs(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void activateConfig(void)
|
||||
{
|
||||
static void activateConfig(void) {
|
||||
activateControlRateConfig();
|
||||
activateBatteryProfile();
|
||||
|
||||
|
@ -309,8 +308,7 @@ static void activateConfig(void)
|
|||
navigationUsePIDs();
|
||||
}
|
||||
|
||||
void readEEPROM(void)
|
||||
{
|
||||
void readEEPROM(void) {
|
||||
suspendRxSignal();
|
||||
|
||||
// Sanity check, read flash
|
||||
|
@ -327,43 +325,56 @@ void readEEPROM(void)
|
|||
resumeRxSignal();
|
||||
}
|
||||
|
||||
void writeEEPROM(void)
|
||||
{
|
||||
void processSaveConfigAndNotify(void) {
|
||||
writeEEPROM();
|
||||
readEEPROM();
|
||||
beeperConfirmationBeeps(1);
|
||||
osdShowEEPROMSavedNotification();
|
||||
}
|
||||
|
||||
void writeEEPROM(void) {
|
||||
suspendRxSignal();
|
||||
|
||||
writeConfigToEEPROM();
|
||||
|
||||
resumeRxSignal();
|
||||
}
|
||||
|
||||
void resetEEPROM(void)
|
||||
{
|
||||
void resetEEPROM(void) {
|
||||
resetConfigs();
|
||||
writeEEPROM();
|
||||
}
|
||||
|
||||
void ensureEEPROMContainsValidData(void)
|
||||
{
|
||||
void ensureEEPROMContainsValidData(void) {
|
||||
if (isEEPROMContentValid()) {
|
||||
return;
|
||||
}
|
||||
resetEEPROM();
|
||||
}
|
||||
|
||||
void saveConfigAndNotify(void)
|
||||
{
|
||||
writeEEPROM();
|
||||
readEEPROM();
|
||||
beeperConfirmationBeeps(1);
|
||||
void saveConfigAndNotify(void) {
|
||||
osdStartedSaveProcess();
|
||||
saveState = SAVESTATE_SAVEANDNOTIFY;
|
||||
}
|
||||
|
||||
uint8_t getConfigProfile(void)
|
||||
{
|
||||
void processDelayedSave(timeUs_t currentTimeUs) {
|
||||
UNUSED(currentTimeUs);
|
||||
|
||||
switch (saveState) {
|
||||
case SAVESTATE_SAVEANDNOTIFY:
|
||||
processSaveConfigAndNotify();
|
||||
saveState = SAVESTATE_NONE;
|
||||
break;
|
||||
case SAVESTATE_SAVEONLY:
|
||||
writeEEPROM();
|
||||
saveState = SAVESTATE_NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getConfigProfile(void) {
|
||||
return systemConfig()->current_profile_index;
|
||||
}
|
||||
|
||||
bool setConfigProfile(uint8_t profileIndex)
|
||||
{
|
||||
bool setConfigProfile(uint8_t profileIndex) {
|
||||
bool ret = true; // return true if current_profile_index has changed
|
||||
if (systemConfig()->current_profile_index == profileIndex) {
|
||||
ret = false;
|
||||
|
@ -378,8 +389,7 @@ bool setConfigProfile(uint8_t profileIndex)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void setConfigProfileAndWriteEEPROM(uint8_t profileIndex)
|
||||
{
|
||||
void setConfigProfileAndWriteEEPROM(uint8_t profileIndex) {
|
||||
if (setConfigProfile(profileIndex)) {
|
||||
// profile has changed, so ensure current values saved before new profile is loaded
|
||||
writeEEPROM();
|
||||
|
@ -388,13 +398,11 @@ void setConfigProfileAndWriteEEPROM(uint8_t profileIndex)
|
|||
beeperConfirmationBeeps(profileIndex + 1);
|
||||
}
|
||||
|
||||
uint8_t getConfigBatteryProfile(void)
|
||||
{
|
||||
uint8_t getConfigBatteryProfile(void) {
|
||||
return systemConfig()->current_battery_profile_index;
|
||||
}
|
||||
|
||||
bool setConfigBatteryProfile(uint8_t profileIndex)
|
||||
{
|
||||
bool setConfigBatteryProfile(uint8_t profileIndex) {
|
||||
bool ret = true; // return true if current_battery_profile_index has changed
|
||||
if (systemConfig()->current_battery_profile_index == profileIndex) {
|
||||
ret = false;
|
||||
|
@ -407,8 +415,7 @@ bool setConfigBatteryProfile(uint8_t profileIndex)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void setConfigBatteryProfileAndWriteEEPROM(uint8_t profileIndex)
|
||||
{
|
||||
void setConfigBatteryProfileAndWriteEEPROM(uint8_t profileIndex) {
|
||||
if (setConfigBatteryProfile(profileIndex)) {
|
||||
// profile has changed, so ensure current values saved before new profile is loaded
|
||||
writeEEPROM();
|
||||
|
@ -427,42 +434,34 @@ void setGravityCalibrationAndWriteEEPROM(float getGravity) {
|
|||
gyroConfigMutable()->gravity_cmss_cal = getGravity;
|
||||
}
|
||||
|
||||
void beeperOffSet(uint32_t mask)
|
||||
{
|
||||
void beeperOffSet(uint32_t mask) {
|
||||
beeperConfigMutable()->beeper_off_flags |= mask;
|
||||
}
|
||||
|
||||
void beeperOffSetAll(uint8_t beeperCount)
|
||||
{
|
||||
void beeperOffSetAll(uint8_t beeperCount) {
|
||||
beeperConfigMutable()->beeper_off_flags = (1 << beeperCount) -1;
|
||||
}
|
||||
|
||||
void beeperOffClear(uint32_t mask)
|
||||
{
|
||||
void beeperOffClear(uint32_t mask) {
|
||||
beeperConfigMutable()->beeper_off_flags &= ~(mask);
|
||||
}
|
||||
|
||||
void beeperOffClearAll(void)
|
||||
{
|
||||
void beeperOffClearAll(void) {
|
||||
beeperConfigMutable()->beeper_off_flags = 0;
|
||||
}
|
||||
|
||||
uint32_t getBeeperOffMask(void)
|
||||
{
|
||||
uint32_t getBeeperOffMask(void) {
|
||||
return beeperConfig()->beeper_off_flags;
|
||||
}
|
||||
|
||||
void setBeeperOffMask(uint32_t mask)
|
||||
{
|
||||
void setBeeperOffMask(uint32_t mask) {
|
||||
beeperConfigMutable()->beeper_off_flags = mask;
|
||||
}
|
||||
|
||||
uint32_t getPreferredBeeperOffMask(void)
|
||||
{
|
||||
uint32_t getPreferredBeeperOffMask(void) {
|
||||
return beeperConfig()->preferred_beeper_off_flags;
|
||||
}
|
||||
|
||||
void setPreferredBeeperOffMask(uint32_t mask)
|
||||
{
|
||||
void setPreferredBeeperOffMask(uint32_t mask) {
|
||||
beeperConfigMutable()->preferred_beeper_off_flags = mask;
|
||||
}
|
||||
|
|
|
@ -122,6 +122,7 @@ void resetEEPROM(void);
|
|||
void readEEPROM(void);
|
||||
void writeEEPROM(void);
|
||||
void ensureEEPROMContainsValidData(void);
|
||||
void processDelayedSave(timeUs_t currentTimeUs);
|
||||
|
||||
void saveConfigAndNotify(void);
|
||||
void validateAndFixConfig(void);
|
||||
|
|
|
@ -319,6 +319,8 @@ void fcTasksInit(void)
|
|||
{
|
||||
schedulerInit();
|
||||
|
||||
setTaskEnabled(TASK_SAVE_SETTINGS, true);
|
||||
|
||||
rescheduleTask(TASK_PID, getLooptime());
|
||||
setTaskEnabled(TASK_PID, true);
|
||||
|
||||
|
@ -410,6 +412,12 @@ cfTask_t cfTasks[TASK_COUNT] = {
|
|||
.desiredPeriod = TASK_PERIOD_HZ(10), // run every 100 ms, 10Hz
|
||||
.staticPriority = TASK_PRIORITY_HIGH,
|
||||
},
|
||||
[TASK_SAVE_SETTINGS] = {
|
||||
.taskName = "SAVE",
|
||||
.taskFunc = processDelayedSave,
|
||||
.desiredPeriod = TASK_PERIOD_HZ(10),
|
||||
.staticPriority = TASK_PRIORITY_HIGH,
|
||||
},
|
||||
[TASK_PID] = {
|
||||
.taskName = "PID",
|
||||
.taskFunc = taskMainPidLoop,
|
||||
|
|
|
@ -64,7 +64,7 @@ void statsOnDisarm(void)
|
|||
flyingEnergy += energy;
|
||||
}
|
||||
#endif
|
||||
writeEEPROM();
|
||||
saveConfigAndNotify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -556,7 +556,7 @@ void processContinuousServoAutotrim(const float dT)
|
|||
}
|
||||
} else if (trimState == AUTOTRIM_COLLECTING) {
|
||||
// We have disarmed, save midpoints to EEPROM
|
||||
writeEEPROM();
|
||||
saveConfigAndNotify();
|
||||
trimState = AUTOTRIM_IDLE;
|
||||
}
|
||||
|
||||
|
|
|
@ -148,6 +148,9 @@ FILE_COMPILE_FOR_SPEED
|
|||
|
||||
#define OSD_MIN_FONT_VERSION 3
|
||||
|
||||
static timeMs_t notify_settings_saved = 0;
|
||||
static bool savingSettings = false;
|
||||
|
||||
static unsigned currentLayout = 0;
|
||||
static int layoutOverride = -1;
|
||||
static bool hasExtendedFont = false; // Wether the font supports characters > 256
|
||||
|
@ -200,6 +203,15 @@ static bool osdDisplayHasCanvas;
|
|||
PG_REGISTER_WITH_RESET_TEMPLATE(osdConfig_t, osdConfig, PG_OSD_CONFIG, 7);
|
||||
PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t, osdLayoutsConfig, PG_OSD_LAYOUTS_CONFIG, 1);
|
||||
|
||||
void osdStartedSaveProcess() {
|
||||
savingSettings = true;
|
||||
}
|
||||
|
||||
void osdShowEEPROMSavedNotification() {
|
||||
savingSettings = false;
|
||||
notify_settings_saved = millis() + 5000;
|
||||
}
|
||||
|
||||
static int digitCount(int32_t value)
|
||||
{
|
||||
int digits = 1;
|
||||
|
@ -3902,6 +3914,17 @@ static void osdShowStatsPage1(void)
|
|||
|
||||
displayWrite(osdDisplayPort, statNameX, top, "DISARMED BY :");
|
||||
displayWrite(osdDisplayPort, statValuesX, top++, disarmReasonStr[getDisarmReason()]);
|
||||
|
||||
if (savingSettings == true) {
|
||||
displayWrite(osdDisplayPort, statNameX, top++, OSD_MESSAGE_STR(OSD_MSG_SAVING_SETTNGS));
|
||||
} else if (notify_settings_saved > 0) {
|
||||
if (millis() > notify_settings_saved) {
|
||||
notify_settings_saved = 0;
|
||||
} else {
|
||||
displayWrite(osdDisplayPort, statNameX, top++, OSD_MESSAGE_STR(OSD_MSG_SETTINGS_SAVED));
|
||||
}
|
||||
}
|
||||
|
||||
displayCommitTransaction(osdDisplayPort);
|
||||
}
|
||||
|
||||
|
@ -4043,6 +4066,17 @@ static void osdShowStatsPage2(void)
|
|||
displayWrite(osdDisplayPort, statValuesX - 1, top, buff);
|
||||
osdFormatCentiNumber(buff, acc_extremes[Z].max * 100, 0, 2, 0, 3);
|
||||
displayWrite(osdDisplayPort, statValuesX + 4, top++, buff);
|
||||
|
||||
if (savingSettings == true) {
|
||||
displayWrite(osdDisplayPort, statNameX, top++, OSD_MESSAGE_STR(OSD_MSG_SAVING_SETTNGS));
|
||||
} else if (notify_settings_saved > 0) {
|
||||
if (millis() > notify_settings_saved) {
|
||||
notify_settings_saved = 0;
|
||||
} else {
|
||||
displayWrite(osdDisplayPort, statNameX, top++, OSD_MESSAGE_STR(OSD_MSG_SETTINGS_SAVED));
|
||||
}
|
||||
}
|
||||
|
||||
displayCommitTransaction(osdDisplayPort);
|
||||
}
|
||||
|
||||
|
@ -4528,6 +4562,16 @@ textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenter
|
|||
}
|
||||
|
||||
/* Messages that are shown regardless of Arming state */
|
||||
if (savingSettings == true) {
|
||||
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_SAVING_SETTNGS);
|
||||
} else if (notify_settings_saved > 0) {
|
||||
if (millis() > notify_settings_saved) {
|
||||
notify_settings_saved = 0;
|
||||
} else {
|
||||
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_SETTINGS_SAVED);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_DEV_TOOLS
|
||||
if (systemConfig()->groundTestMode) {
|
||||
messages[messageCount++] = OSD_MESSAGE_STR(OSD_MSG_GRD_TEST_MODE);
|
||||
|
|
|
@ -115,6 +115,8 @@
|
|||
#define OSD_MSG_HEADFREE "(HEADFREE)"
|
||||
#define OSD_MSG_NAV_SOARING "(SOARING)"
|
||||
#define OSD_MSG_UNABLE_ARM "UNABLE TO ARM"
|
||||
#define OSD_MSG_SAVING_SETTNGS "** SAVING SETTINGS **"
|
||||
#define OSD_MSG_SETTINGS_SAVED "** SETTINGS SAVED **"
|
||||
|
||||
#ifdef USE_DEV_TOOLS
|
||||
#define OSD_MSG_GRD_TEST_MODE "GRD TEST > MOTORS DISABLED"
|
||||
|
@ -464,6 +466,9 @@ displayCanvas_t *osdGetDisplayPortCanvas(void);
|
|||
int16_t osdGetHeading(void);
|
||||
int32_t osdGetAltitude(void);
|
||||
|
||||
void osdStartedSaveProcess(void);
|
||||
void osdShowEEPROMSavedNotification(void);
|
||||
|
||||
void osdCrosshairPosition(uint8_t *x, uint8_t *y);
|
||||
bool osdFormatCentiNumber(char *buff, int32_t centivalue, uint32_t scale, int maxDecimals, int maxScaledDecimals, int length);
|
||||
void osdFormatAltitudeSymbol(char *buff, int32_t alt);
|
||||
|
|
|
@ -122,6 +122,7 @@ typedef enum {
|
|||
#ifdef USE_SECONDARY_IMU
|
||||
TASK_SECONDARY_IMU,
|
||||
#endif
|
||||
TASK_SAVE_SETTINGS,
|
||||
/* Count of real tasks */
|
||||
TASK_COUNT,
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue