From be937da6b9f798757e4be2c89ba5d14fc085ba55 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Mon, 30 Oct 2023 22:20:19 +0100 Subject: [PATCH 01/20] Fix connecting to node --- src/lib/pin/mcp23017_pin.cpp | 0 src/lib/pin/mcp23017_pin.hpp | 6 ------ src/lib/pin/native_pin.cpp | 0 src/lib/pin/native_pin.hpp | 6 ------ src/lib/pin/pcf8575_pin.cpp | 0 src/lib/pin/pcf8575_pin.hpp | 6 ------ src/lib/pin/universal_pin.cpp | 5 ----- src/lib/pin/universal_pin.hpp | 12 ------------ src/lib/webserver.cpp | 2 +- src/main.cpp | 2 +- src/screens/halvingcountdown.cpp | 19 ++++++------------- src/screens/time.cpp | 9 +++++---- src/shared.hpp | 2 +- src/tasks/blocknotify.cpp | 20 +++++++++++--------- src/tasks/minute.cpp | 2 +- 15 files changed, 26 insertions(+), 65 deletions(-) delete mode 100644 src/lib/pin/mcp23017_pin.cpp delete mode 100644 src/lib/pin/mcp23017_pin.hpp delete mode 100644 src/lib/pin/native_pin.cpp delete mode 100644 src/lib/pin/native_pin.hpp delete mode 100644 src/lib/pin/pcf8575_pin.cpp delete mode 100644 src/lib/pin/pcf8575_pin.hpp delete mode 100644 src/lib/pin/universal_pin.cpp delete mode 100644 src/lib/pin/universal_pin.hpp diff --git a/src/lib/pin/mcp23017_pin.cpp b/src/lib/pin/mcp23017_pin.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/pin/mcp23017_pin.hpp b/src/lib/pin/mcp23017_pin.hpp deleted file mode 100644 index a9e5c0e..0000000 --- a/src/lib/pin/mcp23017_pin.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "universal_pin.hpp" - -class MCP23017_Pin : public UniversalPin -{ - -}; \ No newline at end of file diff --git a/src/lib/pin/native_pin.cpp b/src/lib/pin/native_pin.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/pin/native_pin.hpp b/src/lib/pin/native_pin.hpp deleted file mode 100644 index 3b2c5f3..0000000 --- a/src/lib/pin/native_pin.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "universal_pin.hpp" - -class Native_Pin : public UniversalPin -{ - -}; \ No newline at end of file diff --git a/src/lib/pin/pcf8575_pin.cpp b/src/lib/pin/pcf8575_pin.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/lib/pin/pcf8575_pin.hpp b/src/lib/pin/pcf8575_pin.hpp deleted file mode 100644 index 9795fae..0000000 --- a/src/lib/pin/pcf8575_pin.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "universal_pin.hpp" - -class PCF8575_Pin : public UniversalPin -{ - -}; \ No newline at end of file diff --git a/src/lib/pin/universal_pin.cpp b/src/lib/pin/universal_pin.cpp deleted file mode 100644 index b64aa72..0000000 --- a/src/lib/pin/universal_pin.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "universal_pin.hpp" - -UniversalPin::UniversalPin(uint pinNumber) { - this->pinNumber = pinNumber; -} \ No newline at end of file diff --git a/src/lib/pin/universal_pin.hpp b/src/lib/pin/universal_pin.hpp deleted file mode 100644 index e673632..0000000 --- a/src/lib/pin/universal_pin.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -class UniversalPin -{ - public: - UniversalPin(uint pinNumber); - virtual void pinMode(uint8_t mode); - virtual uint8_t digitalRead(); - virtual void digitalWrite(uint8_t value); - protected: - uint pinNumber; -}; \ No newline at end of file diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 1a4782d..f1fb48e 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -75,7 +75,7 @@ void onApiStatus(AsyncWebServerRequest *request) StaticJsonDocument<512> root; root["currentScreen"] = String(getCurrentScreen()); root["timerRunning"] = timerRunning; - + root["numScreens"] = NUM_SCREENS; JsonArray data = root.createNestedArray("data"); JsonArray rendered = root.createNestedArray("rendered"); String epdContent[7]; diff --git a/src/main.cpp b/src/main.cpp index b5208a1..3f3228f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,7 @@ #include "tasks/button.hpp" #include "tasks/led_handler.hpp" -//WiFiClient wifiClientInsecure; +WiFiClient wifiClientInsecure; WiFiClientSecure wifiClient; ESP32Time rtc(3600); diff --git a/src/screens/halvingcountdown.cpp b/src/screens/halvingcountdown.cpp index 5d8cf4d..9cb02b1 100644 --- a/src/screens/halvingcountdown.cpp +++ b/src/screens/halvingcountdown.cpp @@ -25,8 +25,7 @@ void HalvingCountdownScreen::init() for (int i = 0; i < NUM_SCREENS; i++) { epdContentP[i] = HalvingCountdownScreen::psramBuffer + i * maxStringLength; - // strcpy(epdContent[i], "x"); - strcpy(epdContentP[i], "x"); + strcpy(epdContentP[i], ""); } initialized = true; setupBlockNotify(); @@ -48,18 +47,12 @@ void HalvingCountdownScreen::showScreen() snprintf(HalvingCountdownScreen::epdContentP[0], maxStringLength, "BIT/COIN"); snprintf(HalvingCountdownScreen::epdContentP[1], maxStringLength, "HALV/ING"); - snprintf(HalvingCountdownScreen::epdContentP[2], maxStringLength, "%d/YRS", years); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-5)], maxStringLength, "%d/YRS", years); - snprintf(HalvingCountdownScreen::epdContentP[3], maxStringLength, "%d/DAYS", days); - snprintf(HalvingCountdownScreen::epdContentP[4], maxStringLength, "%d/HRS", hours); - snprintf(HalvingCountdownScreen::epdContentP[5], maxStringLength, "%d/MINS", mins); - snprintf(HalvingCountdownScreen::epdContentP[6], maxStringLength, "TO/GO"); - - // // strcpy(epdContent[2], sprintf(String(years) + "/YRS").c_str()); - // // snprintf(epdContent[2], sizeof(epdContent[2]), "%d/YRS", years); - // // strcpy(epdContent[3], String(days) + "/DAYS"); - // // strcpy(epdContent[4], String(hours) + "/HRS"); - // // strcpy(epdContent[5], String(mins) + "/MINS"); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-4)], maxStringLength, "%d/DAYS", days); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-3)], maxStringLength, "%d/HRS", hours); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-2)], maxStringLength, "%d/MINS", mins); + snprintf(HalvingCountdownScreen::epdContentP[(NUM_SCREENS-1)], maxStringLength, "TO/GO"); } uint HalvingCountdownScreen::getNextHalvingBlockNr() diff --git a/src/screens/time.cpp b/src/screens/time.cpp index 9968a06..2d8717c 100644 --- a/src/screens/time.cpp +++ b/src/screens/time.cpp @@ -8,12 +8,13 @@ void TimeScreen::init() { } void TimeScreen::showScreen() { - // String(String(rtc.getDay()) + "/" + String(rtc.getMonth() + 1)).toCharArray(TimeScreen::dateString, 5); - // rtc.getTime("%H:%M").toCharArray(TimeScreen::timeString, 5); - std::string timeString = rtc.getTime("%H:%M").c_str(); timeString.insert(timeString.begin(), NUM_SCREENS - timeString.length(), ' '); - TimeScreen::epdContent[0] = String(rtc.getDay()) + "/" + String(rtc.getMonth() + 1); + char dateTmp[6]; + snprintf(dateTmp, 6, "%d/%d", rtc.getDay(), (rtc.getMonth() + 1)); + + TimeScreen::epdContent[0] = dateTmp; + for (uint i = 1; i < NUM_SCREENS; i++) { TimeScreen::epdContent[i] = timeString[i]; diff --git a/src/shared.hpp b/src/shared.hpp index 9fe97ff..e3af487 100644 --- a/src/shared.hpp +++ b/src/shared.hpp @@ -26,7 +26,7 @@ typedef std::function EventCallback; typedef std::function EventCallbackWithNumber; -//extern WiFiClient wifiClientInsecure; +extern WiFiClient wifiClientInsecure; extern WiFiClientSecure wifiClient; extern ESP32Time rtc; diff --git a/src/tasks/blocknotify.cpp b/src/tasks/blocknotify.cpp index b09e603..4614b85 100644 --- a/src/tasks/blocknotify.cpp +++ b/src/tasks/blocknotify.cpp @@ -18,20 +18,23 @@ bool useBitcoind = true; void checkBitcoinBlock(void *pvParameters) { uint blockHeight = preferences.getUInt("blockHeight", currentBlockHeight); - - - useBitcoind = preferences.getBool("useNode", false) && wifiClient.connect(preferences.getString("rpcHost", BITCOIND_HOST).c_str(), preferences.getUInt("rpcPort", BITCOIND_PORT)); + + useBitcoind = preferences.getBool("useNode", false) && wifiClientInsecure.connect(preferences.getString("rpcHost", BITCOIND_HOST).c_str(), preferences.getUInt("rpcPort", BITCOIND_PORT)); if (useBitcoind) Serial.println(F("bitcoind node is reachable, using this for blocks.")); else Serial.println(F("bitcoind node is not reachable, using mempool API instead.")); - IPAddress result; + if (!useBitcoind) + { + IPAddress result; - int err = WiFi.hostByName(preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE).c_str(), result) ; + int err = WiFi.hostByName(preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE).c_str(), result); - if (err != 1) { - flashTemporaryLights(255, 0, 0); + if (err != 1) + { + flashTemporaryLights(255, 0, 0); + } } for (;;) @@ -79,7 +82,6 @@ void checkBitcoinBlock(void *pvParameters) Serial.print(F("Error in HTTP request to mempool API: ")); Serial.print(httpCode); Serial.println(http->errorToString(httpCode)); - } http->end(); @@ -93,7 +95,7 @@ void checkBitcoinBlock(void *pvParameters) currentBlockHeight = blockHeight; preferences.putUInt("blockHeight", currentBlockHeight); } - delete http; + delete http; vTaskDelay(pdMS_TO_TICKS(BLOCKNOTIFY_WAIT_TIME)); // wait 1 minute before checking again } } diff --git a/src/tasks/minute.cpp b/src/tasks/minute.cpp index dc57bde..83fe04e 100644 --- a/src/tasks/minute.cpp +++ b/src/tasks/minute.cpp @@ -35,7 +35,7 @@ void minuteTask(void * parameter) { void setupMinuteEvent() { - xTaskCreate(minuteTask, "MinuteTask", 2048, NULL, 1, &minuteTaskHandle); // Create the FreeRTOS task + xTaskCreate(minuteTask, "MinuteTask", 4096, NULL, 1, &minuteTaskHandle); // Create the FreeRTOS task } void registerNewMinuteCallback(const EventCallback cb) From f18219964e7d9d8bcdd7d7ce41ba1bd9196787e7 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Mon, 30 Oct 2023 22:41:22 +0100 Subject: [PATCH 02/20] Switching to own universal pin library --- platformio.ini | 3 ++- src/tasks/epd.cpp | 43 +++++++++++++++++++++++++++---------------- src/tasks/epd.hpp | 3 ++- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/platformio.ini b/platformio.ini index 67eb5fa..518b64d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -22,7 +22,8 @@ build_flags = !python scripts/git_rev.py lib_deps = bblanchon/ArduinoJson@^6.21.2 fbiego/ESP32Time@^2.0.1 - zinggjm/GxEPD2@^1.5.2 + https://github.com/dsbaars/GxEPD2#universal_pin + https://github.com/dsbaars/universal_pin adafruit/Adafruit MCP23017 Arduino Library@^2.3.0 adafruit/Adafruit NeoPixel@^1.11.0 https://github.com/me-no-dev/ESPAsyncWebServer.git diff --git a/src/tasks/epd.cpp b/src/tasks/epd.cpp index 0cfc422..4df6333 100644 --- a/src/tasks/epd.cpp +++ b/src/tasks/epd.cpp @@ -1,12 +1,23 @@ #include "epd.hpp" #ifdef IS_S3 -const char EPD_CS[NUM_SCREENS] = {2, 4, 6, 10, 33, 21, 17}; -const char EPD_BUSY[NUM_SCREENS] = {3, 5, 7, 9, 37, 18, 16}; -const char EPD_RESET_MPD[NUM_SCREENS] = {8, 9, 10, 11, 12, 13, 14}; -const char EPD_DC = 14; -const char RST_PIN = 15; +// GxEPD2_BW displays[NUM_SCREENS] = { +// GxEPD2_213_B74(&Native_Pin(EPD_CS[0]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[0]), &Native_Pin(EPD_BUSY[0])), +// GxEPD2_213_B74(&Native_Pin(EPD_CS[1]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[1]), &Native_Pin(EPD_BUSY[1])), +// GxEPD2_213_B74(&Native_Pin(EPD_CS[2]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[2]), &Native_Pin(EPD_BUSY[2])), +// GxEPD2_213_B74(&Native_Pin(EPD_CS[3]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[3]), &Native_Pin(EPD_BUSY[3])), +// GxEPD2_213_B74(&Native_Pin(EPD_CS[4]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[4]), &Native_Pin(EPD_BUSY[4])), +// GxEPD2_213_B74(&Native_Pin(EPD_CS[5]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[5]), &Native_Pin(EPD_BUSY[5])), +// GxEPD2_213_B74(&Native_Pin(EPD_CS[6]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[6]), &Native_Pin(EPD_BUSY[6])), +// }; + +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_DC = Native_Pin(14); +//const char RST_PIN = 15; #elif defined(IS_S2) // reversed @@ -42,13 +53,13 @@ const int RST_PIN = 2; #ifdef IS_BW GxEPD2_BW displays[NUM_SCREENS] = { - GxEPD2_213_B74(EPD_CS[0], EPD_DC, /*RST=*/-1, EPD_BUSY[0]), - GxEPD2_213_B74(EPD_CS[1], EPD_DC, /*RST=*/-1, EPD_BUSY[1]), - GxEPD2_213_B74(EPD_CS[2], EPD_DC, /*RST=*/-1, EPD_BUSY[2]), - GxEPD2_213_B74(EPD_CS[3], EPD_DC, /*RST=*/-1, EPD_BUSY[3]), - GxEPD2_213_B74(EPD_CS[4], EPD_DC, /*RST=*/-1, EPD_BUSY[4]), - GxEPD2_213_B74(EPD_CS[5], EPD_DC, /*RST=*/-1, EPD_BUSY[5]), - GxEPD2_213_B74(EPD_CS[6], EPD_DC, /*RST=*/-1, EPD_BUSY[6]), + GxEPD2_213_B74(&EPD_CS[0], &EPD_DC, &EPD_RESET_MPD[0], &EPD_BUSY[0]), + GxEPD2_213_B74(&EPD_CS[1], &EPD_DC, &EPD_RESET_MPD[1], &EPD_BUSY[1]), + GxEPD2_213_B74(&EPD_CS[2], &EPD_DC, &EPD_RESET_MPD[2], &EPD_BUSY[2]), + GxEPD2_213_B74(&EPD_CS[3], &EPD_DC, &EPD_RESET_MPD[3], &EPD_BUSY[3]), + 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]), }; // GxEPD2_BW * displays2 = (GxEPD2_BW *) ps_malloc(7 * sizeof (GxEPD2_BW)); @@ -108,11 +119,11 @@ void resetAllDisplays() void resetSingleDisplay(int i) { #ifndef NO_MCP - mcp.digitalWrite(EPD_RESET_MPD[i], HIGH); + EPD_RESET_MPD[i].digitalWrite(HIGH); delay(20); - mcp.digitalWrite(EPD_RESET_MPD[i], LOW); + EPD_RESET_MPD[i].digitalWrite(LOW); delay(20); - mcp.digitalWrite(EPD_RESET_MPD[i], HIGH); + EPD_RESET_MPD[i].digitalWrite(HIGH); delay(200); #endif } @@ -122,7 +133,7 @@ void initDisplays() for (uint i = 0; i < NUM_SCREENS; i++) { #ifndef NO_MCP - mcp.pinMode(EPD_RESET_MPD[i], OUTPUT); + EPD_RESET_MPD[i].pinMode(OUTPUT); #endif displays[i].init(); #ifndef NO_MCP diff --git a/src/tasks/epd.hpp b/src/tasks/epd.hpp index 46b06cb..f1b4ab9 100644 --- a/src/tasks/epd.hpp +++ b/src/tasks/epd.hpp @@ -15,7 +15,8 @@ #include "screens/countdown.hpp" #include "screens/custom_text.hpp" #include "screens/halvingcountdown.hpp" - +#include +#include #include #include From 3a6be5868d421f8641cd4c7360bde4bc865bcc95 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Mon, 30 Oct 2023 22:52:22 +0100 Subject: [PATCH 03/20] Remove manual reset methods --- src/main.cpp | 1 - src/tasks/epd.cpp | 56 ++++------------------------------------------- src/tasks/epd.hpp | 2 -- 3 files changed, 4 insertions(+), 55 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3f3228f..029006b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,7 +49,6 @@ void setup() setupComponents(); setupPreferences(); #ifndef NO_DISPLAY - resetAllDisplays(); initDisplays(); #endif setupWifi(); diff --git a/src/tasks/epd.cpp b/src/tasks/epd.cpp index 4df6333..e67680a 100644 --- a/src/tasks/epd.cpp +++ b/src/tasks/epd.cpp @@ -14,10 +14,10 @@ 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)}; +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_DC = Native_Pin(14); -//const char RST_PIN = 15; +// const char RST_PIN = 15; #elif defined(IS_S2) // reversed @@ -89,8 +89,7 @@ TaskHandle_t tasks[NUM_SCREENS]; SemaphoreHandle_t epdUpdateSemaphore[NUM_SCREENS]; // -//int *qrcode = (int *) ps_malloc(qrcodegen_BUFFER_LEN_MAX * sizeof(uint8_t)); - +// int *qrcode = (int *) ps_malloc(qrcodegen_BUFFER_LEN_MAX * sizeof(uint8_t)); void setupDisplays() { @@ -98,49 +97,11 @@ void setupDisplays() xTaskCreate(taskEpd, "epd_task", 2048, NULL, 1, NULL); } -void resetAllDisplays() -{ -#ifdef NO_MCP - digitalWrite(RST_PIN, HIGH); - pinMode(RST_PIN, OUTPUT); - delay(20); - digitalWrite(RST_PIN, LOW); - delay(20); - digitalWrite(RST_PIN, HIGH); - delay(200); -#else - for (int i = 0; i < NUM_SCREENS; i++) - { - resetSingleDisplay(i); - } -#endif -} - -void resetSingleDisplay(int i) -{ -#ifndef NO_MCP - EPD_RESET_MPD[i].digitalWrite(HIGH); - delay(20); - EPD_RESET_MPD[i].digitalWrite(LOW); - delay(20); - EPD_RESET_MPD[i].digitalWrite(HIGH); - delay(200); -#endif -} - void initDisplays() { for (uint i = 0; i < NUM_SCREENS; i++) { -#ifndef NO_MCP - EPD_RESET_MPD[i].pinMode(OUTPUT); -#endif displays[i].init(); -#ifndef NO_MCP - resetSingleDisplay(i); -#endif - - // displays[i].epd2.init(SW_SCK, SW_MOSI, 115200, true, 20, false); } for (uint i = 0; i < NUM_SCREENS; i++) @@ -200,9 +161,6 @@ void taskEpd(void *pvParameters) { if (!updatedThisCycle) { -#ifdef NO_MCP - resetAllDisplays(); -#endif updatedThisCycle = true; } @@ -298,8 +256,6 @@ void showDigit(const uint dispNum, char chr, bool partial, const GFXfont *font) void fullRefresh(void *pvParameters) { - resetAllDisplays(); - for (uint i = 0; i < NUM_SCREENS; i++) { lastFullRefresh[i] = NULL; @@ -321,10 +277,7 @@ void updateDisplay(void *pvParameters) if (epdContent[epdIndex].compareTo(currentEpdContent[epdIndex]) != 0) { currentEpdContent[epdIndex] = epdContent[epdIndex]; -#ifndef NO_MCP - displays[epdIndex].init(0, false); - resetSingleDisplay(epdIndex); -#endif + // displays[epdIndex].init(0, false); bool updatePartial = true; @@ -353,4 +306,3 @@ void updateDisplay(void *pvParameters) xSemaphoreGive(epdUpdateSemaphore[epdIndex]); } } - diff --git a/src/tasks/epd.hpp b/src/tasks/epd.hpp index f1b4ab9..ade05f2 100644 --- a/src/tasks/epd.hpp +++ b/src/tasks/epd.hpp @@ -33,8 +33,6 @@ typedef struct { void setupDisplays(); void initDisplays(); void taskEpd(void *pvParameters); -void resetAllDisplays(); -void resetSingleDisplay(int i); std::array getCurrentEpdContent(); From 6fc1dfe70761209ec0fe7a02b4a53848201ca5e0 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Mon, 30 Oct 2023 23:17:37 +0100 Subject: [PATCH 04/20] Remove unsupported PIO configs --- platformio.ini | 64 +++++++-------------------------------------- src/config.h | 2 -- src/main.cpp | 2 -- src/tasks/epd.cpp | 66 +---------------------------------------------- 4 files changed, 10 insertions(+), 124 deletions(-) diff --git a/platformio.ini b/platformio.ini index 518b64d..c027290 100644 --- a/platformio.ini +++ b/platformio.ini @@ -29,24 +29,7 @@ lib_deps = https://github.com/me-no-dev/ESPAsyncWebServer.git https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 -[env:esp32doit-devkit-v1] -board = esp32doit-devkit-v1 -board_build.partitions = partition.csv -build_flags = - -D IS_BW - -D NO_MCP - -D CONFIG_FREERTOS_USE_TRACE_FACILITY - -D ASYNCWEBSERVER_REGEX - -D CONFIG_ASYNC_TCP_PRIORITY=500 - -[env:esp32doit-devkit-v1_3C] -board = esp32doit-devkit-v1 -board_build.partitions = partition.csv -build_flags = - -D IS_3C - -D CONFIG_FREERTOS_USE_TRACE_FACILITY - -[env:esp32wemos-s3-mini_BW] +[esp32wemos-s3-mini_BW_base] platform = espressif32 framework = arduino board = lolin_s3_mini @@ -65,43 +48,14 @@ build_flags = -D HOSTNAME="\"btclock3\"" -mfix-esp32-psram-cache-issue -[env:esp32wemos-s3-mini_3C] -platform = espressif32 -framework = arduino -board = lolin_s3_mini -board_build.partitions = partition.csv +[env:esp32wemos-s3-mini_BW] +extends = esp32wemos-s3-mini_BW_base build_flags = - -D NO_DISPLAY - -D IS_3C - -D IS_S3 - -D CONFIG_FREERTOS_USE_TRACE_FACILITY - -D WITH_RGB_LED - -D NEOPIXEL_COUNT=4 - -D WITH_BUTTONS - -DASYNCWEBSERVER_REGEX - -D HOSTNAME="\"btclock3c\"" - -D CONFIG_ASYNC_TCP_PRIORITY=500 + ${esp32wemos-s3-mini_BW_base.build_flags} + -D NUM_SCREENS=7 -[env:esp32doit-devkit-v1_nodisp] -board = esp32doit-devkit-v1 -board_build.partitions = partition.csv +[env:esp32wemos-s3-mini_BW_9disp] +extends = esp32wemos-s3-mini_BW_base build_flags = - -D NO_DISPLAY - -D CONFIG_FREERTOS_USE_TRACE_FACILITY - -[env:esp32_s3_devkit] -platform = espressif32 -board = esp32-s3-devkitc-1 -board_build.partitions = partition.csv -;upload_protocol = esp-builtin -build_flags = - -D NO_DISPLAY - -D NO_MCP - -D IS_BW - -D WITH_RGB_LED - -D NEOPIXEL_COUNT=1 - -D NEOPIXEL_PIN=38 - -D CONFIG_ASYNC_TCP_PRIORITY=500 - -DASYNCWEBSERVER_REGEX - -D HOSTNAME="\"btclocks3d\"" - + ${esp32wemos-s3-mini_BW_base.build_flags} + -D NUM_SCREENS=9 diff --git a/src/config.h b/src/config.h index 969f86c..e162a17 100644 --- a/src/config.h +++ b/src/config.h @@ -24,6 +24,4 @@ #define USER_AGENT "BTClock/1.0" -#define NUM_SCREENS 7 - #define I2C_DEV_ADDR 0x55 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 029006b..9fea0ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,6 @@ #include #include #include -// #include #include #ifdef CONFIG_BT_ENABLED @@ -18,7 +17,6 @@ #include "screens/blockheight.hpp" #include "screens/ticker.hpp" #include "screens/time.hpp" -//#include "screens/sats_per_dollar.hpp" #include "screens/halvingcountdown.hpp" #include "tasks/ha.hpp" diff --git a/src/tasks/epd.cpp b/src/tasks/epd.cpp index e67680a..1db30b4 100644 --- a/src/tasks/epd.cpp +++ b/src/tasks/epd.cpp @@ -1,56 +1,11 @@ #include "epd.hpp" #ifdef IS_S3 - -// GxEPD2_BW displays[NUM_SCREENS] = { -// GxEPD2_213_B74(&Native_Pin(EPD_CS[0]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[0]), &Native_Pin(EPD_BUSY[0])), -// GxEPD2_213_B74(&Native_Pin(EPD_CS[1]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[1]), &Native_Pin(EPD_BUSY[1])), -// GxEPD2_213_B74(&Native_Pin(EPD_CS[2]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[2]), &Native_Pin(EPD_BUSY[2])), -// GxEPD2_213_B74(&Native_Pin(EPD_CS[3]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[3]), &Native_Pin(EPD_BUSY[3])), -// GxEPD2_213_B74(&Native_Pin(EPD_CS[4]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[4]), &Native_Pin(EPD_BUSY[4])), -// GxEPD2_213_B74(&Native_Pin(EPD_CS[5]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[5]), &Native_Pin(EPD_BUSY[5])), -// GxEPD2_213_B74(&Native_Pin(EPD_CS[6]), &Native_Pin(EPD_DC), &MCP23X17_Pin(mcp, EPD_RESET_MPD[6]), &Native_Pin(EPD_BUSY[6])), -// }; - 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_DC = Native_Pin(14); -// const char RST_PIN = 15; -#elif defined(IS_S2) - -// reversed -const int EPD_CS[7] = {17, 21, 33, 10, 6, 4, 2}; -const int EPD_BUSY[7] = {16, 18, 37, 9, 7, 5, 3}; -const int EPD_RESET_MPD[7] = {14, 13, 12, 11, 10, 9, 8}; - -// const int EPD_CS[7] = {1, 4, 6, 8, 10, 13, 40}; -// const int EPD_BUSY[7] = {3, 5, 7, 9, 11, 12, 39}; -const int EPD_DC = 14; -const int RST_PIN = 15; - -#elif defined(ARDUINO_ESP32S3_DEV) -const int EPD_CS[7] = {40, 39, 9, 10, 3, 8, 18}; -const int EPD_BUSY[7] = {4, 5, 6, 7, 15, 16, 17}; -const int EPD_RESET_MPD[7] = {8, 9, 10, 11, 12, 13, 14}; - -const int EPD_DC = 1; -const int RST_PIN = 2; - -#else -const int EPD_CS[7] = {21, 13, 5, 17, 4, 2, 15}; -const int EPD_BUSY[7] = {36, 39, 34, 35, 32, 33, 25}; - -// const int EPD_CS[7] = {4, 14, 5, 17, 16, 4, 15}; -// const int EPD_BUSY[7] = {5, 27, 34, 35, 32, 33, 25}; -const int EPD_RESET_MPD[7] = {8, 9, 10, 11, 12, 13, 14}; - -const int EPD_DC = 22; -const int RST_PIN = 2; -#endif - -#ifdef IS_BW GxEPD2_BW displays[NUM_SCREENS] = { GxEPD2_213_B74(&EPD_CS[0], &EPD_DC, &EPD_RESET_MPD[0], &EPD_BUSY[0]), @@ -62,23 +17,7 @@ GxEPD2_BW displays[NUM_SCREENS] = { GxEPD2_213_B74(&EPD_CS[6], &EPD_DC, &EPD_RESET_MPD[6], &EPD_BUSY[6]), }; -// GxEPD2_BW * displays2 = (GxEPD2_BW *) ps_malloc(7 * sizeof (GxEPD2_BW)); - const int SEM_WAIT_TIME = 10000; - -#else -GxEPD2_3C displays[7] = { - GxEPD2_213_Z98c(EPD_CS[0], EPD_DC, /*RST=*/-1, EPD_BUSY[0]), - GxEPD2_213_Z98c(EPD_CS[1], EPD_DC, /*RST=*/-1, EPD_BUSY[1]), - GxEPD2_213_Z98c(EPD_CS[2], EPD_DC, /*RST=*/-1, EPD_BUSY[2]), - GxEPD2_213_Z98c(EPD_CS[3], EPD_DC, /*RST=*/-1, EPD_BUSY[3]), - GxEPD2_213_Z98c(EPD_CS[4], EPD_DC, /*RST=*/-1, EPD_BUSY[4]), - GxEPD2_213_Z98c(EPD_CS[5], EPD_DC, /*RST=*/-1, EPD_BUSY[5]), - GxEPD2_213_Z98c(EPD_CS[6], EPD_DC, /*RST=*/-1, EPD_BUSY[6]), -}; - -const int SEM_WAIT_TIME = 30000; - #endif uint32_t lastFullRefresh[NUM_SCREENS]; @@ -87,9 +26,6 @@ std::array currentEpdContent; std::array epdContent; TaskHandle_t tasks[NUM_SCREENS]; SemaphoreHandle_t epdUpdateSemaphore[NUM_SCREENS]; -// - -// int *qrcode = (int *) ps_malloc(qrcodegen_BUFFER_LEN_MAX * sizeof(uint8_t)); void setupDisplays() { @@ -278,7 +214,7 @@ void updateDisplay(void *pvParameters) { currentEpdContent[epdIndex] = epdContent[epdIndex]; - // displays[epdIndex].init(0, false); + displays[epdIndex].init(0, false, 20); // Little longer reset duration because of MCP bool updatePartial = true; // Full Refresh every half hour From 62358a7c6e40a654ce33cc9259a6e6092aeda124 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Mon, 30 Oct 2023 23:50:07 +0100 Subject: [PATCH 05/20] 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); From 7cc524f75fb1fbf0670b7c440231462cba7413c9 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 3 Nov 2023 12:41:54 +0100 Subject: [PATCH 06/20] Modify workflow to only push tags --- .github/workflows/workflow.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f667b8d..83273dd 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,6 +1,9 @@ name: BTClock CI -on: [push] +on: + push: + tags: + - '*' jobs: build: @@ -24,6 +27,9 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.9' + - name: Get current date + id: dateAndTime + run: echo "::set-output name=dateAndTime::$(date +'%Y-%m-%d-%H:%M')" - name: Install PlatformIO Core run: pip install --upgrade platformio @@ -51,6 +57,7 @@ jobs: - name: Upload artifacts uses: actions/upload-artifact@v3 with: + name: path: | .pio/build/esp32wemos-s3-mini_BW/*.bin output/full-firmware.bin @@ -59,8 +66,7 @@ jobs: - name: Create release uses: ncipollo/release-action@v1 with: - tag: main - commit: main + name: release-${{ steps.date.outputs.dateAndTime }} artifacts: "output/full-firmware.bin,output/full-firmware.sha256,.pio/build/esp32wemos-s3-mini_BW/*.bin" allowUpdates: true removeArtifacts: true From 5c165633d1929aed76841367553012961bb2f97e Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 3 Nov 2023 16:03:34 +0100 Subject: [PATCH 07/20] increase vTick for time screen, add lost IP event handler and system status to web interface --- data/src/css/style.scss | 1 + data/src/index.html | 14 ++++++++++++++ data/src/js/script.ts | 19 ++++++++++++++++++- src/lib/functions.cpp | 10 +++++++++- src/lib/functions.hpp | 1 + src/lib/webserver.cpp | 5 +++++ src/tasks/minute.cpp | 2 +- 7 files changed, 49 insertions(+), 3 deletions(-) diff --git a/data/src/css/style.scss b/data/src/css/style.scss index 1de809d..fe56410 100644 --- a/data/src/css/style.scss +++ b/data/src/css/style.scss @@ -20,6 +20,7 @@ $form-range-track-bg: #fff; @import "../node_modules/bootstrap/scss/navbar"; @import "../node_modules/bootstrap/scss/nav"; @import "../node_modules/bootstrap/scss/card"; +@import "../node_modules/bootstrap/scss/progress"; @import "../node_modules/bootstrap/scss/helpers"; @import "../node_modules/bootstrap/scss/utilities/api"; diff --git a/data/src/index.html b/data/src/index.html index 2d8f163..951066f 100644 --- a/data/src/index.html +++ b/data/src/index.html @@ -57,6 +57,20 @@

