forked from jeecrypt/JeeUI2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.cpp
55 lines (47 loc) · 1.12 KB
/
config.cpp
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
#include "JeeUI2.h"
void jeeui2::save()
{
if(SPIFFS.begin()){
}
File configFile = SPIFFS.open(F("/config.json"), "w");
String cfg_str;
serializeJson(cfg, cfg_str);
deserializeJson(cfg, cfg_str);
configFile.print(cfg_str);
cfg_str = "";
if(dbg)Serial.println(F("Save Config"));
}
void jeeui2::autosave(){
if (!sv) return;
if (sv && astimer + asave < millis()){
save();
sv = false;
if(dbg)Serial.println("AutoSave");
upd();
mqtt_update();
}
}
void jeeui2::update(void (*updateFunction) ())
{
upd = updateFunction;
}
void jeeui2::as(){
sv = true;
astimer = millis();
}
void jeeui2::load()
{
if(SPIFFS.begin()){
}
File pre_configFile = SPIFFS.open(F("/config.json"), "r");
if (pre_configFile.readString() == "")
{
if(dbg)Serial.println(F("Failed to open config file"));
save();
return;
}
File configFile = SPIFFS.open(F("/config.json"), "r");
String cfg_str = configFile.readString();
deserializeJson(cfg, cfg_str);
if(dbg)Serial.println(F("JSON config loaded"));
}