Skip to content

Commit

Permalink
Merge pull request #276 from moshe-braner/split_vol
Browse files Browse the repository at this point in the history
better volume setting at end of alarm
  • Loading branch information
iltis42 authored Dec 21, 2023
2 parents 72d9a48 + 005e77c commit df69b58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions main/ESPAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ){
Expand Down
2 changes: 1 addition & 1 deletion main/ESPAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df69b58

Please sign in to comment.