From 2db03fdbe281a030ba670fa40c998f19bb9eeea6 Mon Sep 17 00:00:00 2001 From: robbederks Date: Wed, 24 Feb 2021 15:25:06 +0100 Subject: [PATCH] Turn up brightness a little when UI crashes (#20142) * implement ui check and brightness set in thermald * fix bugs * only set once * duh * forgot factor for tici old-commit-hash: 4c243da0194b8fcefb3c7cba3472fa983ccd7052 --- selfdrive/hardware/base.py | 4 ++++ selfdrive/hardware/eon/hardware.py | 4 ++++ selfdrive/hardware/pc/hardware.py | 3 +++ selfdrive/hardware/tici/hardware.py | 4 ++++ selfdrive/thermald/thermald.py | 10 ++++++++++ 5 files changed, 25 insertions(+) diff --git a/selfdrive/hardware/base.py b/selfdrive/hardware/base.py index f5274deb6c..14a1a6f81b 100644 --- a/selfdrive/hardware/base.py +++ b/selfdrive/hardware/base.py @@ -101,3 +101,7 @@ class HardwareBase: @abstractmethod def get_thermal_config(self): pass + + @abstractmethod + def set_screen_brightness(self, percentage): + pass diff --git a/selfdrive/hardware/eon/hardware.py b/selfdrive/hardware/eon/hardware.py index 4666c2a633..2ef2a8f47d 100644 --- a/selfdrive/hardware/eon/hardware.py +++ b/selfdrive/hardware/eon/hardware.py @@ -348,3 +348,7 @@ class Android(HardwareBase): def get_thermal_config(self): return ThermalConfig(cpu=((5, 7, 10, 12), 10), gpu=((16,), 10), mem=(2, 10), bat=(29, 1000), ambient=(25, 1)) + + def set_screen_brightness(self, percentage): + with open("/sys/class/leds/lcd-backlight/brightness", "w") as f: + f.write(str(int(percentage * 2.55))) diff --git a/selfdrive/hardware/pc/hardware.py b/selfdrive/hardware/pc/hardware.py index 1744b69502..7ee40bd6bd 100644 --- a/selfdrive/hardware/pc/hardware.py +++ b/selfdrive/hardware/pc/hardware.py @@ -76,3 +76,6 @@ class Pc(HardwareBase): def get_thermal_config(self): return ThermalConfig(cpu=((None,), 1), gpu=((None,), 1), mem=(None, 1), bat=(None, 1), ambient=(None, 1)) + + def set_screen_brightness(self, percentage): + pass diff --git a/selfdrive/hardware/tici/hardware.py b/selfdrive/hardware/tici/hardware.py index 7fca07a89f..edae0934cb 100644 --- a/selfdrive/hardware/tici/hardware.py +++ b/selfdrive/hardware/tici/hardware.py @@ -183,3 +183,7 @@ class Tici(HardwareBase): def get_thermal_config(self): return ThermalConfig(cpu=((1, 2, 3, 4, 5, 6, 7, 8), 1000), gpu=((48,49), 1000), mem=(15, 1000), bat=(None, 1), ambient=(70, 1000)) + + def set_screen_brightness(self, percentage): + with open("/sys/class/backlight/panel0-backlight/brightness", "w") as f: + f.write(str(percentage * 10.23)) diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index 23f8602b2d..57014bf8c6 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -154,6 +154,7 @@ def thermald_thread(): pandaState_timeout = int(1000 * 2.5 * DT_TRML) # 2.5x the expected pandaState frequency pandaState_sock = messaging.sub_sock('pandaState', timeout=pandaState_timeout) location_sock = messaging.sub_sock('gpsLocationExternal') + managerState_sock = messaging.sub_sock('managerState', conflate=True) fan_speed = 0 count = 0 @@ -179,6 +180,7 @@ def thermald_thread(): should_start_prev = False handle_fan = None is_uno = False + ui_running_prev = False params = Params() power_monitor = PowerMonitoring() @@ -383,6 +385,14 @@ def thermald_thread(): time.sleep(10) HARDWARE.shutdown() + # If UI has crashed, set the brightness to reasonable non-zero value + manager_state = messaging.recv_one_or_none(managerState_sock) + if manager_state is not None: + ui_running = "ui" in (p.name for p in manager_state.managerState.processes if p.running) + if ui_running_prev and not ui_running: + HARDWARE.set_screen_brightness(20) + ui_running_prev = ui_running + msg.deviceState.chargingError = current_filter.x > 0. and msg.deviceState.batteryPercent < 90 # if current is positive, then battery is being discharged msg.deviceState.started = started_ts is not None msg.deviceState.startedMonoTime = int(1e9*(started_ts or 0))