mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-23 06:43:47 +08:00
cleanup
This commit is contained in:
@@ -2,15 +2,16 @@ import os
|
||||
from openpilot.common.file_chunker import open_file_chunked, get_existing_chunks
|
||||
from openpilot.common.params import Params
|
||||
|
||||
PARAM = "UsbGpuLoadProgress"
|
||||
|
||||
|
||||
class ProgressReader:
|
||||
# wraps a chunked stream, writes byte-read % to a param (throttled to whole percent)
|
||||
def __init__(self, inner, total, param):
|
||||
self._inner, self._total, self._param = inner, total, param
|
||||
def __init__(self, inner, total):
|
||||
self._inner = inner
|
||||
self._total = total
|
||||
self._params = Params()
|
||||
self._read = 0
|
||||
self._pct = -1
|
||||
# sub-read size ~ 1% of total, so big weight buffers advance the % smoothly (not in jumps)
|
||||
self._step = max(64 * 1024, total // 100)
|
||||
|
||||
def _bump(self, n):
|
||||
@@ -19,7 +20,7 @@ class ProgressReader:
|
||||
pct = min(100, self._read * 100 // self._total)
|
||||
if pct != self._pct:
|
||||
self._pct = pct
|
||||
self._params.put(self._param, pct)
|
||||
self._params.put(PARAM, pct)
|
||||
|
||||
def read(self, size=-1):
|
||||
data = self._inner.read(size)
|
||||
@@ -27,7 +28,6 @@ class ProgressReader:
|
||||
return data
|
||||
|
||||
def readinto(self, b):
|
||||
# sub-chunk big buffers so the % advances smoothly instead of jumping per weight
|
||||
view = memoryview(b)
|
||||
done = 0
|
||||
while done < len(view):
|
||||
@@ -39,7 +39,6 @@ class ProgressReader:
|
||||
return done
|
||||
|
||||
|
||||
def open_with_progress(pkl_path, param="UsbGpuLoadProgress"):
|
||||
# chunked reader that reports load progress to `param`
|
||||
def open_with_progress(pkl_path):
|
||||
total = sum(os.path.getsize(p) for p in get_existing_chunks(pkl_path))
|
||||
return ProgressReader(open_file_chunked(pkl_path), total, param)
|
||||
return ProgressReader(open_file_chunked(pkl_path), total)
|
||||
|
||||
@@ -108,7 +108,6 @@ class HudRenderer(Widget):
|
||||
self.v_ego_cluster_seen: bool = False
|
||||
self._engaged: bool = False
|
||||
self._small_model_engaged: bool = False
|
||||
self._egpu_fade_time: float = 0
|
||||
|
||||
self._can_draw_top_icons = True
|
||||
self._show_wheel_critical = False
|
||||
@@ -128,13 +127,11 @@ class HudRenderer(Widget):
|
||||
self._txt_egpu_green: rl.Texture = gui_app.texture('icons_mici/egpu_green.png', 60, 44)
|
||||
self._txt_egpu_orange: rl.Texture = gui_app.texture('icons_mici/egpu_orange.png', 60, 44)
|
||||
self._txt_egpu_crossed: rl.Texture = gui_app.texture('icons_mici/egpu_crossed.png', 60, 52)
|
||||
self._egpu_icon: rl.Texture | None = None
|
||||
|
||||
self._wheel_alpha_filter = FirstOrderFilter(0, 0.05, 1 / gui_app.target_fps)
|
||||
self._wheel_y_filter = FirstOrderFilter(0, 0.1, 1 / gui_app.target_fps)
|
||||
|
||||
self._set_speed_alpha_filter = FirstOrderFilter(0.0, 0.1, 1 / gui_app.target_fps)
|
||||
self._egpu_alpha_filter = FirstOrderFilter(0.0, 0.1, 1 / gui_app.target_fps)
|
||||
|
||||
def set_wheel_critical_icon(self, critical: bool):
|
||||
"""Set the wheel icon to critical or normal state."""
|
||||
@@ -168,8 +165,6 @@ class HudRenderer(Widget):
|
||||
if (engaged and not self._engaged and not ui_state.usbgpu_loading and ui_state.usbgpu_active is not True and
|
||||
ui_state.sm.recv_frame['modelV2'] > ui_state.started_frame):
|
||||
self._small_model_engaged = True
|
||||
if engaged != self._engaged:
|
||||
self._egpu_fade_time = rl.get_time() if engaged else 0
|
||||
if (set_speed != self.set_speed and engaged) or (engaged and not self._engaged):
|
||||
self._set_speed_changed_time = rl.get_time()
|
||||
self._engaged = engaged
|
||||
@@ -220,17 +215,9 @@ class HudRenderer(Widget):
|
||||
icon = self._txt_egpu_green
|
||||
opacity = 1.0
|
||||
|
||||
if icon is not self._egpu_icon:
|
||||
self._egpu_fade_time = rl.get_time()
|
||||
self._egpu_icon = icon
|
||||
# alpha = self._egpu_alpha_filter.update(loading or 0 < rl.get_time() - self._egpu_fade_time < SET_SPEED_PERSISTENCE)
|
||||
# if alpha < 1e-2:
|
||||
# return
|
||||
alpha = 1.0
|
||||
|
||||
pos = rl.Vector2(rect.x + rect.width - 10 - icon.width,
|
||||
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)))
|
||||
rl.draw_texture_ex(icon, pos, 0.0, 1.0, rl.Color(255, 255, 255, int(255 * opacity)))
|
||||
|
||||
if loading:
|
||||
pct_text = f"{ui_state.usbgpu_load_progress}%"
|
||||
|
||||
@@ -165,7 +165,6 @@ class UIState(UIStateSP):
|
||||
# Update started state
|
||||
self.started = self.sm["deviceState"].started and self.ignition
|
||||
|
||||
# Poll gpu load progress per-frame (not 5Hz) so the % counter updates smoothly
|
||||
if self.usbgpu_loading:
|
||||
self.usbgpu_load_progress = self.params.get("UsbGpuLoadProgress", return_default=True)
|
||||
|
||||
@@ -227,7 +226,6 @@ class UIState(UIStateSP):
|
||||
self.usbgpu_compiled = usbgpu_compiled()
|
||||
self.usbgpu_active = self.params.get("UsbGpuActive")
|
||||
self.usbgpu_loading = self.params.get_bool("UsbGpuLoading")
|
||||
self.usbgpu_load_progress = self.params.get("UsbGpuLoadProgress", return_default=True)
|
||||
|
||||
UIStateSP.update_params(self)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user