From 76106e7afe931a4c1f229349c2a5e3e6e406256f Mon Sep 17 00:00:00 2001 From: Thomas Ballmann Date: Sat, 26 Dec 2020 10:44:06 +0100 Subject: [PATCH] #54 refactor playlist to be more dynamic --- lib/playlist/playlist.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/playlist/playlist.cpp b/lib/playlist/playlist.cpp index a4f1744..48f2861 100644 --- a/lib/playlist/playlist.cpp +++ b/lib/playlist/playlist.cpp @@ -2,22 +2,27 @@ #include "settings.h" #include "faceWeather.h" #include "faceCalendar.h" +#include "faceSplash.h" +#include "faceToday.h" #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) -typedef void (*Face)(); -typedef Face FaceList[]; +typedef void (*Callable)(); typedef struct { - Face face; String name; + Callable show; + Callable setup; + Callable loop; } FaceAndName; typedef FaceAndName FaceAndNameList[]; // List of faces to cycle through FaceAndNameList faces = { - {playlistFaceWeather, "Weather"}, - {playlistFaceCalendar, "Calendar"}, + {"Weather", showFaceWeather, setupFaceWeather, loopFaceWeather}, + {"Today", showFaceToday, setupFaceToday, loopFaceToday}, + // {"Splash", showFaceSplash, setupFaceSplash, loopFaceSplash}, + {"Calendar", showFaceCalendar, setupFaceCalendar, loopFaceCalendar}, }; const uint8_t faceCount = ARRAY_SIZE(faces); @@ -38,12 +43,11 @@ void setupPlaylist() timer = 30000; } - setupFaceWeather(); - setupFaceCalendar(); - - //Serial.print(" Timeout is: "); - //Serial.print(timer); - //Serial.println(""); + // setup faces + for (uint8_t i = 0; i < faceCount; i++) + { + faces[i].setup(); + } // force instant update lastSwitch = millis() - timer; @@ -51,8 +55,11 @@ void setupPlaylist() void loopPlaylist() { - loopFaceWeather(); - loopFaceCalendar(); + // loop faces + for (uint8_t i = 0; i < faceCount; i++) + { + faces[i].loop(); + } if (PlaylistGetRemainingTimeMs() <= 0) // && autoplayEnabled { @@ -60,7 +67,7 @@ void loopPlaylist() PlaylistNextFace(); Serial.println("switch face: " + faces[currentFaceIndex].name); - faces[currentFaceIndex].face(); + faces[currentFaceIndex].show(); } }