-
Notifications
You must be signed in to change notification settings - Fork 0
/
k5-eeprom.ino
77 lines (65 loc) · 1.91 KB
/
k5-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
73
74
75
76
77
/***************************************************
* Multi-instrumento
*
* Author: Pavel Milanes Costa
* Email: pavelmc@gmail.com
****************************************************/
// structured data: Main Configuration Parameters
struct mConf {
byte ver = VERSION;
long vfoa;
long vfob;
byte step;
byte mode;
int ppm;
word flashPosition;
byte sspan;
long vfoOffset;
};
// declaring the main configuration variable for mem storage
struct mConf conf;
// check if the EEPROM is initialized
void checkInitEEPROM() {
// read the eeprom config data
byte ver;
EEPROM.get(0, ver);
// check for the initializer and version
if (ver == VERSION) {
// same firmware version, load the values
loadEEPROM();
} else {
// different firmware version, save the default values.
saveEEPROM();
}
}
// initialize the EEPROM mem, also used to store the values in the setup mode
// this procedure has a protection for the EEPROM life using update semantics
// it actually only write a cell if it has changed
void saveEEPROM() {
// load the parameters in the environment
// conf.ver = VERSION; // no need to, this is the default
conf.vfoa = vfoA;
conf.vfob = vfoB;
conf.step = step;
conf.mode = mode;
conf.ppm = ppm;
conf.flashPosition = flashPosition;
conf.sspan = sspan;
conf.vfoOffset = vfoOffset;
// write it
EEPROM.put(0, conf);
}
// load the eprom contents
void loadEEPROM() {
// write it
EEPROM.get(0, conf);
// load the parameters to the environment
vfoA = conf.vfoa;
vfoB = conf.vfob;
step = conf.step;
mode = conf.mode;
ppm = conf.ppm;
flashPosition = conf.flashPosition;
sspan = conf.sspan;
vfoOffset = conf.vfoOffset;
}