diff --git a/main/ESPAudio.cpp b/main/ESPAudio.cpp index c2b3eaedc..5f1423b87 100644 --- a/main/ESPAudio.cpp +++ b/main/ESPAudio.cpp @@ -347,15 +347,13 @@ void Audio::alarm( bool enable, float volume, e_audio_alarm_type_t style ){ // enableAmplifier( true ); } if( !enable && _alarm_mode ){ // End of alarm + _alarm_mode = false; vario_mode_volume = _vol_back_vario; s2f_mode_volume = _vol_back_s2f; - _s2f_mode = _s2f_mode_back; _tonemode = _tonemode_back; - _alarm_mode=false; - if( _s2f_mode ) - writeVolume( s2f_mode_volume ); - else - writeVolume( vario_mode_volume ); + _s2f_mode = _s2f_mode_back; // S2F mode from before the alarm + calcS2Fmode(true); // may update the S2F mode + writeVolume( speaker_volume ); } if( enable ) { // tune alarm // ESP_LOGI(FNAME,"Alarm sound enable volume: %f style: %d", volume, style ); @@ -461,13 +459,16 @@ void Audio::startAudio(){ xTaskCreatePinnedToCore(&dactask, "dactask", 2400, NULL, 16, &dactid, 0); } -void Audio::calcS2Fmode(){ +void Audio::calcS2Fmode( bool recalc ){ if( _alarm_mode ) return; bool mode = Switch::getCruiseState(); if( mode != _s2f_mode ){ ESP_LOGI(FNAME, "S2Fmode changed to %d", mode ); _s2f_mode = mode; // do this first, as... + recalc = true; + } + if( recalc ){ calculateFrequency(); // this needs the new _stf_mode if( _s2f_mode ) speaker_volume = s2f_mode_volume; @@ -581,7 +582,7 @@ void Audio::dactask(void* arg ) calculateFrequency(); if( !(tick%10) ){ - calcS2Fmode(); // if mode changed, affects volume and frequency + calcS2Fmode(false); // if mode changed, affects volume and frequency } if( inDeadBand(_te) && !volume_change ){ diff --git a/main/ESPAudio.h b/main/ESPAudio.h index b306f3f1c..51d97d2e6 100644 --- a/main/ESPAudio.h +++ b/main/ESPAudio.h @@ -52,7 +52,7 @@ class Audio { static void dac_invert_set(dac_channel_t channel, int invert); static void dactask(void* arg); static void modtask(void* arg ); - static void calcS2Fmode(); + static void calcS2Fmode( bool recalc=false ); static bool inDeadBand( float te ); static bool lookup( float f, int& div, int &step ); static void enableAmplifier( bool enable ); // frue ON, false OFF