create api endpoint for playlist

pull/1/head
Thomas Ballmann 3 years ago
parent 28c5fc569c
commit f37c30f7b1

@ -29,6 +29,7 @@ const char *jsonAppVersion = "/dist/version.json";
AppConfig appConfig;
void setupApiDevice();
void setupApiPlaylist();
void setupApiSettings();
void setupApiWifi();
void setupApiCache();
@ -89,6 +90,7 @@ void setupApp()
server.serveStatic("/fs/", SPIFFS, "/");
setupApiDevice();
setupApiPlaylist();
setupApiSettings();
setupApiWifi();
setupApiCache();
@ -130,8 +132,8 @@ void setupApp()
doc["device"]["heap"]["total"] = ESP.getHeapSize();
doc["device"]["heap"]["free"] = ESP.getFreeHeap();
doc["playlist"]["current"] = PlaylistGetCurrentFace();
doc["playlist"]["remaining"] = (PlaylistGetRemainingTimeMs() / 1000) + 3; // + face rendering time 3s
doc["playlist"]["current"] = playlistGetCurrentFace();
doc["playlist"]["remaining"] = (playlistGetRemainingTimeMs() / 1000) + 3; // + face rendering time 3s
doc["firmware"]["created"] = FW_CREATED;
doc["firmware"]["rev"] = FW_GIT_REV;
@ -163,7 +165,7 @@ void loopApp()
Serial.println("loop app update display");
// stop playlist to show the new image
PlaylistResetTimer();
playlistResetTimer();
updateDisplayRequired = false;
displayFlush();
@ -294,7 +296,7 @@ void setupApiDevice()
bool dither = strcmp(filename.c_str(), "dithering") == 0;
ImageNew(0, 0, 0, 0, dither);
PlaylistResetTimer();
playlistResetTimer();
}
ImageWriteBuffer(data, len);
@ -352,6 +354,21 @@ void setupApiDevice()
});
}
/**
* api playlist endpoint
*/
void setupApiPlaylist()
{
server.on("/api/playlist/show", HTTP_GET, [](AsyncWebServerRequest *request) {
if (request->hasParam("face")) {
playlistShow(request->getParam("face")->value().c_str());
}
request->send(200, "application/json", "{}");
});
}
/**
* api wifi endpoint
*/

@ -61,43 +61,58 @@ void loopPlaylist()
faces[i].loop();
}
if (PlaylistGetRemainingTimeMs() <= 0) // && autoplayEnabled
if (playlistGetRemainingTimeMs() <= 0) // && autoplayEnabled
{
PlaylistResetTimer();
PlaylistNextFace();
playlistResetTimer();
playlistNextFace();
Serial.println("switch face: " + faces[currentFaceIndex].name);
faces[currentFaceIndex].show();
}
}
void PlaylistNextFace()
void playlistNextFace()
{
currentFaceIndex++;
// wrap around at the ends
if (currentFaceIndex < 0)
{
currentFaceIndex = faceCount - 1;
currentFaceIndex = 0;
}
// wrap around at the ends
if (currentFaceIndex >= faceCount)
{
currentFaceIndex = 0;
}
}
String PlaylistGetCurrentFace()
String playlistGetCurrentFace()
{
return faces[currentFaceIndex].name;
}
int32_t PlaylistGetRemainingTimeMs()
int32_t playlistGetRemainingTimeMs()
{
return timer - (millis() - lastSwitch);
}
void PlaylistResetTimer()
void playlistResetTimer()
{
lastSwitch = millis();
}
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;
}
}
}

@ -6,9 +6,10 @@
void setupPlaylist();
void loopPlaylist();
void PlaylistNextFace();
String PlaylistGetCurrentFace();
int32_t PlaylistGetRemainingTimeMs();
void PlaylistResetTimer();
void playlistNextFace();
String playlistGetCurrentFace();
int32_t playlistGetRemainingTimeMs();
void playlistResetTimer();
void playlistShow(const char name[]);
#endif
Loading…
Cancel
Save