Skip to content

Commit

Permalink
Update DoEEP.cpp
Browse files Browse the repository at this point in the history
Now this library should work for both AVR and ESP boards!
  • Loading branch information
Init-io authored Feb 4, 2025
1 parent 39408a6 commit a706737
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/DoEEP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@

DoEEP::DoEEP(size_t size) {
_size = size;
EEPROM.begin(_size); // Initialize EEPROM
#ifdef ESP_PLATFORM
EEPROM.begin(_size); // Initialize EEPROM for ESP
#else
// No initialization needed for AVR
#endif
}

// Flash (clear) the EEPROM
void DoEEP::flash() {
for (int i = 0; i < _size; i++) {
EEPROM.write(i, 0xFF); // Write default erased value
}
EEPROM.commit(); // Save changes
#ifdef ESP_PLATFORM
EEPROM.commit(); // Save changes for ESP
#endif
}

// Write a key-value pair to EEPROM
Expand All @@ -33,7 +39,9 @@ void DoEEP::write(String key, String value) {
writeToAddress(valueAddr, value);
}

EEPROM.commit();
#ifdef ESP_PLATFORM
EEPROM.commit(); // Save changes for ESP
#endif
}

// Read a value by its key
Expand Down

0 comments on commit a706737

Please sign in to comment.