From 2f4a67c6ae01992fe2db542d2ae5eb0b9ca934a5 Mon Sep 17 00:00:00 2001 From: arovak Date: Fri, 29 May 2020 20:47:03 +0200 Subject: [PATCH] resetConfig function --- src/hasp_config.cpp | 43 ++++++++++++++++++++++++------------------- src/hasp_config.h | 2 +- src/hasp_http.cpp | 4 +--- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp index 5b601b34..cf07995e 100644 --- a/src/hasp_config.cpp +++ b/src/hasp_config.cpp @@ -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 } \ No newline at end of file diff --git a/src/hasp_config.h b/src/hasp_config.h index 9ccb9b09..cb447c23 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -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 \ No newline at end of file diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp index 13528a79..b83e05ff 100644 --- a/src/hasp_http.cpp +++ b/src/hasp_http.cpp @@ -1547,15 +1547,13 @@ void httpHandleResetConfig() httpMessage += F("
"); if(resetConfirmed) { // User has confirmed, so reset everything -#if HASP_USE_SPIFFS > 0 - bool formatted = SPIFFS.format(); + bool formatted = configClear(); if(formatted) { httpMessage += F("Resetting all saved settings and restarting device into WiFi AP mode"); } else { httpMessage += F("Failed to format the internal flash partition"); resetConfirmed = false; } -#endif } else { httpMessage += F("

Warning

This process will reset all settings to the default values. The internal flash "