Improvents to prevent display artifacts

This commit is contained in:
Djuri Baars 2023-11-13 12:27:34 +01:00
parent f92db527e1
commit 8d8785df1d
8 changed files with 38 additions and 40 deletions

View file

@ -119,7 +119,6 @@ void onWebsocketEvent(void *handler_args, esp_event_base_t base, int32_t event_i
break; break;
case WEBSOCKET_EVENT_DATA: case WEBSOCKET_EVENT_DATA:
onWebsocketMessage(data); onWebsocketMessage(data);
// Handle the received WebSocket message (block notifications) here
break; break;
case WEBSOCKET_EVENT_ERROR: case WEBSOCKET_EVENT_ERROR:
Serial.println(F("Mempool.space WS Connnection error")); Serial.println(F("Mempool.space WS Connnection error"));
@ -143,8 +142,7 @@ void onWebsocketMessage(esp_websocket_event_data_t *event_data)
currentBlockHeight = block["height"].as<uint>(); currentBlockHeight = block["height"].as<uint>();
Serial.printf("New block found: %d\r\n", block["height"].as<uint>()); Serial.printf("New block found: %d\r\n", block["height"].as<uint>());
size_t prefWrite = preferences.putUInt("blockHeight", currentBlockHeight); preferences.putUInt("blockHeight", currentBlockHeight);
Serial.printf("Wrote %d for block\r\n", prefWrite);
if (workQueue != nullptr) if (workQueue != nullptr)
{ {
@ -154,7 +152,16 @@ void onWebsocketMessage(esp_websocket_event_data_t *event_data)
if (getCurrentScreen() != SCREEN_BLOCK_HEIGHT && preferences.getBool("stealFocus", true)) if (getCurrentScreen() != SCREEN_BLOCK_HEIGHT && preferences.getBool("stealFocus", true))
{ {
uint64_t timerPeriod = 0;
if (isTimerActive()) {
// store timer periode before making inactive to prevent artifacts
timerPeriod = getTimerSeconds();
esp_timer_stop(screenRotateTimer);
}
setCurrentScreen(SCREEN_BLOCK_HEIGHT); setCurrentScreen(SCREEN_BLOCK_HEIGHT);
if (timerPeriod > 0) {
esp_timer_start_periodic(screenRotateTimer, timerPeriod * usPerSecond);
}
} }
if (getCurrentScreen() == SCREEN_BLOCK_HEIGHT && preferences.getBool("ledFlashOnUpd", false)) if (getCurrentScreen() == SCREEN_BLOCK_HEIGHT && preferences.getBool("ledFlashOnUpd", false))

View file

@ -6,7 +6,7 @@
#include <HTTPClient.h> #include <HTTPClient.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "shared.hpp" #include "shared.hpp"
#include "esp_timer.h"
#include "esp_websocket_client.h" #include "esp_websocket_client.h"
#include "screen_handler.hpp" #include "screen_handler.hpp"
#include "led_handler.hpp" #include "led_handler.hpp"

View file

@ -58,7 +58,7 @@ TaskHandle_t tasks[NUM_SCREENS];
#define UPDATE_QUEUE_SIZE 14 #define UPDATE_QUEUE_SIZE 14
QueueHandle_t updateQueue; QueueHandle_t updateQueue;
SemaphoreHandle_t epdUpdateSemaphore[NUM_SCREENS]; //SemaphoreHandle_t epdUpdateSemaphore[NUM_SCREENS];
int fgColor = GxEPD_WHITE; int fgColor = GxEPD_WHITE;
int bgColor = GxEPD_BLACK; int bgColor = GxEPD_BLACK;
@ -66,6 +66,8 @@ int bgColor = GxEPD_BLACK;
#define FONT_SMALL Antonio_SemiBold20pt7b #define FONT_SMALL Antonio_SemiBold20pt7b
#define FONT_BIG Antonio_SemiBold90pt7b #define FONT_BIG Antonio_SemiBold90pt7b
std::mutex epdUpdateMutex;
uint8_t qrcode[800]; uint8_t qrcode[800];
void forceFullRefresh() void forceFullRefresh()
@ -89,8 +91,8 @@ void setupDisplays()
for (uint i = 0; i < NUM_SCREENS; i++) for (uint i = 0; i < NUM_SCREENS; i++)
{ {
epdUpdateSemaphore[i] = xSemaphoreCreateBinary(); // epdUpdateSemaphore[i] = xSemaphoreCreateBinary();
xSemaphoreGive(epdUpdateSemaphore[i]); // xSemaphoreGive(epdUpdateSemaphore[i]);
int *taskParam = new int; int *taskParam = new int;
*taskParam = i; *taskParam = i;
@ -116,6 +118,8 @@ void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent)
void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent, bool forceUpdate) void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent, bool forceUpdate)
{ {
std::lock_guard<std::mutex> lock(epdUpdateMutex);
for (uint i = 0; i < NUM_SCREENS; i++) for (uint i = 0; i < NUM_SCREENS; i++)
{ {
if (newEpdContent[i].compareTo(currentEpdContent[i]) != 0 || forceUpdate) if (newEpdContent[i].compareTo(currentEpdContent[i]) != 0 || forceUpdate)
@ -123,15 +127,8 @@ void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent, bool forceUpda
epdContent[i] = newEpdContent[i]; epdContent[i] = newEpdContent[i];
UpdateDisplayTaskItem dispUpdate = {i}; UpdateDisplayTaskItem dispUpdate = {i};
xQueueSend(updateQueue, &dispUpdate, portMAX_DELAY); xQueueSend(updateQueue, &dispUpdate, portMAX_DELAY);
// if (xSemaphoreTake(epdUpdateSemaphore[i], pdMS_TO_TICKS(5000)) == pdTRUE)
// {
// xTaskNotifyGive(tasks[i]);
// }
} }
} }
if (eventSourceTaskHandle != NULL)
xTaskNotifyGive(eventSourceTaskHandle);
} }
void prepareDisplayUpdateTask(void *pvParameters) void prepareDisplayUpdateTask(void *pvParameters)
@ -191,22 +188,17 @@ extern "C" void updateDisplay(void *pvParameters) noexcept
// Wait for the task notification // Wait for the task notification
ulTaskNotifyTake(pdTRUE, portMAX_DELAY); ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
// if (xSemaphoreTake(epdUpdateSemaphore[epdIndex], pdMS_TO_TICKS(5000)) == pdTRUE)
// {
uint count = 0; uint count = 0;
while (EPD_BUSY[epdIndex].digitalRead() == HIGH || count < 10) while (EPD_BUSY[epdIndex].digitalRead() == HIGH || count < 10)
{ {
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelay(pdMS_TO_TICKS(100));
// if (count >= 9)
// {
// displays[epdIndex].init(0, false);
// }
count++; count++;
} }
bool updatePartial = true; bool updatePartial = true;
// Full Refresh every half hour // Full Refresh every x minutes
if (!lastFullRefresh[epdIndex] || (millis() - lastFullRefresh[epdIndex]) > (preferences.getUInt("fullRefreshMin", 30) * 60 * 1000)) if (!lastFullRefresh[epdIndex] || (millis() - lastFullRefresh[epdIndex]) > (preferences.getUInt("fullRefreshMin", 30) * 60 * 1000))
{ {
updatePartial = false; updatePartial = false;
@ -222,14 +214,15 @@ extern "C" void updateDisplay(void *pvParameters) noexcept
if (!updatePartial) if (!updatePartial)
lastFullRefresh[epdIndex] = millis(); lastFullRefresh[epdIndex] = millis();
break; break;
if (eventSourceTaskHandle != NULL)
xTaskNotifyGive(eventSourceTaskHandle);
} }
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelay(pdMS_TO_TICKS(100));
tries++; tries++;
} }
// xSemaphoreGive(epdUpdateSemaphore[epdIndex]);
// }
} }
} }
@ -334,9 +327,6 @@ void renderText(const uint dispNum, const String &text, bool partial)
displays[dispNum].fillScreen(GxEPD_WHITE); displays[dispNum].fillScreen(GxEPD_WHITE);
displays[dispNum].setTextColor(GxEPD_BLACK); displays[dispNum].setTextColor(GxEPD_BLACK);
displays[dispNum].setCursor(0, 50); displays[dispNum].setCursor(0, 50);
// displays[dispNum].setFont(&FreeSans9pt7b);
// std::regex pattern("/\*(.*)\*/");
std::stringstream ss; std::stringstream ss;
ss.str(text.c_str()); ss.str(text.c_str());
@ -358,8 +348,6 @@ void renderText(const uint dispNum, const String &text, bool partial)
displays[dispNum].println(line.c_str()); displays[dispNum].println(line.c_str());
} }
} }
// displays[dispNum].display(partial);
} }
void renderQr(const uint dispNum, const String &text, bool partial) void renderQr(const uint dispNum, const String &text, bool partial)
@ -387,10 +375,6 @@ void renderQr(const uint dispNum, const String &text, bool partial)
displays[dispNum].drawPixel(padding + x, paddingY + y, qrcodegen_getModule(qrcode, floor(float(x) / 4), floor(float(y) / 4)) ? GxEPD_BLACK : GxEPD_WHITE); displays[dispNum].drawPixel(padding + x, paddingY + y, qrcodegen_getModule(qrcode, floor(float(x) / 4), floor(float(y) / 4)) ? GxEPD_BLACK : GxEPD_WHITE);
} }
} }
// displays[dispNum].display(partial);
// free(tempBuffer);
// free(qrcode);
#endif #endif
} }
@ -403,8 +387,11 @@ void waitUntilNoneBusy()
{ {
count++; count++;
vTaskDelay(10); vTaskDelay(10);
if (count > 200) { if (count == 200) {
displays[i].init(0, false); displays[i].init(0, false);
vTaskDelay(100);
} else if (count > 205) {
break;
} }
} }
} }

