Refactor EPD code to EPDManager class

This commit is contained in:
Djuri 2025-01-05 22:11:53 +01:00
parent d023643090
commit a6a8b5a071
Signed by: djuri
GPG key ID: 61B9B2DDE5AA3AC1
11 changed files with 532 additions and 638 deletions

View file

@ -181,45 +181,42 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data)
} }
void processNewBlock(uint32_t newBlockHeight) { void processNewBlock(uint32_t newBlockHeight) {
if (newBlockHeight < currentBlockHeight) if (currentBlockHeight == newBlockHeight)
return; {
return;
}
currentBlockHeight = newBlockHeight; currentBlockHeight = newBlockHeight;
// Serial.printf("New block found: %d\r\n", block["height"].as<uint>());
preferences.putUInt("blockHeight", currentBlockHeight);
lastBlockUpdate = esp_timer_get_time() / 1000000; lastBlockUpdate = esp_timer_get_time() / 1000000;
if (workQueue != nullptr) if (workQueue != nullptr)
{ {
WorkItem blockUpdate = {TASK_BLOCK_UPDATE, 0}; WorkItem blockUpdate = {TASK_BLOCK_UPDATE, 0};
xQueueSend(workQueue, &blockUpdate, portMAX_DELAY); xQueueSend(workQueue, &blockUpdate, portMAX_DELAY);
// xTaskNotifyGive(blockUpdateTaskHandle); }
if (ScreenHandler::getCurrentScreen() != SCREEN_BLOCK_HEIGHT && if (ScreenHandler::getCurrentScreen() != SCREEN_BLOCK_HEIGHT &&
preferences.getBool("stealFocus", DEFAULT_STEAL_FOCUS)) preferences.getBool("stealFocus", DEFAULT_STEAL_FOCUS))
{ {
uint64_t timerPeriod = 0; uint64_t timerPeriod = 0;
if (isTimerActive()) if (isTimerActive())
{ {
// store timer periode before making inactive to prevent artifacts timerPeriod = getTimerSeconds();
timerPeriod = getTimerSeconds(); esp_timer_stop(screenRotateTimer);
esp_timer_stop(screenRotateTimer);
} }
ScreenHandler::setCurrentScreen(SCREEN_BLOCK_HEIGHT); ScreenHandler::setCurrentScreen(SCREEN_BLOCK_HEIGHT);
if (timerPeriod > 0) if (timerPeriod > 0)
{ {
esp_timer_start_periodic(screenRotateTimer, esp_timer_start_periodic(screenRotateTimer,
timerPeriod * usPerSecond); timerPeriod * usPerSecond);
} }
vTaskDelay(pdMS_TO_TICKS(315*NUM_SCREENS)); // Extra delay because of screen switching vTaskDelay(pdMS_TO_TICKS(315*NUM_SCREENS)); // Extra delay because of screen switching
} }
if (preferences.getBool("ledFlashOnUpd", DEFAULT_LED_FLASH_ON_UPD)) if (preferences.getBool("ledFlashOnUpd", DEFAULT_LED_FLASH_ON_UPD))
{ {
vTaskDelay(pdMS_TO_TICKS(250)); // Wait until screens are updated vTaskDelay(pdMS_TO_TICKS(250)); // Wait until screens are updated
getLedHandler().queueEffect(LED_FLASH_BLOCK_NOTIFY); getLedHandler().queueEffect(LED_FLASH_BLOCK_NOTIFY);
}
} }
} }

View file

@ -48,7 +48,7 @@ void setup()
setupPreferences(); setupPreferences();
setupHardware(); setupHardware();
setupDisplays(); EPDManager::getInstance().initialize();
if (preferences.getBool("ledTestOnPower", DEFAULT_LED_TEST_ON_POWER)) if (preferences.getBool("ledTestOnPower", DEFAULT_LED_TEST_ON_POWER))
{ {
auto& ledHandler = getLedHandler(); auto& ledHandler = getLedHandler();
@ -115,7 +115,7 @@ void setup()
ButtonHandler::setup(); ButtonHandler::setup();
setupOTA(); setupOTA();
waitUntilNoneBusy(); EPDManager::getInstance().waitUntilNoneBusy();
#ifdef HAS_FRONTLIGHT #ifdef HAS_FRONTLIGHT
if (!preferences.getBool("flAlwaysOn", DEFAULT_FL_ALWAYS_ON)) if (!preferences.getBool("flAlwaysOn", DEFAULT_FL_ALWAYS_ON))
@ -126,7 +126,7 @@ void setup()
} }
#endif #endif
forceFullRefresh(); EPDManager::getInstance().forceFullRefresh();
} }
void setupWifi() void setupWifi()
@ -181,8 +181,8 @@ void setupWifi()
wifiManager->getConfigPortalSSID().c_str(), wifiManager->getConfigPortalSSID().c_str(),
softAP_password.c_str()); softAP_password.c_str());
// delay(6000); // delay(6000);
setFgColor(GxEPD_BLACK); EPDManager::getInstance().setForegroundColor(GxEPD_BLACK);
setBgColor(GxEPD_WHITE); EPDManager::getInstance().setBackgroundColor(GxEPD_WHITE);
const String qrText = "qrWIFI:S:" + wifiManager->getConfigPortalSSID() + const String qrText = "qrWIFI:S:" + wifiManager->getConfigPortalSSID() +
";T:WPA;P:" + softAP_password.c_str() + ";;"; ";T:WPA;P:" + softAP_password.c_str() + ";;";
const String explainText = "*SSID: *\r\n" + const String explainText = "*SSID: *\r\n" +
@ -212,58 +212,22 @@ void setupWifi()
#endif #endif
"\r\n\r\n*FW build date:*\r\n" + formattedDate, "\r\n\r\n*FW build date:*\r\n" + formattedDate,
qrText}; qrText};
setEpdContent(epdContent); });
EPDManager::getInstance().setContent(epdContent); });
wm.setSaveConfigCallback([]() wm.setSaveConfigCallback([]()
{ {
preferences.putBool("wifiConfigured", true); preferences.putBool("wifiConfigured", true);
delay(1000); delay(1000);
// just restart after succes // just restart after success
ESP.restart(); }); ESP.restart(); });
bool ac = wm.autoConnect(softAP_SSID.c_str(), softAP_password.c_str()); bool ac = wm.autoConnect(softAP_SSID.c_str(), softAP_password.c_str());
// waitUntilNoneBusy();
// std::array<String, NUM_SCREENS> epdContent = {"Welcome!",
// "Bienvenidos!", "Use\r\nweb-interface\r\npara configurar", "Use\r\nla
// interfaz web\r\npara configurar", "Or
// restart\r\nwhile\r\nholding\r\n2nd button\r\r\nto start\r\n QR-config",
// "O reinicie\r\nmientras\r\n mantiene presionado\r\nel segundo
// botón\r\r\npara iniciar\r\nQR-config", ""}; setEpdContent(epdContent);
// esp_task_wdt_init(30, false);
// uint count = 0;
// while (WiFi.status() != WL_CONNECTED)
// {
// if (Serial.available() > 0)
// {
// uint8_t b = Serial.read();
// if (parse_improv_serial_byte(x_position, b, x_buffer,
// onImprovCommandCallback, onImprovErrorCallback))
// {
// x_buffer[x_position++] = b;
// }
// else
// {
// x_position = 0;
// }
// }
// count++;
// if (count > 2000000) {
// queueLedEffect(LED_EFFECT_HEARTBEAT);
// count = 0;
// }
// }
// esp_task_wdt_deinit();
// esp_task_wdt_reset();
} }
EPDManager::getInstance().setForegroundColor(preferences.getUInt("fgColor", isWhiteVersion() ? GxEPD_BLACK : GxEPD_WHITE));
EPDManager::getInstance().setBackgroundColor(preferences.getUInt("bgColor", isWhiteVersion() ? GxEPD_WHITE : GxEPD_BLACK));
setFgColor(preferences.getUInt("fgColor", isWhiteVersion() ? GxEPD_BLACK : GxEPD_WHITE));
setBgColor(preferences.getUInt("bgColor", isWhiteVersion() ? GxEPD_WHITE : GxEPD_BLACK));
} }
// else // else
// { // {
@ -299,8 +263,8 @@ void setupPreferences()
{ {
preferences.begin("btclock", false); preferences.begin("btclock", false);
setFgColor(preferences.getUInt("fgColor", DEFAULT_FG_COLOR)); EPDManager::getInstance().setForegroundColor(preferences.getUInt("fgColor", DEFAULT_FG_COLOR));
setBgColor(preferences.getUInt("bgColor", DEFAULT_BG_COLOR)); EPDManager::getInstance().setBackgroundColor(preferences.getUInt("bgColor", DEFAULT_BG_COLOR));
setBlockHeight(preferences.getUInt("blockHeight", INITIAL_BLOCK_HEIGHT)); setBlockHeight(preferences.getUInt("blockHeight", INITIAL_BLOCK_HEIGHT));
setPrice(preferences.getUInt("lastPrice", INITIAL_LAST_PRICE), CURRENCY_USD); setPrice(preferences.getUInt("lastPrice", INITIAL_LAST_PRICE), CURRENCY_USD);

File diff suppressed because it is too large Load diff

View file

@ -9,6 +9,8 @@
#include <mutex> #include <mutex>
#include <native_pin.hpp> #include <native_pin.hpp>
#include <regex> #include <regex>
#include <array>
#include <memory>
#include "fonts/fonts.hpp" #include "fonts/fonts.hpp"
#include "lib/config.hpp" #include "lib/config.hpp"
@ -32,39 +34,102 @@
#include "qrcodegen.h" #include "qrcodegen.h"
#endif #endif
typedef struct { struct UpdateDisplayTaskItem {
char dispNum; char dispNum;
} UpdateDisplayTaskItem; };
void forceFullRefresh(); struct FontFamily {
void setupDisplays(); GFXfont* big;
void loadFonts(const String& fontName); GFXfont* medium;
GFXfont* small;
};
void splitText(const uint dispNum, const String &top, const String &bottom, class EPDManager {
bool partial); public:
static EPDManager& getInstance();
void showDigit(const uint dispNum, char chr, bool partial, const GFXfont *font); // Delete copy constructor and assignment operator
void showChars(const uint dispNum, const String &chars, bool partial, EPDManager(const EPDManager&) = delete;
const GFXfont *font); EPDManager& operator=(const EPDManager&) = delete;
extern "C" void updateDisplay(void *pvParameters) noexcept; void initialize();
void updateDisplayAlt(int epdIndex); void forceFullRefresh();
void prepareDisplayUpdateTask(void *pvParameters); void loadFonts(const String& fontName);
void setContent(const std::array<String, NUM_SCREENS>& newContent, bool forceUpdate = false);
void setContent(const std::array<std::string, NUM_SCREENS>& newContent);
std::array<String, NUM_SCREENS> getCurrentContent() const;
int getBgColor(); int getBackgroundColor() const { return bgColor; }
int getFgColor(); int getForegroundColor() const { return fgColor; }
void setBgColor(int color); void setBackgroundColor(int color) { bgColor = color; }
void setFgColor(int color); void setForegroundColor(int color) { fgColor = color; }
void waitUntilNoneBusy();
bool renderIcon(const uint dispNum, const String &text, bool partial); private:
void renderText(const uint dispNum, const String &text, bool partial); EPDManager(); // Private constructor for singleton
void renderQr(const uint dispNum, const String &text, bool partial); ~EPDManager(); // Private destructor
void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent, void setupDisplay(uint dispNum, const GFXfont* font);
bool forceUpdate); void splitText(uint dispNum, const String& top, const String& bottom, bool partial);
void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent); void showDigit(uint dispNum, char chr, bool partial, const GFXfont* font);
void showChars(uint dispNum, const String& chars, bool partial, const GFXfont* font);
bool renderIcon(uint dispNum, const String& text, bool partial);
void renderText(uint dispNum, const String& text, bool partial);
void renderQr(uint dispNum, const String& text, bool partial);
int16_t calculateDescent(const GFXfont* font);
void setEpdContent(std::array<std::string, NUM_SCREENS> newEpdContent); static void updateDisplayTask(void* pvParameters) noexcept;
static void prepareDisplayUpdateTask(void* pvParameters);
std::array<String, NUM_SCREENS> getCurrentEpdContent(); // Member variables
void waitUntilNoneBusy(); std::array<String, NUM_SCREENS> currentContent;
std::array<String, NUM_SCREENS> content;
std::array<uint32_t, NUM_SCREENS> lastFullRefresh;
std::array<TaskHandle_t, NUM_SCREENS> tasks;
QueueHandle_t updateQueue;
FontFamily antonioFonts;
FontFamily oswaldFonts;
const GFXfont* fontSmall;
const GFXfont* fontBig;
const GFXfont* fontMedium;
const GFXfont* fontSatsymbol;
int bgColor;
int fgColor;
std::mutex updateMutex;
std::array<std::mutex, NUM_SCREENS> displayMutexes;
// Pin configurations based on board version
#ifdef IS_BTCLOCK_REV_B
static Native_Pin EPD_DC;
static std::array<Native_Pin, NUM_SCREENS> EPD_CS;
static std::array<Native_Pin, NUM_SCREENS> EPD_BUSY;
static std::array<MCP23X17_Pin, NUM_SCREENS> EPD_RESET;
#elif defined(IS_BTCLOCK_V8)
static Native_Pin EPD_DC;
static std::array<MCP23X17_Pin, NUM_SCREENS> EPD_BUSY;
static std::array<MCP23X17_Pin, NUM_SCREENS> EPD_CS;
static std::array<MCP23X17_Pin, NUM_SCREENS> EPD_RESET;
#else
static Native_Pin EPD_DC;
static std::array<Native_Pin, NUM_SCREENS> EPD_CS;
static std::array<Native_Pin, NUM_SCREENS> EPD_BUSY;
static std::array<MCP23X17_Pin, NUM_SCREENS> EPD_RESET;
#endif
// Display array
std::array<GxEPD2_BW<EPD_CLASS, EPD_CLASS::HEIGHT>, NUM_SCREENS> displays;
static constexpr size_t UPDATE_QUEUE_SIZE = 14;
static constexpr uint32_t BUSY_TIMEOUT_COUNT = 200;
static constexpr TickType_t BUSY_RETRY_DELAY = pdMS_TO_TICKS(10);
static constexpr size_t EPD_TASK_STACK_SIZE =
#ifdef IS_BTCLOCK_V8
4096
#else
2048
#endif
;
};

