Bladeren bron

DTMFDolphin: Speaker fixes by nano

Willy-JL 2 jaren geleden
bovenliggende
commit
8ae2535e9f
1 gewijzigde bestanden met toevoegingen van 11 en 6 verwijderingen
  1. 11 6
      dtmf_dolphin/dtmf_dolphin_audio.c

+ 11 - 6
dtmf_dolphin/dtmf_dolphin_audio.c

@@ -214,16 +214,20 @@ bool dtmf_dolphin_audio_play_tones(
     generate_waveform(current_player, 0);
     generate_waveform(current_player, 0);
     generate_waveform(current_player, current_player->half_buffer_length);
     generate_waveform(current_player, current_player->half_buffer_length);
 
 
-    dtmf_dolphin_speaker_init();
     dtmf_dolphin_dma_init((uint32_t)current_player->sample_buffer, current_player->buffer_length);
     dtmf_dolphin_dma_init((uint32_t)current_player->sample_buffer, current_player->buffer_length);
 
 
     furi_hal_interrupt_set_isr(
     furi_hal_interrupt_set_isr(
         FuriHalInterruptIdDma1Ch1, dtmf_dolphin_audio_dma_isr, current_player->queue);
         FuriHalInterruptIdDma1Ch1, dtmf_dolphin_audio_dma_isr, current_player->queue);
-
-    dtmf_dolphin_dma_start();
-    dtmf_dolphin_speaker_start();
-    current_player->playing = true;
-    return true;
+    if(furi_hal_speaker_acquire(1000)) {
+        dtmf_dolphin_speaker_init();
+        dtmf_dolphin_dma_start();
+        dtmf_dolphin_speaker_start();
+        current_player->playing = true;
+        return true;
+    } else {
+        current_player->playing = false;
+        return false;
+    }
 }
 }
 
 
 bool dtmf_dolphin_audio_stop_tones() {
 bool dtmf_dolphin_audio_stop_tones() {
@@ -238,6 +242,7 @@ bool dtmf_dolphin_audio_stop_tones() {
     }
     }
     dtmf_dolphin_speaker_stop();
     dtmf_dolphin_speaker_stop();
     dtmf_dolphin_dma_stop();
     dtmf_dolphin_dma_stop();
+    furi_hal_speaker_release();
 
 
     furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, NULL, NULL);
     furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, NULL, NULL);