-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathg_EEPROM.ino
62 lines (58 loc) · 1.59 KB
/
g_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
#define EEPROM_ID_LEN 32
#define IR_REMOTE_LEN 32
#define IDSTRING "MewPro 4 "
void ROM_Read()
{
int base, i, j;
byte *addr;
boolean f = true;
// signature check
char tmp[EEPROM_ID_LEN + 1] = IDSTRING ":" __VERSION_STRING__;
for (i = 0; i < EEPROM_ID_LEN; i++) {
f &= (EEPROM.read(i) == tmp[i]);
}
if (!f) {
DEBUG_println("factory reset");
base = 0;
for (i = 0; i < EEPROM_ID_LEN; i++) {
EEPROM.write(i, tmp[i]);
}
ROM_write();
// factory reset doesn't override IR remote settings
// because these values are garbage initially.
}
base = EEPROM_ID_LEN;
addr = (byte *)IRkey.l;
for (i = 0; i < sizeof(IRkey); i++) {
*(addr + i) = EEPROM.read(i + base);
}
base += IR_REMOTE_LEN;
for (i = 0; i < SETUP_LEN; i++) {
setting.b[i] = EEPROM.read(i + base);
}
for (j = 0; j < MAX_SUBMODE_SIZE; j++) {
base += SETUP_LEN;
for (i = 0; i < SETUP_LEN; i++) {
storage[j].b[i] = EEPROM.read(i + base);
}
}
setting.p.mode = setting.p.setup.default_app_mode;
setting.p.current_submode[MODE_VIDEO] = setting.p.video.default_sub_mode;
setting.p.current_submode[MODE_PHOTO] = setting.p.photo.default_sub_mode;
setting.p.current_submode[MODE_MULTI_SHOT] = setting.p.multi_shot.default_sub_mode;
loadSetupValue();
}
void ROM_write()
{
int i, j;
int base = EEPROM_ID_LEN + IR_REMOTE_LEN;
for (i = 0; i < SETUP_LEN; i++) {
EEPROM.write(i + base, setting.b[i]);
}
for (j = 0; j < MAX_SUBMODE_SIZE; j++) {
base += SETUP_LEN;
for (i = 0; i < SETUP_LEN; i++) {
EEPROM.write(i + base, storage[j].b[i]);
}
}
}