View file

@ -283,7 +283,7 @@ void handleNostrZapCallback(const String &subId, nostr::SignedNostrEvent *event)
} }
ScreenHandler::setCurrentScreen(SCREEN_CUSTOM); ScreenHandler::setCurrentScreen(SCREEN_CUSTOM);
setEpdContent(textEpdContent); EPDManager::getInstance().setContent(textEpdContent);
vTaskDelay(pdMS_TO_TICKS(315 * NUM_SCREENS) + pdMS_TO_TICKS(250)); vTaskDelay(pdMS_TO_TICKS(315 * NUM_SCREENS) + pdMS_TO_TICKS(250));
if (preferences.getBool("ledFlashOnZap", DEFAULT_LED_FLASH_ON_ZAP)) if (preferences.getBool("ledFlashOnZap", DEFAULT_LED_FLASH_ON_ZAP))
{ {
@ -294,4 +294,20 @@ void handleNostrZapCallback(const String &subId, nostr::SignedNostrEvent *event)
esp_timer_start_periodic(screenRotateTimer, esp_timer_start_periodic(screenRotateTimer,
timerPeriod * usPerSecond); timerPeriod * usPerSecond);
} }
} }
// void onNostrEvent(const String &subId, const nostr::Event &event) {
// // This is the callback that will be called when a new event is received
// if (event.kind == 9735) {
// // Parse the zap amount from the event
// uint16_t amount = parseZapAmount(event);
// if (amount > 0) {
// std::array<std::string, NUM_SCREENS> zapContent = parseZapNotify(amount, true);
// EPDManager::getInstance().setContent(zapContent);
// if (preferences.getBool("ledFlashOnUpd", DEFAULT_LED_FLASH_ON_UPD)) {
// getLedHandler().queueEffect(LED_FLASH_BLOCK_NOTIFY);
// }
// }
// }
// }

