From 62358a7c6e40a654ce33cc9259a6e6092aeda124 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Mon, 30 Oct 2023 23:50:07 +0100 Subject: [PATCH] Make better use of constants --- data/src/js/script.ts | 1 + src/lib/functions.cpp | 2 +- src/lib/webserver.cpp | 5 +++-- src/screens/custom_text.cpp | 4 ++-- src/screens/custom_text.hpp | 2 +- src/screens/time.hpp | 4 ++-- src/tasks/epd.cpp | 36 +++++++++++++++++++++++++++++------- src/tasks/epd.hpp | 4 ++-- 8 files changed, 41 insertions(+), 17 deletions(-) diff --git a/data/src/js/script.ts b/data/src/js/script.ts index 207b59f..90846a4 100644 --- a/data/src/js/script.ts +++ b/data/src/js/script.ts @@ -35,6 +35,7 @@ fetch('/api/settings', { document.getElementById('bgColor').querySelector('[value="0xF800"]').remove(); } + document.getElementById('customText').setAttribute('maxlength', jsonData.numScreens); document.getElementById('output').classList.add("fg-" + jsonData.fgColor.toString(16)); document.getElementById('output').classList.add("bg-" + jsonData.bgColor.toString(16)); diff --git a/src/lib/functions.cpp b/src/lib/functions.cpp index d5e6a43..f6a5a87 100644 --- a/src/lib/functions.cpp +++ b/src/lib/functions.cpp @@ -363,7 +363,7 @@ void previousScreen() void showNetworkSettings() { - std::array epdContent = {"", "", "", "", "", "", ""}; + std::array epdContent = {"", "", "", "", "", "", ""}; String ipAddr = WiFi.localIP().toString(); String subNet = WiFi.subnetMask().toString(); diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index f1fb48e..b6093dc 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -78,7 +78,7 @@ void onApiStatus(AsyncWebServerRequest *request) root["numScreens"] = NUM_SCREENS; JsonArray data = root.createNestedArray("data"); JsonArray rendered = root.createNestedArray("rendered"); - String epdContent[7]; + String epdContent[NUM_SCREENS]; #ifdef WITH_RGB_LED @@ -166,6 +166,7 @@ void onApiActionUpdate(AsyncWebServerRequest *request) void onApiSettingsGet(AsyncWebServerRequest *request) { StaticJsonDocument<768> root; + root["numScreens"] = NUM_SCREENS; root["fgColor"] = getFgColor(); root["bgColor"] = getBgColor(); root["timerSeconds"] = timerSeconds; @@ -403,7 +404,7 @@ void onApiShowTextAdvanced(AsyncWebServerRequest *request, JsonVariant &json) JsonArray screens = json.as(); - std::array epdContent; + std::array epdContent; int i = 0; for (JsonVariant s : screens) { diff --git a/src/screens/custom_text.cpp b/src/screens/custom_text.cpp index 1a293c3..aa6b992 100644 --- a/src/screens/custom_text.cpp +++ b/src/screens/custom_text.cpp @@ -18,7 +18,7 @@ void CustomTextScreen::setSimpleText(const String& text) customText.insert(customText.begin(), NUM_SCREENS - customText.length(), ' '); - for (uint i = 0; i < 7; i++) + for (uint i = 0; i < NUM_SCREENS; i++) { CustomTextScreen::epdContent[i] = customText[i]; } @@ -30,7 +30,7 @@ void CustomTextScreen::setText(std::array customContent) } -std::array CustomTextScreen::getEpdContent() +std::array CustomTextScreen::getEpdContent() { return CustomTextScreen::epdContent; } \ No newline at end of file diff --git a/src/screens/custom_text.hpp b/src/screens/custom_text.hpp index 43191e3..1c1a7db 100644 --- a/src/screens/custom_text.hpp +++ b/src/screens/custom_text.hpp @@ -16,5 +16,5 @@ class CustomTextScreen { static void showScreen(); static std::array getEpdContent(); static void setSimpleText(const String& text); - static void setText(std::array customContent); + static void setText(std::array customContent); }; \ No newline at end of file diff --git a/src/screens/time.hpp b/src/screens/time.hpp index 6061383..0e47c71 100644 --- a/src/screens/time.hpp +++ b/src/screens/time.hpp @@ -7,13 +7,13 @@ class TimeScreen { protected: - static std::array epdContent; + static std::array epdContent; static TimeScreen* instance_; public: static void init(); static void showScreen(); static void onNewMinute(); static void onActivate(); - static std::array getEpdContent(); + static std::array getEpdContent(); static TimeScreen* getInstance(); }; \ No newline at end of file diff --git a/src/tasks/epd.cpp b/src/tasks/epd.cpp index 1db30b4..9dec467 100644 --- a/src/tasks/epd.cpp +++ b/src/tasks/epd.cpp @@ -1,9 +1,27 @@ #include "epd.hpp" #ifdef IS_S3 -Native_Pin EPD_CS[NUM_SCREENS] = {Native_Pin(2), Native_Pin(4), Native_Pin(6), Native_Pin(10), Native_Pin(33), Native_Pin(21), Native_Pin(17)}; -Native_Pin EPD_BUSY[NUM_SCREENS] = {Native_Pin(3), Native_Pin(5), Native_Pin(7), Native_Pin(9), Native_Pin(37), Native_Pin(18), Native_Pin(16)}; -MCP23X17_Pin EPD_RESET_MPD[NUM_SCREENS] = {MCP23X17_Pin(mcp, 8), MCP23X17_Pin(mcp, 9), MCP23X17_Pin(mcp, 10), MCP23X17_Pin(mcp, 11), MCP23X17_Pin(mcp, 12), MCP23X17_Pin(mcp, 13), MCP23X17_Pin(mcp, 14)}; +Native_Pin EPD_CS[NUM_SCREENS] = { + Native_Pin(2), Native_Pin(4), Native_Pin(6), Native_Pin(10), Native_Pin(33), Native_Pin(21), Native_Pin(17), + #if NUM_SCREENS == 9 + Native_Pin(-1), + Native_Pin(-1), + #endif +}; +Native_Pin EPD_BUSY[NUM_SCREENS] = { + Native_Pin(3), Native_Pin(5), Native_Pin(7), Native_Pin(9), Native_Pin(37), Native_Pin(18), Native_Pin(16), + #if NUM_SCREENS == 9 + Native_Pin(-1), + Native_Pin(-1), + #endif +}; +MCP23X17_Pin EPD_RESET_MPD[NUM_SCREENS] = { + MCP23X17_Pin(mcp, 8), MCP23X17_Pin(mcp, 9), MCP23X17_Pin(mcp, 10), MCP23X17_Pin(mcp, 11), MCP23X17_Pin(mcp, 12), MCP23X17_Pin(mcp, 13), MCP23X17_Pin(mcp, 14), + #if NUM_SCREENS == 9 + MCP23X17_Pin(mcp, 15), + MCP23X17_Pin(mcp, 16) + #endif +}; Native_Pin EPD_DC = Native_Pin(14); @@ -15,6 +33,10 @@ GxEPD2_BW displays[NUM_SCREENS] = { GxEPD2_213_B74(&EPD_CS[4], &EPD_DC, &EPD_RESET_MPD[4], &EPD_BUSY[4]), GxEPD2_213_B74(&EPD_CS[5], &EPD_DC, &EPD_RESET_MPD[5], &EPD_BUSY[5]), GxEPD2_213_B74(&EPD_CS[6], &EPD_DC, &EPD_RESET_MPD[6], &EPD_BUSY[6]), + #if NUM_SCREENS == 9 + GxEPD2_213_B74(&EPD_CS[7], &EPD_DC, &EPD_RESET_MPD[7], &EPD_BUSY[7]), + GxEPD2_213_B74(&EPD_CS[8], &EPD_DC, &EPD_RESET_MPD[8], &EPD_BUSY[8]), + #endif }; const int SEM_WAIT_TIME = 10000; @@ -22,8 +44,8 @@ const int SEM_WAIT_TIME = 10000; uint32_t lastFullRefresh[NUM_SCREENS]; -std::array currentEpdContent; -std::array epdContent; +std::array currentEpdContent; +std::array epdContent; TaskHandle_t tasks[NUM_SCREENS]; SemaphoreHandle_t epdUpdateSemaphore[NUM_SCREENS]; @@ -127,12 +149,12 @@ void taskEpd(void *pvParameters) } } -std::array getCurrentEpdContent() +std::array getCurrentEpdContent() { return currentEpdContent; } -void setEpdContent(std::array newEpdContent) +void setEpdContent(std::array newEpdContent) { epdContent = newEpdContent; } diff --git a/src/tasks/epd.hpp b/src/tasks/epd.hpp index ade05f2..0aa2ec0 100644 --- a/src/tasks/epd.hpp +++ b/src/tasks/epd.hpp @@ -34,9 +34,9 @@ void setupDisplays(); void initDisplays(); void taskEpd(void *pvParameters); -std::array getCurrentEpdContent(); +std::array getCurrentEpdContent(); -void setEpdContent(std::array newEpdContent); +void setEpdContent(std::array newEpdContent); void splitText(const uint dispNum, String top, String bottom, bool partial); void showDigit(const uint dispNum, char chr, bool partial, const GFXfont *font);