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:
68
bellEngine.hpp
Normal file
68
bellEngine.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// MELODY PLAYBACK WILL BE HANDLED HERE
|
||||
#include <vector>
|
||||
|
||||
extern melody_attributes melody;
|
||||
extern uint16_t relayMask;
|
||||
|
||||
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(melody.isPlaying && !melody.isPaused){
|
||||
|
||||
// iterate through the beats and call the bell mechanism on each beat
|
||||
for (uint16_t note : melody_steps) {
|
||||
if (melody.hardStop) return;
|
||||
itsHammerTime(note);
|
||||
int tempo = melody.speed;
|
||||
vTaskDelay(pdMS_TO_TICKS(tempo));
|
||||
}
|
||||
|
||||
Serial.println("SINGLE LOOP OVER.");
|
||||
//if (!melody.isPlaying) break; // Stop playback only after completing the loop
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user