View file

@ -57,10 +57,10 @@ void onOTAProgress(unsigned int progress, unsigned int total)
void onOTAStart() void onOTAStart()
{ {
forceFullRefresh(); EPDManager::getInstance().forceFullRefresh();
std::array<String, NUM_SCREENS> epdContent = {"U", "P", "D", "A", std::array<String, NUM_SCREENS> epdContent = {"U", "P", "D", "A",
"T", "E", "!"}; "T", "E", "!"};
setEpdContent(epdContent); EPDManager::getInstance().setContent(epdContent);
// Stop all timers // Stop all timers
esp_timer_stop(screenRotateTimer); esp_timer_stop(screenRotateTimer);
esp_timer_stop(minuteTimer); esp_timer_stop(minuteTimer);

View file

@ -203,7 +203,7 @@ void ScreenHandler::showSystemStatusScreen() {
String((int)round(ESP.getFreeHeap() / 1024)) + "/" + String((int)round(ESP.getFreeHeap() / 1024)) + "/" +
(int)round(ESP.getHeapSize() / 1024); (int)round(ESP.getHeapSize() / 1024);
setCurrentScreen(SCREEN_CUSTOM); setCurrentScreen(SCREEN_CUSTOM);
setEpdContent(sysStatusEpdContent); EPDManager::getInstance().setContent(sysStatusEpdContent);
} }
// Keep these as free functions // Keep these as free functions
@ -222,7 +222,7 @@ void workerTask(void *pvParameters) {
taskEpdContent = (currentScreenValue == SCREEN_BITAXE_HASHRATE) ? taskEpdContent = (currentScreenValue == SCREEN_BITAXE_HASHRATE) ?
parseBitaxeHashRate(BitAxeFetch::getInstance().getHashRate()) : parseBitaxeHashRate(BitAxeFetch::getInstance().getHashRate()) :
parseBitaxeBestDiff(BitAxeFetch::getInstance().getBestDiff()); parseBitaxeBestDiff(BitAxeFetch::getInstance().getBestDiff());
setEpdContent(taskEpdContent); EPDManager::getInstance().setContent(taskEpdContent);
break; break;
} }
@ -235,7 +235,7 @@ void workerTask(void *pvParameters) {
parseMiningPoolStatsDailyEarnings(MiningPoolStatsFetch::getInstance().getDailyEarnings(), parseMiningPoolStatsDailyEarnings(MiningPoolStatsFetch::getInstance().getDailyEarnings(),
MiningPoolStatsFetch::getInstance().getPool()->getDailyEarningsLabel(), MiningPoolStatsFetch::getInstance().getPool()->getDailyEarningsLabel(),
*MiningPoolStatsFetch::getInstance().getPool()); *MiningPoolStatsFetch::getInstance().getPool());
setEpdContent(taskEpdContent); EPDManager::getInstance().setContent(taskEpdContent);
break; break;
} }
@ -256,13 +256,13 @@ void workerTask(void *pvParameters) {
preferences.getBool("mcapBigChar", DEFAULT_MCAP_BIG_CHAR)); preferences.getBool("mcapBigChar", DEFAULT_MCAP_BIG_CHAR));
} }
setEpdContent(taskEpdContent); EPDManager::getInstance().setContent(taskEpdContent);
break; break;
} }
case TASK_FEE_UPDATE: { case TASK_FEE_UPDATE: {
if (currentScreenValue == SCREEN_BLOCK_FEE_RATE) { if (currentScreenValue == SCREEN_BLOCK_FEE_RATE) {
taskEpdContent = parseBlockFees(static_cast<std::uint16_t>(getBlockMedianFee())); taskEpdContent = parseBlockFees(static_cast<std::uint16_t>(getBlockMedianFee()));
setEpdContent(taskEpdContent); EPDManager::getInstance().setContent(taskEpdContent);
} }
break; break;
} }
@ -275,7 +275,7 @@ void workerTask(void *pvParameters) {
if (currentScreenValue == SCREEN_HALVING_COUNTDOWN || if (currentScreenValue == SCREEN_HALVING_COUNTDOWN ||
currentScreenValue == SCREEN_BLOCK_HEIGHT) { currentScreenValue == SCREEN_BLOCK_HEIGHT) {
setEpdContent(taskEpdContent); EPDManager::getInstance().setContent(taskEpdContent);
} }
break; break;
} }
@ -302,7 +302,7 @@ void workerTask(void *pvParameters) {
for (uint i = 1; i < NUM_SCREENS; i++) { for (uint i = 1; i < NUM_SCREENS; i++) {
taskEpdContent[i] = timeString[i]; taskEpdContent[i] = timeString[i];
} }
setEpdContent(taskEpdContent); EPDManager::getInstance().setContent(taskEpdContent);
} }
break; break;
@ -330,8 +330,6 @@ void setupTasks() {
xTaskCreate(taskScreenRotate, "rotateScreen", 4096, NULL, tskIDLE_PRIORITY, xTaskCreate(taskScreenRotate, "rotateScreen", 4096, NULL, tskIDLE_PRIORITY,
&taskScreenRotateTaskHandle); &taskScreenRotateTaskHandle);
waitUntilNoneBusy();
if (findScreenIndexByValue(preferences.getUInt("currentScreen", DEFAULT_CURRENT_SCREEN)) != -1) if (findScreenIndexByValue(preferences.getUInt("currentScreen", DEFAULT_CURRENT_SCREEN)) != -1)
ScreenHandler::setCurrentScreen(preferences.getUInt("currentScreen", DEFAULT_CURRENT_SCREEN)); ScreenHandler::setCurrentScreen(preferences.getUInt("currentScreen", DEFAULT_CURRENT_SCREEN));
} }

