Added initial Melody Playback Ability

Now, controlled via MQTT a Playback of a melody can Start, Stop, Pause 
etc. 

Settings like speed, total duration, pauses etc can be set.
This commit is contained in:
2025-01-19 21:15:07 +02:00
parent 2cbbc8d591
commit a33f626dde
36 changed files with 4263 additions and 236 deletions

View File

@@ -0,0 +1,78 @@
#line 1 "C:\\Users\\espi_\\Documents\\Arduino\\vesper\\bellEngine.hpp"
// MELODY PLAYBACK WILL BE HANDLED HERE
#include <vector>
extern volatile bool playing;
extern melody_attributes melody;
extern uint16_t relayMask;
extern bool forceStop;
void loop_playback(std::vector<uint16_t> &melody_steps);
void itsHammerTime(uint16_t note);
void bellEngine(void *parameter) {
// SETUP TASK
for (;;) {
// Playback until stopped (Completes AT LEAST 1 full loop)
loop_playback(melody_steps);
/*
UBaseType_t highWaterMark = uxTaskGetStackHighWaterMark(NULL);
Serial.print("Stack high water mark: ");
Serial.println(highWaterMark);
*/
}
}
void loop_playback(std::vector<uint16_t> &melody_steps) {
while(playing){
// iterate through the beats and call the bell mechanism on each beat
for (uint16_t note : melody_steps) {
if (forceStop) return;
itsHammerTime(note);
int tempo = melody.speed;
vTaskDelay(pdMS_TO_TICKS(tempo));
}
// pause for "interval_duration"
vTaskDelay(pdMS_TO_TICKS(melody.interval_duration));
// pause for standard "breath-out" duration if interval was less than 3000ms
if (melody.interval_duration<3000) vTaskDelay(pdMS_TO_TICKS(3000));
}
}
void itsHammerTime(uint16_t note){
// THIS NEEDS REWORK, TO WAIT, DYNAMICLY PER RELAY
// MUST BE CONFIGURABLE REMOTELY
for (uint8_t i=0; i<16; i++) {
if (note & (1 << i)) {
relays.digitalWrite(i, LOW);
}
}
vTaskDelay(pdMS_TO_TICKS(relayDurations[0]));
for (uint8_t i=0; i<16; i++) {
relays.digitalWrite(i, HIGH);
}
}