Skip to content

Commit 8ac5d70

Browse files
committed
Add get and put functions to EEPROM
As available in http://www.arduino.cc/en/Reference/EEPROM
1 parent da88852 commit 8ac5d70

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

libraries/EEPROM/EEPROM.h

+21
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ class EEPROMClass
3535
void commit();
3636
void end();
3737

38+
template<typename T> T &get(int address, T &t)
39+
{
40+
if (address < 0 || address >= _size)
41+
return t;
42+
43+
uint8_t *ptr = (uint8_t*) &t;
44+
for(int count = 0; count < sizeof(T); ++count) *ptr++ = _data[address + count];
45+
return t;
46+
}
47+
48+
template<typename T> const T &put(int address, const T &t)
49+
{
50+
if (address < 0 || address >= _size)
51+
return t;
52+
53+
const uint8_t *ptr = (const uint8_t*) &t;
54+
for(int count = 0; count < sizeof(T); ++count) _data[address + count] = *ptr++;
55+
_dirty = true;
56+
return t;
57+
}
58+
3859
protected:
3960
uint8_t* _data;
4061
size_t _size;

0 commit comments

Comments
 (0)