-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom_eeprom.cpp
43 lines (36 loc) · 1003 Bytes
/
custom_eeprom.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Extends the Arduino standard library by read/write functions for all data
* types and defines storage addresses.
*/
#include "custom_eeprom.h"
#define byte uint8_t
// TODO this functions are complicated, because they should support floats,
// long, ... as well. But does not work as expected. See commit 41062e26e70.
/**
* Write an int to EEPROM. Return how many bytes where written.
*
* Stolen from:
* http://playground.arduino.cc/Code/EEPROMWriteAnything
*/
int EEPROM_write(int ee, const int& value)
{
const byte* p = (const byte*)(const void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}
/**
* Write an int from EEPROM. Return how many bytes where read.
*
* Stolen from:
* http://playground.arduino.cc/Code/EEPROMWriteAnything
*/
int EEPROM_read(int ee, int& value)
{
byte* p = (byte*)(void*)&value;
int i;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}