[Taranis] Pull request #610 - Speaker volume hysteresis

This commit is contained in:
Bertrand Songis
2014-02-01 21:44:02 +01:00
parent 281dee18eb
commit 3e2e665955
+8 -1
View File
@@ -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;