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:
commit
3ef9f9db54
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
class EEPROMClass
|
class EEPROMClass
|
||||||
{
|
{
|
||||||
@ -35,6 +36,27 @@ class EEPROMClass
|
|||||||
void commit();
|
void commit();
|
||||||
void end();
|
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:
|
protected:
|
||||||
uint8_t* _data;
|
uint8_t* _data;
|
||||||
size_t _size;
|
size_t _size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user