Skip to content

Commit

Permalink
Apply Custom Defaults at first bootup
Browse files Browse the repository at this point in the history
  • Loading branch information
pmattila committed Nov 9, 2023
1 parent 69c4cf7 commit e637f72
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
8 changes: 0 additions & 8 deletions src/main/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/main/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 11 additions & 8 deletions src/main/fc/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e637f72

Please sign in to comment.