Skip to content
Snippets Groups Projects
Commit acca5d0e authored by Mitchell Pomery's avatar Mitchell Pomery
Browse files

Set LED array via web browser

parent 4df6d9f2
Branches
Tags
No related merge requests found
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#define PREFIX "" // Document root for our pages #define PREFIX "" // Document root for our pages
#define PORT 80 // Web Server Port #define PORT 80 // Web Server Port
#define NAMELEN 8 // Max variable length in request #define NAMELEN 8 // Max variable length in request
#define VALUELEN 256 // Max value from request #define VALUELEN 255 // Max value from request
#define WIDTH 7 // How many LEDs wide our array is #define WIDTH 7 // How many LEDs wide our array is
#define HEIGHT 6 // How many LEDs high our array is #define HEIGHT 6 // How many LEDs high our array is
#define STRIPLENGTH 42 // Number of LED's in light strip #define STRIPLENGTH 42 // Number of LED's in light strip
...@@ -156,7 +156,7 @@ int coordToPos(int xpos, int ypos) { ...@@ -156,7 +156,7 @@ int coordToPos(int xpos, int ypos) {
*/ */
void setLED(int pos, int red, int green, int blue) { void setLED(int pos, int red, int green, int blue) {
if (pos > 0 && pos < STRIPLENGTH) { if (pos > 0 && pos < STRIPLENGTH) {
strip.setPixelColor(i, (int) red, (int) green, (int) blue); strip.setPixelColor(pos, (int) red, (int) green, (int) blue);
} }
} }
...@@ -274,6 +274,51 @@ char *url_tail, bool tail_complete) { ...@@ -274,6 +274,51 @@ char *url_tail, bool tail_complete) {
} }
} }
void webSetArray(WebServer &server, WebServer::ConnectionType type,
char *url_tail, bool tail_complete) {
URLPARAM_RESULT rc;
char name[NAMELEN];
char value[VALUELEN];
server.httpSuccess();
// Kill the connection before doing anything if all they want is head
if (type == WebServer::HEAD) {
return;
}
else if (type == WebServer::GET) {
///TODO: Get rid of these magic numbers
//if (strlen(url_tail) >= 252) {
for (int i = 0; i < WIDTH; i++) {
for (int j = 0; j < HEIGHT; j++) {
char red[3];
char green[3];
char blue[3];
red[2] = '\0';
green[2] = '\0';
blue[2] = '\0';
int start = HEIGHT * i + j;
Serial.print(start);
Serial.print(" ");
red[0] = url_tail[6 * start];
red[1] = url_tail[(6 * start) + 1];
green[0] = url_tail[(6 * start) + 2];
green[1] = url_tail[(6 * start) + 3];
blue[0] = url_tail[(6 * start) + 4];
blue[1] = url_tail[(6 * start) + 5];
Serial.print(red);
Serial.print(green);
Serial.print(blue);
Serial.println("");
setLED(i, j, hexToChar(red), hexToChar(green), hexToChar(blue));
}
}
//}
}
else {
server.print("Unknown Request");
}
}
/** /**
* Set the brightness to a specific magnitude * Set the brightness to a specific magnitude
* @param server * @param server
...@@ -451,10 +496,11 @@ void setup() { ...@@ -451,10 +496,11 @@ void setup() {
//webserver.addCommand("individual", &webSetLED); //webserver.addCommand("individual", &webSetLED);
webserver.addCommand("brightness", &webSetBrightness); webserver.addCommand("brightness", &webSetBrightness);
webserver.addCommand("get", &webGetArray); webserver.addCommand("get", &webGetArray);
webserver.addCommand("set", &webSetArray);
// Start Webserver // Start Webserver
webserver.begin(); webserver.begin();
for (int i = -128; i < 128; i++) { /*for (int i = -128; i < 128; i++) {
Serial.print(i); Serial.print(i);
Serial.print(" "); Serial.print(" ");
Serial.print((char) i); Serial.print((char) i);
...@@ -465,7 +511,7 @@ void setup() { ...@@ -465,7 +511,7 @@ void setup() {
Serial.print(" "); Serial.print(" ");
Serial.print(d); Serial.print(d);
Serial.println(""); Serial.println("");
} }*/
// Start Lights // Start Lights
strip.begin(); strip.begin();
...@@ -476,8 +522,8 @@ void setup() { ...@@ -476,8 +522,8 @@ void setup() {
void loop() void loop()
{ {
// process incoming connections one at a time forever // process incoming connections one at a time forever
char buff[64]; char buff[256];
int len = 64; int len = 256;
webserver.processConnection(buff, &len); webserver.processConnection(buff, &len);
if (lightOption > NUMSEQUENCES) { if (lightOption > NUMSEQUENCES) {
//lightOption = 1; //lightOption = 1;
...@@ -509,7 +555,9 @@ void loop() ...@@ -509,7 +555,9 @@ void loop()
lightOption = 11; lightOption = 11;
break; break;
} }
updateLights();
// Show our lights // Show our lights
if (position == 0 && lightOption > 10) { // if we have completed a sequence, move to the next one if (position == 0 && lightOption > 10) { // if we have completed a sequence, move to the next one
lightOption++; lightOption++;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment