diff --git a/index.h b/index.h index 501c95c..85e7ce3 100644 --- a/index.h +++ b/index.h @@ -16,17 +16,35 @@ const char index_html[] PROGMEM = R"rawliteral( margin: 4px 2px; cursor: pointer; } + textarea { + width: 80%; + height: 200px; + margin-top: 20px; + }

LED Panel Control

- + +
+ +
+ + diff --git a/ledy.ino b/ledy.ino index 94f0109..82f2739 100644 --- a/ledy.ino +++ b/ledy.ino @@ -1,6 +1,7 @@ #include #include #include +#include #include "index.h" // For ESP8266, you would use: @@ -14,7 +15,7 @@ #define PIN 12 #define PANEL_PIXEL_COUNT 16 -#define NUMPIXELS PANEL_PIXEL_COUNT*PANEL_PIXEL_COUNT*3 +#define NUMPIXELS PANEL_PIXEL_COUNT*PANEL_PIXEL_COUNT Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); @@ -25,6 +26,8 @@ struct Pixel uint32_t color; }; +Pixel new_image[PANEL_PIXEL_COUNT][PANEL_PIXEL_COUNT]; + // dont change this Pixel saved_imaged[12][16][16] = { { @@ -93,14 +96,37 @@ Pixel getPixelFromSaved(unsigned char i, int row, int col) return saved_imaged[i][row][col]; } -void drawImageFromArr(int offset_x, int offset_y, unsigned char i) { +Pixel getPixel(int row, int col) +{ + return new_image[row][col]; +} + +void drawImageFromArr(int offset_x, int offset_y) { + for (int row = 0; row < 16; row++) { + for (int col = 0; col < 16; col++) { + Pixel px = getPixel(row, col); + if (px.color == 0) { + continue; + } + + int pixel_x = px.x + offset_x; + int pixel_y = px.y + offset_y; + + if (pixel_x >= 0 && pixel_x < PANEL_PIXEL_COUNT && + pixel_y >= 0 && pixel_y < PANEL_PIXEL_COUNT) { + setPixel(pixel_x, pixel_y, px.color); + } + } + } +} + +void drawImageFromSaved(int offset_x, int offset_y, unsigned char i) { for (int row = 0; row < 16; row++) { for (int col = 0; col < 16; col++) { Pixel px = getPixelFromSaved(i, row, col); if (px.color == 0) { continue; } - int pixel_x = px.x + offset_x; int pixel_y = px.y + offset_y; @@ -117,7 +143,7 @@ void setup() { pixels.begin(); pixels.clear(); pixels.show(); - drawImageFromArr(0, 0, 0); + drawImageFromSaved(0, 0, 0); start_server(); } diff --git a/server.ino b/server.ino index 08fb4b4..aa13007 100644 --- a/server.ino +++ b/server.ino @@ -7,9 +7,36 @@ void handleRoot() { server.send(200, "text/html", index_html); } -void handleShow() { +void handleUpload() { + if (server.hasArg("plain") == false) { + server.send(400, "text/plain", "body not received"); + return; + } + String body = server.arg("plain"); + DynamicJsonDocument doc(8192); + deserializeJson(doc, body); + JsonArray arr = doc.as(); + int row = 0; + for (JsonVariant val : arr) { + int col = 0; + for (JsonVariant val2 : val.as()) { + long color = strtol(val2.as(), NULL, 16); + new_image[row][col] = { (unsigned short)col, (unsigned short)row, (uint32_t)color }; + col++; + } + row++; + } + + pixels.clear(); + drawImageFromArr(0, 0); + pixels.show(); + server.send(200, "text/plain", "OK"); +} + +void handleShowSaved() { + pixels.clear(); + drawImageFromSaved(0, 0, 0); pixels.show(); - drawImageFromArr(0, 0, 0); server.send(200, "text/plain", "OK"); } @@ -23,7 +50,8 @@ void start_server() { Serial.println(WiFi.localIP()); server.on("/", handleRoot); - server.on("/show", handleShow); + server.on("/show-saved", handleShowSaved); + server.on("/upload", HTTP_POST, handleUpload); server.begin(); }