feat: simple global control for backlight/brightness and volume (#6684)

This commit is contained in:
philmoz
2026-01-04 17:56:50 +10:00
committed by GitHub
parent 586a567b0b
commit e80406b274
71 changed files with 812 additions and 374 deletions
+4 -22
View File
@@ -146,9 +146,6 @@ bool isRepeatDelayElapsed(const CustomFunctionData * functions, CustomFunctionsC
}
}
#define VOLUME_HYSTERESIS 10 // how much must a input value change to actually be considered for new volume setting
getvalue_t requiredSpeakerVolumeRawLast = 1024 + 1; //initial value must be outside normal range
void evalFunctions(CustomFunctionData * functions, CustomFunctionsContext & functionsContext)
{
MASK_FUNC_TYPE newActiveFunctions = 0;
@@ -315,14 +312,8 @@ void evalFunctions(CustomFunctionData * functions, CustomFunctionsContext & func
#if defined(AUDIO)
case FUNC_VOLUME: {
getvalue_t raw = getValue(CFN_PARAM(cfn));
// only set volume if input changed more than hysteresis
if (abs(requiredSpeakerVolumeRawLast - raw) > VOLUME_HYSTERESIS) {
requiredSpeakerVolumeRawLast = raw;
}
requiredSpeakerVolume =
((1024 + requiredSpeakerVolumeRawLast) * VOLUME_LEVEL_MAX) /
2048;
newActiveFunctions |= (1u << FUNCTION_VOLUME);
calcVolumeValue(CFN_PARAM(cfn));
break;
}
#endif
@@ -402,18 +393,9 @@ void evalFunctions(CustomFunctionData * functions, CustomFunctionsContext & func
// like original backlight and turn on
// regardless of backlight settings
requiredBacklightBright = BACKLIGHT_FORCED_ON;
break;
} else {
calcBacklightValue(CFN_PARAM(cfn));
}
getvalue_t raw = limit(-RESX, (int)getValue(CFN_PARAM(cfn)), RESX);
#if defined(COLORLCD)
requiredBacklightBright = BACKLIGHT_LEVEL_MAX - (g_eeGeneral.blOffBright +
((1024 + raw) * ((BACKLIGHT_LEVEL_MAX - g_eeGeneral.backlightBright) - g_eeGeneral.blOffBright) / 2048));
#elif defined(OLED_SCREEN)
requiredBacklightBright = (raw + 1024) * 254 / 2048;
#else
requiredBacklightBright = (1024 - raw) * 100 / 2048;
#endif
break;
}