1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-07 16:23:38 +03:00

Merge pull request #80 from boybundit/eeprom-get-put

Add get and put functions to EEPROM
This commit is contained in:
Ivan Grokhotkov 2015-04-19 10:23:06 +08:00
commit 3ef9f9db54

View File

@ -24,6 +24,7 @@
#include <stddef.h>
#include <stdint.h>
#include <string.h>
class EEPROMClass
{
@ -35,6 +36,27 @@ class EEPROMClass
void commit();
void end();
template<typename T> 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<typename T> 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;