mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Add get and put functions to EEPROM
As available in http://www.arduino.cc/en/Reference/EEPROM
This commit is contained in:
parent
da88852693
commit
8ac5d70b70
@ -35,6 +35,27 @@ class EEPROMClass
|
||||
void commit();
|
||||
void end();
|
||||
|
||||
template<typename T> T &get(int address, T &t)
|
||||
{
|
||||
if (address < 0 || address >= _size)
|
||||
return t;
|
||||
|
||||
uint8_t *ptr = (uint8_t*) &t;
|
||||
for(int count = 0; count < sizeof(T); ++count) *ptr++ = _data[address + count];
|
||||
return t;
|
||||
}
|
||||
|
||||
template<typename T> const T &put(int address, const T &t)
|
||||
{
|
||||
if (address < 0 || address >= _size)
|
||||
return t;
|
||||
|
||||
const uint8_t *ptr = (const uint8_t*) &t;
|
||||
for(int count = 0; count < sizeof(T); ++count) _data[address + count] = *ptr++;
|
||||
_dirty = true;
|
||||
return t;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t* _data;
|
||||
size_t _size;
|
||||
|
Loading…
x
Reference in New Issue
Block a user