View file

@ -9,6 +9,7 @@
#include <Fonts/FreeSansBold9pt7b.h> #include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSans9pt7b.h> #include <Fonts/FreeSans9pt7b.h>
#include <regex> #include <regex>
#include <mutex>
#ifdef USE_QR #ifdef USE_QR
#include "qrcodegen.h" #include "qrcodegen.h"

View file

@ -10,8 +10,7 @@ esp_timer_handle_t minuteTimer;
std::array<String, NUM_SCREENS> taskEpdContent = {"", "", "", "", "", "", ""}; std::array<String, NUM_SCREENS> taskEpdContent = {"", "", "", "", "", "", ""};
std::string priceString; std::string priceString;
const int usPerSecond = 1000000;
const int usPerMinute = 60 * usPerSecond;
// typedef enum // typedef enum
// { // {

View file

@ -21,6 +21,8 @@ const PROGMEM int SCREEN_COUNTDOWN = 98;
const PROGMEM int SCREEN_CUSTOM = 99; const PROGMEM int SCREEN_CUSTOM = 99;
const int SCREEN_COUNT = 6; const int SCREEN_COUNT = 6;
const PROGMEM int screens[SCREEN_COUNT] = { SCREEN_BLOCK_HEIGHT, SCREEN_MSCW_TIME, SCREEN_BTC_TICKER, SCREEN_TIME, SCREEN_HALVING_COUNTDOWN, SCREEN_MARKET_CAP }; const PROGMEM int screens[SCREEN_COUNT] = { SCREEN_BLOCK_HEIGHT, SCREEN_MSCW_TIME, SCREEN_BTC_TICKER, SCREEN_TIME, SCREEN_HALVING_COUNTDOWN, SCREEN_MARKET_CAP };
const int usPerSecond = 1000000;
const int usPerMinute = 60 * usPerSecond;
struct SpiRamAllocator { struct SpiRamAllocator {
void* allocate(size_t size) { void* allocate(size_t size) {

View file

@ -12,6 +12,7 @@ void setupWebserver()
return; return;
} }
events.onConnect([](AsyncEventSourceClient *client) events.onConnect([](AsyncEventSourceClient *client)
{ client->send("welcome", NULL, millis(), 1000); }); { client->send("welcome", NULL, millis(), 1000); });
server.addHandler(&events); server.addHandler(&events);
@ -280,8 +281,8 @@ bool processEpdColorSettings(AsyncWebServerRequest *request)
AsyncWebParameter *fgColor = request->getParam("fgColor", true); AsyncWebParameter *fgColor = request->getParam("fgColor", true);
preferences.putUInt("fgColor", strtol(fgColor->value().c_str(), NULL, 16)); preferences.putUInt("fgColor", strtol(fgColor->value().c_str(), NULL, 16));
setFgColor(int(strtol(fgColor->value().c_str(), NULL, 16))); setFgColor(int(strtol(fgColor->value().c_str(), NULL, 16)));
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;
} }
if (request->hasParam("bgColor", true)) if (request->hasParam("bgColor", true))
@ -290,8 +291,8 @@ bool processEpdColorSettings(AsyncWebServerRequest *request)
preferences.putUInt("bgColor", strtol(bgColor->value().c_str(), NULL, 16)); preferences.putUInt("bgColor", strtol(bgColor->value().c_str(), NULL, 16));
setBgColor(int(strtol(bgColor->value().c_str(), NULL, 16))); setBgColor(int(strtol(bgColor->value().c_str(), NULL, 16)));
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;
} }

View file

@ -5,6 +5,7 @@
#include "lib/config.hpp" #include "lib/config.hpp"
#define USE_QR #define USE_QR
//char ptrTaskList[400]; //char ptrTaskList[400];
extern "C" void app_main() extern "C" void app_main()