-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.hpp
90 lines (70 loc) · 1.82 KB
/
Server.hpp
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
#include <RGBEffects.h>
bool efxON;
AsyncWebServer server(80);
const int redPin = D2;
const int greenPin = D1;
const int bluePin = D0;
uint16_t redVal;
uint16_t greenVal;
uint16_t blueVal;
// RGB EFFECTS
RGBEffects rgbEffects( redPin, greenPin, bluePin );
void handleFormLed(AsyncWebServerRequest *request)
{
String rgb = request->arg("rgb");
efxON = false;
Serial.println(rgb);
uint8_t red = 0;
uint8_t green = 0;
uint8_t blue = 0;
ColorConverter::HexToRgb(rgb, red, green, blue);
redVal = 1020 - (red*4);
greenVal = 1020 - (green*4);
blueVal = 1020 - (blue*4);
Serial.println(red);
Serial.println(green);
Serial.println(blue);
Serial.println(redVal);
Serial.println(greenVal);
Serial.println(blueVal);
analogWrite(redPin, (redVal));
analogWrite(greenPin,(greenVal));
analogWrite(bluePin,(blueVal));
request->redirect("/");
}
void handleFormEffect(AsyncWebServerRequest *request)
{
String efx = request->arg("efx");
if(efx == "fade")
{
Serial.println("1");
efxON = true;
rgbEffects.setEffect(EFFECT_CUBE);
}
if(efx == "rainbow")
{
Serial.println("2");
efxON = true;
rgbEffects.setEffect(EFFECT_RAINBOW);
}
if(efx == "off")
{
Serial.println("3");
efxON = false;
digitalWrite(redPin,HIGH);
digitalWrite(greenPin,HIGH);
digitalWrite(bluePin,HIGH);
}
request->redirect("/");
}
void InitServer()
{
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
server.on("/RGB", HTTP_POST, handleFormLed);
server.on("/EFX", HTTP_POST, handleFormEffect);
server.onNotFound([](AsyncWebServerRequest *request) {
request->send(400, "text/plain", "Not found");
});
server.begin();
Serial.println("HTTP server started");
}