From 525798cf248b06c24673108ea633c372b93c2339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Wed, 20 Dec 2023 07:30:04 +0100 Subject: [PATCH] Rework part 1: task-based clock feed --- platformio.ini | 1 + src/main.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index f92d3d2..17eab71 100644 --- a/platformio.ini +++ b/platformio.ini @@ -55,3 +55,4 @@ lib_deps = https://github.com/Bodmer/OpenFontRender#f163cc6 ; no tags or releases to reference :( -> pin to Git revision squix78/JsonStreamingParser@~1.0.5 thingpulse/ESP8266 Weather Station@~2.2.0 + arkhipenko/TaskScheduler@~3.7.0 diff --git a/src/main.cpp b/src/main.cpp index 094e282..f59b0d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "connectivity.h" #include "display.h" @@ -41,6 +42,8 @@ const int16_t centerWidth = tft.width() / 2; OpenWeatherMapCurrentData currentWeather; OpenWeatherMapForecastData forecasts[NUMBER_OF_FORECASTS]; +Scheduler scheduler; + // ---------------------------------------------------------------------------- @@ -60,6 +63,9 @@ void repaint(); void updateData(boolean updateProgressBar); +Task clockTask(1000, TASK_FOREVER, &drawTimeAndDate); + + // ---------------------------------------------------------------------------- // setup() & loop() @@ -79,6 +85,10 @@ void setup(void) { initFileSystem(); initOpenFontRender(); + + scheduler.init(); + scheduler.addTask(clockTask); + clockTask.enable(); } void loop(void) { @@ -89,10 +99,7 @@ void loop(void) { lastUpdateMillis == 0 || (millis() - lastUpdateMillis) > updateIntervalMillis) { repaint(); - } else { - drawTimeAndDate(); } - delay(1000); // if (ts.touched()) { // TS_Point p = ts.getPoint(); @@ -104,6 +111,7 @@ void loop(void) { // // Debouncing; avoid returning the same touch multiple times. // delay(50); // } + scheduler.execute(); }