From e637f720607f83abb866242b3ebdc189877d9ee1 Mon Sep 17 00:00:00 2001 From: Petri Mattila Date: Mon, 6 Nov 2023 21:53:04 +0000 Subject: [PATCH] Apply Custom Defaults at first bootup --- src/main/config/config.c | 8 -------- src/main/config/config.h | 1 - src/main/fc/init.c | 19 +++++++++++-------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/main/config/config.c b/src/main/config/config.c index 6817ccb103..e15ebc6ba4 100644 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -785,14 +785,6 @@ bool resetEEPROM(bool useCustomDefaults) return true; } -void ensureEEPROMStructureIsValid(void) -{ - if (isEEPROMStructureValid()) { - return; - } - resetEEPROM(false); -} - void saveConfigAndNotify(void) { // The write to EEPROM will cause a big delay in the current task, so ignore diff --git a/src/main/config/config.h b/src/main/config/config.h index 254e86e169..74198c66a1 100644 --- a/src/main/config/config.h +++ b/src/main/config/config.h @@ -66,7 +66,6 @@ bool readEEPROM(void); void writeEEPROM(void); void writeEEPROMDelayed(int delayUs); void writeUnmodifiedConfigToEEPROM(void); -void ensureEEPROMStructureIsValid(void); void saveConfigAndNotify(void); void validateAndFixGyroConfig(void); diff --git a/src/main/fc/init.c b/src/main/fc/init.c index e3893a0d77..e42e2c12f5 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -43,6 +43,8 @@ #include "config/config_eeprom.h" #include "config/feature.h" +#include "cli/cli.h" + #include "drivers/accgyro/accgyro.h" #include "drivers/adc.h" #include "drivers/bus.h" @@ -376,20 +378,21 @@ void init(void) initEEPROM(); - ensureEEPROMStructureIsValid(); + if (!isEEPROMVersionValid() || !isEEPROMStructureValid() || !readEEPROM()) { + if (hasCustomDefaults()) + resetConfigToCustomDefaults(); + else + resetConfig(); + writeUnmodifiedConfigToEEPROM(); + systemResetHard(); + } - bool readSuccess = readEEPROM(); + systemState |= SYSTEM_STATE_CONFIG_LOADED; #if defined(USE_BOARD_INFO) initBoardInformation(); #endif - if (!readSuccess || !isEEPROMVersionValid() || strncasecmp(systemConfig()->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) { - resetEEPROM(false); - } - - systemState |= SYSTEM_STATE_CONFIG_LOADED; - #ifdef USE_DEBUG_PIN dbgPinInit(); #endif