From 5845381d1f637581241eebb02f53fa7bc7e07f3c Mon Sep 17 00:00:00 2001 From: royjr Date: Mon, 2 Nov 2026 16:20:54 -0500 Subject: [PATCH] park --- openpilot/common/params_keys.h | 1 + .../ui/sunnypilot/layouts/settings/visuals.py | 5 +++ .../ui/sunnypilot/layouts/trip_summary.py | 34 +++++++++++++------ openpilot/selfdrive/ui/sunnypilot/ui_state.py | 2 ++ .../sunnypilot/sunnylink/settings_ui.json | 6 ++++ .../settings_ui_src/pages/visuals.yaml | 4 +++ 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/openpilot/common/params_keys.h b/openpilot/common/params_keys.h index 1ccd8110a6..677efe533d 100644 --- a/openpilot/common/params_keys.h +++ b/openpilot/common/params_keys.h @@ -199,6 +199,7 @@ inline static std::unordered_map keys = { {"ShowAdvancedControls", {PERSISTENT | BACKUP, BOOL, "0"}}, {"ShowTurnSignals", {PERSISTENT | BACKUP, BOOL, "0"}}, {"StandstillTimer", {PERSISTENT | BACKUP, BOOL, "0"}}, + {"TripSummary", {PERSISTENT | BACKUP, BOOL, "1"}}, {"TrueVEgoUI", {PERSISTENT | BACKUP, BOOL, "0"}}, // MADS params diff --git a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/visuals.py b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/visuals.py index 84be5a26ab..0e493c8fb7 100644 --- a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/visuals.py +++ b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/visuals.py @@ -72,6 +72,11 @@ class VisualsLayout(Widget): "It is the driver's responsibility to observe their environment and make decisions accordingly."), None, ), + "TripSummary": ( + lambda: tr("Trip Summary"), + tr("Show a summary of distance and engagement when you shift into park after a drive."), + None, + ), "TrueVEgoUI": ( lambda: tr("Speedometer: Always Display True Speed"), tr("For applicable vehicles, always display the true vehicle current speed from wheel speed sensors."), diff --git a/openpilot/selfdrive/ui/sunnypilot/layouts/trip_summary.py b/openpilot/selfdrive/ui/sunnypilot/layouts/trip_summary.py index 3c449a7276..ac55a72400 100644 --- a/openpilot/selfdrive/ui/sunnypilot/layouts/trip_summary.py +++ b/openpilot/selfdrive/ui/sunnypilot/layouts/trip_summary.py @@ -7,6 +7,8 @@ See the LICENSE.md file in the root directory for more details. import time import pyray as rl +from opendbc.car.structs import car + from openpilot.common.constants import CV from openpilot.selfdrive.ui.onroad.augmented_road_view import BORDER_COLORS from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus @@ -19,6 +21,8 @@ AUTO_DISMISS = 20. FADE_IN, FADE_OUT = 0.35, 0.3 LAT = (UIStatus.ENGAGED, UIStatus.LAT_ONLY) LONG = (UIStatus.ENGAGED, UIStatus.LONG_ONLY) +GEAR = car.CarState.GearShifter +FORWARD = (GEAR.drive, GEAR.sport, GEAR.low, GEAR.brake, GEAR.eco, GEAR.manumatic) class TripTracker: @@ -32,10 +36,11 @@ class TripTracker: self._t = None self._status = None - def update(self): + def update(self, driving: bool): now = time.monotonic() - if not ui_state.started: + if not driving: self._t = None + self._status = None return dt = 0. if self._t is None else min(now - self._t, 0.5) self._t = now @@ -59,20 +64,27 @@ class TripSummary: def __init__(self): self._trip = TripTracker() self._dialog: TripSummaryDialog | None = None - self._started = False + self._gear = None + self._drove = False gui_app.add_nav_stack_tick(self._tick) def _tick(self): - self._trip.update() - if ui_state.started == self._started: + gear = ui_state.sm["carState"].gearShifter if ui_state.started else None + self._trip.update(gear not in (None, GEAR.park)) + self._drove |= gear in FORWARD + if gear == self._gear: return - self._started = ui_state.started + self._gear = gear - self._pop() - if not ui_state.started and not ui_state.is_body and self._trip.total() >= MIN_DISTANCE: + if gear not in (None, GEAR.park): + self._pop() + elif gear == GEAR.park and self._drove and ui_state.trip_summary and not ui_state.is_body and self._trip.total() >= MIN_DISTANCE: self._dialog = TripSummaryDialog(self._trip, gui_app.get_active_widget(), self._pop) gui_app.push_widget(self._dialog) - self._trip.reset() + if gear is None: + self._trip.reset() + if gear in (None, GEAR.park): + self._drove = False def _pop(self): if self._dialog is not None and gui_app.get_active_widget() is self._dialog: @@ -172,7 +184,7 @@ class TripSummaryDialog(Widget): y += (90 + 70) * k - size = int(70 * k) + size = int(90 * k) parts = [] for i, (value, unit) in enumerate(self._details): if i: @@ -182,7 +194,7 @@ class TripSummaryDialog(Widget): lx = x + (w - sum(widths)) / 2 for (text, font, color), tw in zip(parts, widths, strict=True): if color is None: - rl.draw_circle(int(lx + tw / 2), int(y + 40 * k), 7 * k, _fade(rl.Color(110, 110, 110, 255), a)) + rl.draw_circle(int(lx + tw / 2), int(y + size * 0.6), 12 * k, _fade(rl.Color(110, 110, 110, 255), a)) else: rl.draw_text_ex(font, text, rl.Vector2(lx, y), size, 0, _fade(color, a)) lx += tw diff --git a/openpilot/selfdrive/ui/sunnypilot/ui_state.py b/openpilot/selfdrive/ui/sunnypilot/ui_state.py index 521d1cee34..f60c64a688 100644 --- a/openpilot/selfdrive/ui/sunnypilot/ui_state.py +++ b/openpilot/selfdrive/ui/sunnypilot/ui_state.py @@ -48,6 +48,7 @@ class UIStateSP: self.model_runner_tinygrad: bool = False self.active_runner_tinygrad: bool = False self.blindspot: bool = False + self.trip_summary: bool = True self.chevron_metrics = None self.custom_interactive_timeout: int = 0 self.developer_ui = None @@ -185,6 +186,7 @@ class UIStateSP: self.standstill_timer = self.params.get_bool("StandstillTimer") self.sunnylink_enabled = self.params.get_bool("SunnylinkEnabled") self.torque_bar = self.params.get_bool("TorqueBar") + self.trip_summary = self.params.get_bool("TripSummary") self.enforce_torque_control = self.params.get_bool("EnforceTorqueControl") self.custom_torque_params = self.params.get_bool("CustomTorqueParams") self.torque_override_enabled = self.params.get_bool("TorqueParamsOverrideEnabled") diff --git a/openpilot/sunnypilot/sunnylink/settings_ui.json b/openpilot/sunnypilot/sunnylink/settings_ui.json index 215331dde1..29f7496584 100644 --- a/openpilot/sunnypilot/sunnylink/settings_ui.json +++ b/openpilot/sunnypilot/sunnylink/settings_ui.json @@ -1399,6 +1399,12 @@ } ] }, + { + "key": "TripSummary", + "widget": "toggle", + "title": "Trip Summary", + "description": "Show a summary of distance and engagement when you shift into park after a drive." + }, { "key": "RocketFuel", "widget": "toggle", diff --git a/openpilot/sunnypilot/sunnylink/settings_ui_src/pages/visuals.yaml b/openpilot/sunnypilot/sunnylink/settings_ui_src/pages/visuals.yaml index a253c64122..934907e999 100644 --- a/openpilot/sunnypilot/sunnylink/settings_ui_src/pages/visuals.yaml +++ b/openpilot/sunnypilot/sunnylink/settings_ui_src/pages/visuals.yaml @@ -39,6 +39,10 @@ sections: description: Show a timer on the HUD when the car is at a standstill. visibility: - $ref: '#/macros/hide_on_mici' + - key: TripSummary + widget: toggle + title: Trip Summary + description: Show a summary of distance and engagement when you shift into park after a drive. - key: RocketFuel widget: toggle title: Real-time Acceleration Bar