2020-02-23 16:29:39 +00:00
|
|
|
#include "playlist.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "faceWeather.h"
|
|
|
|
#include "faceCalendar.h"
|
2020-12-26 09:44:06 +00:00
|
|
|
#include "faceSplash.h"
|
|
|
|
#include "faceToday.h"
|
2020-02-23 16:29:39 +00:00
|
|
|
|
2020-02-28 21:02:35 +00:00
|
|
|
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
|
|
|
|
|
2020-12-26 09:44:06 +00:00
|
|
|
typedef void (*Callable)();
|
2020-02-28 21:02:35 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
String name;
|
2020-12-26 09:44:06 +00:00
|
|
|
Callable show;
|
|
|
|
Callable setup;
|
|
|
|
Callable loop;
|
2020-02-28 21:02:35 +00:00
|
|
|
} FaceAndName;
|
|
|
|
typedef FaceAndName FaceAndNameList[];
|
|
|
|
|
|
|
|
// List of faces to cycle through
|
|
|
|
FaceAndNameList faces = {
|
2020-12-26 09:44:06 +00:00
|
|
|
{"Weather", showFaceWeather, setupFaceWeather, loopFaceWeather},
|
|
|
|
{"Today", showFaceToday, setupFaceToday, loopFaceToday},
|
|
|
|
// {"Splash", showFaceSplash, setupFaceSplash, loopFaceSplash},
|
|
|
|
{"Calendar", showFaceCalendar, setupFaceCalendar, loopFaceCalendar},
|
2020-02-28 21:02:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const uint8_t faceCount = ARRAY_SIZE(faces);
|
2020-02-23 16:29:39 +00:00
|
|
|
|
|
|
|
unsigned long lastSwitch = 0;
|
2020-02-28 21:02:35 +00:00
|
|
|
int32_t timer;
|
|
|
|
uint8_t currentFaceIndex = 0;
|
|
|
|
//bool autoplayEnabled = false;
|
2020-02-23 16:29:39 +00:00
|
|
|
|
|
|
|
void setupPlaylist()
|
|
|
|
{
|
|
|
|
Serial.println("setupPlaylist...");
|
2020-02-28 21:02:35 +00:00
|
|
|
|
|
|
|
// load timer
|
2020-02-23 16:29:39 +00:00
|
|
|
timer = NVS.getInt("playlist.timer") * 1000;
|
|
|
|
if (timer < 30000)
|
|
|
|
{
|
|
|
|
timer = 30000;
|
|
|
|
}
|
|
|
|
|
2020-12-26 09:44:06 +00:00
|
|
|
// setup faces
|
|
|
|
for (uint8_t i = 0; i < faceCount; i++)
|
|
|
|
{
|
|
|
|
faces[i].setup();
|
|
|
|
}
|
2020-02-28 21:02:35 +00:00
|
|
|
|
|
|
|
// force instant update
|
|
|
|
lastSwitch = millis() - timer;
|
|
|
|
}
|
2020-02-23 16:29:39 +00:00
|
|
|
|
|
|
|
void loopPlaylist()
|
|
|
|
{
|
2020-12-26 09:44:06 +00:00
|
|
|
// loop faces
|
|
|
|
for (uint8_t i = 0; i < faceCount; i++)
|
|
|
|
{
|
|
|
|
faces[i].loop();
|
|
|
|
}
|
2020-03-18 10:56:12 +00:00
|
|
|
|
2020-12-27 09:16:13 +00:00
|
|
|
if (playlistGetRemainingTimeMs() <= 0) // && autoplayEnabled
|
2020-02-23 16:29:39 +00:00
|
|
|
{
|
2020-12-27 09:16:13 +00:00
|
|
|
playlistResetTimer();
|
|
|
|
playlistNextFace();
|
2020-02-23 16:29:39 +00:00
|
|
|
|
2020-02-28 21:02:35 +00:00
|
|
|
Serial.println("switch face: " + faces[currentFaceIndex].name);
|
2020-12-26 09:44:06 +00:00
|
|
|
faces[currentFaceIndex].show();
|
2020-02-23 16:29:39 +00:00
|
|
|
}
|
2020-02-28 21:02:35 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 09:16:13 +00:00
|
|
|
void playlistNextFace()
|
2020-02-28 21:02:35 +00:00
|
|
|
{
|
|
|
|
currentFaceIndex++;
|
|
|
|
|
|
|
|
if (currentFaceIndex < 0)
|
|
|
|
{
|
2020-12-27 09:16:13 +00:00
|
|
|
currentFaceIndex = 0;
|
2020-02-28 21:02:35 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 09:16:13 +00:00
|
|
|
// wrap around at the ends
|
2020-02-28 21:02:35 +00:00
|
|
|
if (currentFaceIndex >= faceCount)
|
|
|
|
{
|
|
|
|
currentFaceIndex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-27 09:16:13 +00:00
|
|
|
String playlistGetCurrentFace()
|
2020-02-28 21:02:35 +00:00
|
|
|
{
|
|
|
|
return faces[currentFaceIndex].name;
|
|
|
|
}
|
|
|
|
|
2020-12-27 09:16:13 +00:00
|
|
|
int32_t playlistGetRemainingTimeMs()
|
2020-02-28 21:02:35 +00:00
|
|
|
{
|
|
|
|
return timer - (millis() - lastSwitch);
|
|
|
|
}
|
|
|
|
|
2020-12-27 09:16:13 +00:00
|
|
|
void playlistResetTimer()
|
2020-02-28 21:02:35 +00:00
|
|
|
{
|
|
|
|
lastSwitch = millis();
|
2020-12-27 09:16:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void playlistShow(const char name[])
|
|
|
|
{
|
|
|
|
for (uint8_t i = 0; i < faceCount; i++)
|
|
|
|
{
|
|
|
|
if (faces[i].name.equalsIgnoreCase(name))
|
|
|
|
{
|
|
|
|
Serial.println("switch to face " + faces[i].name);
|
|
|
|
|
|
|
|
currentFaceIndex = i -1;
|
|
|
|
lastSwitch = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-02-23 16:29:39 +00:00
|
|
|
}
|