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;
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;
}

2
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 */

Loading…
Cancel
Save