-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ino
79 lines (75 loc) · 1.91 KB
/
config.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
78
79
#define TEMP_MIN 25.0
#define TEMP_MAX 39.0
#define HUM_MIN 20
#define HUM_MAX 80
#define HUM_CAL_MIN -5
#define HUM_CAL_MAX 5
#define TEMP_CAL_MIN -1.0
#define TEMP_CAL_MAX 1.0
void loadConfig() {
byte buttons = module->getButtons();
Serial.println(buttons);
if (buttons & 0b10000000) {
restoreDefaults();
module->setLEDs(0b0101010110101010);
saveConfig();
delay(1000);
//changeDisplay(display_state);
} else {
loadConfigFromEEPROM();
}
}
void loadConfigFromEEPROM() {
config_temp_up = EEPROM.read(0)/10.f+TEMP_MIN;
config_hum = EEPROM.read(1);
config_temp_cal_up = EEPROM.read(2)/10.f;
config_temp_cal_down = EEPROM.read(3)/10.f;
config_hum_calibration = EEPROM.read(4);
spin_1 = EEPROM.read(5);
m1g1 = EEPROM.read(6);
m2g1 = EEPROM.read(7);
cmg1 = EEPROM.read(8);
m1g2 = EEPROM.read(9);
m2g2 = EEPROM.read(10);
cmg2 = EEPROM.read(11);
config_temp_down = EEPROM.read(12)/10.f+TEMP_MIN;
spinner_delay = EEPROM.read(13);
spinner_power = EEPROM.read(14);
spin_2 = EEPROM.read(15);
}
void restoreDefaults() {
config_temp_up = 37.0;
config_temp_down = 37.0;
config_hum = 50;
config_temp_cal_up = 0;
config_temp_cal_down = 0;
config_hum_calibration = 0;
spin_1 = 255;
spin_2 = 255;
m1g1 = 255;
m2g1 = 25;
cmg1 = 5;
m1g2 = 255;
m2g2 = 255;
cmg2 = 255;
spinner_delay = 100;
spinner_power = 255;
}
void saveConfig() {
EEPROM.write(0, (config_temp_up-TEMP_MIN)*10);
EEPROM.write(1, config_hum);
EEPROM.write(2, config_temp_cal_up*10);
EEPROM.write(3, config_temp_cal_down*10);
EEPROM.write(4, config_hum_calibration);
EEPROM.write(5, spin_1);
EEPROM.write(6, m1g1);
EEPROM.write(7, m2g1);
EEPROM.write(8, cmg1);
EEPROM.write(9, m1g2);
EEPROM.write(10, m2g2);
EEPROM.write(11, cmg2);
EEPROM.write(12, (config_temp_down-TEMP_MIN)*10);
EEPROM.write(13, spinner_delay);
EEPROM.write(14, spinner_power);
EEPROM.write(15, spin_2);
}