From c4941f07db430a3b6725656da5b56eba7dc83abc Mon Sep 17 00:00:00 2001 From: royjr Date: Sun, 23 Aug 2026 21:23:21 -0400 Subject: [PATCH] move to sp --- openpilot/common/params_keys.h | 2 +- openpilot/selfdrive/modeld/modeld.py | 3 +-- .../selfdrive/ui/mici/onroad/hud_renderer.py | 14 +--------- .../ui/sunnypilot/mici/onroad/hud_renderer.py | 26 ++++++++++++++++++- openpilot/selfdrive/ui/sunnypilot/ui_state.py | 4 +++ openpilot/selfdrive/ui/ui_state.py | 4 --- .../modeld_v2}/load_progress.py | 5 ++-- openpilot/sunnypilot/modeld_v2/modeld.py | 2 +- 8 files changed, 36 insertions(+), 24 deletions(-) rename openpilot/{selfdrive/modeld => sunnypilot/modeld_v2}/load_progress.py (91%) diff --git a/openpilot/common/params_keys.h b/openpilot/common/params_keys.h index 2be75a050e..4674b59fae 100644 --- a/openpilot/common/params_keys.h +++ b/openpilot/common/params_keys.h @@ -132,7 +132,6 @@ inline static std::unordered_map keys = { {"UptimeOnroad", {PERSISTENT, FLOAT, "0.0"}}, {"UsbGpuActive", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, BOOL}}, {"UsbGpuLoading", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, BOOL}}, - {"UsbGpuLoadProgress", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, INT, "0"}}, {"Version", {PERSISTENT, STRING}}, // --- sunnypilot params --- // @@ -286,4 +285,5 @@ inline static std::unordered_map keys = { {"TorqueParamsOverrideEnabled", {PERSISTENT | BACKUP, BOOL, "0"}}, {"TorqueParamsOverrideFriction", {PERSISTENT | BACKUP, FLOAT, "0.1"}}, {"TorqueParamsOverrideLatAccelFactor", {PERSISTENT | BACKUP, FLOAT, "2.5"}}, + {"UsbGpuLoadProgress", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_IGNITION_ON, INT, "0"}}, }; diff --git a/openpilot/selfdrive/modeld/modeld.py b/openpilot/selfdrive/modeld/modeld.py index 62e4867efb..ca3343ed69 100755 --- a/openpilot/selfdrive/modeld/modeld.py +++ b/openpilot/selfdrive/modeld/modeld.py @@ -29,11 +29,11 @@ from openpilot.selfdrive.modeld.parse_model_outputs import Parser from openpilot.selfdrive.modeld.compile_modeld import make_input_queues, WARP_INPUTS, POLICY_INPUTS from openpilot.selfdrive.modeld.fill_model_msg import fill_model_msg, fill_driving_model_data, fill_pose_msg, PublishState from openpilot.common.file_chunker import open_file_chunked -from openpilot.selfdrive.modeld.load_progress import open_with_progress from openpilot.selfdrive.modeld.constants import ModelConstants, Plan from openpilot.selfdrive.modeld.helpers import usbgpu_present, usbgpu_compiled, modeld_pkl_path, get_tg_input_devices, load_oob from openpilot.sunnypilot.livedelay.helpers import get_lat_delay +from openpilot.sunnypilot.modeld_v2.load_progress import open_with_progress from openpilot.sunnypilot.modeld_v2.modeld_base import ModelStateBase from openpilot.sunnypilot.selfdrive.controls.lib.relc import RoadEdgeLaneChangeController @@ -224,7 +224,6 @@ def main(demo=False): os.environ['HCQDEV_WAIT_TIMEOUT_MS'] = '3000' params = Params() params.put_bool("UsbGpuLoading", USBGPU) - params.put("UsbGpuLoadProgress", 0) params.remove("UsbGpuActive") config_realtime_process(7, 54) diff --git a/openpilot/selfdrive/ui/mici/onroad/hud_renderer.py b/openpilot/selfdrive/ui/mici/onroad/hud_renderer.py index c816a0adc4..2d1f954122 100644 --- a/openpilot/selfdrive/ui/mici/onroad/hud_renderer.py +++ b/openpilot/selfdrive/ui/mici/onroad/hud_renderer.py @@ -223,7 +223,7 @@ class HudRenderer(Widget): if icon is not self._egpu_icon: self._egpu_fade_time = rl.get_time() self._egpu_icon = icon - alpha = self._egpu_alpha_filter.update(True) + alpha = self._egpu_alpha_filter.update(loading or 0 < rl.get_time() - self._egpu_fade_time < SET_SPEED_PERSISTENCE) if alpha < 1e-2: return @@ -231,18 +231,6 @@ class HudRenderer(Widget): rect.y + rect.height - 14 - (self._txt_wheel.height + icon.height) / 2) rl.draw_texture_ex(icon, pos, 0.0, 1.0, rl.Color(255, 255, 255, int(255 * opacity * alpha))) - if loading: - pct_text = f"{ui_state.usbgpu_load_progress}%" - size = FONT_SIZES.max_speed - cell = measure_text_cached(self._font_bold, "0", size) - widths = [cell.x if c.isdigit() else measure_text_cached(self._font_bold, c, size).x for c in pct_text] - x = pos.x - 8 - sum(widths) - y = pos.y + (icon.height - cell.y) / 2 - for c, w in zip(pct_text, widths, strict=True): - glyph = measure_text_cached(self._font_bold, c, size).x - rl.draw_text_ex(self._font_bold, c, rl.Vector2(x + (w - glyph) / 2, y), size, 0, rl.WHITE) - x += w - def _draw_steering_wheel(self, rect: rl.Rectangle) -> None: wheel_txt = self._txt_wheel_critical if self._show_wheel_critical else self._txt_wheel diff --git a/openpilot/selfdrive/ui/sunnypilot/mici/onroad/hud_renderer.py b/openpilot/selfdrive/ui/sunnypilot/mici/onroad/hud_renderer.py index 9d39d01727..a9e4605a2a 100644 --- a/openpilot/selfdrive/ui/sunnypilot/mici/onroad/hud_renderer.py +++ b/openpilot/selfdrive/ui/sunnypilot/mici/onroad/hud_renderer.py @@ -6,8 +6,10 @@ See the LICENSE.md file in the root directory for more details. """ import pyray as rl -from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer +from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer, FONT_SIZES, SET_SPEED_PERSISTENCE from openpilot.selfdrive.ui.sunnypilot.onroad.blind_spot_indicators import BlindSpotIndicators +from openpilot.selfdrive.ui.ui_state import ui_state +from openpilot.system.ui.lib.text_measure import measure_text_cached class HudRendererSP(HudRenderer): @@ -23,6 +25,28 @@ class HudRendererSP(HudRenderer): super()._render(rect) self.blind_spot_indicators.render(rect) + def _draw_model_source(self, rect: rl.Rectangle) -> None: + self._egpu_fade_time = rl.get_time() - SET_SPEED_PERSISTENCE / 2 + super()._draw_model_source(rect) + + if not ui_state.usbgpu_loading or ui_state.sm.recv_frame['selfdriveState'] < ui_state.started_frame: + return + + icon = self._txt_egpu + pos = rl.Vector2(rect.x + rect.width - 10 - icon.width, + rect.y + rect.height - 14 - (self._txt_wheel.height + icon.height) / 2) + + pct_text = f"{ui_state.usbgpu_load_progress}%" + size = FONT_SIZES.max_speed + cell = measure_text_cached(self._font_bold, "0", size) + widths = [cell.x if c.isdigit() else measure_text_cached(self._font_bold, c, size).x for c in pct_text] + x = pos.x - 8 - sum(widths) + y = pos.y + (icon.height - cell.y) / 2 + for c, w in zip(pct_text, widths): + glyph = measure_text_cached(self._font_bold, c, size).x + rl.draw_text_ex(self._font_bold, c, rl.Vector2(x + (w - glyph) / 2, y), size, 0, rl.WHITE) + x += w + def _has_blind_spot_detected(self) -> bool: return self.blind_spot_indicators.detected diff --git a/openpilot/selfdrive/ui/sunnypilot/ui_state.py b/openpilot/selfdrive/ui/sunnypilot/ui_state.py index 602830a4db..7c7f546e86 100644 --- a/openpilot/selfdrive/ui/sunnypilot/ui_state.py +++ b/openpilot/selfdrive/ui/sunnypilot/ui_state.py @@ -42,6 +42,8 @@ class UIStateSP: self.screensaver = ScreenSaverSP(params=self.params) self.screensaver_enabled: bool = False + self.usbgpu_load_progress: int = self.params.get("UsbGpuLoadProgress", return_default=True) + self.active_bundle = None self.blindspot: bool = False self.chevron_metrics = None @@ -175,6 +177,8 @@ class UIStateSP: self.boot_offroad_mode = self.params.get("DeviceBootMode", return_default=True) self.always_offroad = self.params.get_bool("OffroadMode") self.screensaver_enabled = self.params.get_bool("ScreenSaverEnabled") + if self.usbgpu_loading: + self.usbgpu_load_progress = self.params.get("UsbGpuLoadProgress", return_default=True) if not self._sp_initialized: self._sp_initialized = True diff --git a/openpilot/selfdrive/ui/ui_state.py b/openpilot/selfdrive/ui/ui_state.py index 425ebcad5c..e0aca74ff2 100644 --- a/openpilot/selfdrive/ui/ui_state.py +++ b/openpilot/selfdrive/ui/ui_state.py @@ -86,7 +86,6 @@ class UIState(UIStateSP): self.usbgpu_compiled: bool = usbgpu_compiled() self.usbgpu_active: bool | None = self.params.get("UsbGpuActive") self.usbgpu_loading: bool = self.params.get_bool("UsbGpuLoading") - self.usbgpu_load_progress: int = self.params.get("UsbGpuLoadProgress", return_default=True) self.started: bool = False self.ignition: bool = False self.recording_audio: bool = False @@ -165,9 +164,6 @@ class UIState(UIStateSP): # Update started state self.started = self.sm["deviceState"].started and self.ignition - if self.usbgpu_loading: - self.usbgpu_load_progress = self.params.get("UsbGpuLoadProgress", return_default=True) - # Update body state if self.CP is not None and self.is_body != self.CP.notCar: self.is_body = self.CP.notCar diff --git a/openpilot/selfdrive/modeld/load_progress.py b/openpilot/sunnypilot/modeld_v2/load_progress.py similarity index 91% rename from openpilot/selfdrive/modeld/load_progress.py rename to openpilot/sunnypilot/modeld_v2/load_progress.py index 8c861f38ea..cc08aa444c 100644 --- a/openpilot/selfdrive/modeld/load_progress.py +++ b/openpilot/sunnypilot/modeld_v2/load_progress.py @@ -1,5 +1,5 @@ import os -from openpilot.common.file_chunker import open_file_chunked, get_existing_chunks +from openpilot.common.file_chunker import open_file_chunked, get_existing_chunks, get_manifest_path from openpilot.common.params import Params PARAM = "UsbGpuLoadProgress" @@ -40,5 +40,6 @@ class ProgressReader: def open_with_progress(pkl_path): - total = sum(os.path.getsize(p) for p in get_existing_chunks(pkl_path)) + manifest = get_manifest_path(pkl_path) + total = sum(os.path.getsize(p) for p in get_existing_chunks(pkl_path) if p != manifest) return ProgressReader(open_file_chunked(pkl_path), total) diff --git a/openpilot/sunnypilot/modeld_v2/modeld.py b/openpilot/sunnypilot/modeld_v2/modeld.py index 2faf9ace14..66ff360066 100755 --- a/openpilot/sunnypilot/modeld_v2/modeld.py +++ b/openpilot/sunnypilot/modeld_v2/modeld.py @@ -25,7 +25,7 @@ from opendbc.car.car_helpers import get_demo_car_params from tinygrad.tensor import Tensor from openpilot.common.file_chunker import open_file_chunked -from openpilot.selfdrive.modeld.load_progress import open_with_progress +from openpilot.sunnypilot.modeld_v2.load_progress import open_with_progress from openpilot.common.swaglog import cloudlog from openpilot.common.params import Params from openpilot.common.filter_simple import FirstOrderFilter