Factory Reset #13
@ -26,7 +26,8 @@ bool StateManager::initialize(AppState& app) {
|
|||||||
return loadData(app, MAX_SAVE_SLOTS);
|
return loadData(app, MAX_SAVE_SLOTS);
|
||||||
} else {
|
} else {
|
||||||
// EEPROM does not contain save data for this firmware & version.
|
// 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);
|
reset(app);
|
||||||
_saveMetadata();
|
_saveMetadata();
|
||||||
// MAX_SAVE_SLOTS slot is reserved for transient state.
|
// MAX_SAVE_SLOTS slot is reserved for transient state.
|
||||||
@ -82,6 +83,15 @@ void StateManager::markDirty() {
|
|||||||
_lastChangeTime = millis();
|
_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() {
|
bool StateManager::_isDataValid() {
|
||||||
Metadata load_meta;
|
Metadata load_meta;
|
||||||
EEPROM.get(0, load_meta);
|
EEPROM.get(0, load_meta);
|
||||||
|
|||||||
@ -19,8 +19,8 @@
|
|||||||
struct AppState;
|
struct AppState;
|
||||||
|
|
||||||
// Define the constants for the current firmware.
|
// Define the constants for the current firmware.
|
||||||
const char SKETCH_NAME[] = "Gravity";
|
const char SKETCH_NAME[] = "AltGravity";
|
||||||
const byte SKETCH_VERSION = 7;
|
const byte SKETCH_VERSION = 1;
|
||||||
|
|
||||||
// Number of available save slots.
|
// Number of available save slots.
|
||||||
const byte MAX_SAVE_SLOTS = 10;
|
const byte MAX_SAVE_SLOTS = 10;
|
||||||
@ -52,6 +52,8 @@ class StateManager {
|
|||||||
void update(const AppState& app);
|
void update(const AppState& app);
|
||||||
// Indicate that state has changed and we should save.
|
// Indicate that state has changed and we should save.
|
||||||
void markDirty();
|
void markDirty();
|
||||||
|
// Erase all data stored in the EEPROM.
|
||||||
|
void factoryReset();
|
||||||
|
|
||||||
// This struct holds the data that identifies the firmware version.
|
// This struct holds the data that identifies the firmware version.
|
||||||
struct Metadata {
|
struct Metadata {
|
||||||
|
|||||||
Reference in New Issue
Block a user