From 30dfba88f4387928ded4ca068e035d54f5a83d54 Mon Sep 17 00:00:00 2001 From: Harald Schafer Date: Mon, 15 Nov 2021 13:52:49 -0800 Subject: [PATCH 1/8] set brightness --- selfdrive/hardware/base.h | 2 +- selfdrive/hardware/eon/hardware.h | 2 +- selfdrive/hardware/tici/hardware.h | 13 ++++++++++++- selfdrive/ui/qt/util.cc | 2 +- selfdrive/ui/ui.cc | 3 ++- selfdrive/ui/ui.h | 2 ++ 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/selfdrive/hardware/base.h b/selfdrive/hardware/base.h index 05e55cc0340c66..a93f433ccf845d 100644 --- a/selfdrive/hardware/base.h +++ b/selfdrive/hardware/base.h @@ -13,7 +13,7 @@ class HardwareNone { static void reboot() {} static void poweroff() {} - static void set_brightness(int percent) {} + static void set_brightness(int percent, float ui_running_time) {} static void set_display_power(bool on) {} static bool get_ssh_enabled() { return false; } diff --git a/selfdrive/hardware/eon/hardware.h b/selfdrive/hardware/eon/hardware.h index bcd1aaba740302..0638cf33b219bf 100644 --- a/selfdrive/hardware/eon/hardware.h +++ b/selfdrive/hardware/eon/hardware.h @@ -22,7 +22,7 @@ class HardwareEon : public HardwareNone { static void reboot() { std::system("reboot"); }; static void poweroff() { std::system("LD_LIBRARY_PATH= svc power shutdown"); }; - static void set_brightness(int percent) { + static void set_brightness(int percent, float ui_running_time) { std::ofstream brightness_control("/sys/class/leds/lcd-backlight/brightness"); if (brightness_control.is_open()) { brightness_control << (int)(percent * (255/100.)) << "\n"; diff --git a/selfdrive/hardware/tici/hardware.h b/selfdrive/hardware/tici/hardware.h index abd7e9297a1426..8822c4771194fb 100644 --- a/selfdrive/hardware/tici/hardware.h +++ b/selfdrive/hardware/tici/hardware.h @@ -11,6 +11,12 @@ class HardwareTici : public HardwareNone { public: static constexpr float MAX_VOLUME = 1.0; static constexpr float MIN_VOLUME = 0.4; + static constexpr float SECONDS_IN_HOUR = 60*60; + static constexpr float HOURLY_BRIGHTNESS_DECREASE = 5; + static constexpr float BRIGHTNESS_LIMIT_MIN = 30; + static constexpr float BRIGHTNESS_LIMIT_MAX = 100; + static constexpr float MAX_BRIGHTNESS_HOURS = 4; + static bool TICI() { return true; } static std::string get_os_version() { return "AGNOS " + util::read_file("/VERSION"); @@ -18,7 +24,12 @@ class HardwareTici : public HardwareNone { static void reboot() { std::system("sudo reboot"); }; static void poweroff() { std::system("sudo poweroff"); }; - static void set_brightness(int percent) { + static void set_brightness(int percent, float ui_running_time) { + float ui_running_hours = ui_running_time / SECONDS_IN_HOUR; + int anti_burnin_max_percent = std::clamp((int) (BRIGHTNESS_LIMIT_MAX - HOURLY_BRIGHTNESS_DECREASE * (ui_running_hours - MAX_BRIGHTNESS_HOURS)), + BRIGHTNESS_LIMIT_MIN, + BRIGHTNESS_LIMIT_MIN); + percent = std::min(percent, anti_burnin_max_percent); std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness"); if (brightness_control.is_open()) { brightness_control << (percent * (int)(1023/100.)) << "\n"; diff --git a/selfdrive/ui/qt/util.cc b/selfdrive/ui/qt/util.cc index 93bb2b0e79e181..e5fcf305376d94 100644 --- a/selfdrive/ui/qt/util.cc +++ b/selfdrive/ui/qt/util.cc @@ -81,7 +81,7 @@ void setQtSurfaceFormat() { void initApp() { Hardware::set_display_power(true); - Hardware::set_brightness(65); + Hardware::set_brightness(65, 0); setQtSurfaceFormat(); if (Hardware::EON()) { QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index d0c3c04879c9e7..e8fa5c0155cb93 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -105,6 +105,7 @@ static void update_sockets(UIState *s) { static void update_state(UIState *s) { SubMaster &sm = *(s->sm); UIScene &scene = s->scene; + s->running_time = 1e-9 * (sm["deviceState"].getLogMonoTime() - sm["deviceState"].getDeviceState().getStartedMonoTime()); // update engageability and DM icons at 2Hz if (sm.frame % (UI_FREQ / 2) == 0) { @@ -301,7 +302,7 @@ void Device::updateBrightness(const UIState &s) { } if (brightness != last_brightness) { - std::thread{Hardware::set_brightness, brightness}.detach(); + std::thread{Hardware::set_brightness, brightness, s.running_time}.detach(); } last_brightness = brightness; } diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 4fcc137df7d8ff..44fe2c9dbd37f1 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -149,6 +149,8 @@ typedef struct UIState { float car_space_transform[6]; bool wide_camera; + + float running_time; } UIState; From 6159f346810f4f1f9994e640af1a7dc46b64ed0c Mon Sep 17 00:00:00 2001 From: Harald Schafer Date: Mon, 15 Nov 2021 17:45:38 -0800 Subject: [PATCH 2/8] until its in agnos --- selfdrive/hardware/base.h | 2 +- selfdrive/hardware/eon/hardware.h | 2 +- selfdrive/hardware/tici/hardware.h | 12 +----------- selfdrive/ui/qt/util.cc | 2 +- selfdrive/ui/ui.cc | 12 ++++++++++-- selfdrive/ui/ui.h | 6 ++++++ 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/selfdrive/hardware/base.h b/selfdrive/hardware/base.h index a93f433ccf845d..05e55cc0340c66 100644 --- a/selfdrive/hardware/base.h +++ b/selfdrive/hardware/base.h @@ -13,7 +13,7 @@ class HardwareNone { static void reboot() {} static void poweroff() {} - static void set_brightness(int percent, float ui_running_time) {} + static void set_brightness(int percent) {} static void set_display_power(bool on) {} static bool get_ssh_enabled() { return false; } diff --git a/selfdrive/hardware/eon/hardware.h b/selfdrive/hardware/eon/hardware.h index 0638cf33b219bf..bcd1aaba740302 100644 --- a/selfdrive/hardware/eon/hardware.h +++ b/selfdrive/hardware/eon/hardware.h @@ -22,7 +22,7 @@ class HardwareEon : public HardwareNone { static void reboot() { std::system("reboot"); }; static void poweroff() { std::system("LD_LIBRARY_PATH= svc power shutdown"); }; - static void set_brightness(int percent, float ui_running_time) { + static void set_brightness(int percent) { std::ofstream brightness_control("/sys/class/leds/lcd-backlight/brightness"); if (brightness_control.is_open()) { brightness_control << (int)(percent * (255/100.)) << "\n"; diff --git a/selfdrive/hardware/tici/hardware.h b/selfdrive/hardware/tici/hardware.h index 8822c4771194fb..9ac25262925bb6 100644 --- a/selfdrive/hardware/tici/hardware.h +++ b/selfdrive/hardware/tici/hardware.h @@ -11,11 +11,6 @@ class HardwareTici : public HardwareNone { public: static constexpr float MAX_VOLUME = 1.0; static constexpr float MIN_VOLUME = 0.4; - static constexpr float SECONDS_IN_HOUR = 60*60; - static constexpr float HOURLY_BRIGHTNESS_DECREASE = 5; - static constexpr float BRIGHTNESS_LIMIT_MIN = 30; - static constexpr float BRIGHTNESS_LIMIT_MAX = 100; - static constexpr float MAX_BRIGHTNESS_HOURS = 4; static bool TICI() { return true; } static std::string get_os_version() { @@ -24,12 +19,7 @@ class HardwareTici : public HardwareNone { static void reboot() { std::system("sudo reboot"); }; static void poweroff() { std::system("sudo poweroff"); }; - static void set_brightness(int percent, float ui_running_time) { - float ui_running_hours = ui_running_time / SECONDS_IN_HOUR; - int anti_burnin_max_percent = std::clamp((int) (BRIGHTNESS_LIMIT_MAX - HOURLY_BRIGHTNESS_DECREASE * (ui_running_hours - MAX_BRIGHTNESS_HOURS)), - BRIGHTNESS_LIMIT_MIN, - BRIGHTNESS_LIMIT_MIN); - percent = std::min(percent, anti_burnin_max_percent); + static void set_brightness(int percent) { std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness"); if (brightness_control.is_open()) { brightness_control << (percent * (int)(1023/100.)) << "\n"; diff --git a/selfdrive/ui/qt/util.cc b/selfdrive/ui/qt/util.cc index e5fcf305376d94..93bb2b0e79e181 100644 --- a/selfdrive/ui/qt/util.cc +++ b/selfdrive/ui/qt/util.cc @@ -81,7 +81,7 @@ void setQtSurfaceFormat() { void initApp() { Hardware::set_display_power(true); - Hardware::set_brightness(65, 0); + Hardware::set_brightness(65); setQtSurfaceFormat(); if (Hardware::EON()) { QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index e8fa5c0155cb93..44dbb5bfe7bca9 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -289,8 +289,16 @@ void Device::updateBrightness(const UIState &s) { clipped_brightness = std::pow((clipped_brightness + 16.0) / 116.0, 3.0); } + + // Limit brightness if running for too long + float ui_running_hours = s.running_time / SECONDS_IN_HOUR; + float anti_burnin_max_percent = std::clamp(BRIGHTNESS_LIMIT_MAX - + HOURLY_BRIGHTNESS_DECREASE * (ui_running_hours - MAX_BRIGHTNESS_HOURS), + BRIGHTNESS_LIMIT_MIN, + BRIGHTNESS_LIMIT_MIN); + // Scale back to 10% to 100% - clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, 100.0f); + clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, anti_burnin_max_percent); if (!s.scene.started) { clipped_brightness = BACKLIGHT_OFFROAD; @@ -302,7 +310,7 @@ void Device::updateBrightness(const UIState &s) { } if (brightness != last_brightness) { - std::thread{Hardware::set_brightness, brightness, s.running_time}.detach(); + std::thread{Hardware::set_brightness, brightness}.detach(); } last_brightness = brightness; } diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 44fe2c9dbd37f1..bb9c42ac871281 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -31,6 +31,12 @@ const int header_h = 420; const int footer_h = 280; const int UI_FREQ = 20; // Hz + +const float SECONDS_IN_HOUR = 60*60; +const float HOURLY_BRIGHTNESS_DECREASE = 5; +const float BRIGHTNESS_LIMIT_MIN = 30; +const float BRIGHTNESS_LIMIT_MAX = 100; +const float MAX_BRIGHTNESS_HOURS = 4; typedef cereal::CarControl::HUDControl::AudibleAlert AudibleAlert; From bb3d31eb9576a1f5edcd982d7f67eed3945e4447 Mon Sep 17 00:00:00 2001 From: Harald Schafer Date: Mon, 15 Nov 2021 19:11:00 -0800 Subject: [PATCH 3/8] undo whitespace --- selfdrive/hardware/tici/hardware.h | 1 - 1 file changed, 1 deletion(-) diff --git a/selfdrive/hardware/tici/hardware.h b/selfdrive/hardware/tici/hardware.h index 9ac25262925bb6..abd7e9297a1426 100644 --- a/selfdrive/hardware/tici/hardware.h +++ b/selfdrive/hardware/tici/hardware.h @@ -11,7 +11,6 @@ class HardwareTici : public HardwareNone { public: static constexpr float MAX_VOLUME = 1.0; static constexpr float MIN_VOLUME = 0.4; - static bool TICI() { return true; } static std::string get_os_version() { return "AGNOS " + util::read_file("/VERSION"); From 8b04beb6f901086c11568a1913a3217173e3eaec Mon Sep 17 00:00:00 2001 From: Harald Schafer Date: Mon, 15 Nov 2021 19:12:46 -0800 Subject: [PATCH 4/8] typo --- selfdrive/ui/ui.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 44dbb5bfe7bca9..c79c371421983e 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -295,7 +295,7 @@ void Device::updateBrightness(const UIState &s) { float anti_burnin_max_percent = std::clamp(BRIGHTNESS_LIMIT_MAX - HOURLY_BRIGHTNESS_DECREASE * (ui_running_hours - MAX_BRIGHTNESS_HOURS), BRIGHTNESS_LIMIT_MIN, - BRIGHTNESS_LIMIT_MIN); + BRIGHTNESS_LIMIT_MAX); // Scale back to 10% to 100% clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, anti_burnin_max_percent); From b1e0c9fdd5bd313e7bc1d9927913e9f3d254aad3 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 15 Nov 2021 21:51:25 -0800 Subject: [PATCH 5/8] only tici --- selfdrive/ui/ui.cc | 47 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index c79c371421983e..f5e1206ece5c17 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -12,7 +12,7 @@ #define BACKLIGHT_DT 0.05 #define BACKLIGHT_TS 10.00 -#define BACKLIGHT_OFFROAD 75 +#define BACKLIGHT_OFFROAD 50 // Projects a point in car to space to the corresponding point in full frame @@ -105,7 +105,7 @@ static void update_sockets(UIState *s) { static void update_state(UIState *s) { SubMaster &sm = *(s->sm); UIScene &scene = s->scene; - s->running_time = 1e-9 * (sm["deviceState"].getLogMonoTime() - sm["deviceState"].getDeviceState().getStartedMonoTime()); + s->running_time = 1e-9 * (nanos_since_boot() - sm["deviceState"].getDeviceState().getStartedMonoTime()); // update engageability and DM icons at 2Hz if (sm.frame % (UI_FREQ / 2) == 0) { @@ -279,29 +279,30 @@ void Device::setAwake(bool on, bool reset) { } void Device::updateBrightness(const UIState &s) { - // Scale to 0% to 100% - float clipped_brightness = 100.0 * 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); - } - - - // Limit brightness if running for too long - float ui_running_hours = s.running_time / SECONDS_IN_HOUR; - float anti_burnin_max_percent = std::clamp(BRIGHTNESS_LIMIT_MAX - - HOURLY_BRIGHTNESS_DECREASE * (ui_running_hours - MAX_BRIGHTNESS_HOURS), - BRIGHTNESS_LIMIT_MIN, - BRIGHTNESS_LIMIT_MAX); + float clipped_brightness = BACKLIGHT_OFFROAD; + if (s.scene.started) { + // Scale to 0% to 100% + float clipped_brightness = 100.0 * 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, anti_burnin_max_percent); + // Scale back to 10% to 100% + clipped_brightness = std::clamp(100.0f * clipped_brightness, 10.0f, 100.0f); - if (!s.scene.started) { - clipped_brightness = BACKLIGHT_OFFROAD; + // Limit brightness if running for too long + if (Hardware::TICI()) { + const float MAX_BRIGHTNESS_HOURS = 4; + const float HOURLY_BRIGHTNESS_DECREASE = 5; + float ui_running_hours = s.running_time / (60*60); + float anti_burnin_max_percent = std::max(100.0f - HOURLY_BRIGHTNESS_DECREASE * (ui_running_hours - MAX_BRIGHTNESS_HOURS), + 30.0f, 100.0f); + clipped_brightness = std::min(clipped_brightness, anti_burnin_max_percent); + } } int brightness = brightness_filter.update(clipped_brightness); From 5931908b94bd0cf67123468b70576c7bf9b7360d Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 15 Nov 2021 21:52:18 -0800 Subject: [PATCH 6/8] remove duplicates --- selfdrive/ui/ui.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index bb9c42ac871281..6bb388eab9b67d 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -32,12 +32,6 @@ const int footer_h = 280; const int UI_FREQ = 20; // Hz -const float SECONDS_IN_HOUR = 60*60; -const float HOURLY_BRIGHTNESS_DECREASE = 5; -const float BRIGHTNESS_LIMIT_MIN = 30; -const float BRIGHTNESS_LIMIT_MAX = 100; -const float MAX_BRIGHTNESS_HOURS = 4; - typedef cereal::CarControl::HUDControl::AudibleAlert AudibleAlert; // TODO: this is also hardcoded in common/transformations/camera.py From 1c8da1f1c77c5c56132cab001b46f14bcc66ed3e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 15 Nov 2021 21:55:39 -0800 Subject: [PATCH 7/8] Update selfdrive/ui/ui.h --- selfdrive/ui/ui.h | 1 - 1 file changed, 1 deletion(-) diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 6bb388eab9b67d..3f52bf120d94cc 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -31,7 +31,6 @@ const int header_h = 420; const int footer_h = 280; const int UI_FREQ = 20; // Hz - typedef cereal::CarControl::HUDControl::AudibleAlert AudibleAlert; // TODO: this is also hardcoded in common/transformations/camera.py From f51092b21c6fb5cdfee4a81ded40d6f69a2cf94a Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Mon, 15 Nov 2021 21:57:08 -0800 Subject: [PATCH 8/8] clamp --- selfdrive/ui/ui.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index f5e1206ece5c17..054e90e1768a82 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -282,7 +282,7 @@ void Device::updateBrightness(const UIState &s) { float clipped_brightness = BACKLIGHT_OFFROAD; if (s.scene.started) { // Scale to 0% to 100% - float clipped_brightness = 100.0 * s.scene.light_sensor; + clipped_brightness = 100.0 * s.scene.light_sensor; // CIE 1931 - https://www.photonstophotos.net/GeneralTopics/Exposure/Psychometric_Lightness_and_Gamma.htm if (clipped_brightness <= 8) { @@ -299,8 +299,8 @@ void Device::updateBrightness(const UIState &s) { const float MAX_BRIGHTNESS_HOURS = 4; const float HOURLY_BRIGHTNESS_DECREASE = 5; float ui_running_hours = s.running_time / (60*60); - float anti_burnin_max_percent = std::max(100.0f - HOURLY_BRIGHTNESS_DECREASE * (ui_running_hours - MAX_BRIGHTNESS_HOURS), - 30.0f, 100.0f); + float anti_burnin_max_percent = std::clamp(100.0f - HOURLY_BRIGHTNESS_DECREASE * (ui_running_hours - MAX_BRIGHTNESS_HOURS), + 30.0f, 100.0f); clipped_brightness = std::min(clipped_brightness, anti_burnin_max_percent); } }