#54 refactor playlist to be more dynamic

pull/1/head
Thomas Ballmann 3 years ago
parent 153b5d9811
commit 76106e7afe

@ -2,22 +2,27 @@
#include "settings.h" #include "settings.h"
#include "faceWeather.h" #include "faceWeather.h"
#include "faceCalendar.h" #include "faceCalendar.h"
#include "faceSplash.h"
#include "faceToday.h"
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
typedef void (*Face)(); typedef void (*Callable)();
typedef Face FaceList[];
typedef struct typedef struct
{ {
Face face;
String name; String name;
Callable show;
Callable setup;
Callable loop;
} FaceAndName; } FaceAndName;
typedef FaceAndName FaceAndNameList[]; typedef FaceAndName FaceAndNameList[];
// List of faces to cycle through // List of faces to cycle through
FaceAndNameList faces = { FaceAndNameList faces = {
{playlistFaceWeather, "Weather"}, {"Weather", showFaceWeather, setupFaceWeather, loopFaceWeather},
{playlistFaceCalendar, "Calendar"}, {"Today", showFaceToday, setupFaceToday, loopFaceToday},
// {"Splash", showFaceSplash, setupFaceSplash, loopFaceSplash},
{"Calendar", showFaceCalendar, setupFaceCalendar, loopFaceCalendar},
}; };
const uint8_t faceCount = ARRAY_SIZE(faces); const uint8_t faceCount = ARRAY_SIZE(faces);
@ -38,12 +43,11 @@ void setupPlaylist()
timer = 30000; timer = 30000;
} }
setupFaceWeather(); // setup faces
setupFaceCalendar(); for (uint8_t i = 0; i < faceCount; i++)
{
//Serial.print(" Timeout is: "); faces[i].setup();
//Serial.print(timer); }
//Serial.println("");
// force instant update // force instant update
lastSwitch = millis() - timer; lastSwitch = millis() - timer;
@ -51,8 +55,11 @@ void setupPlaylist()
void loopPlaylist() void loopPlaylist()
{ {
loopFaceWeather(); // loop faces
loopFaceCalendar(); for (uint8_t i = 0; i < faceCount; i++)
{
faces[i].loop();
}
if (PlaylistGetRemainingTimeMs() <= 0) // && autoplayEnabled if (PlaylistGetRemainingTimeMs() <= 0) // && autoplayEnabled
{ {
@ -60,7 +67,7 @@ void loopPlaylist()
PlaylistNextFace(); PlaylistNextFace();
Serial.println("switch face: " + faces[currentFaceIndex].name); Serial.println("switch face: " + faces[currentFaceIndex].name);
faces[currentFaceIndex].face(); faces[currentFaceIndex].show();
} }
} }

Loading…
Cancel
Save