diff --git a/selfdrive/ui/mici/layouts/home.py b/selfdrive/ui/mici/layouts/home.py index f37cbf4798..60c5fcf1d4 100644 --- a/selfdrive/ui/mici/layouts/home.py +++ b/selfdrive/ui/mici/layouts/home.py @@ -132,13 +132,11 @@ class MiciHomeLayout(Widget): self._on_alerts_click: Callable | None = None self._alert_count_callback: Callable[[], int] | None = None - self._last_refresh = 0 self._mouse_down_t: None | float = None self._did_long_press = False self._is_pressed_prev = False self._version_text = self._get_version_text() - self._experimental_mode = False self._experimental_icon = IconWidget("icons_mici/experimental_mode.png", (48, 48)) self._mic_icon = IconWidget("icons_mici/microphone.png", (32, 46)) @@ -161,13 +159,6 @@ 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) - def show_event(self): - super().show_event() - self._update_params() - - def _update_params(self): - self._experimental_mode = ui_state.params.get_bool("ExperimentalMode") - def _update_state(self): if self.is_pressed and not self._is_pressed_prev: self._mouse_down_t = time.monotonic() @@ -180,15 +171,11 @@ class MiciHomeLayout(Widget): if time.monotonic() - self._mouse_down_t > 0.5: # long gating for experimental mode - only allow toggle if longitudinal control is available if ui_state.has_longitudinal_control: - self._experimental_mode = not self._experimental_mode - ui_state.params.put("ExperimentalMode", self._experimental_mode, block=True) + ui_state.experimental_mode = not ui_state.experimental_mode + ui_state.params.put("ExperimentalMode", ui_state.experimental_mode, block=True) self._mouse_down_t = None self._did_long_press = True - if rl.get_time() - self._last_refresh > 5.0: - self._last_refresh = rl.get_time() - self._update_params() - def set_callbacks(self, on_settings: Callable | None = None, on_alerts: Callable | None = None, alert_count_callback: Callable[[], int] | None = None, max_severity_callback: Callable[[], int | None] | None = None): @@ -256,7 +243,7 @@ class MiciHomeLayout(Widget): self._version_commit_label.render() # ***** Center-aligned bottom section icons ***** - self._experimental_icon.set_visible(self._experimental_mode) + self._experimental_icon.set_visible(ui_state.experimental_mode) self._mic_icon.set_visible(ui_state.recording_audio) self._body_icon.set_visible(ui_state.is_body) diff --git a/selfdrive/ui/ui_state.py b/selfdrive/ui/ui_state.py index 52426f510b..3bcdfa10c8 100644 --- a/selfdrive/ui/ui_state.py +++ b/selfdrive/ui/ui_state.py @@ -73,6 +73,7 @@ class UIState: self.is_metric: bool = self.params.get_bool("IsMetric") self.is_release = self.params.get_bool("IsReleaseBranch") self.always_on_dm: bool = self.params.get_bool("AlwaysOnDM") + self.experimental_mode: bool = self.params.get_bool("ExperimentalMode") self.started: bool = False self.ignition: bool = False self.recording_audio: bool = False @@ -191,6 +192,8 @@ class UIState: for callback in self._on_body_changed_callbacks: callback() + self.experimental_mode = self.params.get_bool("ExperimentalMode") + self._param_update_time = time.monotonic()