forked from Torxgewinde/Desk-Lamp-Alternative-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha90_main.ino
98 lines (83 loc) · 3.62 KB
/
a90_main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*******************************************************************************
# #
# An alternative firmware for Xiaomi Desk Lamp (Yeelight) #
# #
# #
# Copyright (C) 2018 Tom Stöveken #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
# #
********************************************************************************/
#include <Ticker.h>
/******************************************************************************
Description.: prepares everything, sets the light up first and then does the
more time consuming tasks
Input Value.: -
Return Value: -
******************************************************************************/
void setup(void){
state = BOOTUP;
Serial.begin(115200);
Serial.println("XIAOMI Desk Lamp starting up\nCompiled at: " __DATE__ " - " __TIME__);
log_messages.resize(LOG_LENGTH, "-");
Log("XIAOMI Desk Lamp starting up");
Log("Compiled at: " __DATE__ " - " __TIME__);
if( !SPIFFS.begin() ) {
Log("SPIFFS not mounted correctly, retrying...");
delay(1000);
if( !SPIFFS.begin() ) {
Log("mounting failed twice, formatting and then restarting");
SPIFFS.format();
ESP.restart();
} else {
Log("SPIFFS mounted at second try, proceeding as usual");
}
}
// read configuration file
readConfig();
// apply brightness and ratio from config
g_brightness = configuration.brightness;
g_ratio = configuration.ratio;
// apply hostname
wifi_station_set_hostname(configuration.hostname);
setup_LEDs();
setup_wifi();
setup_webserver();
setup_knob();
state = CONSTANTCOLOR;
}
/******************************************************************************
Description.: execute the different subtasks, none may block or not return
Input Value.: -
Return Value: -
******************************************************************************/
void loop(void) {
loop_wifi();
loop_webserver();
loop_LEDs();
loop_knob();
if(state == RESET_CONFIGURATION) {
Log("deleting configuration file /config.json");
SPIFFS.remove("/config.json");
//keep running for ~5 more seconds, then restart
for(int i=0; i<5000; i++) {
loop_wifi();
loop_webserver();
loop_LEDs();
// slow down this loop and yield at once
delay(1);
}
ESP.restart();
}
}