From 3e2e665955e2d25c4f321460422c84f9773da2be Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 1 Feb 2014 21:44:02 +0100 Subject: [PATCH] [Taranis] Pull request #610 - Speaker volume hysteresis --- radio/src/opentx.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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;