clean up
This commit is contained in:
@@ -18,6 +18,7 @@ static const char *TAG = "buzzer";
|
||||
#define BUZZER_CHANNEL LEDC_CHANNEL_0
|
||||
|
||||
static QueueHandle_t s_sound_queue = NULL;
|
||||
static volatile bool s_melody_playing = false;
|
||||
|
||||
static const buzzer_note_t MELODY_VICTORY[] = {
|
||||
{NOTE_C5, 90}, {NOTE_C5, 90}, {NOTE_C5, 90}, {NOTE_C5, 220},
|
||||
@@ -57,6 +58,7 @@ static void buzzer_task(void *arg)
|
||||
buzzer_sound_t sound;
|
||||
while (1) {
|
||||
if (xQueueReceive(s_sound_queue, &sound, portMAX_DELAY) == pdTRUE) {
|
||||
s_melody_playing = true;
|
||||
switch (sound) {
|
||||
case BUZZER_SOUND_VICTORY:
|
||||
buzzer_play_notes(MELODY_VICTORY, sizeof(MELODY_VICTORY) / sizeof(MELODY_VICTORY[0]));
|
||||
@@ -70,6 +72,7 @@ static void buzzer_task(void *arg)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
s_melody_playing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,6 +142,9 @@ esp_err_t buzzer_stop(void)
|
||||
|
||||
esp_err_t buzzer_chirp(uint32_t freq_hz, uint32_t duration_ms)
|
||||
{
|
||||
if (s_melody_playing) {
|
||||
return ESP_OK; /* Don't disrupt ongoing background chiptune melody */
|
||||
}
|
||||
esp_err_t ret = buzzer_start(freq_hz, 30);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user