Improvents to prevent display artifacts
This commit is contained in:
parent
f92db527e1
commit
8d8785df1d
8 changed files with 38 additions and 40 deletions
|
@ -119,7 +119,6 @@ void onWebsocketEvent(void *handler_args, esp_event_base_t base, int32_t event_i
|
|||
break;
|
||||
case WEBSOCKET_EVENT_DATA:
|
||||
onWebsocketMessage(data);
|
||||
// Handle the received WebSocket message (block notifications) here
|
||||
break;
|
||||
case WEBSOCKET_EVENT_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>();
|
||||
|
||||
Serial.printf("New block found: %d\r\n", block["height"].as<uint>());
|
||||
size_t prefWrite = preferences.putUInt("blockHeight", currentBlockHeight);
|
||||
Serial.printf("Wrote %d for block\r\n", prefWrite);
|
||||
preferences.putUInt("blockHeight", currentBlockHeight);
|
||||
|
||||
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))
|
||||
{
|
||||
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);
|
||||
if (timerPeriod > 0) {
|
||||
esp_timer_start_periodic(screenRotateTimer, timerPeriod * usPerSecond);
|
||||
}
|
||||
}
|
||||
|
||||
if (getCurrentScreen() == SCREEN_BLOCK_HEIGHT && preferences.getBool("ledFlashOnUpd", false))
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <HTTPClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include "shared.hpp"
|
||||
|
||||
#include "esp_timer.h"
|
||||
#include "esp_websocket_client.h"
|
||||
#include "screen_handler.hpp"
|
||||
#include "led_handler.hpp"
|
||||
|
|
|
@ -58,7 +58,7 @@ TaskHandle_t tasks[NUM_SCREENS];
|
|||
#define UPDATE_QUEUE_SIZE 14
|
||||
QueueHandle_t updateQueue;
|
||||
|
||||
SemaphoreHandle_t epdUpdateSemaphore[NUM_SCREENS];
|
||||
//SemaphoreHandle_t epdUpdateSemaphore[NUM_SCREENS];
|
||||
|
||||
int fgColor = GxEPD_WHITE;
|
||||
int bgColor = GxEPD_BLACK;
|
||||
|
@ -66,6 +66,8 @@ int bgColor = GxEPD_BLACK;
|
|||
#define FONT_SMALL Antonio_SemiBold20pt7b
|
||||
#define FONT_BIG Antonio_SemiBold90pt7b
|
||||
|
||||
std::mutex epdUpdateMutex;
|
||||
|
||||
uint8_t qrcode[800];
|
||||
|
||||
void forceFullRefresh()
|
||||
|
@ -89,8 +91,8 @@ void setupDisplays()
|
|||
|
||||
for (uint i = 0; i < NUM_SCREENS; i++)
|
||||
{
|
||||
epdUpdateSemaphore[i] = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(epdUpdateSemaphore[i]);
|
||||
// epdUpdateSemaphore[i] = xSemaphoreCreateBinary();
|
||||
// xSemaphoreGive(epdUpdateSemaphore[i]);
|
||||
|
||||
int *taskParam = new int;
|
||||
*taskParam = i;
|
||||
|
@ -116,6 +118,8 @@ void setEpdContent(std::array<String, NUM_SCREENS> newEpdContent)
|
|||
|
||||
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++)
|
||||
{
|
||||
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];
|
||||
UpdateDisplayTaskItem dispUpdate = {i};
|
||||
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)
|
||||
|
@ -191,22 +188,17 @@ extern "C" void updateDisplay(void *pvParameters) noexcept
|
|||
// Wait for the task notification
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
|
||||
// if (xSemaphoreTake(epdUpdateSemaphore[epdIndex], pdMS_TO_TICKS(5000)) == pdTRUE)
|
||||
// {
|
||||
|
||||
uint count = 0;
|
||||
while (EPD_BUSY[epdIndex].digitalRead() == HIGH || count < 10)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
// if (count >= 9)
|
||||
// {
|
||||
// displays[epdIndex].init(0, false);
|
||||
// }
|
||||
count++;
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
updatePartial = false;
|
||||
|
@ -222,14 +214,15 @@ extern "C" void updateDisplay(void *pvParameters) noexcept
|
|||
if (!updatePartial)
|
||||
lastFullRefresh[epdIndex] = millis();
|
||||
break;
|
||||
|
||||
|
||||
if (eventSourceTaskHandle != NULL)
|
||||
xTaskNotifyGive(eventSourceTaskHandle);
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
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].setTextColor(GxEPD_BLACK);
|
||||
displays[dispNum].setCursor(0, 50);
|
||||
// displays[dispNum].setFont(&FreeSans9pt7b);
|
||||
|
||||
// std::regex pattern("/\*(.*)\*/");
|
||||
|
||||
std::stringstream ss;
|
||||
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].display(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].display(partial);
|
||||
|
||||
// free(tempBuffer);
|
||||
// free(qrcode);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -403,8 +387,11 @@ void waitUntilNoneBusy()
|
|||
{
|
||||
count++;
|
||||
vTaskDelay(10);
|
||||
if (count > 200) {
|
||||
if (count == 200) {
|
||||
displays[i].init(0, false);
|
||||
vTaskDelay(100);
|
||||
} else if (count > 205) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <Fonts/FreeSansBold9pt7b.h>
|
||||
#include <Fonts/FreeSans9pt7b.h>
|
||||
#include <regex>
|
||||
#include <mutex>
|
||||
|
||||
#ifdef USE_QR
|
||||
#include "qrcodegen.h"
|
||||
|
|
|
@ -10,8 +10,7 @@ esp_timer_handle_t minuteTimer;
|
|||
|
||||
std::array<String, NUM_SCREENS> taskEpdContent = {"", "", "", "", "", "", ""};
|
||||
std::string priceString;
|
||||
const int usPerSecond = 1000000;
|
||||
const int usPerMinute = 60 * usPerSecond;
|
||||
|
||||
|
||||
// typedef enum
|
||||
// {
|
||||
|
|
|
@ -21,6 +21,8 @@ const PROGMEM int SCREEN_COUNTDOWN = 98;
|
|||
const PROGMEM int SCREEN_CUSTOM = 99;
|
||||
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 int usPerSecond = 1000000;
|
||||
const int usPerMinute = 60 * usPerSecond;
|
||||
|
||||
struct SpiRamAllocator {
|
||||
void* allocate(size_t size) {
|
||||
|
|
|
@ -12,6 +12,7 @@ void setupWebserver()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
events.onConnect([](AsyncEventSourceClient *client)
|
||||
{ client->send("welcome", NULL, millis(), 1000); });
|
||||
server.addHandler(&events);
|
||||
|
@ -280,8 +281,8 @@ bool processEpdColorSettings(AsyncWebServerRequest *request)
|
|||
AsyncWebParameter *fgColor = request->getParam("fgColor", true);
|
||||
preferences.putUInt("fgColor", strtol(fgColor->value().c_str(), NULL, 16));
|
||||
setFgColor(int(strtol(fgColor->value().c_str(), NULL, 16)));
|
||||
Serial.print(F("Setting foreground color to "));
|
||||
Serial.println(fgColor->value().c_str());
|
||||
// Serial.print(F("Setting foreground color to "));
|
||||
// Serial.println(fgColor->value().c_str());
|
||||
settingsChanged = true;
|
||||
}
|
||||
if (request->hasParam("bgColor", true))
|
||||
|
@ -290,8 +291,8 @@ bool processEpdColorSettings(AsyncWebServerRequest *request)
|
|||
|
||||
preferences.putUInt("bgColor", strtol(bgColor->value().c_str(), NULL, 16));
|
||||
setBgColor(int(strtol(bgColor->value().c_str(), NULL, 16)));
|
||||
Serial.print(F("Setting background color to "));
|
||||
Serial.println(bgColor->value().c_str());
|
||||
// Serial.print(F("Setting background color to "));
|
||||
// Serial.println(bgColor->value().c_str());
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "lib/config.hpp"
|
||||
#define USE_QR
|
||||
|
||||
//char ptrTaskList[400];
|
||||
|
||||
extern "C" void app_main()
|
||||
|
|
Loading…
Reference in a new issue