resetConfig function

This commit is contained in:
arovak 2020-05-29 20:47:03 +02:00
parent f61f9330f5
commit 2f4a67c6ae
3 changed files with 26 additions and 23 deletions

View File

@ -374,25 +374,6 @@ void configSetup()
//#endif
}
void configClear()
{
#if defined(STM32F4xx)
// Method 2
Log.verbose(F("CONF: Clearing EEPROM"));
char buffer[1024 + 128];
memset(buffer, 1 ,sizeof(buffer));
if(sizeof(buffer) > 0) {
uint16_t i;
for(i = 0; i < sizeof(buffer); i++) eeprom_buffered_write_byte(i, buffer[i]);
eeprom_buffered_write_byte(i, 0);
eeprom_buffer_flush();
Log.verbose(F("CONF: [SUCCESS] Cleared EEPROM"));
} else {
Log.error(F("CONF: Failed to clear to EEPROM"));
}
#endif
}
void configOutput(const JsonObject & settings)
{
String output((char *)0);
@ -411,4 +392,28 @@ void configOutput(const JsonObject & settings)
if(password.length() > 2) output.replace(password, passmask);
Log.trace(F("CONF: %s"), output.c_str());
}
bool configClear()
{
#if defined(STM32F4xx)
Log.verbose(F("CONF: Clearing EEPROM"));
char buffer[1024 + 128];
memset(buffer, 1 ,sizeof(buffer));
if(sizeof(buffer) > 0) {
uint16_t i;
for(i = 0; i < sizeof(buffer); i++) eeprom_buffered_write_byte(i, buffer[i]);
eeprom_buffered_write_byte(i, 0);
eeprom_buffer_flush();
Log.verbose(F("CONF: [SUCCESS] Cleared EEPROM"));
return true;
} else {
Log.error(F("CONF: Failed to clear to EEPROM"));
return false;
}
#elif HASP_USE_SPIFFS > 0
return SPIFFS.format();
#else
return false;
#endif
}

View File

@ -38,11 +38,11 @@ void configStop(void);
void configSetConfig(JsonObject & settings);
void configGetConfig(JsonDocument & settings);
void configWriteConfig();
void configClear(void);
void configOutput(const JsonObject & settings);
bool configSet(int8_t & value, const JsonVariant & setting, const char * name);
bool configSet(uint8_t & value, const JsonVariant & setting, const char * name);
bool configSet(uint16_t & value, const JsonVariant & setting, const char * name);
bool configClear();
#endif

View File

@ -1547,15 +1547,13 @@ void httpHandleResetConfig()
httpMessage += F("</h1><hr>");
if(resetConfirmed) { // User has confirmed, so reset everything
#if HASP_USE_SPIFFS > 0
bool formatted = SPIFFS.format();
bool formatted = configClear();
if(formatted) {
httpMessage += F("<b>Resetting all saved settings and restarting device into WiFi AP mode</b>");
} else {
httpMessage += F("<b>Failed to format the internal flash partition</b>");
resetConfirmed = false;
}
#endif
} else {
httpMessage +=
F("<h2>Warning</h2><b>This process will reset all settings to the default values. The internal flash "