-
Notifications
You must be signed in to change notification settings - Fork 3
/
Config.ino
74 lines (59 loc) · 1.64 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
#include "Config.h"
config_t current_config;
bool config_modified = false;
void config_setup()
{
File file = SPIFFS.open("/config.bin", "r");
if(!file)
{
Serial.println("[E] failed to open file for reading");
}
else
{
file.read((uint8_t *)¤t_config, sizeof(current_config));
file.close();
Serial.println("[i] read status from SPIFFS");
}
if(current_config.magic1 != 0xDEADBEEF || current_config.magic2 != 0x55AA55AA || current_config.version != CONFIG_VERSION)
{
Serial.println("[i] incorrect magics or version, reinit status");
memset((void *)¤t_config, 0x00, sizeof(current_config));
current_config.magic1 = 0xDEADBEEF;
current_config.magic2 = 0x55AA55AA;
current_config.version = CONFIG_VERSION;
/* set default config */
current_config.swap = false;
current_config.kinematics = true;
current_config.invert[0] = false;
current_config.invert[1] = false;
current_config.light_intensity = 32;
config_modified = true;
}
}
bool config_loop()
{
int curTime = millis();
static int nextTimeSave = 0x7FFFFFFF;
if(config_modified)
{
Serial.println("[i] config modified");
nextTimeSave = curTime + 5000;
config_modified = false;
}
if(nextTimeSave <= curTime)
{
File file = SPIFFS.open("/config.bin", "w");
if(!file)
{
Serial.println("[E] failed to open file for writing");
}
else
{
file.write((const uint8_t *)¤t_config, sizeof(current_config));
file.close();
Serial.println("[i] saved config");
}
nextTimeSave = 0x7FFFFFFF;
led_anim_red(led_anim_shortdoubleblink);
}
}