From 7b7bc80d5da32d57111dfbed55adbd45fa9518d0 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 13 Nov 2026 18:56:27 -0800 Subject: [PATCH] mici: night mode (#39134) --- openpilot/selfdrive/ui/ui_state.py | 9 +++++++-- openpilot/system/ui/lib/application.py | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/openpilot/selfdrive/ui/ui_state.py b/openpilot/selfdrive/ui/ui_state.py index bf94726256..3c584da154 100644 --- a/openpilot/selfdrive/ui/ui_state.py +++ b/openpilot/selfdrive/ui/ui_state.py @@ -18,6 +18,9 @@ from openpilot.selfdrive.modeld.helpers import chestnut_compiled from openpilot.selfdrive.selfdrived.alertmanager import OFFROAD_ALERTS BACKLIGHT_OFFROAD = 65 if HARDWARE.get_device_type() == "mici" else 50 +BACKLIGHT_MIN = 30 # the lowest backlight the display shows properly +# auto brightness goes below the backlight's floor by dimming the UI, down to 40% black +BRIGHTNESS_MIN = BACKLIGHT_MIN * 0.6 if HARDWARE.get_device_type() == "mici" else BACKLIGHT_MIN PARAM_UPDATE_TIME = 1 / 5.0 @@ -357,9 +360,11 @@ class Device: else: clipped_brightness = ((clipped_brightness + 16.0) / 116.0) ** 3.0 - clipped_brightness = float(np.interp(clipped_brightness, [0, 1], [30, 100])) + clipped_brightness = float(np.interp(clipped_brightness, [0, 1], [BRIGHTNESS_MIN, 100])) - brightness = round(self._brightness_filter.update(clipped_brightness)) + brightness = self._brightness_filter.update(clipped_brightness) + gui_app.set_dim(1 - brightness / BACKLIGHT_MIN) + brightness = round(max(brightness, BACKLIGHT_MIN)) if not self._awake: brightness = 0 diff --git a/openpilot/system/ui/lib/application.py b/openpilot/system/ui/lib/application.py index 1c98db00cc..5d8e5c5326 100644 --- a/openpilot/system/ui/lib/application.py +++ b/openpilot/system/ui/lib/application.py @@ -233,6 +233,7 @@ class GuiApplication: self._mouse_history: deque[MousePosWithTime] = deque(maxlen=MOUSE_THREAD_RATE) self._show_touches = SHOW_TOUCHES self._show_fps = SHOW_FPS + self._dim_color = rl.BLANK self._grid_size = GRID_SIZE self._profile_render_frames = PROFILE_RENDER self._render_profiler = None @@ -248,6 +249,10 @@ class GuiApplication: def set_show_fps(self, show: bool): self._show_fps = show + def set_dim(self, dim: float): + """darken the whole screen, from 0 to 1""" + self._dim_color = rl.Color(0, 0, 0, round(255 * min(max(dim, 0.0), 1.0))) + @property def show_touches(self) -> bool: return self._show_touches @@ -614,6 +619,9 @@ class GuiApplication: if self._scale != 1.0: rl.rl_pop_matrix() + if self._dim_color.a > 0: + rl.draw_rectangle(0, 0, self._scaled_width, self._scaled_height, self._dim_color) + if RECORD: self._ffmpeg_queue.put(rl.cpu.screen().tobytes()) # Async write via background thread