From 4f2f0fccda7f1f1f3a4dc08b861e097e8cc922aa Mon Sep 17 00:00:00 2001 From: Mitchell Marino Date: Fri, 28 Mar 2025 00:39:32 -0500 Subject: [PATCH] impl state tracking for speaker driver --- main/drivers/speaker.cpp | 17 ++++++++++++++--- main/drivers/speaker.h | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/main/drivers/speaker.cpp b/main/drivers/speaker.cpp index 7bfab53..29ca618 100644 --- a/main/drivers/speaker.cpp +++ b/main/drivers/speaker.cpp @@ -1,4 +1,5 @@ #include "speaker.h" +#include "state_tracking.h" static const char *TAG = "speaker"; @@ -156,7 +157,7 @@ static void speaker_task(void* arg) { vTaskDelete(NULL); } -bool play_clip_wav(const char* file_name, bool play_immediatly, bool repeat, uint8_t prescaler, TickType_t ticks_to_wait) { +bool play_clip_wav(const char* file_name, bool play_immediately, bool repeat, uint8_t prescaler, TickType_t ticks_to_wait) { // clone the passed in string to the heap. size_t len = strlen(file_name); char* dynamic_file_name = (char*) malloc(len+1); @@ -166,10 +167,16 @@ bool play_clip_wav(const char* file_name, bool play_immediatly, bool repeat, uin .file_name = dynamic_file_name, .prescaler = prescaler, .repeat = repeat, - .play_immediatly = play_immediatly, + .play_immediatly = play_immediately, }; - if (play_immediatly) { + if (is_state_tracking()) { + char buf[64]; + sprintf(buf, "%s:%d:%d:%d", file_name, play_immediately, repeat, prescaler); + event_occured("PLAY_WAV", buf); + } + + if (play_immediately) { return xQueueSendToFront(play_clip_queue, &clip, ticks_to_wait) == pdTRUE; } return xQueueSend(play_clip_queue, &clip, ticks_to_wait) == pdTRUE; @@ -181,6 +188,10 @@ bool stop_clip(const char* file_name, TickType_t ticks_to_wait) { char* dynamic_file_name = (char*) malloc(len+1); strcpy(dynamic_file_name, file_name); + if (is_state_tracking()) { + event_occured("STOP_WAV", file_name); + } + return xQueueSend(stop_clip_queue, &dynamic_file_name, ticks_to_wait) == pdTRUE; } diff --git a/main/drivers/speaker.h b/main/drivers/speaker.h index 16d190f..7762750 100644 --- a/main/drivers/speaker.h +++ b/main/drivers/speaker.h @@ -52,7 +52,7 @@ void init_speaker(); /// loud. Useful for loud audio files. /// @param ticks_to_wait The number of ticks to wait if the queue is full. /// @return true if the clip was added to the queue. -bool play_clip_wav(const char* file_name, bool play_immediatly, bool repeat, uint8_t prescaler, TickType_t ticks_to_wait); +bool play_clip_wav(const char* file_name, bool play_immediately, bool repeat, uint8_t prescaler, TickType_t ticks_to_wait); /// @brief Stops an audio clip from playing. /// @param file_name The file name of the audio clip that was played.