-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.cpp
81 lines (69 loc) · 3.02 KB
/
settings.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**The MIT License (MIT)
Copyright (c) 2017 Radim Keseg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "settings.h"
extern settings_t settins;
void CustomSettings::init() {
//http://esp8266.github.io/Arduino/versions/2.0.0/doc/filesystem.html
Serial.print("SPIFFS begin - ");
if(SPIFFS.begin()){
Serial.println("OK");
//SPIFFS.format(); //uncomment if formating needed
delay(100);
}else{
Serial.println("FAILED");
}
}
void CustomSettings::write(){
Serial.println("writing custom setting start");
Serial.println("file: " + CUSTOM_SETTINGS);
//write location to SPIFF
File f = SPIFFS.open(CUSTOM_SETTINGS, "w");
if (f){
f.write((uint8_t*) &settings, sizeof(settings_t));
}else{
Serial.println("open file for writing failed: " + CUSTOM_SETTINGS);
}
f.flush();
f.close();
Serial.println("writing custom setting end");
}
void CustomSettings::read(){
//read setting from SPIFF
Serial.println("reading custom setting start");
File f = SPIFFS.open(CUSTOM_SETTINGS, "r");
if(f){
f.read((uint8_t*) &settings, sizeof(settings_t));
}else{
Serial.println("open file for reading failed: " + CUSTOM_SETTINGS);
}
f.close();
Serial.println("reading custom setting end");
}
void CustomSettings::print(){
Serial.print("UTC TimeOffset: "); Serial.println(settings.UTC_OFFSET);
Serial.print("DST: "); Serial.println(settings.DST);
Serial.print("brightness: "); Serial.println(settings.brightness);
Serial.print("brightness night: "); Serial.println(settings.brightness_night);
Serial.print("color hand hour: "); Serial.println(settings.color_hand_hour);
Serial.print("color hand mins: "); Serial.println(settings.color_hand_mins);
Serial.print("color hand secs: "); Serial.println(settings.color_hand_secs);
Serial.print("color segment hour: "); Serial.println(settings.color_segm_hour);
Serial.print("color dots hour: "); Serial.println(settings.color_dots_hour);
Serial.print("color dots quarter: "); Serial.println(settings.color_dots_qrtr);
}