Skip to content

Commit 525798c

Browse files
committed
Rework part 1: task-based clock feed
1 parent 22f189d commit 525798c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

platformio.ini

+1
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ lib_deps =
5555
https://github.com/Bodmer/OpenFontRender#f163cc6 ; no tags or releases to reference :( -> pin to Git revision
5656
squix78/JsonStreamingParser@~1.0.5
5757
thingpulse/ESP8266 Weather Station@~2.2.0
58+
arkhipenko/TaskScheduler@~3.7.0

src/main.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <OpenWeatherMapCurrent.h>
1414
#include <OpenWeatherMapForecast.h>
1515
#include <SunMoonCalc.h>
16+
#include <TaskScheduler.h>
1617

1718
#include "connectivity.h"
1819
#include "display.h"
@@ -41,6 +42,8 @@ const int16_t centerWidth = tft.width() / 2;
4142
OpenWeatherMapCurrentData currentWeather;
4243
OpenWeatherMapForecastData forecasts[NUMBER_OF_FORECASTS];
4344

45+
Scheduler scheduler;
46+
4447

4548

4649
// ----------------------------------------------------------------------------
@@ -60,6 +63,9 @@ void repaint();
6063
void updateData(boolean updateProgressBar);
6164

6265

66+
Task clockTask(1000, TASK_FOREVER, &drawTimeAndDate);
67+
68+
6369

6470
// ----------------------------------------------------------------------------
6571
// setup() & loop()
@@ -79,6 +85,10 @@ void setup(void) {
7985

8086
initFileSystem();
8187
initOpenFontRender();
88+
89+
scheduler.init();
90+
scheduler.addTask(clockTask);
91+
clockTask.enable();
8292
}
8393

8494
void loop(void) {
@@ -89,10 +99,7 @@ void loop(void) {
8999
lastUpdateMillis == 0 ||
90100
(millis() - lastUpdateMillis) > updateIntervalMillis) {
91101
repaint();
92-
} else {
93-
drawTimeAndDate();
94102
}
95-
delay(1000);
96103

97104
// if (ts.touched()) {
98105
// TS_Point p = ts.getPoint();
@@ -104,6 +111,7 @@ void loop(void) {
104111
// // Debouncing; avoid returning the same touch multiple times.
105112
// delay(50);
106113
// }
114+
scheduler.execute();
107115
}
108116

109117

0 commit comments

Comments
 (0)