From aeae08e1c0fee901117a90ecc687b34c4d64d557 Mon Sep 17 00:00:00 2001 From: Thomas Ballmann Date: Wed, 18 Mar 2020 11:56:12 +0100 Subject: [PATCH] small refactoring how the playlist works. allow faces to do working stuff in a loop thread --- include/faceCalendar.h | 1 + include/faceWeather.h | 1 + src/faceCalendar.cpp | 6 ++++++ src/faceWeather.cpp | 15 +++++++++++++++ src/playlist.cpp | 7 +++++-- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/faceCalendar.h b/include/faceCalendar.h index e868d01..7c8c353 100644 --- a/include/faceCalendar.h +++ b/include/faceCalendar.h @@ -4,6 +4,7 @@ void setupFaceCalendar(); void loopFaceCalendar(); +void playlistFaceCalendar(); bool updateCalendarData(); #endif \ No newline at end of file diff --git a/include/faceWeather.h b/include/faceWeather.h index a20b298..16807b0 100644 --- a/include/faceWeather.h +++ b/include/faceWeather.h @@ -37,6 +37,7 @@ extern faceWeatherData weatherData; void setupFaceWeather(); void loopFaceWeather(); +void playlistFaceWeather(); bool updateWeatherData(); diff --git a/src/faceCalendar.cpp b/src/faceCalendar.cpp index b01b884..6a6be36 100644 --- a/src/faceCalendar.cpp +++ b/src/faceCalendar.cpp @@ -31,6 +31,12 @@ void setupFaceCalendar() } void loopFaceCalendar() +{ + //downloadRandomePicture(); + //downloadFile("https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0&w=390&h=384&fm=png&fit=crop&duotone=000000,FFFFFF", "/tom"); +} + +void playlistFaceCalendar() { // TODO update picture every x seconds showFaceCalendar(); diff --git a/src/faceWeather.cpp b/src/faceWeather.cpp index ca2b45f..04f169a 100644 --- a/src/faceWeather.cpp +++ b/src/faceWeather.cpp @@ -5,6 +5,7 @@ #include "display.h" #include "download.h" #include "settings.h" +#include "datetime.h" #include // current day #include // current day @@ -13,6 +14,8 @@ const char faceWeatherCurrent[] = "/weatherCurrent.json"; const char faceWeatherForecast[] = "/weatherForecast.json"; faceWeatherData weatherData; +unsigned long lastWeatherDataUpdate = 0; + void render_current(); void render_forecast(); bool readWeatherData(); @@ -20,9 +23,21 @@ bool readWeatherData(); void setupFaceWeather() { readWeatherData(); + lastWeatherDataUpdate = millis(); } void loopFaceWeather() +{ + // update every 10 min + if ((millis() - lastWeatherDataUpdate) >= 600000) + { + Serial.println(&now, "update weather data @ %A, %B %d %Y %H:%M:%S"); + lastWeatherDataUpdate = millis(); + updateWeatherData(); + } +} + +void playlistFaceWeather() { display.setRotation(0); display.setFullWindow(); diff --git a/src/playlist.cpp b/src/playlist.cpp index c07b07c..a4f1744 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -16,8 +16,8 @@ typedef FaceAndName FaceAndNameList[]; // List of faces to cycle through FaceAndNameList faces = { - {loopFaceWeather, "Weather"}, - {loopFaceCalendar, "Calendar"}, + {playlistFaceWeather, "Weather"}, + {playlistFaceCalendar, "Calendar"}, }; const uint8_t faceCount = ARRAY_SIZE(faces); @@ -51,6 +51,9 @@ void setupPlaylist() void loopPlaylist() { + loopFaceWeather(); + loopFaceCalendar(); + if (PlaylistGetRemainingTimeMs() <= 0) // && autoplayEnabled { PlaylistResetTimer();