BMP280 Code cleanup
[openXsensor.git] / openXsensor / EEPROMAnything.h
blob645502b080e1795199ed329e295fdece2431dd53
1 #ifndef EEPROMANYTHING_h
2 #define EEPROMANYTHING_h
4 #include <EEPROM.h>
5 #include <Arduino.h> // for type definitions
7 template <class T> int EEPROM_writeAnything(int ee, const T& value)
9 const byte* p = (const byte*)(const void*)&value;
10 unsigned int i;
11 for (i = 0; i < sizeof(value); i++)
12 EEPROM.write(ee++, *p++);
13 return i;
16 template <class T> int EEPROM_readAnything(int ee, T& value)
18 byte* p = (byte*)(void*)&value;
19 unsigned int i;
20 for (i = 0; i < sizeof(value); i++)
21 *p++ = EEPROM.read(ee++);
22 return i;
25 #endif // end EEPROMANYTHING