-
Notifications
You must be signed in to change notification settings - Fork 0
/
eprom.cpp
84 lines (81 loc) · 2.07 KB
/
eprom.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
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
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************
EEPROM*/
#include "eprom.h"
EpromEntry* Eprom::Data = NULL;
void Eprom::Add(void*content, byte len) {
EpromEntry* entry = new EpromEntry();
entry->Content = content;
entry->Length = len;
EpromEntry** mi;
for (mi = &Data; *mi != NULL; mi = &((*mi)->Next));
*mi = entry;
};
void Eprom::Add(int*content) {
Eprom::Add((void*)content, sizeof(int));
};
void Eprom::Add(byte*content) {
Eprom::Add((void*)content, sizeof(byte));
};
void Eprom::Add(bool*content) {
Eprom::Add((void*)content, sizeof(bool));
};
void Eprom::Add(float*content){
Eprom::Add((void*)content,sizeof(float));
};
void Eprom::Add(double*content) {
Eprom::Add((void*)content, sizeof(double));
};
void Eprom::Add(long*content) {
Eprom::Add((void*)content, sizeof(long));
};
void Eprom::Add(int*content, byte len) {
Eprom::Add((void*)content, sizeof(int)*len);
};
void Eprom::Add(byte*content, byte len) {
Eprom::Add((void*)content, sizeof(byte)*len);
};
void Eprom::Add(bool*content, byte len) {
Eprom::Add((void*)content, sizeof(bool)*len);
};
void Eprom::Add(float*content, byte len){
Eprom::Add((void*)content,sizeof(float)*len);
};
void Eprom::Add(double*content, byte len) {
Eprom::Add((void*)content, sizeof(double)*len);
};
void Eprom::Add(long*content, byte len) {
Eprom::Add((void*)content, sizeof(long)*len);
};
void Eprom::RestoreDefaults() {
if (EEPROM.read(0) != 0)
EEPROM.write(0, (byte)0);
}
void Eprom::Load() {
int address = 1;
if (EEPROM.read(0) != 67)
return;
for (EpromEntry*entry = Data; entry != NULL; entry = entry->Next)
{
byte* b = (byte*)entry->Content;
for (int i = 0; i < entry->Length; i++)
{
b[i] = EEPROM.read(address);
address++;
}
}
};
void Eprom::Store() {
int address = 1;
if (EEPROM.read(0) != 67)
EEPROM.write(0, (byte)67);
for (EpromEntry*entry = Data; entry != NULL; entry = entry->Next)
{
byte* b = (byte*)entry->Content;
for (int i = 0; i < entry->Length; i++)
{
if (b[i] != EEPROM.read(address))
EEPROM.write(address, b[i]);
address++;
}
}
};