-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebsiteHelper.ino
119 lines (105 loc) · 2.58 KB
/
WebsiteHelper.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
void createRoutes(AsyncWebServer *server)
{
// Route to load style.css file
server->on("/style.css", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SPIFFS, "/style.css", "text/css");
});
server->on("/main.js", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SPIFFS, "/main.js", "text/javascript");
});
// Route for root / web page
server->on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
int paramsNr = request->params();
for (int i = 0; i < paramsNr; i++)
{
AsyncWebParameter *p = request->getParam(i);
Serial.print("Param name: ");
Serial.println(p->name());
Serial.print("Param value: ");
Serial.println(p->value());
Serial.println("------");
if (p->name() == "brightness")
{
brightness.target = p->value().toInt();
brightness.debounce = millis() + 1420;
}
if (p->name() == "favorite")
{
startSmoothOperator();
int patternMode = p->value().toInt();
patternSettings.pattern[globals.mode] = patternMode;
globals.mode = 0;
}
}
request->send(SPIFFS, "/index.html", String(), false, websiteProcessor);
});
// server->on("/obama_not_bad.jpg", HTTP_GET, [](AsyncWebServerRequest *request) {
// request->send(SPIFFS, "/obama_not_bad.jpg", "image/jpg");
// });
}
void startWebsite(AsyncWebServer *server)
{
createRoutes(server);
dnsServer.start(53, "*", WiFi.softAPIP());
//only when requested from AP
server->addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER);
// Start server
server->begin();
}
String websiteProcessor(const String &var)
{
//Multithread timing issue
delay(5);
if (var == "BRIGHTNESS")
{
if (brightness.target == 0)
{
return "Off";
}
else if (brightness.target == 255)
{
return "Max";
}
else if (brightness.target > 200)
{
return "Bright";
}
else if (brightness.target > 160)
{
return "Half";
}
else if (brightness.target > 120)
{
return "Third";
}
else if (brightness.target > 80)
{
return "Quarter";
}
else if (brightness.target > 40)
{
return "Dim";
}
else if (brightness.target > 0)
{
return "Moody";
}
}
if (var == "IP_ADDRESS")
{
return globals.ipAddress;
}
if (var == "CATEGORY_NAME")
{
return globalStrings.categoryNameOutString;
}
if (var == "FUNCTION_NAME")
{
return globalStrings.functionNameOutString;
}
if (var == "MODE")
{
return website.returnText;
}
return String();
}