From 0894686bb57662ae3ff464269c0676c5e6ccfa68 Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Sat, 27 Jul 2024 23:09:30 +0200 Subject: [PATCH] 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. --- selfdrive/ui/sunnypilot/ui.cc | 16 +--------------- selfdrive/ui/ui.cc | 3 ++- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/selfdrive/ui/sunnypilot/ui.cc b/selfdrive/ui/sunnypilot/ui.cc index 592e20b387..7460a7acf7 100644 --- a/selfdrive/ui/sunnypilot/ui.cc +++ b/selfdrive/ui/sunnypilot/ui.cc @@ -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; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 43bec276ae..5d6b6c5722 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -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;