mici: wake animation on home (#39331)

This commit is contained in:
Adeeb Shihadeh
2026-11-13 18:52:15 -08:00
committed by GitHub
parent 7d5647bdde
commit 011b357814
2 changed files with 59 additions and 2 deletions
+47 -2
View File
@@ -18,6 +18,13 @@ HEAD_BUTTON_FONT_SIZE = 40
HOME_PADDING = 8
ALERTS_ZONE_WIDTH = 180
# wake animation: (start, duration, slide distance) in seconds and px
WAKE_TITLE = (0.0, 0.8, 44)
WAKE_VERSION = (0.2, 0.8, 22)
WAKE_ICONS_START = 0.7
WAKE_ICON_STAGGER = 0.1
WAKE_ICON_DURATION = 0.5
NetworkType = log.DeviceState.NetworkType
NETWORK_TYPES = {
@@ -155,6 +162,23 @@ class MiciHomeLayout(Widget):
self._branch_label = UnifiedLabel("", font_size=36, text_color=rl.GRAY, font_weight=FontWeight.ROMAN, scroll=True)
self._version_commit_label = UnifiedLabel("", font_size=36, text_color=rl.GRAY, font_weight=FontWeight.ROMAN, max_width=480, wrap_text=False)
self._wake_pending = True # greet on boot
self._wake_start: float | None = None
def play_wake_animation(self):
self._wake_pending = True
def _wake_progress(self, start: float, duration: float) -> float:
if self._wake_start is None:
return 1.0
return min(max((rl.get_time() - self._wake_start - start) / duration, 0.0), 1.0)
@staticmethod
def _fade_in(rect: rl.Rectangle, progress: float):
# background is black, so fading in is drawing black over it
if progress < 1.0:
rl.draw_rectangle_rec(rect, rl.Color(0, 0, 0, int(255 * (1.0 - progress))))
def set_callbacks(self, on_settings: Callable | None = None, on_alerts: Callable | None = None,
alert_count_callback: Callable[[], int] | None = None,
alert_icon_callback: Callable[[], rl.Texture | None] | None = None):
@@ -191,15 +215,25 @@ class MiciHomeLayout(Widget):
return version, branch, commit[:7], date_str
def _render(self, _):
# start once home is actually on screen, e.g. after swiping past boot alerts
if self._wake_pending and abs(self.rect.x) < self.rect.width / 2:
self._wake_pending = False
self._wake_start = rl.get_time()
# TODO: why is there extra space here to get it to be flush?
text_pos = rl.Vector2(self.rect.x - 2 + HOME_PADDING, self.rect.y - 16)
self._openpilot_label.set_position(text_pos.x, text_pos.y)
title_progress = self._wake_progress(*WAKE_TITLE[:2])
title_y = text_pos.y + WAKE_TITLE[2] * (1.0 - title_progress) ** 3
self._openpilot_label.set_position(text_pos.x, title_y)
self._openpilot_label.render()
self._fade_in(rl.Rectangle(self.rect.x, title_y, self.rect.width, self._openpilot_label.font_size + 16), title_progress)
if self._version_text is not None:
# release branch
release_branch = self._version_text[1] in RELEASE_BRANCHES
version_pos = rl.Rectangle(text_pos.x, text_pos.y + self._openpilot_label.font_size + 16, 100, 44)
version_progress = self._wake_progress(*WAKE_VERSION[:2])
version_y = text_pos.y + self._openpilot_label.font_size + 16 + WAKE_VERSION[2] * (1.0 - version_progress) ** 3
version_pos = rl.Rectangle(text_pos.x, version_y, 100, 44)
self._version_label.set_text(self._version_text[0])
self._version_label.set_position(version_pos.x, version_pos.y)
self._version_label.render()
@@ -219,6 +253,9 @@ class MiciHomeLayout(Widget):
self._version_commit_label.set_position(version_pos.x, version_pos.y + self._date_label.font_size + 7)
self._version_commit_label.render()
version_h = self._date_label.font_size * (1 if release_branch else 2) + 7
self._fade_in(rl.Rectangle(self.rect.x, version_y, self.rect.width, version_h), version_progress)
# ***** Center-aligned bottom section icons *****
usb_connected = ui_state.usb_connected
usb_unknown = ui_state.usb_unknown
@@ -240,3 +277,11 @@ class MiciHomeLayout(Widget):
self._alerts_pill.set_position(self.rect.x + self.rect.width - self._alerts_pill.rect.width - HOME_PADDING,
self.rect.y + self.rect.height - self._alerts_pill.rect.height)
self._alerts_pill.render()
# status icons fade in one after another, alerts pill last
if self._wake_start is not None:
icons = [w.rect for w in self._status_bar_layout.widgets if w.is_visible] + [self._alerts_pill.rect]
for i, rect in enumerate(icons):
self._fade_in(rect, self._wake_progress(WAKE_ICONS_START + i * WAKE_ICON_STAGGER, WAKE_ICON_DURATION))
if self._wake_progress(WAKE_ICONS_START + len(icons) * WAKE_ICON_STAGGER, WAKE_ICON_DURATION) >= 1.0:
self._wake_start = None
@@ -1,3 +1,4 @@
import time
import raylib_nb as rl
import openpilot.cereal.messaging as messaging
from openpilot.selfdrive.ui.mici.layouts.home import MiciHomeLayout
@@ -13,6 +14,7 @@ from openpilot.system.ui.lib.application import gui_app
ONROAD_DELAY = 2.5 # seconds
GREET_IGNITION_OFF_TIME = 60 * 60 # greet again when the car turns on after being off this long
class MiciMainLayout(Scroller):
@@ -24,6 +26,8 @@ class MiciMainLayout(Scroller):
self._prev_onroad = False
self._prev_standstill = False
self._onroad_time_delay: float | None = None
self._prev_ignition = False
self._ignition_off_time = time.monotonic() # home already greets on boot
self._setup = False
# Initialize widgets
@@ -105,6 +109,14 @@ class MiciMainLayout(Scroller):
super()._render(self._rect)
def _handle_transitions(self):
# greet when getting in the car after it's been off for a while
if ui_state.ignition != self._prev_ignition:
self._prev_ignition = ui_state.ignition
if not ui_state.ignition:
self._ignition_off_time = time.monotonic()
elif time.monotonic() - self._ignition_off_time > GREET_IGNITION_OFF_TIME:
self._home_layout.play_wake_animation()
# Don't pop if onboarding
if gui_app.widget_in_stack(self._onboarding_window):
return