Refactor brightness update logic in DeviceSP

Remove redundant brightness calculation from DeviceSP by leveraging Device's implementation. Introduce a conditional return to handle Sunnypilot-specific logic cleanly.
This commit is contained in:
DevTekVE
2024-07-27 23:09:30 +02:00
parent f242f6b55d
commit 0894686bb5
2 changed files with 3 additions and 16 deletions
+1 -15
View File
@@ -293,21 +293,7 @@ DeviceSP::DeviceSP(QObject *parent) : Device(parent){
//todo: revisit this
void DeviceSP::updateBrightness(const UIStateSP &s) {
float clipped_brightness = offroad_brightness;
if (s.scene.started && s.scene.light_sensor > 0) {
clipped_brightness = s.scene.light_sensor;
// CIE 1931 - https://www.photonstophotos.net/GeneralTopics/Exposure/Psychometric_Lightness_and_Gamma.htm
if (clipped_brightness <= 8) {
clipped_brightness = (clipped_brightness / 903.3);
} else {
clipped_brightness = std::pow((clipped_brightness + 16.0) / 116.0, 3.0);
}
// Scale back to 10% to 100%
clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, 100.0f);
}
Device::updateBrightness(s);
int brightness = brightness_filter.update(clipped_brightness);
if (!awake) {
brightness = 0;
+2 -1
View File
@@ -339,7 +339,8 @@ void Device::updateBrightness(const UIState &s) {
// Scale back to 10% to 100%
clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, 100.0f);
}
RETURN_IF_SUNNYPILOT
int brightness = brightness_filter.update(clipped_brightness);
if (!awake) {
brightness = 0;