diff --git a/data/index.html b/data/index.html index 23ca0e2..bc2e1ec 100644 --- a/data/index.html +++ b/data/index.html @@ -5,68 +5,166 @@ Sporttafel - - - - - - - - - - - - - - - - - -
- - - -  
- - - - - -
  - -  
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + +  
+ + + + + +
  + +  
\ No newline at end of file diff --git a/src/core/http.cpp b/src/core/http.cpp index 907c62d..9c9983b 100644 --- a/src/core/http.cpp +++ b/src/core/http.cpp @@ -8,6 +8,8 @@ AsyncWebServer server(80); AsyncWebSocket ws("/ws"); +auto websocketStarted = false; + void httpIndex(AsyncWebServerRequest *request) { info(request->url().c_str()); request->send(LittleFS, "/index.html", "text/html"); @@ -90,8 +92,15 @@ void httpSetup() { server.on("/action/cancel", HTTP_GET, httpActionCancel); server.on("/action/confirm", HTTP_GET, httpActionConfirm); server.begin(); + websocketStarted = true; } void httpLoop() { ws.cleanupClients(); } + +void websocketSend(const char *message) { + if (websocketStarted) { + ws.textAll(message); + } +} diff --git a/src/core/http.h b/src/core/http.h index 81f29da..05f75b2 100644 --- a/src/core/http.h +++ b/src/core/http.h @@ -5,4 +5,6 @@ void httpSetup(); void httpLoop(); +void websocketSend(const char *message); + #endif diff --git a/src/core/log.cpp b/src/core/log.cpp index 69b99cd..d77ba06 100644 --- a/src/core/log.cpp +++ b/src/core/log.cpp @@ -59,13 +59,14 @@ void logLoop() { const auto c = static_cast(Serial.read()); switch (c) { case 13: + Serial.print(c); execute(cmd); write = cmd; *write = 0; break; case 8: - Serial.print(c); if (write > cmd) { + Serial.print(c); *write-- = 0; } break; diff --git a/src/display/Display.h b/src/display/Display.h index 28a85bf..3806b08 100644 --- a/src/display/Display.h +++ b/src/display/Display.h @@ -7,6 +7,7 @@ #include "Color.h" #include "font.h" +#include "core/http.h" #define PIXELS_PER_SEGMENT 3 #define SEGMENTS_PER_DIGIT 7 @@ -24,7 +25,7 @@ class Display { // Adafruit_NeoPixel leds; - Color buffer[PIXEL_COUNT] = {}; + Color pixels[PIXEL_COUNT] = {}; Color color = WHITE; @@ -46,12 +47,28 @@ public: } void clear() { - memset(buffer, 0, PIXEL_BYTE_COUNT); + memset(pixels, 0, PIXEL_BYTE_COUNT); } void flush() { // memcpy(leds.getPixels(), buffer, PIXEL_BYTE_COUNT); // leds.show(); + + const auto now = millis(); + static auto last = now; + if (now - last >= 500) { + last = now; + send(); + } + } + + void send() { + char buffer[512]; + char *b = buffer; + for (const auto& pixel: pixels) { + b += snprintf(b, sizeof buffer - (b - buffer), "%02X%02X%02X,", pixel.r, pixel.g, pixel.b); + } + websocketSend(buffer); } int printf(const char *format, ...) { @@ -78,12 +95,18 @@ public: case '\'': case '"': case '`': - case '.': return printDots(pixel, false, false, false, true); - case ',': return printDots(pixel, false, false, true, true); - case ':': return printDots(pixel, false, true, true, false); - case ';': return printDots(pixel, false, true, true, true); - case '|': return printDots(pixel, true, true, true, true); - default: return printCharacter(pixel, character); + case '.': + return printDots(pixel, false, false, false, true); + case ',': + return printDots(pixel, false, false, true, true); + case ':': + return printDots(pixel, false, true, true, false); + case ';': + return printDots(pixel, false, true, true, true); + case '|': + return printDots(pixel, true, true, true, true); + default: + return printCharacter(pixel, character); } } @@ -93,19 +116,19 @@ public: return 0; } if (dot0) { - buffer[pixel] = color; + pixels[pixel] = color; } pixel++; if (dot1) { - buffer[pixel] = color; + pixels[pixel] = color; } pixel++; if (dot2) { - buffer[pixel] = color; + pixels[pixel] = color; } pixel++; if (dot3) { - buffer[pixel] = color; + pixels[pixel] = color; } return pixel; } @@ -115,9 +138,9 @@ public: const auto symbol = getSymbol(character); for (auto s = *symbol; s < *symbol + SYMBOL_SIZE; s++) { if (*s) { - buffer[pixel++] = color; - buffer[pixel++] = color; - buffer[pixel++] = color; + pixels[pixel++] = color; + pixels[pixel++] = color; + pixels[pixel++] = color; } else { pixel += 3; }