-
Notifications
You must be signed in to change notification settings - Fork 0
/
neopixel_webapp.cpp
100 lines (88 loc) · 3.44 KB
/
neopixel_webapp.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "neopixel_webapp.hpp"
#include "neopixel.hpp"
extern NeopixelGrid grid;
bool NeopixelWebapp::matches(const char* verb, const char* path){
bool accept = false;
if(strcmp(verb,"GET") == 0) {
accept =
strncmp(path,"/set",4) == 0 ||
strncmp(path,"/cycle",6) == 0 ||
strncmp(path,"/colour",7) == 0 ||
strncmp(path,"/ripples",8) == 0 ||
strncmp(path,"/spokes",7) == 0 ||
strncmp(path,"/horizontal",11) == 0 ||
strncmp(path,"/vertical",9) == 0 ||
strncmp(path,"/sparkle",8) == 0 ||
strncmp(path,"/show",5) == 0 ||
false;
;
if(accept) printf("Neopixel Webapp Accepting path %s\n", path);
}
return accept;
}
void NeopixelWebapp::process( HttpRequest& request, HttpResponse& response){
printf("Neopixel Webapp Processing request for %s\n",request.path());
unsigned int rate = 1;
uint32_t rgb = 0;
int w = 0;
float increment = 0.1f;
float value = 0.0f;
float hue = 0.0f;
float hue2 = -1.0f;
float count = 1.0f;
BlockListIter<Parameter> iter = request.Parameters().iter();
Parameter* p;
while(p = iter.next()){
printf("Parameter %s -> %s\n", p->name(), p->value());
if(strcmp(p->name(), "rate") == 0) rate = (unsigned) p->asInt();
if(strcmp(p->name(), "white") == 0) w = p->asInt();
if(strcmp(p->name(), "rgb") == 0) rgb = p->asRgb();
if(strcmp(p->name(), "inc") == 0) increment = p->asFloat();
if(strcmp(p->name(), "value") == 0) value = p->asFloat();
if(strcmp(p->name(), "hue") == 0) hue = p->asFloat();
if(strcmp(p->name(), "hue2") == 0) hue2 = p->asFloat();
if(strcmp(p->name(), "count") == 0) count = p->asFloat();
}
if(strncmp(request.path(),"/set",4) == 0) {
grid.setAsync(rgb, w);
} else if(strncmp(request.path(),"/cycle",6) == 0) {
grid.rateAsync(rate);
} else if (strncmp(request.path(),"/colour",7) == 0){
grid.colourChangeAsync(value, increment, w);
} else if (strncmp(request.path(),"/ripples",8) == 0) {
grid.rippleAsync(hue, hue2, value, (int) increment, count, w);
} else if (strncmp(request.path(),"/spokes",7) == 0) {
grid.spokesAsync(hue, hue2, value, increment, count, w);
} else if (strncmp(request.path(),"/horizontal",11) == 0) {
grid.horizontalAsync(hue, hue2, value, increment, count, w);
} else if (strncmp(request.path(),"/vertical",9) == 0) {
grid.verticalAsync(hue, hue2, value, increment, count, w);
} else if (strncmp(request.path(),"/sparkle",8) == 0) {
grid.sparkleAsync();
} else if (strncmp(request.path(),"/show",5) == 0) {
printf("Radius\n");
int idx = 0;
for(int iy=0; iy<GRID_HEIGHT; ++iy){
for(int ix=0; ix<GRID_WIDTH;++ix){
float r = grid.coordinate(idx).r;
printf("%f\t", r);
++idx;
}
printf("\n");
}
printf("Theta\n");
idx = 0;
for(int iy=0; iy<GRID_HEIGHT; ++iy){
for(int ix=0; ix<GRID_WIDTH;++ix){
float t = grid.coordinate(idx).theta;
printf("%f\t", t);
++idx;
}
printf("\n");
}
} else {
}
response.setStatus(200,"OK");
response.addHeader("Server", "PicoW");
response.addHeader("Access-Control-Allow-Origin","*");
}