View file

@ -179,4 +179,5 @@ void HttpHelper::end(HTTPClient* http) {
http->end(); http->end();
delete http; delete http;
} }
} }

View file

@ -16,6 +16,8 @@
#include <mutex> #include <mutex>
#include <utils.hpp> #include <utils.hpp>
#include <array>
#include <string>
#include "defaults.hpp" #include "defaults.hpp"
@ -118,4 +120,5 @@ private:
static WiFiClientSecure secureClient; static WiFiClientSecure secureClient;
static bool certBundleSet; static bool certBundleSet;
static WiFiClient insecureClient; static WiFiClient insecureClient;
}; };

View file

@ -106,6 +106,11 @@ namespace V2Notify
JsonDocument doc; JsonDocument doc;
DeserializationError error = deserializeMsgPack(doc, payload, length); DeserializationError error = deserializeMsgPack(doc, payload, length);
if (error) {
Serial.println(F("Error deserializing message"));
break;
}
V2Notify::handleV2Message(doc); V2Notify::handleV2Message(doc);
break; break;
} }

View file

@ -309,7 +309,7 @@ void eventSourceUpdate() {
doc["leds"] = getLedStatusObject()["data"]; doc["leds"] = getLedStatusObject()["data"];
// Get current EPD content directly as array // Get current EPD content directly as array
std::array<String, NUM_SCREENS> epdContent = getCurrentEpdContent(); std::array<String, NUM_SCREENS> epdContent = EPDManager::getInstance().getCurrentContent();
// Add EPD content arrays // Add EPD content arrays
JsonArray data = doc["data"].to<JsonArray>(); JsonArray data = doc["data"].to<JsonArray>();
@ -336,7 +336,7 @@ void onApiStatus(AsyncWebServerRequest *request)
JsonDocument root = getStatusObject(); JsonDocument root = getStatusObject();
// Get current EPD content directly as array // Get current EPD content directly as array
std::array<String, NUM_SCREENS> epdContent = getCurrentEpdContent(); std::array<String, NUM_SCREENS> epdContent = EPDManager::getInstance().getCurrentContent();
// Add EPD content arrays // Add EPD content arrays
JsonArray data = root["data"].to<JsonArray>(); JsonArray data = root["data"].to<JsonArray>();
@ -378,11 +378,9 @@ void onApiActionTimerRestart(AsyncWebServerRequest *request)
*/ */
void onApiFullRefresh(AsyncWebServerRequest *request) void onApiFullRefresh(AsyncWebServerRequest *request)
{ {
forceFullRefresh(); EPDManager::getInstance().forceFullRefresh();
std::array<String, NUM_SCREENS> newEpdContent = getCurrentEpdContent(); std::array<String, NUM_SCREENS> newEpdContent = EPDManager::getInstance().getCurrentContent();
EPDManager::getInstance().setContent(newEpdContent, true);
setEpdContent(newEpdContent, true);
request->send(HTTP_OK); request->send(HTTP_OK);
} }
@ -429,7 +427,7 @@ void onApiShowText(AsyncWebServerRequest *request)
textEpdContent[i] = t[i]; textEpdContent[i] = t[i];
} }
setEpdContent(textEpdContent); EPDManager::getInstance().setContent(textEpdContent);
} }
ScreenHandler::setCurrentScreen(SCREEN_CUSTOM); ScreenHandler::setCurrentScreen(SCREEN_CUSTOM);
request->send(HTTP_OK); request->send(HTTP_OK);
@ -447,7 +445,7 @@ void onApiShowTextAdvanced(AsyncWebServerRequest *request, JsonVariant &json)
i++; i++;
} }
setEpdContent(epdContent); EPDManager::getInstance().setContent(epdContent);
ScreenHandler::setCurrentScreen(SCREEN_CUSTOM); ScreenHandler::setCurrentScreen(SCREEN_CUSTOM);
request->send(HTTP_OK); request->send(HTTP_OK);
@ -475,13 +473,13 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json)
if (inverted) { if (inverted) {
preferences.putUInt("fgColor", GxEPD_WHITE); preferences.putUInt("fgColor", GxEPD_WHITE);
preferences.putUInt("bgColor", GxEPD_BLACK); preferences.putUInt("bgColor", GxEPD_BLACK);
setFgColor(GxEPD_WHITE); EPDManager::getInstance().setForegroundColor(GxEPD_WHITE);
setBgColor(GxEPD_BLACK); EPDManager::getInstance().setBackgroundColor(GxEPD_BLACK);
} else { } else {
preferences.putUInt("fgColor", GxEPD_BLACK); preferences.putUInt("fgColor", GxEPD_BLACK);
preferences.putUInt("bgColor", GxEPD_WHITE); preferences.putUInt("bgColor", GxEPD_WHITE);
setFgColor(GxEPD_BLACK); EPDManager::getInstance().setForegroundColor(GxEPD_BLACK);
setBgColor(GxEPD_WHITE); EPDManager::getInstance().setBackgroundColor(GxEPD_WHITE);
} }
Serial.printf("Setting invertedColor to %d\r\n", inverted); Serial.printf("Setting invertedColor to %d\r\n", inverted);
settingsChanged = true; settingsChanged = true;
@ -680,7 +678,7 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
JsonDocument root; JsonDocument root;
root["numScreens"] = NUM_SCREENS; root["numScreens"] = NUM_SCREENS;
root["invertedColor"] = preferences.getBool("invertedColor", getFgColor() == GxEPD_WHITE); root["invertedColor"] = preferences.getBool("invertedColor", EPDManager::getInstance().getForegroundColor() == GxEPD_WHITE);
root["timerSeconds"] = getTimerSeconds(); root["timerSeconds"] = getTimerSeconds();
root["timerRunning"] = isTimerActive(); root["timerRunning"] = isTimerActive();
root["minSecPriceUpd"] = preferences.getUInt( root["minSecPriceUpd"] = preferences.getUInt(
@ -818,7 +816,7 @@ bool processEpdColorSettings(AsyncWebServerRequest *request)
const AsyncWebParameter *fgColor = request->getParam("fgColor", true); const AsyncWebParameter *fgColor = request->getParam("fgColor", true);
uint32_t color = strtol(fgColor->value().c_str(), NULL, 16); uint32_t color = strtol(fgColor->value().c_str(), NULL, 16);
preferences.putUInt("fgColor", color); preferences.putUInt("fgColor", color);
setFgColor(color); EPDManager::getInstance().setForegroundColor(color);
// Serial.print(F("Setting foreground color to ")); // Serial.print(F("Setting foreground color to "));
// Serial.println(fgColor->value().c_str()); // Serial.println(fgColor->value().c_str());
settingsChanged = true; settingsChanged = true;
@ -829,7 +827,7 @@ bool processEpdColorSettings(AsyncWebServerRequest *request)
uint32_t color = strtol(bgColor->value().c_str(), NULL, 16); uint32_t color = strtol(bgColor->value().c_str(), NULL, 16);
preferences.putUInt("bgColor", color); preferences.putUInt("bgColor", color);
setBgColor(color); EPDManager::getInstance().setBackgroundColor(color);
// Serial.print(F("Setting background color to ")); // Serial.print(F("Setting background color to "));
// Serial.println(bgColor->value().c_str()); // Serial.println(bgColor->value().c_str());
settingsChanged = true; settingsChanged = true;
@ -1202,7 +1200,7 @@ void onApiLightsGet(AsyncWebServerRequest *request)
auto& ledHandler = getLedHandler(); auto& ledHandler = getLedHandler();
auto& pixels = ledHandler.getPixels(); auto& pixels = ledHandler.getPixels();
DynamicJsonDocument doc(1024); JsonDocument doc;
JsonArray lights = doc.createNestedArray("lights"); JsonArray lights = doc.createNestedArray("lights");
for (uint i = 0; i < pixels.numPixels(); i++) for (uint i = 0; i < pixels.numPixels(); i++)
@ -1225,7 +1223,7 @@ void onApiLightsPost(AsyncWebServerRequest *request, uint8_t *data, size_t len,
auto& ledHandler = getLedHandler(); auto& ledHandler = getLedHandler();
auto& pixels = ledHandler.getPixels(); auto& pixels = ledHandler.getPixels();
DynamicJsonDocument doc(1024); JsonDocument doc;
DeserializationError error = deserializeJson(doc, data); DeserializationError error = deserializeJson(doc, data);
if (error) if (error)
{ {