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
pull/20148/head
robbederks 2021-02-24 15:25:06 +01:00 committed by GitHub
parent 280192ed14
commit 4c243da019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 0 deletions

View File

@ -101,3 +101,7 @@ class HardwareBase:
@abstractmethod
def get_thermal_config(self):
pass
@abstractmethod
def set_screen_brightness(self, percentage):
pass

View File

@ -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)))

View File

@ -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

View File

@ -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))

View File

@ -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))