+
+
+
+
{{ memUsage }}%
+
+
+
Memory usage
+
{{ memFree }} / {{ memTotal }} kB
+
+
+
+
+

Uptime: {{#if uptime.h }}{{ uptime.h }}h {{/if}}{{ uptime.m }}m {{ uptime.s }}s

+
diff --git a/data/src/js/script.ts b/data/src/js/script.ts index 90846a4..e370e02 100644 --- a/data/src/js/script.ts +++ b/data/src/js/script.ts @@ -2,6 +2,23 @@ import './helpers.js'; var screens = ["Block Height", "Moscow Time", "Ticker", "Time", "Halving countdown"]; +toTime = (secs) => { + var hours = Math.floor(secs / (60 * 60)); + + var divisor_for_minutes = secs % (60 * 60); + var minutes = Math.floor(divisor_for_minutes / 60); + + var divisor_for_seconds = divisor_for_minutes % 60; + var seconds = Math.ceil(divisor_for_seconds); + + var obj = { + "h": hours, + "m": minutes, + "s": seconds + }; + return obj; +} + getBcStatus = () => { fetch('/api/status', { method: 'get' @@ -11,7 +28,7 @@ getBcStatus = () => { var source = document.getElementById("entry-template").innerHTML; var template = Handlebars.compile(source); - var context = { timerRunning: jsonData.timerRunning, currentScreen: jsonData.currentScreen, rendered: jsonData.rendered, data: jsonData.data, screens: screens, ledStatus: jsonData.ledStatus ? jsonData.ledStatus.map((t) => (t).toString(16)) : [] }; + var context = { timerRunning: jsonData.timerRunning, memUsage: Math.round(jsonData.espFreeHeap / jsonData.espHeapSize * 100), memFree: (jsonData.espFreeHeap / 1000), memTotal: (jsonData.espHeapSize / 1000), uptime: toTime(jsonData.espUptime), currentScreen: jsonData.currentScreen, rendered: jsonData.rendered, data: jsonData.data, screens: screens, ledStatus: jsonData.ledStatus ? jsonData.ledStatus.map((t) => (t).toString(16)) : [] }; document.getElementById('output').innerHTML = template(context); diff --git a/src/lib/functions.cpp b/src/lib/functions.cpp index f6a5a87..dcaf0e4 100644 --- a/src/lib/functions.cpp +++ b/src/lib/functions.cpp @@ -64,7 +64,7 @@ void setupComponents() // Serial.println(F("Leds should be on")); #ifndef NO_MCP - if (!mcp.begin_I2C()) + if (!mcp.begin_I2C(0x20)) { Serial.println(F("Error MCP23017")); pixels.setPixelColor(0, pixels.Color(255, 0, 0)); @@ -143,6 +143,8 @@ void setupWifi() } #endif + //WiFi.persistent(true); + WiFi.enableLongRange(false); setupSoftAP(); wm.setConfigPortalTimeout(preferences.getUInt("wpTimeout", 600)); @@ -156,6 +158,12 @@ void setupWifi() softAP_password.c_str()); }); bool ac = wm.autoConnect(softAP_SSID.c_str(), softAP_password.c_str()); + WiFi.onEvent(onWifiLostIp, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_LOST_IP); + +} + +void onWifiLostIp(WiFiEvent_t event, WiFiEventInfo_t info) { + ESP.restart(); } void setupPreferences() diff --git a/src/lib/functions.hpp b/src/lib/functions.hpp index 49fcb66..95177b4 100644 --- a/src/lib/functions.hpp +++ b/src/lib/functions.hpp @@ -28,6 +28,7 @@ void setCurrentScreen(uint screen); void handleScreenTasks(uint screen); void showNetworkSettings(); void toggleScreenTimer(); +void onWifiLostIp(WiFiEvent_t event, WiFiEventInfo_t info); void timebasedChangeTask(void *parameter); diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index b6093dc..a9a9d1a 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -76,6 +76,11 @@ void onApiStatus(AsyncWebServerRequest *request) root["currentScreen"] = String(getCurrentScreen()); root["timerRunning"] = timerRunning; root["numScreens"] = NUM_SCREENS; + root["espUptime"] = esp_timer_get_time() / 1000000; + root["espFreeHeap"] = ESP.getFreeHeap(); + root["espHeapSize"] = ESP.getHeapSize(); + root["espFreePsram"] = ESP.getFreePsram(); + root["espPsramSize"] = ESP.getPsramSize(); JsonArray data = root.createNestedArray("data"); JsonArray rendered = root.createNestedArray("rendered"); String epdContent[NUM_SCREENS]; diff --git a/src/tasks/minute.cpp b/src/tasks/minute.cpp index 83fe04e..e62c618 100644 --- a/src/tasks/minute.cpp +++ b/src/tasks/minute.cpp @@ -28,7 +28,7 @@ void minuteTask(void * parameter) { if(rtc.getSecond() != 0) { // Reset the event triggered flag if the second is not 0 eventTriggered = false; } - vTaskDelay(pdMS_TO_TICKS(500)); // Sleep for 500 milliseconds to avoid busy waiting + vTaskDelay(pdMS_TO_TICKS(1000)); // Sleep for 1000 milliseconds to avoid busy waiting #endif } } From 33989c7d02d185c4225b6fecafd8d56c58a8216d Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 3 Nov 2023 16:09:56 +0100 Subject: [PATCH 08/20] Fix workflow --- .github/workflows/workflow.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 83273dd..0f6b4f5 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -57,12 +57,10 @@ jobs: - name: Upload artifacts uses: actions/upload-artifact@v3 with: - name: path: | .pio/build/esp32wemos-s3-mini_BW/*.bin output/full-firmware.bin output/full-firmware.sha256 - - name: Create release uses: ncipollo/release-action@v1 with: From 0db88cd219a03778fa39a492abc613a792353f9f Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 3 Nov 2023 16:17:02 +0100 Subject: [PATCH 09/20] Fix release tagging --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 0f6b4f5..fff9f24 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -64,7 +64,7 @@ jobs: - name: Create release uses: ncipollo/release-action@v1 with: - name: release-${{ steps.date.outputs.dateAndTime }} + name: release-${{ steps.dateAndTime.outputs.dateAndTime }} artifacts: "output/full-firmware.bin,output/full-firmware.sha256,.pio/build/esp32wemos-s3-mini_BW/*.bin" allowUpdates: true removeArtifacts: true From 8c77d5b5d7d75d6e082e330ecc3375466f05dab2 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 3 Nov 2023 16:21:20 +0100 Subject: [PATCH 10/20] Fix deprecated workflow command --- .github/workflows/workflow.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index fff9f24..2a315dd 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -29,7 +29,8 @@ jobs: python-version: '3.9' - name: Get current date id: dateAndTime - run: echo "::set-output name=dateAndTime::$(date +'%Y-%m-%d-%H:%M')" + # run: echo "::set-output name=dateAndTime::$(date +'%Y-%m-%d-%H:%M')" + run: echo "dateAndTime=$(date +'%Y-%m-%d-%H:%M')" >> $GITHUB_OUTPUT - name: Install PlatformIO Core run: pip install --upgrade platformio From 8cc99d243705bba32ba7a57cb90c8851784667e1 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Sat, 4 Nov 2023 13:35:07 +0100 Subject: [PATCH 11/20] Detect freezing screens --- data/src/index.html | 2 +- platformio.ini | 3 ++ src/tasks/epd.cpp | 92 ++++++++++++++++++++++++++++++++++----------- src/tasks/epd.hpp | 3 +- 4 files changed, 77 insertions(+), 23 deletions(-) diff --git a/data/src/index.html b/data/src/index.html index 951066f..a0b4466 100644 --- a/data/src/index.html +++ b/data/src/index.html @@ -227,7 +227,7 @@