diff --git a/src/config.h b/src/config.h index e162a17..969f86c 100644 --- a/src/config.h +++ b/src/config.h @@ -24,4 +24,6 @@ #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/lib/functions.cpp b/src/lib/functions.cpp index 127cfe6..2940140 100644 --- a/src/lib/functions.cpp +++ b/src/lib/functions.cpp @@ -43,6 +43,14 @@ void setupSoftAP() void setupComponents() { + if (psramInit()) + { + Serial.println("\nPSRAM is correctly initialized"); + } + else + { + Serial.println("PSRAM not available"); + } #ifdef WITH_RGB_LED pixels.begin(); pixels.setPixelColor(0, pixels.Color(255, 0, 0)); @@ -299,7 +307,6 @@ void toggleScreenTimer() } } - void timebasedChangeTask(void *parameter) { uint32_t moment = millis(); @@ -393,7 +400,7 @@ void setLights(int r, int g, int b) void flashTemporaryLights(int r, int g, int b) { - #ifdef WITH_RGB_LED +#ifdef WITH_RGB_LED uint32_t oldLights[NEOPIXEL_COUNT]; @@ -404,7 +411,8 @@ void flashTemporaryLights(int r, int g, int b) } // flash three times in given color - for (int t = 0; t < 3; t++) { + for (int t = 0; t < 3; t++) + { for (int i = 0; i < NEOPIXEL_COUNT; i++) { pixels.setPixelColor(i, pixels.Color(r, g, b)); @@ -425,7 +433,7 @@ void flashTemporaryLights(int r, int g, int b) } pixels.show(); - #endif +#endif } void setupI2C() diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 90c66d7..2b71038 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -36,7 +36,6 @@ void setupWebserver() AsyncCallbackJsonWebHandler *handler = new AsyncCallbackJsonWebHandler("/api/show/custom", onApiShowTextAdvanced); server.addHandler(handler); - server.on("/api/wifi/scan", HTTP_GET, onApiWifiScan); server.on("/api/restart", HTTP_GET, onApiRestart); server.on("/api/countdown", HTTP_GET, onApiCountdown); @@ -76,7 +75,7 @@ void onApiStatus(AsyncWebServerRequest *request) { AsyncResponseStream *response = request->beginResponseStream("application/json"); - DynamicJsonDocument root(1024); + StaticJsonDocument<512> root; root["currentScreen"] = String(getCurrentScreen()); root["timerRunning"] = timerRunning; @@ -169,7 +168,7 @@ void onApiActionUpdate(AsyncWebServerRequest *request) */ void onApiSettingsGet(AsyncWebServerRequest *request) { - DynamicJsonDocument root(1024); + StaticJsonDocument<768> root; root["fgColor"] = getFgColor(); root["bgColor"] = getBgColor(); root["timerSeconds"] = timerSeconds; @@ -208,9 +207,10 @@ void onApiSettingsGet(AsyncWebServerRequest *request) o["enabled"] = preferences.getBool(key.c_str(), true); } - String responseText; - serializeJson(root, responseText); - request->send(200, "application/json", responseText); + AsyncResponseStream *response = request->beginResponseStream("application/json"); + serializeJson(root, *response); + + request->send(response); } bool processEpdColorSettings(AsyncWebServerRequest *request) @@ -440,27 +440,27 @@ void onApiRestart(AsyncWebServerRequest *request) esp_restart(); } -void onApiWifiScan(AsyncWebServerRequest *request) -{ - WiFi.scanNetworks(true); +// void onApiWifiScan(AsyncWebServerRequest *request) +// { +// WiFi.scanNetworks(true); - int n = WiFi.scanComplete(); +// int n = WiFi.scanComplete(); - DynamicJsonDocument doc(1024); +// DynamicJsonDocument doc(1024); - for (int i = 0; i < n; ++i) - { - JsonObject wifi = doc.createNestedObject(WiFi.BSSID(i)); - Serial.println(WiFi.SSID(i)); - wifi["ssid"] = WiFi.SSID(i); - wifi["rssi"] = WiFi.RSSI(i); - wifi["encryptionType"] = WiFi.encryptionType(i); - } +// for (int i = 0; i < n; ++i) +// { +// JsonObject wifi = doc.createNestedObject(WiFi.BSSID(i)); +// Serial.println(WiFi.SSID(i)); +// wifi["ssid"] = WiFi.SSID(i); +// wifi["rssi"] = WiFi.RSSI(i); +// wifi["encryptionType"] = WiFi.encryptionType(i); +// } - String responseText; - serializeJson(doc, responseText); - request->send(200, "application/json", responseText); -} +// String responseText; +// serializeJson(doc, responseText); +// request->send(200, "application/json", responseText); +// } void onApiCountdown(AsyncWebServerRequest *request) { @@ -514,14 +514,14 @@ void onApiSystemStatus(AsyncWebServerRequest *request) { AsyncResponseStream *response = request->beginResponseStream("application/json"); - DynamicJsonDocument root(1024); + StaticJsonDocument<128> root; root["espFreeHeap"] = ESP.getFreeHeap(); root["espHeapSize"] = ESP.getHeapSize(); root["espFreePsram"] = ESP.getFreePsram(); root["espPsramSize"] = ESP.getPsramSize(); - String responseText; - serializeJson(root, responseText); - request->send(200, "application/json", responseText); + serializeJson(root, *response); + + request->send(response); } \ No newline at end of file diff --git a/src/lib/webserver.hpp b/src/lib/webserver.hpp index f654966..9d8fcc7 100644 --- a/src/lib/webserver.hpp +++ b/src/lib/webserver.hpp @@ -26,7 +26,7 @@ void onApiShowTextAdvanced(AsyncWebServerRequest *request, JsonVariant &json); void onApiFullRefresh(AsyncWebServerRequest *request); void onApiCountdown(AsyncWebServerRequest *request); -void onApiWifiScan(AsyncWebServerRequest *request); +//void onApiWifiScan(AsyncWebServerRequest *request); void onApiRestart(AsyncWebServerRequest *request); void onApiLightsOff(AsyncWebServerRequest *request); diff --git a/src/screens/blockheight.cpp b/src/screens/blockheight.cpp index 07f29cb..b2576c6 100644 --- a/src/screens/blockheight.cpp +++ b/src/screens/blockheight.cpp @@ -1,7 +1,10 @@ #include "blockheight.hpp" uint BlockHeightScreen::blockNr = 0; -std::array BlockHeightScreen::epdContent = { "", "", "", "", "", "", "" }; +std::array BlockHeightScreen::epdContent = { "", "", "", "", "", "", "" }; + +//std::array * BlockHeightScreen::epdContent = (std::array * ) ps_malloc(7 * sizeof (std::array)); + void BlockHeightScreen::init() { @@ -13,9 +16,9 @@ void BlockHeightScreen::init() void BlockHeightScreen::showScreen() { std::string blockNrString = String(BlockHeightScreen::blockNr).c_str(); - blockNrString.insert(blockNrString.begin(), 7 - blockNrString.length(), ' '); + blockNrString.insert(blockNrString.begin(), NUM_SCREENS - blockNrString.length(), ' '); epdContent[0] = "BLOCK/HEIGHT"; - for (uint i = 1; i < 7; i++) + for (uint i = 1; i < NUM_SCREENS; i++) { BlockHeightScreen::epdContent[i] = blockNrString[i]; } diff --git a/src/screens/blockheight.hpp b/src/screens/blockheight.hpp index 536de1f..bffb25d 100644 --- a/src/screens/blockheight.hpp +++ b/src/screens/blockheight.hpp @@ -9,10 +9,10 @@ class BlockHeightScreen { protected: static uint blockNr; - static std::array epdContent; + static std::array epdContent; public: static void init(); static void showScreen(); static void onNewBlock(uint blockNr); - static std::array getEpdContent(); + static std::array getEpdContent(); }; \ No newline at end of file diff --git a/src/screens/countdown.cpp b/src/screens/countdown.cpp index b4cda23..8df4280 100644 --- a/src/screens/countdown.cpp +++ b/src/screens/countdown.cpp @@ -2,7 +2,7 @@ uint CountdownScreen::countdownMinutes = 1; uint CountdownScreen::countdownSeconds = 0; -std::array CountdownScreen::epdContent = {"COUNT/DOWN", "", "", "", "", "", ""}; +std::array CountdownScreen::epdContent = {"COUNT/DOWN", "", "", "", "", "", ""}; void CountdownScreen::init() { @@ -14,7 +14,7 @@ void CountdownScreen::showScreen() } -std::array CountdownScreen::getEpdContent() +std::array CountdownScreen::getEpdContent() { return CountdownScreen::epdContent; } @@ -27,10 +27,10 @@ void CountdownScreen::countdownTask(void *pvParameters) { for (int i = CountdownScreen::countdownSeconds; i >= 0; i--) { - char countdownString[7]; + char countdownString[NUM_SCREENS]; sprintf(countdownString, "%02d:%02d", i / 60, i % 60); std::string timeString = countdownString; - timeString.insert(timeString.begin(), 7 - timeString.length(), ' '); + timeString.insert(timeString.begin(), NUM_SCREENS - timeString.length(), ' '); CountdownScreen::epdContent[0] = "COUNT/DOWN"; for (uint i = 1; i < 7; i++) { diff --git a/src/screens/countdown.hpp b/src/screens/countdown.hpp index 863880d..ee67561 100644 --- a/src/screens/countdown.hpp +++ b/src/screens/countdown.hpp @@ -11,11 +11,11 @@ class CountdownScreen { protected: static uint countdownMinutes; static uint countdownSeconds; - static std::array epdContent; + static std::array epdContent; public: static void init(); static void showScreen(); - static std::array getEpdContent(); + static std::array getEpdContent(); static void setCountdownSeconds(uint sec); static void countdownTask(void *pvParameters); }; \ No newline at end of file diff --git a/src/screens/custom_text.cpp b/src/screens/custom_text.cpp index 1c69a23..1a293c3 100644 --- a/src/screens/custom_text.cpp +++ b/src/screens/custom_text.cpp @@ -1,7 +1,7 @@ #include "custom_text.hpp" std::string CustomTextScreen::customText = ""; -std::array CustomTextScreen::epdContent = {"", "", "", "", "", "", ""}; +std::array CustomTextScreen::epdContent = {"", "", "", "", "", "", ""}; void CustomTextScreen::init() { @@ -12,11 +12,11 @@ void CustomTextScreen::showScreen() { } -void CustomTextScreen::setSimpleText(String text) +void CustomTextScreen::setSimpleText(const String& text) { customText = text.c_str(); - customText.insert(customText.begin(), 7 - customText.length(), ' '); + customText.insert(customText.begin(), NUM_SCREENS - customText.length(), ' '); for (uint i = 0; i < 7; i++) { @@ -24,7 +24,7 @@ void CustomTextScreen::setSimpleText(String text) } } -void CustomTextScreen::setText(std::array customContent) +void CustomTextScreen::setText(std::array customContent) { epdContent = customContent; } diff --git a/src/screens/custom_text.hpp b/src/screens/custom_text.hpp index b3ca784..43191e3 100644 --- a/src/screens/custom_text.hpp +++ b/src/screens/custom_text.hpp @@ -10,11 +10,11 @@ class CustomTextScreen { protected: static std::string customText; - static std::array epdContent; + static std::array epdContent; public: static void init(); static void showScreen(); - static std::array getEpdContent(); - static void setSimpleText(String text); + static std::array getEpdContent(); + static void setSimpleText(const String& text); static void setText(std::array customContent); }; \ No newline at end of file diff --git a/src/screens/halvingcountdown.cpp b/src/screens/halvingcountdown.cpp index d66fe00..fe014c8 100644 --- a/src/screens/halvingcountdown.cpp +++ b/src/screens/halvingcountdown.cpp @@ -3,7 +3,7 @@ uint HalvingCountdownScreen::currentBlockNr = 0; uint HalvingCountdownScreen::halvingBlockNr = 0; -std::array HalvingCountdownScreen::epdContent = {"", "", "", "", "", "", ""}; +std::array HalvingCountdownScreen::epdContent = {"", "", "", "", "", "", ""}; void HalvingCountdownScreen::init() { @@ -44,7 +44,7 @@ void HalvingCountdownScreen::onNewBlock(uint blockNr) HalvingCountdownScreen::showScreen(); } -std::array HalvingCountdownScreen::getEpdContent() +std::array HalvingCountdownScreen::getEpdContent() { return HalvingCountdownScreen::epdContent; } \ No newline at end of file diff --git a/src/screens/halvingcountdown.hpp b/src/screens/halvingcountdown.hpp index 15bba34..562aced 100644 --- a/src/screens/halvingcountdown.hpp +++ b/src/screens/halvingcountdown.hpp @@ -10,11 +10,11 @@ class HalvingCountdownScreen { protected: static uint currentBlockNr; static uint halvingBlockNr; - static std::array epdContent; + static std::array epdContent; public: static void init(); static void showScreen(); static void onNewBlock(uint blockNr); static uint getNextHalvingBlockNr(); - static std::array getEpdContent(); + static std::array getEpdContent(); }; \ No newline at end of file diff --git a/src/screens/sats_per_dollar.cpp b/src/screens/sats_per_dollar.cpp index c4dbe9d..3cb7a5b 100644 --- a/src/screens/sats_per_dollar.cpp +++ b/src/screens/sats_per_dollar.cpp @@ -1,7 +1,7 @@ #include "sats_per_dollar.hpp" uint SatsPerDollarScreen::satsPerDollar = 0; -std::array SatsPerDollarScreen::epdContent = { "", "", "", "", "", "", "" }; +std::array SatsPerDollarScreen::epdContent = { "", "", "", "", "", "", "" }; void SatsPerDollarScreen::init() { SatsPerDollarScreen::satsPerDollar = int(round(1 / preferences.getFloat("btcPrice", 12345) * 10e7)); @@ -13,7 +13,7 @@ void SatsPerDollarScreen::showScreen() { std::string satsPerDollarString = String(SatsPerDollarScreen::satsPerDollar).c_str(); satsPerDollarString.insert(satsPerDollarString.begin(), 7 - satsPerDollarString.length(), ' '); epdContent[0] = "MSCW/TIME"; - for (uint i = 1; i < 7; i++) + for (uint i = 1; i < NUM_SCREENS; i++) { SatsPerDollarScreen::epdContent[i] = satsPerDollarString[i]; } @@ -25,6 +25,6 @@ void SatsPerDollarScreen::onPriceUpdate(uint price) { SatsPerDollarScreen::showScreen(); } -std::array SatsPerDollarScreen::getEpdContent() { +std::array SatsPerDollarScreen::getEpdContent() { return SatsPerDollarScreen::epdContent; } \ No newline at end of file diff --git a/src/screens/sats_per_dollar.hpp b/src/screens/sats_per_dollar.hpp index f2fcbcc..ef93668 100644 --- a/src/screens/sats_per_dollar.hpp +++ b/src/screens/sats_per_dollar.hpp @@ -8,10 +8,10 @@ class SatsPerDollarScreen { protected: static uint satsPerDollar; - static std::array epdContent; + static std::array epdContent; public: static void init(); static void showScreen(); static void onPriceUpdate(uint price); - static std::array getEpdContent(); + static std::array getEpdContent(); }; \ No newline at end of file diff --git a/src/screens/ticker.cpp b/src/screens/ticker.cpp index b873314..77342ec 100644 --- a/src/screens/ticker.cpp +++ b/src/screens/ticker.cpp @@ -1,7 +1,7 @@ #include "ticker.hpp" uint TickerScreen::price = 12345; -std::array TickerScreen::epdContent = { "", "", "", "", "", "", "" }; +std::array TickerScreen::epdContent = { "", "", "", "", "", "", "" }; void TickerScreen::init() { TickerScreen::price = preferences.getFloat("btcPrice", 12345);; @@ -11,9 +11,9 @@ void TickerScreen::init() { void TickerScreen::showScreen() { std::string priceString = ("$" + String(TickerScreen::price)).c_str(); - priceString.insert(priceString.begin(), 7 - priceString.length(), ' '); + priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); epdContent[0] = "BTC/USD"; - for (uint i = 1; i < 7; i++) + for (uint i = 1; i < NUM_SCREENS; i++) { TickerScreen::epdContent[i] = priceString[i]; } @@ -24,6 +24,6 @@ void TickerScreen::onPriceUpdate(uint price) { TickerScreen::showScreen(); } -std::array TickerScreen::getEpdContent() { +std::array TickerScreen::getEpdContent() { return TickerScreen::epdContent; } \ No newline at end of file diff --git a/src/screens/ticker.hpp b/src/screens/ticker.hpp index f433ca4..d0f988d 100644 --- a/src/screens/ticker.hpp +++ b/src/screens/ticker.hpp @@ -9,11 +9,11 @@ class TickerScreen { protected: static uint price; - static std::array epdContent; + static std::array epdContent; public: static void init(); static void showScreen(); static void onPriceUpdate(uint price); - static std::array getEpdContent(); + static std::array getEpdContent(); }; \ No newline at end of file diff --git a/src/screens/time.cpp b/src/screens/time.cpp index 1d56150..9968a06 100644 --- a/src/screens/time.cpp +++ b/src/screens/time.cpp @@ -1,8 +1,6 @@ #include "time.hpp" -String TimeScreen::timeString = ""; -String TimeScreen::dateString = ""; -std::array TimeScreen::epdContent = { "", "", "", "", "", "", "" }; +std::array TimeScreen::epdContent = { "", "", "", "", "", "", "" }; void TimeScreen::init() { setupMinuteEvent(); @@ -10,13 +8,13 @@ void TimeScreen::init() { } void TimeScreen::showScreen() { - TimeScreen::dateString = String(rtc.getDay()) + "/" + String(rtc.getMonth() + 1); - TimeScreen::timeString = rtc.getTime("%H:%M").c_str(); + // String(String(rtc.getDay()) + "/" + String(rtc.getMonth() + 1)).toCharArray(TimeScreen::dateString, 5); + // rtc.getTime("%H:%M").toCharArray(TimeScreen::timeString, 5); - std::string timeString = TimeScreen::timeString.c_str(); - timeString.insert(timeString.begin(), 7 - timeString.length(), ' '); - TimeScreen::epdContent[0] = TimeScreen::dateString; - for (uint i = 1; i < 7; i++) + 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); + for (uint i = 1; i < NUM_SCREENS; i++) { TimeScreen::epdContent[i] = timeString[i]; } @@ -30,7 +28,7 @@ void TimeScreen::onActivate() { TimeScreen::showScreen(); } -std::array TimeScreen::getEpdContent() { +std::array TimeScreen::getEpdContent() { return TimeScreen::epdContent; } diff --git a/src/screens/time.hpp b/src/screens/time.hpp index 1ee2a0c..6061383 100644 --- a/src/screens/time.hpp +++ b/src/screens/time.hpp @@ -7,8 +7,6 @@ class TimeScreen { protected: - static String timeString; - static String dateString; static std::array epdContent; static TimeScreen* instance_; public: diff --git a/src/shared.hpp b/src/shared.hpp index ae4b845..0f60b6c 100644 --- a/src/shared.hpp +++ b/src/shared.hpp @@ -2,7 +2,7 @@ #include //##include - +#include #include #include @@ -50,4 +50,16 @@ const PROGMEM int SCREEN_COUNTDOWN = 98; const PROGMEM int SCREEN_CUSTOM = 99; const PROGMEM int screens[5] = { SCREEN_BLOCK_HEIGHT, SCREEN_MSCW_TIME, SCREEN_BTC_TICKER, SCREEN_TIME, SCREEN_HALVING_COUNTDOWN }; -const uint screenCount = sizeof(screens) / sizeof(int); \ No newline at end of file +const uint screenCount = sizeof(screens) / sizeof(int); + +struct SpiRamAllocator { + void* allocate(size_t size) { + return ps_malloc(size); + + } + void deallocate(void* pointer) { + free(pointer); + } +}; + +using SpiRamJsonDocument = BasicJsonDocument; diff --git a/src/tasks/blocknotify.cpp b/src/tasks/blocknotify.cpp index 005521f..71bf47e 100644 --- a/src/tasks/blocknotify.cpp +++ b/src/tasks/blocknotify.cpp @@ -1,6 +1,6 @@ #include "blocknotify.hpp" -int currentBlockHeight = 789000; +uint currentBlockHeight = 789000; QueueHandle_t bitcoinQueue; BitcoinEvent bitcoinEvent; const String NEW_BLOCK_MINED_EVENT = "new_block_mined"; @@ -17,7 +17,7 @@ bool useBitcoind = true; void checkBitcoinBlock(void *pvParameters) { - int blockHeight = preferences.getUInt("blockHeight", currentBlockHeight); + uint blockHeight = preferences.getUInt("blockHeight", currentBlockHeight); useBitcoind = preferences.getBool("useNode", false) && wifiClientInsecure.connect(preferences.getString("rpcHost", BITCOIND_HOST).c_str(), preferences.getUInt("rpcPort", BITCOIND_PORT)); @@ -26,7 +26,14 @@ void checkBitcoinBlock(void *pvParameters) else Serial.println("bitcoind node is not reachable, using mempool API instead."); - + IPAddress result; + + int err = WiFi.hostByName(preferences.getString("mempoolInstance", DEFAULT_MEMPOOL_INSTANCE).c_str(), result) ; + + if (err != 1) { + flashTemporaryLights(255, 0, 0); + } + for (;;) { HTTPClient http; diff --git a/src/tasks/blocknotify.hpp b/src/tasks/blocknotify.hpp index 218628e..8164a61 100644 --- a/src/tasks/blocknotify.hpp +++ b/src/tasks/blocknotify.hpp @@ -6,6 +6,7 @@ #include #include #include "base64.h" +#include "lib/functions.hpp" #include "shared.hpp" #include "config.h" diff --git a/src/tasks/epd.cpp b/src/tasks/epd.cpp index 0abb996..a68db4f 100644 --- a/src/tasks/epd.cpp +++ b/src/tasks/epd.cpp @@ -6,9 +6,9 @@ // 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] = {2, 4, 6, 10, 33, 21, 17}; -const int EPD_BUSY[7] = {3, 5, 7, 9, 37, 18, 16}; -const int EPD_RESET_MPD[7] = {8, 9, 10, 11, 12, 13, 14}; +const int EPD_CS[NUM_SCREENS] = {2, 4, 6, 10, 33, 21, 17}; +const int EPD_BUSY[NUM_SCREENS] = {3, 5, 7, 9, 37, 18, 16}; +const int EPD_RESET_MPD[NUM_SCREENS] = {8, 9, 10, 11, 12, 13, 14}; const int EPD_DC = 14; const int RST_PIN = 15; @@ -45,7 +45,8 @@ const int RST_PIN = 2; #endif #ifdef IS_BW -GxEPD2_BW displays[7] = { + +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]), @@ -55,6 +56,8 @@ GxEPD2_BW displays[7] = { GxEPD2_213_B74(EPD_CS[6], EPD_DC, /*RST=*/-1, EPD_BUSY[6]), }; +//GxEPD2_BW * displays2 = (GxEPD2_BW *) ps_malloc(7 * sizeof (GxEPD2_BW)); + const int SEM_WAIT_TIME = 10000; #else @@ -72,13 +75,12 @@ const int SEM_WAIT_TIME = 30000; #endif -const uint displaySize = 7; -uint32_t lastFullRefresh[displaySize]; +uint32_t lastFullRefresh[NUM_SCREENS]; std::array currentEpdContent; std::array epdContent; -TaskHandle_t tasks[displaySize]; -SemaphoreHandle_t epdUpdateSemaphore[displaySize]; +TaskHandle_t tasks[NUM_SCREENS]; +SemaphoreHandle_t epdUpdateSemaphore[NUM_SCREENS]; uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX]; void setupDisplays() @@ -98,7 +100,7 @@ void resetAllDisplays() digitalWrite(RST_PIN, HIGH); delay(200); #else - for (int i = 0; i < displaySize; i++) { + for (int i = 0; i < NUM_SCREENS; i++) { resetSingleDisplay(i); } #endif NO_MCP @@ -118,7 +120,7 @@ void resetSingleDisplay(int i) void initDisplays() { - for (uint i = 0; i < displaySize; i++) + for (uint i = 0; i < NUM_SCREENS; i++) { #ifndef NO_MCP mcp.pinMode(EPD_RESET_MPD[i], OUTPUT); @@ -131,8 +133,7 @@ void initDisplays() // displays[i].epd2.init(SW_SCK, SW_MOSI, 115200, true, 20, false); } - std::string text = "BTClock"; - for (uint i = 0; i < displaySize; i++) + for (uint i = 0; i < NUM_SCREENS; i++) { epdUpdateSemaphore[i] = xSemaphoreCreateBinary(); xSemaphoreGive(epdUpdateSemaphore[i]); @@ -145,7 +146,7 @@ void initDisplays() // delay(1000); } epdContent = {"B", "T", "C", "L", "O", "C", "K"}; - for (uint i = 0; i < displaySize; i++) + for (uint i = 0; i < NUM_SCREENS; i++) { xTaskNotifyGive(tasks[i]); } @@ -185,7 +186,7 @@ void taskEpd(void *pvParameters) bool updatedThisCycle = false; - for (uint i = 0; i < displaySize; i++) + for (uint i = 0; i < NUM_SCREENS; i++) { if (epdContent[i].compareTo(currentEpdContent[i]) != 0) { @@ -234,7 +235,7 @@ void setEpdContent(std::array newEpdContent) epdContent = newEpdContent; } -void splitText(uint dispNum, String top, String bottom, bool partial) +void splitText(const uint dispNum, String top, String bottom, bool partial) { displays[dispNum].setRotation(2); displays[dispNum].setFont(&FONT_SMALL); @@ -270,7 +271,7 @@ void splitText(uint dispNum, String top, String bottom, bool partial) displays[dispNum].print(bottom); } -void showDigit(uint dispNum, char chr, bool partial, const GFXfont *font) +void showDigit(const uint dispNum, char chr, bool partial, const GFXfont *font) { String str(chr); displays[dispNum].setRotation(2); @@ -291,7 +292,7 @@ void fullRefresh(void *pvParameters) { resetAllDisplays(); - for (uint i = 0; i < displaySize; i++) + for (uint i = 0; i < NUM_SCREENS; i++) { lastFullRefresh[i] = NULL; } @@ -428,13 +429,13 @@ void showSetupQr(String ssid, String password) displays[displayIndex].println("Welcome!"); } while (displays[displayIndex].nextPage()); - for (int i = 1; i < displaySize; (i = i+2)) { + for (int i = 1; i < NUM_SCREENS; (i = i+2)) { displays[i].setPartialWindow(0, 0, displays[i].width(), displays[i].height()); displays[i].fillScreen(GxEPD_WHITE); displays[i].display(true); } - for (int i = 0; i < displaySize; i++) { + for (int i = 0; i < NUM_SCREENS; i++) { displays[i].hibernate(); } } \ No newline at end of file diff --git a/src/tasks/epd.hpp b/src/tasks/epd.hpp index 2a2bca6..717d20e 100644 --- a/src/tasks/epd.hpp +++ b/src/tasks/epd.hpp @@ -40,8 +40,8 @@ void resetSingleDisplay(int i); std::array getCurrentEpdContent(); void setEpdContent(std::array newEpdContent); -void splitText(uint dispNum, String top, String bottom, bool partial); -void showDigit(uint dispNum, char chr, bool partial, const GFXfont *font); +void splitText(const uint dispNum, String top, String bottom, bool partial); +void showDigit(const uint dispNum, char chr, bool partial, const GFXfont *font); void refreshDisplay(void *pvParameters); void fullRefresh(void *pvParameters); diff --git a/src/tasks/get_price.cpp b/src/tasks/get_price.cpp index ddd61d5..f9ed448 100644 --- a/src/tasks/get_price.cpp +++ b/src/tasks/get_price.cpp @@ -31,7 +31,7 @@ void taskGetPrice(void *pvParameters) if (httpCode == 200) { String payload = http.getString(); - StaticJsonDocument<768> doc; + SpiRamJsonDocument doc(768); deserializeJson(doc, payload); JsonObject bpi = doc["bitcoin"]; usdPrice = bpi["usd"]; @@ -61,7 +61,7 @@ void taskGetPrice(void *pvParameters) if (httpCode == 200) { String payload = http.getString(); - StaticJsonDocument<768> doc; + SpiRamJsonDocument doc(768); deserializeJson(doc, payload); JsonObject bpi = doc["bpi"]; usdPrice = bpi["USD"]["rate_float"];