forked from hjd1964/OnStep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EEProm.ino
73 lines (62 loc) · 1.76 KB
/
EEProm.ino
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// -----------------------------------------------------------------------------------
// EEPROM related functions
// write int numbers into EEPROM at position i (2 bytes)
void EEPROM_writeInt(int i,int j) {
uint8_t *k = (uint8_t*)&j;
EEPROM.update(i+0,*k); k++;
EEPROM.update(i+1,*k);
}
// read int numbers from EEPROM at position i (2 bytes)
int EEPROM_readInt(int i) {
uint16_t j;
uint8_t *k = (uint8_t*)&j;
*k=EEPROM.read(i+0); k++;
*k=EEPROM.read(i+1);
return j;
}
// write 4 byte variable into EEPROM at position i (4 bytes)
void EEPROM_writeQuad(int i,byte *v) {
EEPROM.update(i+0,*v); v++;
EEPROM.update(i+1,*v); v++;
EEPROM.update(i+2,*v); v++;
EEPROM.update(i+3,*v);
}
// read 4 byte variable from EEPROM at position i (4 bytes)
void EEPROM_readQuad(int i,byte *v) {
*v=EEPROM.read(i+0); v++;
*v=EEPROM.read(i+1); v++;
*v=EEPROM.read(i+2); v++;
*v=EEPROM.read(i+3);
}
// write String into EEPROM at position i (16 bytes)
void EEPROM_writeString(int i,char l[]) {
for (int l1=0; l1<16; l1++) {
EEPROM.update(i+l1,*l); l++;
}
}
// read String from EEPROM at position i (16 bytes)
void EEPROM_readString(int i, char l[]) {
for (int l1=0; l1<16; l1++) {
*l=EEPROM.read(i+l1); l++;
}
}
// write 4 byte float into EEPROM at position i (4 bytes)
void EEPROM_writeFloat(int i,float f) {
EEPROM_writeQuad(i,(byte*)&f);
}
// read 4 byte float from EEPROM at position i (4 bytes)
float EEPROM_readFloat(int i) {
float f;
EEPROM_readQuad(i,(byte*)&f);
return f;
}
// write 4 byte long into EEPROM at position i (4 bytes)
void EEPROM_writeLong(int i,long l) {
EEPROM_writeQuad(i,(byte*)&l);
}
// read 4 byte long from EEPROM at position i (4 bytes)
long EEPROM_readLong(int i) {
long l;
EEPROM_readQuad(i,(byte*)&l);
return l;
}