diff --git a/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h b/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h index 0c7068d1cd..52de839091 100644 --- a/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h +++ b/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h @@ -24,6 +24,7 @@ #include #include +#include class EEPROMClass { @@ -35,6 +36,27 @@ class EEPROMClass void commit(); void end(); + template T &get(int address, T &t) + { + if (address < 0 || address + sizeof(T) > _size) + return t; + + uint8_t *ptr = (uint8_t*) &t; + memcpy(ptr, _data + address, sizeof(T)); + return t; + } + + template const T &put(int address, const T &t) + { + if (address < 0 || address + sizeof(T) > _size) + return t; + + const uint8_t *ptr = (const uint8_t*) &t; + memcpy(_data + address, ptr, sizeof(T)); + _dirty = true; + return t; + } + protected: uint8_t* _data; size_t _size;