Now, controlled via MQTT a Playback of a melody can Start, Stop, Pause etc. Settings like speed, total duration, pauses etc can be set.
79 lines
1.5 KiB
C++
79 lines
1.5 KiB
C++
#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);
|
|
}
|
|
|
|
|
|
}
|