mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-08 20:23:42 +08:00
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:
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user