Browse Source

sound getInstance and release mutex correctly

main
Hendrik Langer 8 years ago
parent
commit
3410eb5ce8
  1. 9
      src/sound.cpp
  2. 2
      src/sound.h

9
src/sound.cpp

@ -32,9 +32,15 @@ using namespace std;
SemaphoreHandle_t xPlayingSemaphore = NULL; SemaphoreHandle_t xPlayingSemaphore = NULL;
static TaskHandle_t xTaskToNotify = NULL; static TaskHandle_t xTaskToNotify = NULL;
Sound* Sound::instance = NULL;
Sound::Sound() { Sound::Sound() {
xPlayingSemaphore = xSemaphoreCreateMutex(); xPlayingSemaphore = xSemaphoreCreateMutex();
Sound::instance = this;
}
Sound* Sound::getInstance() {
return Sound::instance;
} }
void Sound::init() { 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! File file = SDCard::open(path); // ToDo: accessing static member function loads 1500 words onto stack!
if (!file) { if (!file) {
xTaskToNotify = NULL;
Serial.print("Failed to open file: "); Serial.println(path); Serial.print("Failed to open file: "); Serial.println(path);
xTaskToNotify = NULL;
xSemaphoreGive( xPlayingSemaphore );
vTaskDelete( NULL ); vTaskDelete( NULL );
return; return;
} }

2
src/sound.h

@ -18,8 +18,10 @@ class Sound {
// void stop(); // void stop();
static const i2s_port_t i2s_num = (i2s_port_t)I2S_NUM; static const i2s_port_t i2s_num = (i2s_port_t)I2S_NUM;
static void play_task(void *pvParameter); static void play_task(void *pvParameter);
static Sound* getInstance();
private: private:
TaskHandle_t xTaskSound = NULL; TaskHandle_t xTaskSound = NULL;
static Sound* instance;
}; };
#endif /* _SOUND_H */ #endif /* _SOUND_H */

Loading…
Cancel
Save