non workking vibe coded screen displaying

This commit is contained in:
2026-02-05 08:27:20 +01:00
parent e5f2a567da
commit cddc24e147
6 changed files with 124 additions and 113 deletions
-4
View File
@@ -1,8 +1,4 @@
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include "ledy.ino"
#include "lowLevel.ino"
#include "server.ino"
#endif // FUNCTIONS_H
+1
View File
@@ -26,6 +26,7 @@ const char index_html[] PROGMEM = R"rawliteral(
<body>
<h1>LED Panel Control</h1>
<button class="button" onclick="showSavedPixels()">Show Saved Pixels</button>
<button class="button" onclick="location.href='/upload-page'">Upload Image</button>
<br>
<textarea id="jsonInput" placeholder="Paste your JSON image data here..."></textarea>
<br>
+5 -45
View File
@@ -6,6 +6,8 @@
#include "index.h"
#include "fonts.h"
#include "lowLevel.h"
#include "upload_page.h"
#include "prototypes.h"
#ifdef __AVR__
#include <avr/power.h> // 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();
}
+13 -15
View File
@@ -1,25 +1,23 @@
#ifndef PROTOTYPES_H
#define PROTOTYPES_H
#include <Adafruit_NeoPixel.h>
#include "config.h"
#include "structs.h"
#include <Adafruit_NeoPixel.h>
// 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
+58 -37
View File
@@ -2,6 +2,8 @@
#include <WebServer.h>
#include <ArduinoJson.h>
#include "structs.h"
#include "upload_page.h"
#include "prototypes.h"
const char* ssid = "PPIA";
const char* password = "pawelpdaldonejta";
@@ -9,61 +11,77 @@ 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");
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;
}
String body = server.arg("plain");
DynamicJsonDocument doc(8192);
deserializeJson(doc, body);
JsonArray arr = doc.as<JsonArray>();
int row = 0;
for (JsonVariant val : arr)
{
int col = 0;
for (JsonVariant val2 : val.as<JsonArray>())
{
unsigned long color = strtoul(val2.as<const char*>(), 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;
}
saved_images[0].width = width;
saved_images[0].height = height;
// 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;
// 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];
}
}
saved_images[saved_images_count].width = 16;
saved_images[saved_images_count].height = 16;
pixels.clear();
drawImageFromMemoryByIndex(saved_images_count, 0, 0);
drawImageFromMemoryByIndex(0, 0, 0);
pixels.show();
server.send(200, "text/plain", "OK");
saved_images_count++;
free(fileContent);
fileContent = nullptr;
fileContent_len = 0;
}
}
}
void handleShowSaved()
{
@@ -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();
}
+35
View File
@@ -0,0 +1,35 @@
#ifndef UPLOAD_PAGE_H
#define UPLOAD_PAGE_H
const char upload_page_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<title>Upload Image</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { font-family: Arial; text-align: center; margin:0px auto; padding-top: 30px;}
.button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Upload BMP Image</h1>
<form action="/upload-bmp" method="post" enctype="multipart/form-data">
<input type="file" name="image" accept=".bmp">
<input type="submit" value="Upload" class="button">
</form>
</body>
</html>
)rawliteral";
#endif // UPLOAD_PAGE_H