Merge branch 'main' of https://git.pinkduck.xyz/adam/libGravity into global-state-metadata

This commit is contained in:
2025-07-20 17:04:39 -07:00
6 changed files with 96 additions and 34 deletions

View File

@ -25,8 +25,11 @@ bool StateManager::initialize(AppState& app) {
if (_isDataValid()) {
// Load data from the transient slot.
return loadData(app, MAX_SAVE_SLOTS);
} else {
// EEPROM does not contain save data for this firmware & version.
}
// EEPROM does not contain save data for this firmware & version.
else {
// Erase EEPROM and initialize state. Save default pattern to all save slots.
factoryReset();
// Initialize eeprom and save default patter to all save slots.
_saveMetadata(app);
reset(app);
@ -89,6 +92,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(METADATA_START_ADDR, load_meta);