Added basic Scheduling Functionality
A JSON message can now be received on: 'vesper/DEV_ID/control/addSchedule" Each message, must hold a "file" and "data". The file is the month's name in 3 letter mode (eg jan, feb, mar) The data is an entry for each day of the month. Each day can be an array containing multiple items.
This commit is contained in:
70
vesper/PlaybackControls.hpp
Normal file
70
vesper/PlaybackControls.hpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
extern Player melody;
|
||||
|
||||
bool timeToStop(unsigned long now);
|
||||
bool timeToPause(unsigned long now);
|
||||
bool timeToResume(unsigned long now);
|
||||
void durationTimer(void *param);
|
||||
|
||||
// Timer TASK to control playback state
|
||||
void durationTimer(void *param) {
|
||||
|
||||
// Task Setup
|
||||
|
||||
|
||||
// Task Loop
|
||||
while (true) {
|
||||
|
||||
unsigned long now = millis();
|
||||
|
||||
if (timeToStop(now)) {
|
||||
player.stop();
|
||||
} else if (timeToPause(now)) {
|
||||
player.pause();
|
||||
} else if (timeToResume(now)) {
|
||||
player.unpause();
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000)); // Check every 100ms
|
||||
}
|
||||
}
|
||||
|
||||
// Check if it's time to stop playback
|
||||
bool timeToStop(unsigned long now) {
|
||||
if (player.isPlaying) {
|
||||
uint64_t stopTime = player.startTime + player.duration;
|
||||
if (now >= stopTime) {
|
||||
Serial.println("TIMER: Total Duration Reached");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if it's time to pause playback
|
||||
bool timeToPause(unsigned long now) {
|
||||
if (player.isPlaying && player.loop_duration > 0) {
|
||||
uint64_t pauseTimeLimit = player.loopStartTime + player.loop_duration;
|
||||
Serial.printf("PTL: %lu // NOW: ",pauseTimeLimit);
|
||||
Serial.println(now);
|
||||
if (now >= pauseTimeLimit && !player.isPaused) {
|
||||
Serial.println("TIMER: Segment Duration Reached");
|
||||
player.pauseTime = now;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if it's time to resume playback
|
||||
bool timeToResume(unsigned long now) {
|
||||
if (player.isPaused) {
|
||||
uint64_t resumeTime = player.pauseTime + player.interval;
|
||||
if (now >= resumeTime) {
|
||||
Serial.println("TIMER: Pause Duration Reached");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user