Option for forced formatting of spiffs and eeprom

This commit is contained in:
Stefan Kremser 2019-05-17 11:38:48 +02:00
parent b80cf4811d
commit e703486543
4 changed files with 31 additions and 2 deletions

View File

@ -1,7 +1,11 @@
#ifndef config_h
#define config_h
/* !!! Uncomment the board taht you're using !!! */
#define DEFAULT_ESP8266
/* ---------------------------------------------------------- */
/* ===>> !!! Uncomment the board taht you're using: !!! <<=== */
/* ---------------------------------------------------------- */
// #define NODEMCU
// #define WEMOS_D1_MINI
@ -34,7 +38,9 @@
// #define LYASI_7W_E27_LAMP
// #define AVATAR_5W_E14_LAMP
#define DEFAULT_ESP8266
// Forces formatting of SPIFFS and EEPROM ot startup
// #define FORMAT_SPIFFS
// #define FORMAT_EEPROM
// Forces a reset of all settings at startup
// #define RESET_SETTINGS

View File

@ -53,6 +53,11 @@ class EEPROMHelper {
static void resetBootNum(const int address) {
saveObject(address, boot{ BOOT_MAGIC_NUM, 1 });
}
static void format(unsigned long size) {
for (unsigned long i = 0; i<size; i++) EEPROM.write(i, 0x00);
EEPROM.commit();
}
};
#endif /* ifndef EEPROMHELPER_H */

View File

@ -72,11 +72,28 @@ void setup() {
// Start EEPROM
EEPROMHelper::begin(EEPROM_SIZE);
#ifdef FORMAT_SPIFFS
prnt(SETUP_FORMAT_SPIFFS);
SPIFFS.format();
prntln(SETUP_OK);
#endif // ifdef FORMAT_SPIFFS
#ifdef FORMAT_EEPROM
prnt(SETUP_FORMAT_EEPROM);
EEPROMHelper::format(EEPROM_SIZE);
prntln(SETUP_OK);
#endif // ifdef FORMAT_EEPROM
// Format SPIFFS when in boot-loop
if (spiffsError || !EEPROMHelper::checkBootNum(BOOT_COUNTER_ADDR)) {
prnt(SETUP_FORMAT_SPIFFS);
SPIFFS.format();
prntln(SETUP_OK);
prnt(SETUP_FORMAT_EEPROM);
EEPROMHelper::format(EEPROM_SIZE);
prntln(SETUP_OK);
EEPROMHelper::resetBootNum(BOOT_COUNTER_ADDR);
}

View File

@ -71,6 +71,7 @@ const char SETUP_OK[] PROGMEM = "OK";
const char SETUP_ERROR[] PROGMEM = "ERROR";
const char SETUP_MOUNT_SPIFFS[] PROGMEM = "Mounting SPIFFS...";
const char SETUP_FORMAT_SPIFFS[] PROGMEM = "Formatting SPIFFS...";
const char SETUP_FORMAT_EEPROM[] PROGMEM = "Formatting EEPROM...";
const char SETUP_SERIAL_WARNING[] PROGMEM = "Warning: Serial deactivated";
const char SETUP_STARTED[] PROGMEM = "STARTED! \\o/";
const char SETUP_COPYING[] PROGMEM = "Copying ";