diff --git a/functions.h b/functions.h
index 57d8a3a..06823ef 100644
--- a/functions.h
+++ b/functions.h
@@ -1,8 +1,4 @@
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
-#include "ledy.ino"
-#include "lowLevel.ino"
-#include "server.ino"
-
#endif // FUNCTIONS_H
\ No newline at end of file
diff --git a/index.h b/index.h
index 85e7ce3..a0cc5e8 100644
--- a/index.h
+++ b/index.h
@@ -26,6 +26,7 @@ const char index_html[] PROGMEM = R"rawliteral(
LED Panel Control
+
diff --git a/ledy.ino b/ledy.ino
index 1f46857..191c0c1 100644
--- a/ledy.ino
+++ b/ledy.ino
@@ -6,6 +6,8 @@
#include "index.h"
#include "fonts.h"
#include "lowLevel.h"
+#include "upload_page.h"
+#include "prototypes.h"
#ifdef __AVR__
#include // Required for 16 MHz Adafruit Trinket
@@ -18,45 +20,7 @@ Cursor cursor;
short ever_created_text_nodes = 0;
Image saved_images[MAX_IMAGES_SAVED] = {
- {
- {
- // Row 0
- {{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,255,0}, {0,255,0}, {0,255,0}, {0,255,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {255,255,0}, {255,255,0}, {255,255,0}, {255,255,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {255,0,255}, {255,0,255}, {255,0,255}, {255,0,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,255,255}, {0,255,255}, {0,255,255}, {0,255,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
- // Row 1
- {{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,255,0}, {0,255,0}, {0,255,0}, {0,255,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {255,255,0}, {255,255,0}, {255,255,0}, {255,255,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {255,0,255}, {255,0,255}, {255,0,255}, {255,0,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,255,255}, {0,255,255}, {0,255,255}, {0,255,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
- // Row 2
- {{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,255,0}, {0,255,0}, {0,255,0}, {0,255,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {255,255,0}, {255,255,0}, {255,255,0}, {255,255,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {255,0,255}, {255,0,255}, {255,0,255}, {255,0,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,255,255}, {0,255,255}, {0,255,255}, {0,255,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
- // Row 3
- {{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,255,0}, {0,255,0}, {0,255,0}, {0,255,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {255,255,0}, {255,255,0}, {255,255,0}, {255,255,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {255,0,255}, {255,0,255}, {255,0,255}, {255,0,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,255,255}, {0,255,255}, {0,255,255}, {0,255,255}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
- // Row 4
- {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
- // Row 5
- {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
- // Row 6
- {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
- // Row 7
- {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
- // Row 8
- {{255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}},
- // Row 9
- {{255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}},
- // Row 10
- {{255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}},
- // Row 11
- {{255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}, {255,255,255}},
- // Row 12
- {{128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}},
- // Row 13
- {{128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}},
- // Row 14
- {{128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}},
- // Row 15
- {{128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}, {128,128,128}}
- },
- 48, // width
- 16 // height
- },
- {}
+ {},{}
};
@@ -74,8 +38,8 @@ short getTextNodeX2(TextNode *node)
void addNewTextNode
(
- char text[TEXT_MAX_LENGTH + 1], uint32_t color = 0x00010101, bool handle_pos_via_cursor = true, short pos_x = 0, short pos_y = 0,
- unsigned char scroll_slowness = 0, bool is_scrolling = true, bool is_small = true
+ char text[TEXT_MAX_LENGTH + 1], uint32_t color, bool handle_pos_via_cursor = true, short pos_x = 0, short pos_y = 0,
+ unsigned char scroll_slowness = 1, bool is_scrolling = true, bool is_small = true
)
{
unsigned char text_length = strlen(text);
@@ -200,10 +164,6 @@ void loop()
{
pixels.clear();
handle_server();
- if (text_nodes[0].is_deleted && text_nodes[2].is_deleted)
- {
-
- }
scrollAllScrollableTexts();
pixels.show();
}
\ No newline at end of file
diff --git a/prototypes.h b/prototypes.h
index 72c7f16..c84cb36 100644
--- a/prototypes.h
+++ b/prototypes.h
@@ -1,25 +1,23 @@
#ifndef PROTOTYPES_H
#define PROTOTYPES_H
-#include
-#include "config.h"
#include "structs.h"
+#include
-// lowLevel.ino
+extern Adafruit_NeoPixel pixels;
+extern Image saved_images[MAX_IMAGES_SAVED];
+extern unsigned char saved_images_count;
+extern TextNode text_nodes[MAX_TEXT_NODES_COUNT];
+extern Cursor cursor;
+
+
+void drawImageFromMemoryByIndex(unsigned char image_index, short pos_x, short pos_y);
void setPixel(short x, short y, uint32_t color);
-uint32_t getPixelColor(short x, short y);
-void drawImageFromSaved(short offset_x, short offset_y, unsigned char i);
-void drawCharacterPart(const bool* character_row, unsigned char width, uint32_t color, short start_x, short start_y);
-void drawCharacter(const bool (*character)[5], unsigned char height, unsigned char width, uint32_t color, Cursor (*used_cursor));
-void fillPixels(short x1, short y1, short x2, short y2, uint32_t color);
-void shiftGivenRectangleLeft(short x1, short y1, short x2, short y2, unsigned char shift_by);
-void shiftGivenRectangleRight(short x1, short y1, short x2, short y2, unsigned char shift_by);
-
-// server.ino
-void handleRoot();
-void handleUpload();
-void handleShowSaved();
void start_server();
void handle_server();
+void addNewTextNode(char text[TEXT_MAX_LENGTH + 1], uint32_t color, bool handle_pos_via_cursor, short pos_x, short pos_y, unsigned char scroll_slowness, bool is_scrolling, bool is_small);
+void scrollAllScrollableTexts(bool split_scroll_mode);
+void drawCharacter(const bool (*character)[5], unsigned char height, unsigned char width, uint32_t color, Cursor (*used_cursor));
-#endif // PROTOTYPES_H
+
+#endif // PROTOTYPES_H
\ No newline at end of file
diff --git a/server.ino b/server.ino
index 32ca7d3..43c3b46 100644
--- a/server.ino
+++ b/server.ino
@@ -2,6 +2,8 @@
#include
#include
#include "structs.h"
+#include "upload_page.h"
+#include "prototypes.h"
const char* ssid = "PPIA";
const char* password = "pawelpdaldonejta";
@@ -9,62 +11,78 @@ const char* password = "pawelpdaldonejta";
WebServer server(80);
Pixel new_image[16][16];
+char* fileContent = nullptr;
+size_t fileContent_len = 0;
+
void handleRoot()
{
server.send(200, "text/html", index_html);
}
-void handleUpload()
+void handleUploadPage()
{
- 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())
- {
- unsigned long color = strtoul(val2.as(), NULL, 16);
- new_image[row][col] = { (unsigned short)col, (unsigned short)row, (uint32_t)color };
- col++;
- }
- row++;
- }
-
- // Save the new image to the next slot
- if (saved_images_count >= MAX_IMAGES_SAVED) {
- saved_images_count = 0;
- }
-
- // Copy new_image data to saved_images array
- for (int r = 0; r < 16; r++)
- {
- for (int c = 0; c < 16; c++)
- {
- uint32_t color = new_image[r][c].color;
- RGB rgb = {(unsigned char)((color >> 16) & 0xFF), (unsigned char)((color >> 8) & 0xFF), (unsigned char)(color & 0xFF)};
- saved_images[saved_images_count].pixels[r][c] = rgb;
- }
- }
- saved_images[saved_images_count].width = 16;
- saved_images[saved_images_count].height = 16;
-
- pixels.clear();
- drawImageFromMemoryByIndex(saved_images_count, 0, 0);
- pixels.show();
- server.send(200, "text/plain", "OK");
-
- saved_images_count++;
+ server.send(200, "text/html", upload_page_html);
}
+
+void handleBmpUpload() {
+ HTTPUpload& upload = server.upload();
+ if (upload.status == UPLOAD_FILE_START) {
+ if (fileContent) {
+ free(fileContent);
+ fileContent = nullptr;
+ fileContent_len = 0;
+ }
+ } else if (upload.status == UPLOAD_FILE_WRITE) {
+ if (upload.name == "image") {
+ fileContent = (char*)realloc(fileContent, fileContent_len + upload.currentSize);
+ memcpy(fileContent + fileContent_len, upload.buf, upload.currentSize);
+ fileContent_len += upload.currentSize;
+ }
+ } else if (upload.status == UPLOAD_FILE_END) {
+ if (upload.name == "image") {
+ // Read BMP header
+ char header[54];
+ memcpy(header, fileContent, 54);
+
+ int width = *(int*)&header[18];
+ int height = *(int*)&header[22];
+
+ if (width < 1 || width > 48 || height < 1 || height > 16) {
+ server.send(400, "text/plain", "Invalid image dimensions");
+ return;
+ }
+
+ saved_images[0].width = width;
+ saved_images[0].height = height;
+
+ // Read pixel data
+ int row_padded = (width*3 + 3) & (~3);
+ char* pixel_data = fileContent + 54;
+
+ for (int y = height - 1; y >= 0; y--) {
+ for (int x = 0; x < width; x++) {
+ saved_images[0].pixels[y][x].b = pixel_data[y*row_padded + x*3 + 0];
+ saved_images[0].pixels[y][x].g = pixel_data[y*row_padded + x*3 + 1];
+ saved_images[0].pixels[y][x].r = pixel_data[y*row_padded + x*3 + 2];
+ }
+ }
+
+ pixels.clear();
+ drawImageFromMemoryByIndex(0, 0, 0);
+ pixels.show();
+ server.send(200, "text/plain", "OK");
+
+ free(fileContent);
+ fileContent = nullptr;
+ fileContent_len = 0;
+ }
+ }
+}
+
+
+
void handleShowSaved()
{
pixels.clear();
@@ -86,7 +104,10 @@ void start_server()
server.on("/", handleRoot);
server.on("/show-saved", handleShowSaved);
- server.on("/upload", HTTP_POST, handleUpload);
+ server.on("/upload-page", HTTP_GET, handleUploadPage);
+ server.on("/upload-bmp", HTTP_POST, []() {
+ server.send(200, "text/plain", "");
+ }, handleBmpUpload);
server.begin();
}
diff --git a/upload_page.h b/upload_page.h
new file mode 100644
index 0000000..29cb2b0
--- /dev/null
+++ b/upload_page.h
@@ -0,0 +1,35 @@
+
+#ifndef UPLOAD_PAGE_H
+#define UPLOAD_PAGE_H
+
+const char upload_page_html[] PROGMEM = R"rawliteral(
+
+
+ Upload Image
+
+
+
+
+ Upload BMP Image
+
+
+
+)rawliteral";
+
+#endif // UPLOAD_PAGE_H