diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index b1d0ef3b0..ff3729fae 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -3035,8 +3035,10 @@ uint8_t mSwitchDuration[1+NUM_ROTARY_ENCODERS] = { 0 }; #endif #if defined(CPUARM) +#define VOLUME_HYSTERESIS 10 // how much must a input value change to actually be considered for new volume setting uint8_t currentSpeakerVolume = 255; uint8_t requiredSpeakerVolume; +getvalue_t requiredSpeakerVolumeRawLast = 1024 + 1; //initial value must be outside normal range uint8_t fnSwitchDuration[NUM_CFN] = { 0 }; inline void playCustomFunctionFile(CustomFnData *sd, uint8_t id) @@ -3262,7 +3264,12 @@ void evalFunctions() } else if (CFN_FUNC(sd) == FUNC_VOLUME) { if (CFN_ACTIVE(sd)) { - requiredSpeakerVolume = ((1024 + getValue(CFN_PARAM(sd))) * VOLUME_LEVEL_MAX) / 2048; + getvalue_t raw = getValue(CFN_PARAM(sd)); + //only set volume if input changed more than hysteresis + if (abs(requiredSpeakerVolumeRawLast - raw) > VOLUME_HYSTERESIS) { + requiredSpeakerVolumeRawLast = raw; + } + requiredSpeakerVolume = ((1024 + requiredSpeakerVolumeRawLast) * VOLUME_LEVEL_MAX) / 2048; } else { active = false;