Add optional file to most recent settings check

This commit is contained in:
Theo Arends 2021-01-12 17:18:56 +01:00
parent 9c5e6acdc1
commit 37ee4e6d8e

View File

@ -566,39 +566,48 @@ void SettingsSave(uint8_t rotate)
void SettingsLoad(void) { void SettingsLoad(void) {
#ifdef ESP8266 #ifdef ESP8266
#ifdef USE_UFILESYS // Load configuration from optional file and flash (eeprom and 7 additonal slots) if first valid load does not stop_flash_rotate
if (TfsLoadFile(TASM_FILE_SETTINGS, (uint8_t*)&Settings, sizeof(Settings))) {
settings_location = 1;
AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded from File, " D_COUNT " %lu"), Settings.save_flag);
} else {
#endif
// Load configuration from eeprom or one of 7 slots below if first valid load does not stop_flash_rotate
// Activated with version 8.4.0.2 - Fails to read any config before version 6.6.0.11 // Activated with version 8.4.0.2 - Fails to read any config before version 6.6.0.11
settings_location = 0; settings_location = 0;
uint32_t save_flag = 0; uint32_t save_flag = 0;
uint32_t flash_location = FLASH_EEPROM_START; uint32_t max_slots = CFG_ROTATES +1;
for (uint32_t i = 0; i <= CFG_ROTATES; i++) { // Read all config pages in search of valid and latest uint32_t flash_location;
if (1 == i) { flash_location = SETTINGS_LOCATION; } uint32_t slot = 1;
#ifdef USE_UFILESYS
if (TfsLoadFile(TASM_FILE_SETTINGS, (uint8_t*)&Settings, sizeof(Settings))) {
flash_location = 1;
slot = 0;
}
#endif
while (slot <= max_slots) { // Read all config pages in search of valid and latest
if (slot > 0) {
flash_location = (1 == slot) ? FLASH_EEPROM_START : (2 == slot) ? SETTINGS_LOCATION : flash_location -1;
ESP.flashRead(flash_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings)); ESP.flashRead(flash_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings));
}
if ((Settings.cfg_crc32 != 0xFFFFFFFF) && (Settings.cfg_crc32 != 0x00000000) && (Settings.cfg_crc32 == GetSettingsCrc32())) { if ((Settings.cfg_crc32 != 0xFFFFFFFF) && (Settings.cfg_crc32 != 0x00000000) && (Settings.cfg_crc32 == GetSettingsCrc32())) {
if (Settings.save_flag > save_flag) { // Find latest page based on incrementing save_flag if (Settings.save_flag > save_flag) { // Find latest page based on incrementing save_flag
save_flag = Settings.save_flag; save_flag = Settings.save_flag;
settings_location = flash_location; settings_location = flash_location;
if (Settings.flag.stop_flash_rotate && (0 == i)) { // Stop if only eeprom area should be used and it is valid if (Settings.flag.stop_flash_rotate && (1 == slot)) { // Stop if only eeprom area should be used and it is valid
break; break;
} }
} }
} }
flash_location--; slot++;
delay(1); delay(1);
} }
if (settings_location > 0) { if (settings_location > 0) {
#ifdef USE_UFILESYS
if (1 == settings_location) {
TfsLoadFile(TASM_FILE_SETTINGS, (uint8_t*)&Settings, sizeof(Settings));
AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded from File, " D_COUNT " %lu"), Settings.save_flag);
} else
#endif
{
ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings)); ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings));
AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %lu"), settings_location, Settings.save_flag); AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %lu"), settings_location, Settings.save_flag);
} }
#ifdef USE_UFILESYS
} }
#endif
#endif // ESP8266 #endif // ESP8266
#ifdef ESP32 #ifdef ESP32
uint32_t source = SettingsRead(&Settings, sizeof(Settings)); uint32_t source = SettingsRead(&Settings, sizeof(Settings));