-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEeprom.ino
32 lines (27 loc) · 1022 Bytes
/
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
const unsigned maxWrites = 100;
const unsigned initValue = 12341; // take another value for new initialization
void Eeprom::init()
{ setMemPool(0, EEPROMSizeATmega328);
setMaxAllowedWrites(maxWrites);
storedInitValue = getAddress(sizeof(unsigned));
preweld_ms = getAddress(sizeof(unsigned));
pause_ms = getAddress(sizeof(unsigned));
weld_ms = getAddress(sizeof(unsigned));
orientation = getAddress(sizeof(unsigned));
if(!initialized()) write(); // fill an empty EEPROM
}
void Eeprom::read()
{ menuItems[0].upDownVal.value = readInt(preweld_ms);
menuItems[1].upDownVal.value = readInt(pause_ms);
menuItems[2].upDownVal.value = readInt(weld_ms);
}
void Eeprom::write()
{ writeInt(storedInitValue, initValue); // todo with update()?
writeInt(preweld_ms, menuItems[0].upDownVal.value);
writeInt(pause_ms, menuItems[1].upDownVal.value);
writeInt(weld_ms, menuItems[2].upDownVal.value);
writeInt(orientation, 0);
}
bool Eeprom::initialized()
{ return readInt(storedInitValue) == initValue;
}