From 3410eb5ce8b7bf2b838ce84cf7f76789116c5f78 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Tue, 25 Apr 2017 21:05:48 +0200 Subject: [PATCH] sound getInstance and release mutex correctly --- src/sound.cpp | 9 ++++++++- src/sound.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sound.cpp b/src/sound.cpp index 8e272d3..efdf1fd 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -32,9 +32,15 @@ using namespace std; SemaphoreHandle_t xPlayingSemaphore = NULL; static TaskHandle_t xTaskToNotify = NULL; +Sound* Sound::instance = NULL; Sound::Sound() { xPlayingSemaphore = xSemaphoreCreateMutex(); + Sound::instance = this; +} + +Sound* Sound::getInstance() { + return Sound::instance; } void Sound::init() { @@ -117,8 +123,9 @@ void Sound::play_task(void *pvParameter) { File file = SDCard::open(path); // ToDo: accessing static member function loads 1500 words onto stack! if (!file) { - xTaskToNotify = NULL; Serial.print("Failed to open file: "); Serial.println(path); + xTaskToNotify = NULL; + xSemaphoreGive( xPlayingSemaphore ); vTaskDelete( NULL ); return; } diff --git a/src/sound.h b/src/sound.h index b383776..333bf89 100644 --- a/src/sound.h +++ b/src/sound.h @@ -18,8 +18,10 @@ class Sound { // void stop(); static const i2s_port_t i2s_num = (i2s_port_t)I2S_NUM; static void play_task(void *pvParameter); + static Sound* getInstance(); private: TaskHandle_t xTaskSound = NULL; + static Sound* instance; }; #endif /* _SOUND_H */