2025-07-21 00:00:47 +00:00
parent 385ce85da3
commit 5729eef037
5 changed files with 62 additions and 28 deletions

View File

@ -26,7 +26,8 @@ bool StateManager::initialize(AppState& app) {
return loadData(app, MAX_SAVE_SLOTS);
} else {
// EEPROM does not contain save data for this firmware & version.
// Initialize eeprom and save default patter to all save slots.
// Erase EEPROM and initialize state. Save default pattern to all save slots.
factoryReset();
reset(app);
_saveMetadata();
// MAX_SAVE_SLOTS slot is reserved for transient state.
@ -82,6 +83,15 @@ void StateManager::markDirty() {
_lastChangeTime = millis();
}
// Erases all data in the EEPROM by writing 0 to every address.
void StateManager::factoryReset() {
noInterrupts();
for (unsigned int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
interrupts();
}
bool StateManager::_isDataValid() {
Metadata load_meta;
EEPROM.get(0, load_meta);