From de2ac23c6096910c3f188e452d59a7c9f2172a33 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Fri, 21 Aug 2026 21:01:02 +0000 Subject: [PATCH 01/30] tesla_preap: auto-read donor radar VIN Wire card to persist F190 and add a Settings override. Leave the VIN blank and a working radar stays on this-car passthrough. Co-authored-by: Cursor --- common/params_keys.h | 3 ++ opendbc_repo | 2 +- selfdrive/car/card.py | 28 +++++++++++ selfdrive/ui/layouts/settings/nap.py | 70 ++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/common/params_keys.h b/common/params_keys.h index 12b89d87e93f85..6a75b33752ecb0 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -145,8 +145,11 @@ inline static std::unordered_map keys = { {"NAPPedalEnabled", {PERSISTENT, BOOL}}, {"NAPPedalProfile", {PERSISTENT, INT, "4"}}, {"NAPRadarBehindNosecone", {PERSISTENT, BOOL}}, + {"NAPRadarDonorVin", {PERSISTENT, STRING}}, {"NAPRadarEnabled", {PERSISTENT, BOOL}}, + {"NAPRadarEpasType", {PERSISTENT, INT, "0"}}, {"NAPRadarOffset", {PERSISTENT, FLOAT, "0.0"}}, + {"NAPRadarPosition", {PERSISTENT, INT, "0"}}, {"NAPScriptRunning", {CLEAR_ON_MANAGER_START, BOOL}}, {"TermsVersion", {PERSISTENT, STRING}}, {"TrainingVersion", {PERSISTENT, STRING}}, diff --git a/opendbc_repo b/opendbc_repo index 5c30f9491a872a..347ac59b236e71 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit 5c30f9491a872a545a410365bbc0aafd78b22c4a +Subproject commit 347ac59b236e710d33de8909b15f4135da9fcaea diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 5ece1bce8782ff..884f1e5fa36134 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -158,11 +158,26 @@ def __init__(self, CI=None, RI=None) -> None: # card is driven by can recv, expected at 100Hz self.rk = Ratekeeper(100, print_delay_threshold=None) + self._can_packets: list[CanData] = [] + self.radar_donor_vin = None + tesla_preap = any(cfg.safetyModel == car.CarParams.SafetyModel.teslaPreap for cfg in self.CP.safetyConfigs) + if tesla_preap: + from opendbc.car.tesla.preap.nap_conf import nap_conf + from opendbc.car.tesla.preap.radar_donor_vin import RadarDonorVinCommissioner + + def store_donor_vin(vin: str) -> None: + nap_conf.radar_donor_vin = vin + cloudlog.info("preap radar donor vin stored") + + self._nap_conf = nap_conf + self.radar_donor_vin = RadarDonorVinCommissioner(store_donor_vin) + def state_update(self) -> tuple[car.CarState, structs.RadarDataT | None]: """carState update loop, driven by can""" can_strs = messaging.drain_sock_raw(self.can_sock, wait_for_one=True) can_list = can_capnp_to_list(can_strs) + self._can_packets = [CanData(addr, dat, src) for _ts, frames in can_list for addr, dat, src in frames] # Update carState from CAN CS = self.CI.update(can_list) @@ -258,6 +273,19 @@ def controls_update(self, CS: car.CarState, CC: car.CarControl): # send car controls over can now_nanos = self.can_log_mono_time if REPLAY else int(time.monotonic() * 1e9) self.last_actuators_output, can_sends = self.CI.apply(CC, now_nanos) + can_sends = list(can_sends) + if self.radar_donor_vin is not None: + controls_allowed = False + if self.sm.valid['pandaStates']: + controls_allowed = any(ps.controlsAllowed for ps in self.sm['pandaStates']) + can_sends.extend(self.radar_donor_vin.update( + self._can_packets, + time.monotonic(), + radar_enabled=self._nap_conf.radar_enabled, + stored_vin=self._nap_conf.radar_donor_vin, + controls_allowed=controls_allowed, + enabled=bool(CC.enabled), + )) self.pm.send('sendcan', can_list_to_can_capnp(can_sends, msgtype='sendcan', valid=CS.canValid)) self.CC_prev = CC diff --git a/selfdrive/ui/layouts/settings/nap.py b/selfdrive/ui/layouts/settings/nap.py index 69fe36019ba79c..4caefb3263143f 100644 --- a/selfdrive/ui/layouts/settings/nap.py +++ b/selfdrive/ui/layouts/settings/nap.py @@ -188,6 +188,40 @@ def _build_items(self): ) self._all_items.append(self._radar_offset_btn) + self._radar_vin_keyboard = Keyboard(max_text_size=17) + self._radar_vin_btn = button_item( + "Donor Radar VIN", + self._get_radar_vin_text, + description=( + "VIN already programmed in a salvage radar. Leave empty to send this car. " + + "A 17-character VIN makes panda impersonate the donor (Tinkla 0.6.6)." + ), + callback=self._on_radar_vin_click, + ) + self._all_items.append(self._radar_vin_btn) + + radar_position = int(self._params.get(NAPParamKeys.RADAR_POSITION, return_default=True) or 0) + self._radar_position_buttons = multiple_button_item( + "Donor Radar Position", + "Must match the donor car: 0 pre-facelift S, 1 post-facelift S, 2 Model X.", + buttons=["0", "1", "2"], + button_width=130, + selected_index=max(0, min(2, radar_position)), + callback=self._on_radar_position, + ) + self._all_items.append(self._radar_position_buttons) + + radar_epas = int(self._params.get(NAPParamKeys.RADAR_EPAS_TYPE, return_default=True) or 0) + self._radar_epas_buttons = multiple_button_item( + "Donor EPAS Type", + "Must match the donor car rack: 0 Bosch L538, 1 L405, 2 Mando FGR64, 3 VGR66, 4 VGR66 Gen3.", + buttons=["0", "1", "2", "3", "4"], + button_width=100, + selected_index=max(0, min(4, radar_epas)), + callback=self._on_radar_epas, + ) + self._all_items.append(self._radar_epas_buttons) + self._calibrate_radar_btn = button_item( "Calibrate Radar", "Start", @@ -335,6 +369,42 @@ def _get_radar_offset(self) -> float: def _get_radar_offset_text(self) -> str: return f"{self._get_radar_offset():+.2f}m" + def _get_radar_vin_text(self) -> str: + raw = self._params.get(NAPParamKeys.RADAR_DONOR_VIN, return_default=True) or "" + if isinstance(raw, bytes): + raw = raw.decode("ascii", errors="ignore") + vin = "".join(ch for ch in str(raw).upper() if ch.isalnum()) + return vin if len(vin) == 17 else "Not set" + + def _on_radar_vin_click(self): + current = self._get_radar_vin_text() + self._radar_vin_keyboard.reset(min_text_size=0) + self._radar_vin_keyboard.set_title("Donor Radar VIN") + self._radar_vin_keyboard.set_text("" if current == "Not set" else current) + self._radar_vin_keyboard.set_callback(self._on_radar_vin_submit) + gui_app.push_widget(self._radar_vin_keyboard) + + def _on_radar_vin_submit(self, result: DialogResult): + if result != DialogResult.CONFIRM: + return + text = "".join(ch for ch in (self._radar_vin_keyboard.text or "").upper() if ch.isalnum()) + try: + self._params.put(NAPParamKeys.RADAR_DONOR_VIN, text if len(text) == 17 else "") + except Exception: + pass + + def _on_radar_position(self, index: int): + try: + self._params.put(NAPParamKeys.RADAR_POSITION, int(index)) + except Exception: + pass + + def _on_radar_epas(self, index: int): + try: + self._params.put(NAPParamKeys.RADAR_EPAS_TYPE, int(index)) + except Exception: + pass + def _on_radar_offset_click(self): self._radar_offset_keyboard.reset(min_text_size=1) self._radar_offset_keyboard.set_title("Radar Lateral Offset (m)") From e59da745999cf8eaf2eea16046cbecc9bf58e366 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Sat, 22 Aug 2026 02:48:37 +0000 Subject: [PATCH 02/30] restore x86_64 acados pointers comma LFS can fetch Device checkout smudges every LFS file, including unused x86_64 acados. Process replay rebuilt those blobs onto hashes that are not on comma's GitLab LFS, so installer and updater 404. Point them back at the nap-release objects. Co-authored-by: Cursor --- third_party/acados/x86_64/lib/libacados.so | 4 ++-- third_party/acados/x86_64/lib/libblasfeo.so | 4 ++-- third_party/acados/x86_64/lib/libhpipm.so | 4 ++-- third_party/acados/x86_64/lib/libqpOASES_e.so.3.1 | 4 ++-- third_party/acados/x86_64/t_renderer | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) mode change 100755 => 100644 third_party/acados/x86_64/lib/libacados.so mode change 100755 => 100644 third_party/acados/x86_64/lib/libblasfeo.so mode change 100755 => 100644 third_party/acados/x86_64/lib/libhpipm.so mode change 100755 => 100644 third_party/acados/x86_64/lib/libqpOASES_e.so.3.1 diff --git a/third_party/acados/x86_64/lib/libacados.so b/third_party/acados/x86_64/lib/libacados.so old mode 100755 new mode 100644 index 310e5c667fc241..50d647a8621fdd --- a/third_party/acados/x86_64/lib/libacados.so +++ b/third_party/acados/x86_64/lib/libacados.so @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e5aa31ab510a3abd857c8bed05eba3bf7a9c1492a5d3af16a4a661f1a2594362 -size 524840 +oid sha256:05a1ba3cf37fa929cdd56f892608b2f89c35a05ef1b07fedb86b2f0d76607263 +size 540488 diff --git a/third_party/acados/x86_64/lib/libblasfeo.so b/third_party/acados/x86_64/lib/libblasfeo.so old mode 100755 new mode 100644 index 86f2b99977a1e5..a98f45abd2e47c --- a/third_party/acados/x86_64/lib/libblasfeo.so +++ b/third_party/acados/x86_64/lib/libblasfeo.so @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bf9f20d8a35a9c6d950baa2dacddbde79a27802c6333b932e4dc861db5f25b55 -size 1826800 +oid sha256:c0bf22898d9c59b672d3d0961f5f4c804b9957478125d99eb297de3091bedd15 +size 2416112 diff --git a/third_party/acados/x86_64/lib/libhpipm.so b/third_party/acados/x86_64/lib/libhpipm.so old mode 100755 new mode 100644 index 248a52dae5e7f7..f40cb487cd7cfa --- a/third_party/acados/x86_64/lib/libhpipm.so +++ b/third_party/acados/x86_64/lib/libhpipm.so @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ca818463ac47da7eb4cb8a504d19b913e9882dcd338f864faa98a47c6e3791fc -size 1547672 +oid sha256:5b6875fb47940764d4ebb916c2373cb0e04929229feb654b290676c28d48fa9d +size 1531024 diff --git a/third_party/acados/x86_64/lib/libqpOASES_e.so.3.1 b/third_party/acados/x86_64/lib/libqpOASES_e.so.3.1 old mode 100755 new mode 100644 index 2057e5676fbbbc..81afd059f7ea12 --- a/third_party/acados/x86_64/lib/libqpOASES_e.so.3.1 +++ b/third_party/acados/x86_64/lib/libqpOASES_e.so.3.1 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:964de7e4102fc72066df5acedff8d0a6f274f7176f85836697091346e6ffdd9d -size 270464 +oid sha256:04be908c3f707e5c968022b9cdd79ab75ae7af46e7fa019ceee98f854ddd3f64 +size 262464 diff --git a/third_party/acados/x86_64/t_renderer b/third_party/acados/x86_64/t_renderer index a083dfe6184e0a..d41f6c37255482 100755 --- a/third_party/acados/x86_64/t_renderer +++ b/third_party/acados/x86_64/t_renderer @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:58b8e3ee9943ad2730604e6e61591afbfa880a7c6055581758bac56b7d92575f -size 5404496 +oid sha256:a53ae46650c4df5b0ddb87a658f59a0422e41743e8bc2d822da0aefd1d280791 +size 5088536 From 2c03ea0ea23657c4f7e62883d81aa2e4a1e7c61f Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Sat, 22 Aug 2026 04:22:43 +0000 Subject: [PATCH 03/30] nap: radar settings page and Read VIN Testers need a one-shot F190 read without a VIN fault, and the radar controls were crowding the main NAP page. Nested under Radar Settings on 3X and C4. Co-authored-by: Cursor --- common/params_keys.h | 1 + opendbc_repo | 2 +- selfdrive/car/card.py | 4 + selfdrive/ui/layouts/settings/nap.py | 284 ++++++++++++++-------- selfdrive/ui/mici/layouts/settings/nap.py | 209 +++++++++++----- 5 files changed, 330 insertions(+), 170 deletions(-) diff --git a/common/params_keys.h b/common/params_keys.h index 6a75b33752ecb0..913d46409180fc 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -150,6 +150,7 @@ inline static std::unordered_map keys = { {"NAPRadarEpasType", {PERSISTENT, INT, "0"}}, {"NAPRadarOffset", {PERSISTENT, FLOAT, "0.0"}}, {"NAPRadarPosition", {PERSISTENT, INT, "0"}}, + {"NAPRadarReadVin", {CLEAR_ON_MANAGER_START, BOOL}}, {"NAPScriptRunning", {CLEAR_ON_MANAGER_START, BOOL}}, {"TermsVersion", {PERSISTENT, STRING}}, {"TrainingVersion", {PERSISTENT, STRING}}, diff --git a/opendbc_repo b/opendbc_repo index 347ac59b236e71..f29a061c7a67dd 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit 347ac59b236e710d33de8909b15f4135da9fcaea +Subproject commit f29a061c7a67ddc9189500a2db04717ee56593f1 diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 884f1e5fa36134..bac56c9fb2e7a3 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -278,6 +278,7 @@ def controls_update(self, CS: car.CarState, CC: car.CarControl): controls_allowed = False if self.sm.valid['pandaStates']: controls_allowed = any(ps.controlsAllowed for ps in self.sm['pandaStates']) + force_read = self.params.get_bool("NAPRadarReadVin") can_sends.extend(self.radar_donor_vin.update( self._can_packets, time.monotonic(), @@ -285,7 +286,10 @@ def controls_update(self, CS: car.CarState, CC: car.CarControl): stored_vin=self._nap_conf.radar_donor_vin, controls_allowed=controls_allowed, enabled=bool(CC.enabled), + force_read=force_read, )) + if force_read and self.radar_donor_vin.read_finished: + self.params.put_bool("NAPRadarReadVin", False) self.pm.send('sendcan', can_list_to_can_capnp(can_sends, msgtype='sendcan', valid=CS.canValid)) self.CC_prev = CC diff --git a/selfdrive/ui/layouts/settings/nap.py b/selfdrive/ui/layouts/settings/nap.py index 4caefb3263143f..67d563c414e628 100644 --- a/selfdrive/ui/layouts/settings/nap.py +++ b/selfdrive/ui/layouts/settings/nap.py @@ -10,6 +10,7 @@ ITEM_PADDING, ) from openpilot.system.ui.widgets.scroller_tici import Scroller +from openpilot.system.ui.widgets.button import Button from openpilot.system.ui.widgets.confirm_dialog import ConfirmDialog from openpilot.system.ui.lib.application import gui_app, FontWeight from openpilot.system.ui.lib.text_measure import measure_text_cached @@ -89,16 +90,21 @@ class NAPLayout(Widget): def __init__(self): super().__init__() self._params = Params() + self._page = "main" self._build_items() - self._scroller = Scroller(self._all_items, line_separator=True, spacing=0) + self._scroller = Scroller(self._main_items, line_separator=True, spacing=0) + self._radar_scroller = Scroller(self._radar_items, line_separator=True, spacing=0) + self._radar_back_btn = Button("Back", click_callback=self._close_radar) + self._radar_back_btn.set_rect(rl.Rectangle(0, 0, 220, 90)) def _build_items(self): """Build all list items organized into sections.""" - self._all_items = [] + self._main_items = [] + self._radar_items = [] self._toggle_map = {} # param_key -> ListItem (for refresh) # ── Section 1: Longitudinal Control ── - self._all_items.append(section_header_item("Longitudinal Control")) + self._main_items.append(section_header_item("Longitudinal Control")) self._add_toggle( NAPParamKeys.PEDAL_ENABLED, @@ -123,10 +129,10 @@ def _build_items(self): selected_index=max(0, min(6, follow_dist - 1)), callback=self._on_follow_distance, ) - self._all_items.append(self._follow_buttons) + self._main_items.append(self._follow_buttons) # ── Section 2: Pedal Hardware ── - self._all_items.append(section_header_item("Pedal Hardware")) + self._main_items.append(section_header_item("Pedal Hardware")) pedal_bus = self._params.get(NAPParamKeys.PEDAL_CAN_BUS, return_default=True) @@ -139,14 +145,14 @@ def _build_items(self): callback=self._on_pedal_can_bus, ) self._pedal_bus_buttons.action_item.set_enabled(ui_state.is_offroad) - self._all_items.append(self._pedal_bus_buttons) + self._main_items.append(self._pedal_bus_buttons) self._pedal_calib_status = text_item( "Pedal Calibration", lambda: "Calibrated" if self._params.get_bool(NAPParamKeys.PEDAL_CALIB_DONE) else "Not Calibrated", description="Shows whether the pedal interceptor has been calibrated.", ) - self._all_items.append(self._pedal_calib_status) + self._main_items.append(self._pedal_calib_status) self._calibrate_pedal_btn = button_item( "Calibrate Pedal", @@ -155,93 +161,21 @@ def _build_items(self): callback=self._on_calibrate_pedal, ) self._calibrate_pedal_btn.action_item.set_enabled(ui_state.is_offroad) - self._all_items.append(self._calibrate_pedal_btn) + self._main_items.append(self._calibrate_pedal_btn) - # ── Section 3: Radar ── - self._all_items.append(section_header_item("Radar")) - - self._add_toggle( - NAPParamKeys.RADAR_ENABLED, - "Radar Enabled", - "Enable the stock Bosch radar for lead car detection. Requires reboot.", - enabled=ui_state.is_offroad, - needs_reboot=True, - ) - - self._add_toggle( - NAPParamKeys.RADAR_BEHIND_NOSECONE, - "Radar Behind Nosecone", - "Apply signal attenuation adjustment for radar mounted behind the nosecone. Requires reboot.", - enabled=ui_state.is_offroad, - needs_reboot=True, + # ── Section 3: Radar (submenu) ── + self._main_items.append(section_header_item("Radar")) + self._radar_settings_btn = button_item( + "Radar Settings", + "Open", + description="Donor VIN, position, offset, test, and calibration.", + callback=self._open_radar, ) - - self._radar_offset_keyboard = Keyboard(max_text_size=10) - self._radar_offset_btn = button_item( - "Radar Lateral Offset", - self._get_radar_offset_text, - description=( - "Lateral offset in meters added to radar yRel. Negative shifts leads toward the left of current radar " - + "reading; positive shifts right. Example: -0.27 for the 3D-printed factory-location mount." - ), - callback=self._on_radar_offset_click, - ) - self._all_items.append(self._radar_offset_btn) - - self._radar_vin_keyboard = Keyboard(max_text_size=17) - self._radar_vin_btn = button_item( - "Donor Radar VIN", - self._get_radar_vin_text, - description=( - "VIN already programmed in a salvage radar. Leave empty to send this car. " - + "A 17-character VIN makes panda impersonate the donor (Tinkla 0.6.6)." - ), - callback=self._on_radar_vin_click, - ) - self._all_items.append(self._radar_vin_btn) - - radar_position = int(self._params.get(NAPParamKeys.RADAR_POSITION, return_default=True) or 0) - self._radar_position_buttons = multiple_button_item( - "Donor Radar Position", - "Must match the donor car: 0 pre-facelift S, 1 post-facelift S, 2 Model X.", - buttons=["0", "1", "2"], - button_width=130, - selected_index=max(0, min(2, radar_position)), - callback=self._on_radar_position, - ) - self._all_items.append(self._radar_position_buttons) - - radar_epas = int(self._params.get(NAPParamKeys.RADAR_EPAS_TYPE, return_default=True) or 0) - self._radar_epas_buttons = multiple_button_item( - "Donor EPAS Type", - "Must match the donor car rack: 0 Bosch L538, 1 L405, 2 Mando FGR64, 3 VGR66, 4 VGR66 Gen3.", - buttons=["0", "1", "2", "3", "4"], - button_width=100, - selected_index=max(0, min(4, radar_epas)), - callback=self._on_radar_epas, - ) - self._all_items.append(self._radar_epas_buttons) - - self._calibrate_radar_btn = button_item( - "Calibrate Radar", - "Start", - description="Run the radar calibration routine.", - callback=self._on_calibrate_radar, - ) - self._calibrate_radar_btn.action_item.set_enabled(ui_state.is_offroad) - self._all_items.append(self._calibrate_radar_btn) - - self._test_radar_btn = button_item( - "Test Radar", - "Test", - description="Test radar connectivity and verify signals.", - callback=self._on_test_radar, - ) - self._test_radar_btn.action_item.set_enabled(ui_state.is_offroad) - self._all_items.append(self._test_radar_btn) + self._main_items.append(self._radar_settings_btn) + self._build_radar_items() # ── Section 4: iBooster / Braking (not yet implemented — grayed out) ── - self._all_items.append(section_header_item("iBooster / Braking")) + self._main_items.append(section_header_item("iBooster / Braking")) self._add_toggle( NAPParamKeys.IBOOSTER_ENABLED, @@ -260,10 +194,10 @@ def _build_items(self): callback=self._on_brake_factor, ) self._brake_factor_buttons.action_item.set_enabled(False) - self._all_items.append(self._brake_factor_buttons) + self._main_items.append(self._brake_factor_buttons) # ── Section 5: Advanced ── - self._all_items.append(section_header_item("Advanced")) + self._main_items.append(section_header_item("Advanced")) # Force Pre-AP is always on for now — grayed out in the ON position self._params.put_bool(NAPParamKeys.FORCE_PRE_AP, True) @@ -275,7 +209,7 @@ def _build_items(self): ) # ── Section 6: Actions ── - self._all_items.append(section_header_item("Actions")) + self._main_items.append(section_header_item("Actions")) self._backup_epas_btn = button_item( "Backup EPAS", @@ -284,7 +218,7 @@ def _build_items(self): callback=self._on_backup_epas, ) self._backup_epas_btn.action_item.set_enabled(ui_state.is_offroad) - self._all_items.append(self._backup_epas_btn) + self._main_items.append(self._backup_epas_btn) self._flash_epas_btn = button_item( "Flash EPAS", @@ -293,7 +227,7 @@ def _build_items(self): callback=self._on_flash_epas, ) self._flash_epas_btn.action_item.set_enabled(ui_state.is_offroad) - self._all_items.append(self._flash_epas_btn) + self._main_items.append(self._flash_epas_btn) self._restore_epas_btn = button_item( "Restore EPAS", @@ -302,7 +236,7 @@ def _build_items(self): callback=self._on_restore_epas, ) self._restore_epas_btn.action_item.set_enabled(ui_state.is_offroad) - self._all_items.append(self._restore_epas_btn) + self._main_items.append(self._restore_epas_btn) self._emergency_disable_btn = button_item( "Emergency Disable", @@ -310,7 +244,7 @@ def _build_items(self): description="Immediately disable pedal interceptor and clear calibration. Restart required.", callback=self._on_emergency_disable, ) - self._all_items.append(self._emergency_disable_btn) + self._main_items.append(self._emergency_disable_btn) self._reset_defaults_btn = button_item( "Reset to Defaults", @@ -319,14 +253,111 @@ def _build_items(self): callback=self._on_reset_defaults, ) self._reset_defaults_btn.action_item.set_enabled(ui_state.is_offroad) - self._all_items.append(self._reset_defaults_btn) + self._main_items.append(self._reset_defaults_btn) # ── Acknowledgments ── - self._all_items.append(section_header_item("Acknowledgments")) - self._all_items.append(CreditsBlock(acknowledgments_html())) + self._main_items.append(section_header_item("Acknowledgments")) + self._main_items.append(CreditsBlock(acknowledgments_html())) + + def _build_radar_items(self): + self._radar_items.append(section_header_item("Radar")) + + self._add_toggle( + NAPParamKeys.RADAR_ENABLED, + "Radar Enabled", + "Enable the stock Bosch radar for lead car detection. Requires reboot.", + enabled=ui_state.is_offroad, + needs_reboot=True, + dest=self._radar_items, + ) + + self._add_toggle( + NAPParamKeys.RADAR_BEHIND_NOSECONE, + "Radar Behind Nosecone", + "Apply signal attenuation adjustment for radar mounted behind the nosecone. Requires reboot.", + enabled=ui_state.is_offroad, + needs_reboot=True, + dest=self._radar_items, + ) + + self._radar_offset_keyboard = Keyboard(max_text_size=10) + self._radar_offset_btn = button_item( + "Radar Lateral Offset", + self._get_radar_offset_text, + description=( + "Lateral offset in meters added to radar yRel. Negative shifts leads toward the left of current radar " + + "reading; positive shifts right. Example: -0.27 for the 3D-printed factory-location mount." + ), + callback=self._on_radar_offset_click, + ) + self._radar_items.append(self._radar_offset_btn) + + self._radar_vin_keyboard = Keyboard(max_text_size=17) + self._radar_vin_btn = button_item( + "Donor Radar VIN", + self._get_radar_vin_text, + description=( + "VIN already programmed in a salvage radar. Leave empty to send this car. " + + "A 17-character VIN makes panda impersonate the donor (Tinkla 0.6.6)." + ), + callback=self._on_radar_vin_click, + ) + self._radar_items.append(self._radar_vin_btn) + + self._read_vin_btn = button_item( + "Read VIN", + self._get_read_vin_text, + description=( + "Read the VIN stored in the radar (F190). Does not write or flash. " + + "Car must be on and not engaged. Power-cycle after it fills." + ), + callback=self._on_read_vin, + ) + self._radar_items.append(self._read_vin_btn) + + radar_position = int(self._params.get(NAPParamKeys.RADAR_POSITION, return_default=True) or 0) + self._radar_position_buttons = multiple_button_item( + "Donor Radar Position", + "Must match the donor car: 0 pre-facelift S, 1 post-facelift S, 2 Model X.", + buttons=["0", "1", "2"], + button_width=130, + selected_index=max(0, min(2, radar_position)), + callback=self._on_radar_position, + ) + self._radar_items.append(self._radar_position_buttons) + + radar_epas = int(self._params.get(NAPParamKeys.RADAR_EPAS_TYPE, return_default=True) or 0) + self._radar_epas_buttons = multiple_button_item( + "Donor EPAS Type", + "Must match the donor car rack: 0 Bosch L538, 1 L405, 2 Mando FGR64, 3 VGR66, 4 VGR66 Gen3.", + buttons=["0", "1", "2", "3", "4"], + button_width=100, + selected_index=max(0, min(4, radar_epas)), + callback=self._on_radar_epas, + ) + self._radar_items.append(self._radar_epas_buttons) + + self._calibrate_radar_btn = button_item( + "Calibrate Radar", + "Start", + description="Run the radar calibration routine.", + callback=self._on_calibrate_radar, + ) + self._calibrate_radar_btn.action_item.set_enabled(ui_state.is_offroad) + self._radar_items.append(self._calibrate_radar_btn) + + self._test_radar_btn = button_item( + "Test Radar", + "Test", + description="Test radar connectivity and verify signals.", + callback=self._on_test_radar, + ) + self._test_radar_btn.action_item.set_enabled(ui_state.is_offroad) + self._radar_items.append(self._test_radar_btn) def _add_toggle(self, param_key: str, title: str, description: str, - enabled: bool | None = None, needs_reboot: bool = False): + enabled: bool | None = None, needs_reboot: bool = False, + dest: list | None = None): """Helper to add a toggle item and register it for state refresh.""" kwargs = {} if enabled is not None: @@ -345,7 +376,7 @@ def on_toggle(state, k=param_key): **kwargs, ) self._toggle_map[param_key] = item - self._all_items.append(item) + (dest if dest is not None else self._main_items).append(item) # ── Multiple-button callbacks ── @@ -376,6 +407,38 @@ def _get_radar_vin_text(self) -> str: vin = "".join(ch for ch in str(raw).upper() if ch.isalnum()) return vin if len(vin) == 17 else "Not set" + def _get_read_vin_text(self) -> str: + return "Reading..." if self._params.get_bool(NAPParamKeys.RADAR_READ_VIN) else "Read" + + def _open_radar(self): + self._page = "radar" + self._radar_scroller.show_event() + + def _close_radar(self): + self._page = "main" + self._scroller.show_event() + + def _on_read_vin(self): + if ui_state.engaged: + dlg = ConfirmDialog( + "

Disengage first


VIN read is blocked while openpilot is engaged.

", + "OK", cancel_text="Close", rich=True, + ) + gui_app.push_widget(dlg) + return + + def confirm_callback(result: int): + if result == DialogResult.CONFIRM: + self._params.put_bool(NAPParamKeys.RADAR_READ_VIN, True) + + content = ( + "

Read VIN


" + + "

Reads the VIN stored in the radar. Does not write or flash. " + + "Leave the car on and do not engage. Power-cycle after it fills.

" + ) + dlg = ConfirmDialog(content, "Read", rich=True, callback=confirm_callback) + gui_app.push_widget(dlg) + def _on_radar_vin_click(self): current = self._get_radar_vin_text() self._radar_vin_keyboard.reset(min_text_size=0) @@ -546,9 +609,19 @@ def _reset_all_to_defaults(self): # ── Render / lifecycle ── def _render(self, rect): - self._scroller.render(rect) + if self._page == "radar": + self._radar_back_btn.set_position(rect.x, rect.y + 10) + self._radar_back_btn.render() + content = rl.Rectangle( + rect.x, rect.y + self._radar_back_btn.rect.height + 20, + rect.width, rect.height - self._radar_back_btn.rect.height - 20, + ) + self._radar_scroller.render(content) + else: + self._scroller.render(rect) def show_event(self): + self._page = "main" self._scroller.show_event() self._refresh_toggles() @@ -569,3 +642,8 @@ def _refresh_toggles(self): brake_factor = self._params.get(NAPParamKeys.BRAKE_FACTOR, return_default=True) self._brake_factor_buttons.action_item.set_selected_button( find_preset_index(BRAKE_FACTOR_PRESETS, brake_factor)) + + radar_position = int(self._params.get(NAPParamKeys.RADAR_POSITION, return_default=True) or 0) + self._radar_position_buttons.action_item.set_selected_button(max(0, min(2, radar_position))) + radar_epas = int(self._params.get(NAPParamKeys.RADAR_EPAS_TYPE, return_default=True) or 0) + self._radar_epas_buttons.action_item.set_selected_button(max(0, min(4, radar_epas))) diff --git a/selfdrive/ui/mici/layouts/settings/nap.py b/selfdrive/ui/mici/layouts/settings/nap.py index c6ba0a213291dd..1740c08af26df7 100644 --- a/selfdrive/ui/mici/layouts/settings/nap.py +++ b/selfdrive/ui/mici/layouts/settings/nap.py @@ -10,7 +10,7 @@ from openpilot.system.ui.widgets.scroller import NavScroller from openpilot.selfdrive.ui.mici.widgets.big_multi_value_param import BigMultiValueParamToggle from openpilot.selfdrive.ui.mici.widgets.button import BigButton, BigParamControl -from openpilot.selfdrive.ui.mici.widgets.dialog import BigConfirmationDialog, BigInputDialog +from openpilot.selfdrive.ui.mici.widgets.dialog import BigConfirmationDialog, BigDialog, BigInputDialog from openpilot.selfdrive.ui.mici.layouts.settings.nap_script import launch_script from openpilot.selfdrive.ui.layouts.settings.nap_content import ( BACKUP_EPAS_INSTRUCTIONS, @@ -50,6 +50,145 @@ def confirm(): gui_app.push_widget(BigConfirmationDialog(slider_title, icon, confirm, red=True)) +class RadarSettingsLayoutMici(NavScroller): + def __init__(self): + super().__init__() + self._params = Params() + + radar_enabled = BigParamControl("radar enabled", NAPParamKeys.RADAR_ENABLED, + toggle_callback=_reboot_on_toggle) + radar_enabled.set_enabled(ui_state.is_offroad) + + radar_behind_nosecone = BigParamControl( + "radar behind nosecone", NAPParamKeys.RADAR_BEHIND_NOSECONE, + toggle_callback=_reboot_on_toggle, + ) + radar_behind_nosecone.set_enabled(ui_state.is_offroad) + + radar_offset_btn = BigButton("radar lateral offset", self._radar_offset_label()) + radar_offset_btn.set_click_callback(lambda: self._open_radar_offset_input(radar_offset_btn)) + + donor_vin_btn = BigButton("donor radar vin", self._radar_vin_label()) + donor_vin_btn.set_click_callback(lambda: self._open_radar_vin_input(donor_vin_btn)) + + read_vin_btn = BigButton("read vin", self._read_vin_label()) + read_vin_btn.set_click_callback(lambda: self._on_read_vin(read_vin_btn)) + + radar_position = BigMultiValueParamToggle( + "donor radar position", + NAPParamKeys.RADAR_POSITION, + values=[0, 1, 2], + labels=["0", "1", "2"], + default_value=0, + ) + + radar_epas = BigMultiValueParamToggle( + "donor epas type", + NAPParamKeys.RADAR_EPAS_TYPE, + values=[0, 1, 2, 3, 4], + labels=["0", "1", "2", "3", "4"], + default_value=0, + ) + + calibrate_radar_btn = BigButton("calibrate radar", "start") + calibrate_radar_btn.set_click_callback( + lambda: launch_script("Radar Calibration", CALIBRATE_RADAR_INSTRUCTIONS, + "scripts.nap.calibrate_radar", + )) + calibrate_radar_btn.set_enabled(ui_state.is_offroad) + + test_radar_btn = BigButton("test radar", "test") + test_radar_btn.set_click_callback( + lambda: launch_script("Radar Test", TEST_RADAR_INSTRUCTIONS, + "scripts.nap.test_radar", + )) + test_radar_btn.set_enabled(ui_state.is_offroad) + + self._scroller.add_widgets([ + radar_enabled, + radar_behind_nosecone, + radar_offset_btn, + donor_vin_btn, + read_vin_btn, + radar_position, + radar_epas, + calibrate_radar_btn, + test_radar_btn, + ]) + + def _radar_offset_label(self) -> str: + raw = self._params.get(NAPParamKeys.RADAR_OFFSET, return_default=True) + try: + return f"{float(raw or 0):+.2f}m" + except (TypeError, ValueError): + return "+0.00m" + + def _radar_vin_label(self) -> str: + raw = self._params.get(NAPParamKeys.RADAR_DONOR_VIN, return_default=True) or "" + if isinstance(raw, bytes): + raw = raw.decode("ascii", errors="ignore") + vin = "".join(ch for ch in str(raw).upper() if ch.isalnum()) + return vin if len(vin) == 17 else "not set" + + def _read_vin_label(self) -> str: + return "reading..." if self._params.get_bool(NAPParamKeys.RADAR_READ_VIN) else "read" + + def _open_radar_offset_input(self, btn: BigButton) -> None: + raw = self._params.get(NAPParamKeys.RADAR_OFFSET, return_default=True) + try: + default_text = f"{float(raw or 0):.2f}" + except (TypeError, ValueError): + default_text = "0.00" + + def on_confirm(text: str) -> None: + try: + v = float(text) + except (TypeError, ValueError): + return + v = max(RADAR_OFFSET_MIN, min(RADAR_OFFSET_MAX, v)) + try: + self._params.put(NAPParamKeys.RADAR_OFFSET, v) + except Exception: + return + btn.set_value(self._radar_offset_label()) + + gui_app.push_widget(BigInputDialog( + f"radar offset (m, {RADAR_OFFSET_MIN} to {RADAR_OFFSET_MAX})", + default_text=default_text, + confirm_callback=on_confirm, + )) + + def _open_radar_vin_input(self, btn: BigButton) -> None: + current = self._radar_vin_label() + + def on_confirm(text: str) -> None: + vin = "".join(ch for ch in (text or "").upper() if ch.isalnum()) + try: + self._params.put(NAPParamKeys.RADAR_DONOR_VIN, vin if len(vin) == 17 else "") + except Exception: + return + btn.set_value(self._radar_vin_label()) + + gui_app.push_widget(BigInputDialog( + "donor radar vin", + default_text="" if current == "not set" else current, + minimum_length=0, + confirm_callback=on_confirm, + )) + + def _on_read_vin(self, btn: BigButton) -> None: + if ui_state.engaged: + gui_app.push_widget(BigDialog("disengage first", "VIN read is blocked while engaged.")) + return + + def confirm(): + self._params.put_bool(NAPParamKeys.RADAR_READ_VIN, True) + btn.set_value(self._read_vin_label()) + + icon = gui_app.texture("icons_mici/buttons/button_circle_red.png", 180, 180) + gui_app.push_widget(BigConfirmationDialog("slide to\nread vin", icon, confirm)) + + class NAPLayoutMici(NavScroller): def __init__(self): super().__init__() @@ -102,33 +241,8 @@ def __init__(self): )) calibrate_pedal_btn.set_enabled(ui_state.is_offroad) - # ── Radar ──────────────────────────────────────── - radar_enabled = BigParamControl("radar enabled", NAPParamKeys.RADAR_ENABLED, - toggle_callback=_reboot_on_toggle) - radar_enabled.set_enabled(ui_state.is_offroad) - - radar_behind_nosecone = BigParamControl( - "radar behind nosecone", NAPParamKeys.RADAR_BEHIND_NOSECONE, - toggle_callback=_reboot_on_toggle, - ) - radar_behind_nosecone.set_enabled(ui_state.is_offroad) - - radar_offset_btn = BigButton("radar lateral offset", self._radar_offset_label()) - radar_offset_btn.set_click_callback(lambda: self._open_radar_offset_input(radar_offset_btn)) - - calibrate_radar_btn = BigButton("calibrate radar", "start") - calibrate_radar_btn.set_click_callback( - lambda: launch_script("Radar Calibration", CALIBRATE_RADAR_INSTRUCTIONS, - "scripts.nap.calibrate_radar", - )) - calibrate_radar_btn.set_enabled(ui_state.is_offroad) - - test_radar_btn = BigButton("test radar", "test") - test_radar_btn.set_click_callback( - lambda: launch_script("Radar Test", TEST_RADAR_INSTRUCTIONS, - "scripts.nap.test_radar", - )) - test_radar_btn.set_enabled(ui_state.is_offroad) + radar_settings_btn = BigButton("radar settings", "open") + radar_settings_btn.set_click_callback(lambda: gui_app.push_widget(RadarSettingsLayoutMici())) # ── iBooster (locked off) ──────────────────────── ibooster_enabled = BigParamControl("ibooster enabled", NAPParamKeys.IBOOSTER_ENABLED) @@ -168,11 +282,7 @@ def __init__(self): pedal_can_bus, pedal_calib_status, calibrate_pedal_btn, - radar_enabled, - radar_behind_nosecone, - radar_offset_btn, - calibrate_radar_btn, - test_radar_btn, + radar_settings_btn, ibooster_enabled, force_pre_ap, backup_epas_btn, @@ -180,36 +290,3 @@ def __init__(self): restore_epas_btn, ]) - def _radar_offset_label(self) -> str: - raw = self._params.get(NAPParamKeys.RADAR_OFFSET, return_default=True) - try: - return f"{float(raw or 0):+.2f}m" - except (TypeError, ValueError): - return "+0.00m" - - def _open_radar_offset_input(self, btn: BigButton) -> None: - raw = self._params.get(NAPParamKeys.RADAR_OFFSET, return_default=True) - try: - default_text = f"{float(raw or 0):.2f}" - except (TypeError, ValueError): - default_text = "0.00" - - def on_confirm(text: str) -> None: - try: - v = float(text) - except (TypeError, ValueError): - return - v = max(RADAR_OFFSET_MIN, min(RADAR_OFFSET_MAX, v)) - try: - self._params.put(NAPParamKeys.RADAR_OFFSET, v) - except Exception: - # FLOAT keys raise on bad value type; swallow so the UI - # doesn't crash on a corrupt write. - return - btn.set_value(self._radar_offset_label()) - - gui_app.push_widget(BigInputDialog( - f"radar offset (m, {RADAR_OFFSET_MIN} to {RADAR_OFFSET_MAX})", - default_text=default_text, - confirm_callback=on_confirm, - )) From 7b667ddd55e5938fed21b3cd2f2ceab385c03ed2 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Sat, 22 Aug 2026 23:37:15 +0000 Subject: [PATCH 04/30] nap: drop behind-nosecone toggle Position is only Donor Position on 0x560 now, including empty VIN. Read VIN shows whether F190 stuck instead of sitting on Read. Co-authored-by: Cursor --- common/params_keys.h | 1 + opendbc_repo | 2 +- selfdrive/car/card.py | 30 ++++++++++++------ selfdrive/test/process_replay/fixture_tool.py | 4 +-- selfdrive/ui/layouts/settings/nap.py | 31 ++++++++++++------- selfdrive/ui/mici/layouts/settings/nap.py | 7 ----- 6 files changed, 44 insertions(+), 31 deletions(-) diff --git a/common/params_keys.h b/common/params_keys.h index 913d46409180fc..4bea832c0c46e7 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -151,6 +151,7 @@ inline static std::unordered_map keys = { {"NAPRadarOffset", {PERSISTENT, FLOAT, "0.0"}}, {"NAPRadarPosition", {PERSISTENT, INT, "0"}}, {"NAPRadarReadVin", {CLEAR_ON_MANAGER_START, BOOL}}, + {"NAPRadarVinReadStatus", {CLEAR_ON_MANAGER_START, STRING}}, {"NAPScriptRunning", {CLEAR_ON_MANAGER_START, BOOL}}, {"TermsVersion", {PERSISTENT, STRING}}, {"TrainingVersion", {PERSISTENT, STRING}}, diff --git a/opendbc_repo b/opendbc_repo index f29a061c7a67dd..f00c8cb99aa4c1 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit f29a061c7a67ddc9189500a2db04717ee56593f1 +Subproject commit f00c8cb99aa4c1bdc0f3afbbab097e1a0e74753d diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index bac56c9fb2e7a3..bd3fef0023cb04 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -167,6 +167,7 @@ def __init__(self, CI=None, RI=None) -> None: def store_donor_vin(vin: str) -> None: nap_conf.radar_donor_vin = vin + self.params.put("NAPRadarVinReadStatus", f"saved {vin}") cloudlog.info("preap radar donor vin stored") self._nap_conf = nap_conf @@ -279,17 +280,26 @@ def controls_update(self, CS: car.CarState, CC: car.CarControl): if self.sm.valid['pandaStates']: controls_allowed = any(ps.controlsAllowed for ps in self.sm['pandaStates']) force_read = self.params.get_bool("NAPRadarReadVin") - can_sends.extend(self.radar_donor_vin.update( - self._can_packets, - time.monotonic(), - radar_enabled=self._nap_conf.radar_enabled, - stored_vin=self._nap_conf.radar_donor_vin, - controls_allowed=controls_allowed, - enabled=bool(CC.enabled), - force_read=force_read, - )) - if force_read and self.radar_donor_vin.read_finished: + if force_read and not self._nap_conf.radar_enabled: + self.params.put("NAPRadarVinReadStatus", "enable radar first") self.params.put_bool("NAPRadarReadVin", False) + else: + can_sends.extend(self.radar_donor_vin.update( + self._can_packets, + time.monotonic(), + radar_enabled=self._nap_conf.radar_enabled, + stored_vin=self._nap_conf.radar_donor_vin, + controls_allowed=controls_allowed, + enabled=bool(CC.enabled), + force_read=force_read, + )) + if force_read and self.radar_donor_vin.read_finished: + if not self.radar_donor_vin.reader.vin and self.radar_donor_vin.reader.failure: + self.params.put( + "NAPRadarVinReadStatus", + self.radar_donor_vin.reader.failure.name.lower().replace("_", " "), + ) + self.params.put_bool("NAPRadarReadVin", False) self.pm.send('sendcan', can_list_to_can_capnp(can_sends, msgtype='sendcan', valid=CS.canValid)) self.CC_prev = CC diff --git a/selfdrive/test/process_replay/fixture_tool.py b/selfdrive/test/process_replay/fixture_tool.py index 52a54e8829292d..2ad3d1fdeac4a8 100755 --- a/selfdrive/test/process_replay/fixture_tool.py +++ b/selfdrive/test/process_replay/fixture_tool.py @@ -1250,8 +1250,8 @@ def accept_six_process_outputs( raise FixtureError("case_params.NAPPedalEnabled must be a bool") if bool(case_params["NAPPedalEnabled"]) != (mode == "pedal"): raise FixtureError("case_params.NAPPedalEnabled does not match case mode") - if case_params.get("NAPRadarEnabled") is not True or case_params.get("NAPRadarBehindNosecone") is not True: - raise FixtureError("case_params must enable radar emulation and nosecone flags") + if case_params.get("NAPRadarEnabled") is not True: + raise FixtureError("case_params must enable radar emulation") missing = [name for name in SIX_PROCESS_OUTPUTS if name not in process_outputs] if missing: diff --git a/selfdrive/ui/layouts/settings/nap.py b/selfdrive/ui/layouts/settings/nap.py index 67d563c414e628..ecb78aac006284 100644 --- a/selfdrive/ui/layouts/settings/nap.py +++ b/selfdrive/ui/layouts/settings/nap.py @@ -271,15 +271,6 @@ def _build_radar_items(self): dest=self._radar_items, ) - self._add_toggle( - NAPParamKeys.RADAR_BEHIND_NOSECONE, - "Radar Behind Nosecone", - "Apply signal attenuation adjustment for radar mounted behind the nosecone. Requires reboot.", - enabled=ui_state.is_offroad, - needs_reboot=True, - dest=self._radar_items, - ) - self._radar_offset_keyboard = Keyboard(max_text_size=10) self._radar_offset_btn = button_item( "Radar Lateral Offset", @@ -318,7 +309,7 @@ def _build_radar_items(self): radar_position = int(self._params.get(NAPParamKeys.RADAR_POSITION, return_default=True) or 0) self._radar_position_buttons = multiple_button_item( "Donor Radar Position", - "Must match the donor car: 0 pre-facelift S, 1 post-facelift S, 2 Model X.", + "Always sent when radar is on, including empty VIN. 0 pre-facelift S, 1 post-facelift S, 2 Model X.", buttons=["0", "1", "2"], button_width=130, selected_index=max(0, min(2, radar_position)), @@ -408,7 +399,17 @@ def _get_radar_vin_text(self) -> str: return vin if len(vin) == 17 else "Not set" def _get_read_vin_text(self) -> str: - return "Reading..." if self._params.get_bool(NAPParamKeys.RADAR_READ_VIN) else "Read" + if self._params.get_bool(NAPParamKeys.RADAR_READ_VIN): + return "Reading..." + raw = self._params.get(NAPParamKeys.RADAR_VIN_READ_STATUS, return_default=True) or "" + if isinstance(raw, bytes): + raw = raw.decode("ascii", errors="ignore") + status = str(raw).strip() + if status.startswith("saved "): + return "Cycle car" + if status: + return status[:18] + return "Read" def _open_radar(self): self._page = "radar" @@ -427,6 +428,14 @@ def _on_read_vin(self): gui_app.push_widget(dlg) return + if not self._params.get_bool(NAPParamKeys.RADAR_ENABLED): + dlg = ConfirmDialog( + "

Enable radar first


Read VIN needs radar on. Toggle it and reboot, then try again.

", + "OK", cancel_text="Close", rich=True, + ) + gui_app.push_widget(dlg) + return + def confirm_callback(result: int): if result == DialogResult.CONFIRM: self._params.put_bool(NAPParamKeys.RADAR_READ_VIN, True) diff --git a/selfdrive/ui/mici/layouts/settings/nap.py b/selfdrive/ui/mici/layouts/settings/nap.py index 1740c08af26df7..438020c6a72e87 100644 --- a/selfdrive/ui/mici/layouts/settings/nap.py +++ b/selfdrive/ui/mici/layouts/settings/nap.py @@ -59,12 +59,6 @@ def __init__(self): toggle_callback=_reboot_on_toggle) radar_enabled.set_enabled(ui_state.is_offroad) - radar_behind_nosecone = BigParamControl( - "radar behind nosecone", NAPParamKeys.RADAR_BEHIND_NOSECONE, - toggle_callback=_reboot_on_toggle, - ) - radar_behind_nosecone.set_enabled(ui_state.is_offroad) - radar_offset_btn = BigButton("radar lateral offset", self._radar_offset_label()) radar_offset_btn.set_click_callback(lambda: self._open_radar_offset_input(radar_offset_btn)) @@ -106,7 +100,6 @@ def __init__(self): self._scroller.add_widgets([ radar_enabled, - radar_behind_nosecone, radar_offset_btn, donor_vin_btn, read_vin_btn, From d13ef7bb9f10e8cf321ecadf0de8dcd90341f817 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Sun, 23 Aug 2026 01:57:30 +0000 Subject: [PATCH 05/30] tesla_preap: keep chassis xWD when impersonating donor VIN Stop forcing 4WD on this RWD car when a saved VIN has character 8 of 2. --- opendbc_repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc_repo b/opendbc_repo index f00c8cb99aa4c1..4578cec639929d 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit f00c8cb99aa4c1bdc0f3afbbab097e1a0e74753d +Subproject commit 4578cec639929d977941a43f8991b7bbace883a8 From f62b5fe8bcbb28886b6846838e923a2ae567ba8d Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Sun, 23 Aug 2026 12:48:43 +0000 Subject: [PATCH 06/30] tesla_preap: add ignore-radar-HWFail toggle --- common/params_keys.h | 1 + opendbc_repo | 2 +- selfdrive/ui/layouts/settings/nap.py | 7 +++++++ selfdrive/ui/mici/layouts/settings/nap.py | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/common/params_keys.h b/common/params_keys.h index 4bea832c0c46e7..3f19b67515f367 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -148,6 +148,7 @@ inline static std::unordered_map keys = { {"NAPRadarDonorVin", {PERSISTENT, STRING}}, {"NAPRadarEnabled", {PERSISTENT, BOOL}}, {"NAPRadarEpasType", {PERSISTENT, INT, "0"}}, + {"NAPRadarIgnoreHwFail", {PERSISTENT, BOOL}}, {"NAPRadarOffset", {PERSISTENT, FLOAT, "0.0"}}, {"NAPRadarPosition", {PERSISTENT, INT, "0"}}, {"NAPRadarReadVin", {CLEAR_ON_MANAGER_START, BOOL}}, diff --git a/opendbc_repo b/opendbc_repo index 4578cec639929d..a4c8a40fc16bea 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit 4578cec639929d977941a43f8991b7bbace883a8 +Subproject commit a4c8a40fc16bea35fc3cd0822f49686e484cffcd diff --git a/selfdrive/ui/layouts/settings/nap.py b/selfdrive/ui/layouts/settings/nap.py index ecb78aac006284..12670acb0f5e80 100644 --- a/selfdrive/ui/layouts/settings/nap.py +++ b/selfdrive/ui/layouts/settings/nap.py @@ -271,6 +271,13 @@ def _build_radar_items(self): dest=self._radar_items, ) + self._add_toggle( + NAPParamKeys.RADAR_IGNORE_HW_FAIL, + "Ignore radar hardware fail", + "Lets you engage when Bosch raises HWFail even though tracks are still live.", + dest=self._radar_items, + ) + self._radar_offset_keyboard = Keyboard(max_text_size=10) self._radar_offset_btn = button_item( "Radar Lateral Offset", diff --git a/selfdrive/ui/mici/layouts/settings/nap.py b/selfdrive/ui/mici/layouts/settings/nap.py index 438020c6a72e87..6a56c4d2e67be9 100644 --- a/selfdrive/ui/mici/layouts/settings/nap.py +++ b/selfdrive/ui/mici/layouts/settings/nap.py @@ -59,6 +59,8 @@ def __init__(self): toggle_callback=_reboot_on_toggle) radar_enabled.set_enabled(ui_state.is_offroad) + ignore_hw_fail = BigParamControl("ignore radar hardware fail", NAPParamKeys.RADAR_IGNORE_HW_FAIL) + radar_offset_btn = BigButton("radar lateral offset", self._radar_offset_label()) radar_offset_btn.set_click_callback(lambda: self._open_radar_offset_input(radar_offset_btn)) @@ -100,6 +102,7 @@ def __init__(self): self._scroller.add_widgets([ radar_enabled, + ignore_hw_fail, radar_offset_btn, donor_vin_btn, read_vin_btn, From 6a7cdd08a68b7ba0ede92d18beb0ed99c2bb274b Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Sun, 23 Aug 2026 12:57:53 +0000 Subject: [PATCH 07/30] tesla_preap: honor ignore-HWFail on freeze+SGUFail Bump opendbc so ignore also covers the leftover freeze+SGUFail lockout and reads NAPRadarIgnoreHwFail live from disk if params_pyx misses it. --- opendbc_repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc_repo b/opendbc_repo index a4c8a40fc16bea..0894437f52f078 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit a4c8a40fc16bea35fc3cd0822f49686e484cffcd +Subproject commit 0894437f52f0782ec2c00608ededd20565512366 From 06947800f4a9bb2f4b8a2a10915ef3f0594cb59a Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Sun, 23 Aug 2026 22:07:16 +0000 Subject: [PATCH 08/30] tesla_preap: do not let IgnoreHwFail bypass freeze+SGUFail Bump opendbc so IgnoreHwFail no longer lets frozen SGUFail tracks become leadOne and slam aTarget. --- opendbc_repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc_repo b/opendbc_repo index 0894437f52f078..e512a07cef506c 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit 0894437f52f0782ec2c00608ededd20565512366 +Subproject commit e512a07cef506ca812e67d8bcc8f5b737e4f2d5f From 45054492fbce344e143368431550d4df850a2e4e Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Sun, 23 Aug 2026 22:52:59 +0000 Subject: [PATCH 09/30] tesla_preap: IgnoreHwFail drops frozen+SGU tracks instead of faulting Bump opendbc so Ignore keeps engage and drops frozen SGUFail ghosts instead of setting radarFault. --- opendbc_repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc_repo b/opendbc_repo index e512a07cef506c..ebd04ce3de1b9b 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit e512a07cef506ca812e67d8bcc8f5b737e4f2d5f +Subproject commit ebd04ce3de1b9b1031cee886b94e5bfe1cdfd520 From 47ed616de06b95d8fb48577684f2b30e4ac11175 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Mon, 24 Aug 2026 22:45:52 +0000 Subject: [PATCH 10/30] tesla_preap: restore Tinkla 4WD nibble for VIN char 2/4 so this spare clears xwdValidity --- opendbc_repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc_repo b/opendbc_repo index ebd04ce3de1b9b..e59c8e11c2f429 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit ebd04ce3de1b9b1031cee886b94e5bfe1cdfd520 +Subproject commit e59c8e11c2f42924c8330c23fa36d5b5ec0b9ea5 From a78a3e9761aea21c9873928dd715bf125b849eac Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 03:38:35 +0000 Subject: [PATCH 11/30] ui: live radar modal instead of panda-killing scripts Calibrate/test used to spawn run_script.py, which takes over the display and stops pandad. Tinkla C2 already watched cereal can without doing that. Live Radar is a push_widget overlay; Radar HUD draws the same status on the driving view. Both work onroad and close without a reboot. --- common/params_keys.h | 1 + opendbc_repo | 2 +- selfdrive/ui/layouts/settings/nap.py | 55 ++-- selfdrive/ui/mici/layouts/settings/nap.py | 27 +- .../ui/mici/onroad/augmented_road_view.py | 9 + selfdrive/ui/onroad/augmented_road_view.py | 9 + selfdrive/ui/radar/__init__.py | 3 + selfdrive/ui/radar/bosch_status.py | 234 +++++++++++++++++ selfdrive/ui/radar/preview_radar_ui.py | 95 +++++++ selfdrive/ui/radar/radar_view.py | 243 ++++++++++++++++++ selfdrive/ui/tests/test_radar_monitor.py | 109 ++++++++ selfdrive/ui/ui_state.py | 19 ++ 12 files changed, 757 insertions(+), 49 deletions(-) create mode 100644 selfdrive/ui/radar/__init__.py create mode 100644 selfdrive/ui/radar/bosch_status.py create mode 100644 selfdrive/ui/radar/preview_radar_ui.py create mode 100644 selfdrive/ui/radar/radar_view.py create mode 100644 selfdrive/ui/tests/test_radar_monitor.py diff --git a/common/params_keys.h b/common/params_keys.h index 3f19b67515f367..e929b3afb56003 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -148,6 +148,7 @@ inline static std::unordered_map keys = { {"NAPRadarDonorVin", {PERSISTENT, STRING}}, {"NAPRadarEnabled", {PERSISTENT, BOOL}}, {"NAPRadarEpasType", {PERSISTENT, INT, "0"}}, + {"NAPRadarHud", {PERSISTENT, BOOL}}, {"NAPRadarIgnoreHwFail", {PERSISTENT, BOOL}}, {"NAPRadarOffset", {PERSISTENT, FLOAT, "0.0"}}, {"NAPRadarPosition", {PERSISTENT, INT, "0"}}, diff --git a/opendbc_repo b/opendbc_repo index e59c8e11c2f429..1e8af832d6aff8 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit e59c8e11c2f42924c8330c23fa36d5b5ec0b9ea5 +Subproject commit 1e8af832d6aff8b83cec633f1ea504c08e17d3e2 diff --git a/selfdrive/ui/layouts/settings/nap.py b/selfdrive/ui/layouts/settings/nap.py index 12670acb0f5e80..2abe14f87a6aa0 100644 --- a/selfdrive/ui/layouts/settings/nap.py +++ b/selfdrive/ui/layouts/settings/nap.py @@ -17,13 +17,14 @@ from openpilot.system.ui.widgets.html_render import HtmlRenderer, ElementType from openpilot.selfdrive.ui.layouts.settings.nap_content import ( BACKUP_EPAS_INSTRUCTIONS, BRAKE_FACTOR_PRESETS, - CALIBRATE_PEDAL_INSTRUCTIONS, CALIBRATE_RADAR_INSTRUCTIONS, + CALIBRATE_PEDAL_INSTRUCTIONS, FLASH_EPAS_INSTRUCTIONS, PEDAL_CAN_BUS_VALUES, RADAR_OFFSET_MAX, RADAR_OFFSET_MIN, - RESTORE_EPAS_INSTRUCTIONS, TEST_RADAR_INSTRUCTIONS, + RESTORE_EPAS_INSTRUCTIONS, acknowledgments_html, find_preset_index, ) from opendbc.car.tesla.preap.nap_params import NAPParamKeys, DEFAULTS +from openpilot.selfdrive.ui.radar.radar_view import RadarMonitorDialog from openpilot.selfdrive.ui.ui_state import ui_state @@ -278,6 +279,19 @@ def _build_radar_items(self): dest=self._radar_items, ) + def on_radar_hud(state): + self._params.put_bool(NAPParamKeys.RADAR_HUD, state) + ui_state.radar_hud = state + + hud_item = toggle_item( + "Radar HUD", + description="Show live tracks, lamps, and alert bits over the driving view. Works while driving.", + initial_state=self._params.get_bool(NAPParamKeys.RADAR_HUD), + callback=on_radar_hud, + ) + self._toggle_map[NAPParamKeys.RADAR_HUD] = hud_item + self._radar_items.append(hud_item) + self._radar_offset_keyboard = Keyboard(max_text_size=10) self._radar_offset_btn = button_item( "Radar Lateral Offset", @@ -335,23 +349,13 @@ def _build_radar_items(self): ) self._radar_items.append(self._radar_epas_buttons) - self._calibrate_radar_btn = button_item( - "Calibrate Radar", - "Start", - description="Run the radar calibration routine.", - callback=self._on_calibrate_radar, - ) - self._calibrate_radar_btn.action_item.set_enabled(ui_state.is_offroad) - self._radar_items.append(self._calibrate_radar_btn) - - self._test_radar_btn = button_item( - "Test Radar", - "Test", - description="Test radar connectivity and verify signals.", - callback=self._on_test_radar, + self._live_radar_btn = button_item( + "Live Radar", + "Open", + description="Live tracks, ECU lamps, and alert bits. Stays in this session; works while driving.", + callback=self._on_live_radar, ) - self._test_radar_btn.action_item.set_enabled(ui_state.is_offroad) - self._radar_items.append(self._test_radar_btn) + self._radar_items.append(self._live_radar_btn) def _add_toggle(self, param_key: str, title: str, description: str, enabled: bool | None = None, needs_reboot: bool = False, @@ -536,19 +540,8 @@ def _on_calibrate_pedal(self): script_module="scripts.nap.calibrate_pedal", ) - def _on_calibrate_radar(self): - self._show_script_runner( - title="Radar Calibration", - instructions=CALIBRATE_RADAR_INSTRUCTIONS, - script_module="scripts.nap.calibrate_radar", - ) - - def _on_test_radar(self): - self._show_script_runner( - title="Radar Test", - instructions=TEST_RADAR_INSTRUCTIONS, - script_module="scripts.nap.test_radar", - ) + def _on_live_radar(self): + gui_app.push_widget(RadarMonitorDialog()) def _on_flash_epas(self): self._show_script_runner( diff --git a/selfdrive/ui/mici/layouts/settings/nap.py b/selfdrive/ui/mici/layouts/settings/nap.py index 6a56c4d2e67be9..c3732406021d00 100644 --- a/selfdrive/ui/mici/layouts/settings/nap.py +++ b/selfdrive/ui/mici/layouts/settings/nap.py @@ -15,14 +15,13 @@ from openpilot.selfdrive.ui.layouts.settings.nap_content import ( BACKUP_EPAS_INSTRUCTIONS, CALIBRATE_PEDAL_INSTRUCTIONS, - CALIBRATE_RADAR_INSTRUCTIONS, FLASH_EPAS_INSTRUCTIONS, PEDAL_CAN_BUS_VALUES, RADAR_OFFSET_MAX, RADAR_OFFSET_MIN, RESTORE_EPAS_INSTRUCTIONS, - TEST_RADAR_INSTRUCTIONS, ) +from openpilot.selfdrive.ui.radar.radar_view import RadarMonitorDialog from openpilot.selfdrive.ui.ui_state import ui_state from opendbc.car.tesla.preap.nap_params import NAPParamKeys @@ -61,6 +60,11 @@ def __init__(self): ignore_hw_fail = BigParamControl("ignore radar hardware fail", NAPParamKeys.RADAR_IGNORE_HW_FAIL) + def on_radar_hud(checked): + ui_state.radar_hud = checked + + radar_hud = BigParamControl("radar HUD", NAPParamKeys.RADAR_HUD, toggle_callback=on_radar_hud) + radar_offset_btn = BigButton("radar lateral offset", self._radar_offset_label()) radar_offset_btn.set_click_callback(lambda: self._open_radar_offset_input(radar_offset_btn)) @@ -86,30 +90,19 @@ def __init__(self): default_value=0, ) - calibrate_radar_btn = BigButton("calibrate radar", "start") - calibrate_radar_btn.set_click_callback( - lambda: launch_script("Radar Calibration", CALIBRATE_RADAR_INSTRUCTIONS, - "scripts.nap.calibrate_radar", - )) - calibrate_radar_btn.set_enabled(ui_state.is_offroad) - - test_radar_btn = BigButton("test radar", "test") - test_radar_btn.set_click_callback( - lambda: launch_script("Radar Test", TEST_RADAR_INSTRUCTIONS, - "scripts.nap.test_radar", - )) - test_radar_btn.set_enabled(ui_state.is_offroad) + live_radar_btn = BigButton("live radar", "open") + live_radar_btn.set_click_callback(lambda: gui_app.push_widget(RadarMonitorDialog())) self._scroller.add_widgets([ radar_enabled, ignore_hw_fail, + radar_hud, radar_offset_btn, donor_vin_btn, read_vin_btn, radar_position, radar_epas, - calibrate_radar_btn, - test_radar_btn, + live_radar_btn, ]) def _radar_offset_label(self) -> str: diff --git a/selfdrive/ui/mici/onroad/augmented_road_view.py b/selfdrive/ui/mici/onroad/augmented_road_view.py index 2c083e84b98606..405efebca199a9 100644 --- a/selfdrive/ui/mici/onroad/augmented_road_view.py +++ b/selfdrive/ui/mici/onroad/augmented_road_view.py @@ -9,6 +9,7 @@ from openpilot.selfdrive.ui.mici.onroad.driver_state import DriverStateRenderer from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer from openpilot.selfdrive.ui.mici.onroad.model_renderer import ModelRenderer +from openpilot.selfdrive.ui.radar.radar_view import RadarHudOverlay from openpilot.selfdrive.ui.mici.onroad.confidence_ball import ConfidenceBall from openpilot.selfdrive.ui.mici.onroad.cameraview import CameraView from openpilot.system.ui.lib.application import FontWeight, gui_app, MousePos, MouseEvent @@ -151,6 +152,7 @@ def __init__(self, bookmark_callback=None, stream_type: VisionStreamType = Visio self._model_renderer = ModelRenderer() self._hud_renderer = HudRenderer() + self._radar_hud = RadarHudOverlay() self._alert_renderer = AlertRenderer() self._driver_state_renderer = DriverStateRenderer() self._confidence_ball = ConfidenceBall() @@ -231,6 +233,13 @@ def _render(self, _): if ui_state.started: self._alert_renderer.render(self._content_rect) self._hud_renderer.render(self._content_rect) + radar_rect = rl.Rectangle( + self._content_rect.x + 8, + self._content_rect.y + self._content_rect.height - 148, + min(320, self._content_rect.width - 16), + 140, + ) + self._radar_hud.render(radar_rect) # Draw fake rounded border rl.draw_rectangle_rounded_lines_ex(self._content_rect, 0.2 * 1.02, 10, 50, rl.BLACK) diff --git a/selfdrive/ui/onroad/augmented_road_view.py b/selfdrive/ui/onroad/augmented_road_view.py index 17d89fbd509d87..448ab6b0536426 100644 --- a/selfdrive/ui/onroad/augmented_road_view.py +++ b/selfdrive/ui/onroad/augmented_road_view.py @@ -9,6 +9,7 @@ from openpilot.selfdrive.ui.onroad.driver_state import DriverStateRenderer from openpilot.selfdrive.ui.onroad.hud_renderer import HudRenderer from openpilot.selfdrive.ui.onroad.model_renderer import ModelRenderer +from openpilot.selfdrive.ui.radar.radar_view import RadarHudOverlay from openpilot.selfdrive.ui.onroad.cameraview import CameraView from openpilot.system.ui.lib.application import gui_app from openpilot.common.transformations.camera import DEVICE_CAMERAS, DeviceCameraConfig, view_frame_from_device_frame @@ -46,6 +47,7 @@ def __init__(self, stream_type: VisionStreamType = VisionStreamType.VISION_STREA self.model_renderer = ModelRenderer() self._hud_renderer = HudRenderer() + self._radar_hud = RadarHudOverlay() self.alert_renderer = AlertRenderer() self.driver_state_renderer = DriverStateRenderer() @@ -86,6 +88,13 @@ def _render(self, rect): # Draw all UI overlays self.model_renderer.render(self._content_rect) self._hud_renderer.render(self._content_rect) + radar_rect = rl.Rectangle( + self._content_rect.x + 24, + self._content_rect.y + self._content_rect.height - 300, + 560, + 280, + ) + self._radar_hud.render(radar_rect) self.alert_renderer.render(self._content_rect) self.driver_state_renderer.render(self._content_rect) diff --git a/selfdrive/ui/radar/__init__.py b/selfdrive/ui/radar/__init__.py new file mode 100644 index 00000000000000..c4306147ae75c0 --- /dev/null +++ b/selfdrive/ui/radar/__init__.py @@ -0,0 +1,3 @@ +from openpilot.selfdrive.ui.radar.bosch_status import BoschRadarMonitor, BoschRadarStatus, RadarTrack + +__all__ = ["BoschRadarMonitor", "BoschRadarStatus", "RadarTrack"] diff --git a/selfdrive/ui/radar/bosch_status.py b/selfdrive/ui/radar/bosch_status.py new file mode 100644 index 00000000000000..cb6593e6c0da24 --- /dev/null +++ b/selfdrive/ui/radar/bosch_status.py @@ -0,0 +1,234 @@ +"""Live Bosch radar health from cereal CAN + liveTracks. + +The radar interface already owns track lifecycle. This module only +decodes what a driver needs to see: ECU lamps, the 0x501 alert matrix, +the GTW identity bytes we are sending, and whether the published table +has stopped changing. +""" + +from __future__ import annotations + +from collections import deque +from dataclasses import dataclass + +RADAR_BUS = 1 +ADDR_SGU = 0x301 +ADDR_POINT0 = 0x310 +ADDR_ALERT = 0x501 +ADDR_CAR_CONFIG = 0x2A9 +ADDR_VIN_FEED = 0x2B9 + +# DBC TeslaRadarSguInfo / TeslaRadarAlertMatrix, little-endian @1+. +SGU_HW_FAIL_BIT = 45 +SGU_FAIL_BIT = 46 +SGU_DIRTY_BIT = 44 + +ALERT_BITS: tuple[tuple[int, str], ...] = ( + (3, "adjustmentNotDone"), + (4, "adjustmentReq"), + (5, "adjustmentNotOk"), + (6, "sensorBlinded"), + (8, "configMismatch"), + (11, "espMIA"), + (12, "gtwMIA"), + (13, "sccmMIA"), + (36, "vinValidity"), + (41, "xwdValidity"), + (60, "radPositionMismatch"), + (61, "strRackMismatch"), +) + +FREEZE_HOLD_S = 5.0 +FREEZE_MIN_TRACKS = 4 +ALIGN_D_MIN = 2.5 +ALIGN_D_MAX = 14.5 +ALIGN_Y_MAX = 1.0 + + +def radar_bus(src: int) -> bool: + return (int(src) & 0x7F) == RADAR_BUS + + +def _bit(dat: bytes, index: int) -> bool: + byte_i, bit_i = divmod(index, 8) + if byte_i >= len(dat): + return False + return bool((dat[byte_i] >> bit_i) & 1) + + +def decode_car_config(dat: bytes) -> tuple[bool, int, int]: + lo = int.from_bytes(dat[:4], "little") + hi = int.from_bytes(dat[4:8], "little") if len(dat) >= 8 else 0 + return bool(lo & 0x08), (hi >> 4) & 0x03, (hi >> 12) & 0x07 + + +def vin_mux_chars(dat: bytes) -> tuple[int, tuple[str, ...]] | None: + if not dat: + return None + rec = dat[0] + if rec == 0x10 and len(dat) >= 8: + return 0, tuple(chr(b) if 32 <= b < 127 else "?" for b in dat[5:8]) + if rec == 0x11 and len(dat) >= 8: + return 3, tuple(chr(b) if 32 <= b < 127 else "?" for b in dat[1:8]) + if rec == 0x12 and len(dat) >= 8: + return 10, tuple(chr(b) if 32 <= b < 127 else "?" for b in dat[1:8]) + return None + + +@dataclass(frozen=True) +class RadarTrack: + track_id: int + d_rel: float + y_rel: float + v_rel: float + measured: bool + + +@dataclass(frozen=True) +class BoschRadarStatus: + tracks: tuple[RadarTrack, ...] = () + hw_fail: bool = False + sgu_fail: bool = False + dirty: bool = False + alerts: tuple[str, ...] = () + table_frozen: bool = False + can_error: bool = False + radar_fault: bool = False + radar_unavailable: bool = False + awd: bool | None = None + position: int | None = None + epas_type: int | None = None + vin: str = "" + unique_raw: int = 0 + last_sgu_age_s: float | None = None + last_tracks_age_s: float | None = None + + @property + def health_label(self) -> str: + if self.radar_fault or self.hw_fail: + return "FAULT" + if self.table_frozen: + return "FROZEN" + if self.can_error: + return "CAN" + if "vinValidity" in self.alerts or "xwdValidity" in self.alerts or "radPositionMismatch" in self.alerts: + return "REJECT" + if self.sgu_fail: + return "SGU" + if self.radar_unavailable: + return "UNAVAIL" + if not self.tracks: + return "NO TRACKS" + return "LIVE" + + @property + def health_ok(self) -> bool: + return self.health_label == "LIVE" + + +class BoschRadarMonitor: + def __init__(self): + self._vin = ["."] * 17 + self._status = BoschRadarStatus() + self._fingerprints: deque[tuple[float, tuple]] = deque() + self._raw_seen: deque[tuple[float, bytes]] = deque() + self._last_sgu_t: float | None = None + self._last_tracks_t: float | None = None + + @property + def status(self) -> BoschRadarStatus: + return self._status + + def update(self, now: float, can_messages, live_tracks=None) -> BoschRadarStatus: + hw_fail = self._status.hw_fail + sgu_fail = self._status.sgu_fail + dirty = self._status.dirty + alerts = self._status.alerts + awd = self._status.awd + position = self._status.position + epas_type = self._status.epas_type + can_error = self._status.can_error + radar_fault = self._status.radar_fault + radar_unavailable = self._status.radar_unavailable + tracks = self._status.tracks + + for addr, dat, src in can_messages: + if not radar_bus(src): + continue + dat = bytes(dat) + if addr == ADDR_SGU: + hw_fail = _bit(dat, SGU_HW_FAIL_BIT) + sgu_fail = _bit(dat, SGU_FAIL_BIT) + dirty = _bit(dat, SGU_DIRTY_BIT) + self._last_sgu_t = now + elif addr == ADDR_ALERT: + alerts = tuple(name for bit_i, name in ALERT_BITS if _bit(dat, bit_i)) + elif addr == ADDR_CAR_CONFIG and len(dat) >= 8: + awd, position, epas_type = decode_car_config(dat) + elif addr == ADDR_VIN_FEED: + parsed = vin_mux_chars(dat) + if parsed is not None: + start, chars = parsed + for i, ch in enumerate(chars): + if start + i < 17: + self._vin[start + i] = ch + elif addr == ADDR_POINT0: + self._raw_seen.append((now, dat[:6])) + + while self._raw_seen and now - self._raw_seen[0][0] > FREEZE_HOLD_S: + self._raw_seen.popleft() + + if live_tracks is not None: + errors = getattr(live_tracks, "errors", None) + if errors is not None: + can_error = bool(getattr(errors, "canError", False)) + radar_fault = bool(getattr(errors, "radarFault", False)) + radar_unavailable = bool(getattr(errors, "radarUnavailableTemporary", False)) + points = getattr(live_tracks, "points", ()) + tracks = tuple( + RadarTrack( + track_id=int(p.trackId), + d_rel=float(p.dRel), + y_rel=float(p.yRel), + v_rel=float(p.vRel), + measured=bool(p.measured), + ) + for p in points + ) + self._last_tracks_t = now + fingerprint = tuple((t.track_id, round(t.d_rel, 1), round(t.v_rel, 1)) for t in tracks) + self._fingerprints.append((now, fingerprint)) + + while self._fingerprints and now - self._fingerprints[0][0] > FREEZE_HOLD_S: + self._fingerprints.popleft() + + table_frozen = False + if self._fingerprints and len(tracks) >= FREEZE_MIN_TRACKS: + span = now - self._fingerprints[0][0] + same = all(fp == self._fingerprints[-1][1] for _, fp in self._fingerprints) + table_frozen = span >= FREEZE_HOLD_S - 1e-3 and same and bool(self._fingerprints[-1][1]) + + unique_raw = len({payload for _, payload in self._raw_seen}) + vin = "".join(self._vin) + if vin == "." * 17: + vin = "" + + self._status = BoschRadarStatus( + tracks=tracks, + hw_fail=hw_fail, + sgu_fail=sgu_fail, + dirty=dirty, + alerts=alerts, + table_frozen=table_frozen, + can_error=can_error, + radar_fault=radar_fault, + radar_unavailable=radar_unavailable, + awd=awd, + position=position, + epas_type=epas_type, + vin=vin, + unique_raw=unique_raw, + last_sgu_age_s=None if self._last_sgu_t is None else now - self._last_sgu_t, + last_tracks_age_s=None if self._last_tracks_t is None else now - self._last_tracks_t, + ) + return self._status diff --git a/selfdrive/ui/radar/preview_radar_ui.py b/selfdrive/ui/radar/preview_radar_ui.py new file mode 100644 index 00000000000000..f3e48cedae0367 --- /dev/null +++ b/selfdrive/ui/radar/preview_radar_ui.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +"""Render the radar HUD and monitor dialog to PNGs for visual check.""" + +from __future__ import annotations + +import os +import sys +from pathlib import Path + +os.environ.setdefault("OFFSCREEN", "1") +os.environ.setdefault("BIG", "1") +os.environ.setdefault("SCALE", "1") + +from dataclasses import replace + +from openpilot.selfdrive.ui.radar.bosch_status import BoschRadarStatus, RadarTrack +from openpilot.selfdrive.ui.radar.radar_view import RadarHudOverlay, RadarMonitorDialog +from openpilot.selfdrive.ui.ui_state import ui_state +from openpilot.system.ui.lib.application import gui_app +import pyray as rl + + +def _status(label_tracks=True) -> BoschRadarStatus: + tracks = ( + RadarTrack(12, 18.4, -0.31, -1.2, True), + RadarTrack(15, 32.0, 1.10, -0.4, True), + RadarTrack(19, 47.5, -2.80, 0.1, False), + RadarTrack(22, 61.0, 0.20, -3.4, True), + ) if label_tracks else () + return BoschRadarStatus( + tracks=tracks, + hw_fail=False, + sgu_fail=True, + dirty=False, + alerts=("vinValidity", "xwdValidity", "radPositionMismatch"), + table_frozen=True, + awd=True, + position=0, + epas_type=2, + vin="5YJSA1E45FF108485", + unique_raw=2, + ) + + +def main() -> None: + out = Path(sys.argv[1] if len(sys.argv) > 1 else "/tmp/radar-ui") + out.mkdir(parents=True, exist_ok=True) + + gui_app.init_window("radar preview") + ui_state.radar_hud = True + ui_state.radar_status = _status() + + overlay = RadarHudOverlay() + dialog = RadarMonitorDialog() + + rl.begin_drawing() + rl.clear_background(rl.Color(30, 40, 50, 255)) + rl.draw_rectangle(0, 0, gui_app.width, 120, rl.Color(20, 20, 20, 255)) + overlay.render(rl.Rectangle(30, gui_app.height - 320, 560, 280)) + rl.end_drawing() + overlay_path = str(out / "radar_hud.png") + rl.take_screenshot(overlay_path) + + rl.begin_drawing() + dialog.render(rl.Rectangle(0, 0, gui_app.width, gui_app.height)) + rl.end_drawing() + dialog_path = str(out / "radar_monitor.png") + rl.take_screenshot(dialog_path) + + ui_state.radar_status = replace( + _status(), + sgu_fail=False, + alerts=(), + table_frozen=False, + awd=False, + position=1, + epas_type=0, + vin="5YJSA1S11EFP54129", + unique_raw=14, + ) + rl.begin_drawing() + rl.clear_background(rl.Color(30, 40, 50, 255)) + overlay.render(rl.Rectangle(30, gui_app.height - 320, 560, 280)) + rl.end_drawing() + live_path = str(out / "radar_hud_live.png") + rl.take_screenshot(live_path) + + gui_app.close() + print(overlay_path) + print(dialog_path) + print(live_path) + + +if __name__ == "__main__": + main() diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py new file mode 100644 index 00000000000000..f074acf16adea8 --- /dev/null +++ b/selfdrive/ui/radar/radar_view.py @@ -0,0 +1,243 @@ +"""Bird's-eye Bosch radar plot, driving HUD, and in-session monitor dialog. + +Tinkla C2's calibrate/test tools subscribed to cereal `can` and left +pandad running. NAP's script runner killed the comma session instead. +This dialog is a push_widget overlay: open while driving, close without +reboot, no NAPScriptRunning. +""" + +from __future__ import annotations + +from dataclasses import replace + +import pyray as rl + +from openpilot.selfdrive.ui.radar.bosch_status import ( + ALIGN_D_MAX, + ALIGN_D_MIN, + ALIGN_Y_MAX, + BoschRadarStatus, + RadarTrack, +) +from openpilot.selfdrive.ui.ui_state import ui_state +from openpilot.system.ui.lib.application import gui_app, FontWeight +from openpilot.system.ui.widgets import Widget +from openpilot.system.ui.widgets.button import Button, ButtonStyle + +RANGE_M = 120.0 +LATERAL_M = 8.0 + +HEALTH_COLOR = { + "LIVE": rl.Color(70, 200, 120, 255), + "NO TRACKS": rl.Color(180, 180, 180, 255), + "SGU": rl.Color(230, 170, 50, 255), + "REJECT": rl.Color(230, 120, 40, 255), + "UNAVAIL": rl.Color(230, 170, 50, 255), + "CAN": rl.Color(226, 44, 44, 255), + "FROZEN": rl.Color(226, 44, 44, 255), + "FAULT": rl.Color(226, 44, 44, 255), +} + +PANEL_BG = rl.Color(12, 14, 18, 210) +PANEL_BORDER = rl.Color(255, 255, 255, 40) +ALIGN_FILL = rl.Color(70, 91, 234, 40) +ALIGN_LINE = rl.Color(70, 91, 234, 160) +TRACK_FILL = rl.Color(90, 200, 255, 230) +TRACK_COAST = rl.Color(180, 180, 180, 200) +LEAD_FILL = rl.Color(128, 216, 166, 255) +TEXT = rl.Color(230, 230, 230, 255) +MUTED = rl.Color(160, 160, 160, 255) + + +def health_color(label: str) -> rl.Color: + return HEALTH_COLOR.get(label, MUTED) + + +def _draw_text(font, text: str, x: float, y: float, size: int, color: rl.Color): + rl.draw_text_ex(font, text, rl.Vector2(x, y), size, 0, color) + + +def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True) -> None: + rl.draw_rectangle_rec(rect, rl.Color(8, 10, 14, 255)) + rl.draw_rectangle_lines_ex(rect, 2, PANEL_BORDER) + + if rect.width < 8 or rect.height < 8: + return + + def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: + x = rect.x + rect.width * (0.5 - y_rel / (2 * LATERAL_M)) + y = rect.y + rect.height * (1.0 - d_rel / RANGE_M) + return x, y + + if align_box: + left, bottom = to_px(ALIGN_D_MIN, ALIGN_Y_MAX) + right, top = to_px(ALIGN_D_MAX, -ALIGN_Y_MAX) + box = rl.Rectangle(min(left, right), min(top, bottom), abs(right - left), abs(bottom - top)) + rl.draw_rectangle_rec(box, ALIGN_FILL) + rl.draw_rectangle_lines_ex(box, 2, ALIGN_LINE) + + car_x, car_y = to_px(0.0, 0.0) + rl.draw_rectangle(int(car_x - 6), int(car_y - 10), 12, 16, rl.Color(220, 220, 220, 255)) + + closest = None + for track in status.tracks: + if closest is None or track.d_rel < closest.d_rel: + closest = track + + for track in status.tracks: + x, y = to_px(max(0.0, track.d_rel), track.y_rel) + color = LEAD_FILL if track is closest else (TRACK_FILL if track.measured else TRACK_COAST) + radius = 7 if track is closest else 5 + rl.draw_circle(int(x), int(y), radius, color) + + font = gui_app.font(FontWeight.NORMAL) + _draw_text(font, "0m", rect.x + 8, rect.y + rect.height - 28, 18, MUTED) + _draw_text(font, f"{int(RANGE_M)}m", rect.x + 8, rect.y + 6, 18, MUTED) + + +def _status_lines(status: BoschRadarStatus) -> list[str]: + awd = "—" if status.awd is None else ("4WD" if status.awd else "2WD") + pos = "—" if status.position is None else str(status.position) + epas = "—" if status.epas_type is None else str(status.epas_type) + lamps = [] + if status.hw_fail: + lamps.append("HWFail") + if status.sgu_fail: + lamps.append("SGUFail") + if status.dirty: + lamps.append("dirty") + if status.table_frozen: + lamps.append("frozen") + if status.radar_fault: + lamps.append("radarFault") + if status.can_error: + lamps.append("canError") + lamp_text = " ".join(lamps) if lamps else "none" + alerts = ", ".join(status.alerts) if status.alerts else "none" + vin = status.vin if len(status.vin) == 17 else (status.vin or "—") + lines = [ + f"{status.health_label} {len(status.tracks)} tracks raw {status.unique_raw}", + f"lamps {lamp_text}", + ] + if len(alerts) <= 36: + lines.append(f"alerts {alerts}") + else: + lines.append("alerts") + chunk = "" + for name in status.alerts: + nxt = name if not chunk else chunk + ", " + name + if len(nxt) > 36: + if chunk: + lines.append(" " + chunk) + chunk = name + else: + chunk = nxt + if chunk: + lines.append(" " + chunk) + lines.append(f"GTW {awd} pos {pos} EPAS {epas}") + lines.append(f"VIN {vin}") + return lines + + +def draw_status_text(rect: rl.Rectangle, status: BoschRadarStatus, font_size: int = 28) -> None: + font = gui_app.font(FontWeight.MEDIUM) + y = rect.y + label = status.health_label + _draw_text(gui_app.font(FontWeight.BOLD), label, rect.x, y, font_size + 10, health_color(label)) + y += font_size + 18 + for line in _status_lines(status)[1:]: + _draw_text(font, line, rect.x, y, font_size, TEXT) + y += font_size + 8 + + +def _track_row(track: RadarTrack) -> str: + flag = "m" if track.measured else "c" + return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" + + +class RadarHudOverlay(Widget): + """Compact on-road readout. Hidden unless NAPRadarHud is set.""" + + def _render(self, rect: rl.Rectangle): + if not ui_state.radar_hud: + return + status = ui_state.radar_status + panel = rect + rl.draw_rectangle_rounded(panel, 0.08, 8, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.08, 8, 2, health_color(status.health_label)) + + pad = 8 if panel.height < 180 else 12 + plot_w = min(150, panel.width * 0.38) + plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) + draw_radar_plot(plot, status, align_box=False) + text = rl.Rectangle(plot.x + plot.width + 10, panel.y + pad, panel.width - plot.width - pad * 3, panel.height - pad * 2) + draw_status_text(text, status, font_size=18 if panel.height < 180 else 20) + + +class RadarMonitorDialog(Widget): + """Full-screen live radar. Does not stop pandad or set NAPScriptRunning.""" + + def __init__(self): + super().__init__() + self._close = Button("Close", click_callback=self._on_close, button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) + self._align_only = False + self._align_btn = Button("Align", click_callback=self._toggle_align, button_style=ButtonStyle.ACTION) + + def _on_close(self): + gui_app.pop_widget() + + def _toggle_align(self): + self._align_only = not self._align_only + + def _render(self, rect: rl.Rectangle): + status = ui_state.radar_status + if self._align_only: + tracks = tuple( + t for t in status.tracks + if ALIGN_D_MIN <= t.d_rel <= ALIGN_D_MAX and abs(t.y_rel) <= ALIGN_Y_MAX + ) + status = replace(status, tracks=tracks) + + compact = rect.height < 500 + pad = 12 if compact else 30 + title_size = 28 if compact else 52 + body = 18 if compact else 26 + btn_h = 48 if compact else 90 + btn_w = 140 if compact else 280 + header_h = 44 if compact else 110 + footer_h = btn_h + (16 if compact else 40) + + rl.draw_rectangle_rec(rect, rl.Color(0, 0, 0, 230)) + _draw_text(gui_app.font(FontWeight.BOLD), "Live radar", rect.x + pad, rect.y + (8 if compact else 20), title_size, TEXT) + if not compact: + _draw_text(gui_app.font(FontWeight.MEDIUM), "openpilot stays running", rect.x + pad, rect.y + 78, 24, MUTED) + + plot_w = min(rect.width * (0.40 if compact else 0.42), 720) + plot = rl.Rectangle(rect.x + pad, rect.y + header_h, plot_w, rect.height - header_h - footer_h) + draw_radar_plot(plot, status, align_box=True) + + info_x = plot.x + plot.width + (12 if compact else 30) + info_w = rect.x + rect.width - info_x - pad + font_size = 18 if compact else 32 + draw_status_text(rl.Rectangle(info_x, plot.y, info_w, 160 if compact else 220), status, font_size=font_size) + + font = gui_app.font(FontWeight.MEDIUM) + y = plot.y + (190 if compact else 380) + if y + 40 < rect.y + rect.height - footer_h: + _draw_text(font, " ID dRel yRel vRel", info_x, y, body, MUTED) + y += body + 8 + rows = sorted(status.tracks, key=lambda t: t.d_rel)[: 4 if compact else 12] + for track in rows: + if y + body > rect.y + rect.height - footer_h: + break + _draw_text(font, _track_row(track), info_x, y, body, TEXT) + y += body + 6 + if not rows: + _draw_text(font, "no published tracks", info_x, y, body, MUTED) + + btn_y = rect.y + rect.height - footer_h + (8 if compact else 20) + align_w = btn_w if compact else 220 + self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) + self._align_btn.render(rl.Rectangle(rect.x + pad + btn_w + 12, btn_y, align_w, btn_h)) + mode = "align 2.5–14.5m" if self._align_only else "all tracks" + _draw_text(font, mode, rect.x + pad + btn_w + align_w + 28, btn_y + btn_h * 0.28, body, MUTED) diff --git a/selfdrive/ui/tests/test_radar_monitor.py b/selfdrive/ui/tests/test_radar_monitor.py new file mode 100644 index 00000000000000..ab8345aed07c80 --- /dev/null +++ b/selfdrive/ui/tests/test_radar_monitor.py @@ -0,0 +1,109 @@ +from types import SimpleNamespace + +from openpilot.selfdrive.ui.radar.bosch_status import ( + ADDR_ALERT, + ADDR_CAR_CONFIG, + ADDR_SGU, + ADDR_VIN_FEED, + BoschRadarMonitor, + decode_car_config, + vin_mux_chars, +) + + +def _sgu(*, hw=0, sgu=0, dirty=0) -> bytes: + dat = bytearray(6) + if dirty: + dat[5] |= 1 << 4 + if hw: + dat[5] |= 1 << 5 + if sgu: + dat[5] |= 1 << 6 + return bytes(dat) + + +def _alert(*bits: int) -> bytes: + dat = bytearray(8) + for bit in bits: + dat[bit // 8] |= 1 << (bit % 8) + return bytes(dat) + + +def _tracks(*points): + pts = [ + SimpleNamespace(trackId=i, dRel=d, yRel=y, vRel=v, measured=True) + for i, (d, y, v) in enumerate(points) + ] + errors = SimpleNamespace(canError=False, radarFault=False, radarUnavailableTemporary=False) + return SimpleNamespace(points=pts, errors=errors) + + +def test_sgu_and_alert_bits(): + mon = BoschRadarMonitor() + status = mon.update(0.0, [ + (ADDR_SGU, _sgu(sgu=1), 1), + (ADDR_ALERT, _alert(36, 41, 60), 1), + ]) + assert status.sgu_fail is True + assert status.hw_fail is False + assert status.alerts == ("vinValidity", "xwdValidity", "radPositionMismatch") + assert status.health_label == "REJECT" + + +def test_chassis_bus_is_ignored(): + mon = BoschRadarMonitor() + status = mon.update(0.0, [ + (ADDR_SGU, _sgu(hw=1, sgu=1), 0), + (ADDR_ALERT, _alert(36), 0), + ]) + assert status.hw_fail is False + assert status.alerts == () + + +def test_returned_tx_still_counts(): + dat = bytes.fromhex("4a85555300200010") + assert decode_car_config(dat) == (True, 0, 2) + mon = BoschRadarMonitor() + status = mon.update(0.0, [(ADDR_CAR_CONFIG, dat, 129)]) + assert status.awd is True + assert status.position == 0 + assert status.epas_type == 2 + + +def test_vin_mux(): + assert vin_mux_chars(bytes([0x10, 0, 0, 0, 0, 0x35, 0x59, 0x4A])) == (0, ("5", "Y", "J")) + mon = BoschRadarMonitor() + mon.update(0.0, [ + (ADDR_VIN_FEED, bytes([0x10, 0, 0, 0, 0, 0x35, 0x59, 0x4A]), 129), + (ADDR_VIN_FEED, bytes([0x11, 0x53, 0x41, 0x31, 0x45, 0x34, 0x35, 0x46]), 129), + (ADDR_VIN_FEED, bytes([0x12, 0x46, 0x31, 0x30, 0x38, 0x34, 0x38, 0x35]), 129), + ]) + assert mon.status.vin == "5YJSA1E45FF108485" + + +def test_frozen_table(): + mon = BoschRadarMonitor() + frozen = _tracks((20.0, 0.1, -2.0), (30.0, -0.4, -1.5), (40.0, 0.2, 0.0), (50.0, 1.0, -0.5)) + status = None + for i in range(12): + status = mon.update(i * 0.5, [], frozen) + assert status is not None + assert status.table_frozen is True + assert status.health_label == "FROZEN" + + +def test_moving_table_is_live(): + mon = BoschRadarMonitor() + status = None + for i in range(12): + tracks = _tracks((20.0 + i, 0.1, -2.0), (30.0, -0.4, -1.5), (40.0, 0.2, 0.0), (50.0, 1.0, -0.5)) + status = mon.update(i * 0.5, [(ADDR_SGU, _sgu(), 1)], tracks) + assert status is not None + assert status.table_frozen is False + assert status.health_label == "LIVE" + + +def test_hw_fail_is_fault(): + mon = BoschRadarMonitor() + status = mon.update(0.0, [(ADDR_SGU, _sgu(hw=1), 1)], None) + assert status.health_label == "FAULT" diff --git a/selfdrive/ui/ui_state.py b/selfdrive/ui/ui_state.py index 17d5a2d74da93f..ebe22fe4b6c7d2 100644 --- a/selfdrive/ui/ui_state.py +++ b/selfdrive/ui/ui_state.py @@ -9,6 +9,7 @@ from openpilot.common.params import Params from openpilot.common.swaglog import cloudlog from openpilot.selfdrive.ui.lib.prime_state import PrimeState +from openpilot.selfdrive.ui.radar.bosch_status import BoschRadarMonitor, BoschRadarStatus from openpilot.system.ui.lib.application import gui_app from openpilot.system.hardware import HARDWARE, PC @@ -55,6 +56,8 @@ def _initialize(self): "carControl", "liveParameters", "rawAudioData", + "liveTracks", + "can", ] ) @@ -80,6 +83,9 @@ def _initialize(self): self.CP: car.CarParams | None = None self.light_sensor: float = -1.0 self._param_update_time: float = 0.0 + self.radar_monitor = BoschRadarMonitor() + self.radar_status = BoschRadarStatus() + self.radar_hud: bool = False # Callbacks self._offroad_transition_callbacks: list[Callable[[], None]] = [] @@ -141,6 +147,7 @@ def _update_state(self) -> None: self.is_metric = self.params.get_bool("IsMetric") self.always_on_dm = self.params.get_bool("AlwaysOnDM") + self._update_radar_monitor() def _update_status(self) -> None: if self.started and self.sm.updated["selfdriveState"]: @@ -186,6 +193,18 @@ def update_params(self) -> None: else: self.has_longitudinal_control = self.CP.openpilotLongitudinalControl self._param_update_time = time.monotonic() + try: + self.radar_hud = self.params.get_bool("NAPRadarHud") + except Exception: + self.radar_hud = False + + def _update_radar_monitor(self) -> None: + can_messages = [] + if self.sm.updated.get("can", False): + can_messages = [(int(c.address), bytes(c.dat), int(c.src)) for c in self.sm["can"]] + live_tracks = self.sm["liveTracks"] if self.sm.updated.get("liveTracks", False) else None + if can_messages or live_tracks is not None: + self.radar_status = self.radar_monitor.update(time.monotonic(), can_messages, live_tracks) class Device: From 347a2be4c2f84a9f4acf8a1488ddc300359f1c2a Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 14:37:03 +0000 Subject: [PATCH 12/30] ui: show WAIT VIN until panda starts GTW Matches the new silent-until-0x560-complete gate so a cold key-on is visible on the HUD instead of looking like a dead radar. --- opendbc_repo | 2 +- selfdrive/ui/radar/bosch_status.py | 21 +++++++++++++++++++- selfdrive/ui/radar/radar_view.py | 2 ++ selfdrive/ui/tests/test_radar_monitor.py | 25 +++++++++++++++++++++++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/opendbc_repo b/opendbc_repo index 1e8af832d6aff8..604b9c497c2c51 160000 --- a/opendbc_repo +++ b/opendbc_repo @@ -1 +1 @@ -Subproject commit 1e8af832d6aff8b83cec633f1ea504c08e17d3e2 +Subproject commit 604b9c497c2c51573c67379cd1cbbe20d2d3f9e2 diff --git a/selfdrive/ui/radar/bosch_status.py b/selfdrive/ui/radar/bosch_status.py index cb6593e6c0da24..3fb3efd767036f 100644 --- a/selfdrive/ui/radar/bosch_status.py +++ b/selfdrive/ui/radar/bosch_status.py @@ -17,6 +17,7 @@ ADDR_ALERT = 0x501 ADDR_CAR_CONFIG = 0x2A9 ADDR_VIN_FEED = 0x2B9 +ADDR_VIN_HOST = 0x560 # DBC TeslaRadarSguInfo / TeslaRadarAlertMatrix, little-endian @1+. SGU_HW_FAIL_BIT = 45 @@ -100,11 +101,15 @@ class BoschRadarStatus: epas_type: int | None = None vin: str = "" unique_raw: int = 0 + vin_stream_complete: bool = False + gtw_live: bool = False last_sgu_age_s: float | None = None last_tracks_age_s: float | None = None @property def health_label(self) -> str: + if not self.gtw_live and not self.tracks: + return "WAIT GTW" if self.vin_stream_complete else "WAIT VIN" if self.radar_fault or self.hw_fail: return "FAULT" if self.table_frozen: @@ -134,6 +139,8 @@ def __init__(self): self._raw_seen: deque[tuple[float, bytes]] = deque() self._last_sgu_t: float | None = None self._last_tracks_t: float | None = None + self._vin_bits = 0 + self._gtw_live = False @property def status(self) -> BoschRadarStatus: @@ -153,9 +160,18 @@ def update(self, now: float, can_messages, live_tracks=None) -> BoschRadarStatus tracks = self._status.tracks for addr, dat, src in can_messages: + dat = bytes(dat) + if addr == ADDR_VIN_HOST and dat: + rec = dat[0] + if rec == 0: + self._vin_bits |= 1 + elif rec == 1: + self._vin_bits |= 2 + elif rec == 2: + self._vin_bits |= 4 + continue if not radar_bus(src): continue - dat = bytes(dat) if addr == ADDR_SGU: hw_fail = _bit(dat, SGU_HW_FAIL_BIT) sgu_fail = _bit(dat, SGU_FAIL_BIT) @@ -165,6 +181,7 @@ def update(self, now: float, can_messages, live_tracks=None) -> BoschRadarStatus alerts = tuple(name for bit_i, name in ALERT_BITS if _bit(dat, bit_i)) elif addr == ADDR_CAR_CONFIG and len(dat) >= 8: awd, position, epas_type = decode_car_config(dat) + self._gtw_live = True elif addr == ADDR_VIN_FEED: parsed = vin_mux_chars(dat) if parsed is not None: @@ -228,6 +245,8 @@ def update(self, now: float, can_messages, live_tracks=None) -> BoschRadarStatus epas_type=epas_type, vin=vin, unique_raw=unique_raw, + vin_stream_complete=self._vin_bits == 7, + gtw_live=self._gtw_live, last_sgu_age_s=None if self._last_sgu_t is None else now - self._last_sgu_t, last_tracks_age_s=None if self._last_tracks_t is None else now - self._last_tracks_t, ) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index f074acf16adea8..287dbf76754527 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -30,6 +30,8 @@ HEALTH_COLOR = { "LIVE": rl.Color(70, 200, 120, 255), "NO TRACKS": rl.Color(180, 180, 180, 255), + "WAIT VIN": rl.Color(230, 170, 50, 255), + "WAIT GTW": rl.Color(230, 170, 50, 255), "SGU": rl.Color(230, 170, 50, 255), "REJECT": rl.Color(230, 120, 40, 255), "UNAVAIL": rl.Color(230, 170, 50, 255), diff --git a/selfdrive/ui/tests/test_radar_monitor.py b/selfdrive/ui/tests/test_radar_monitor.py index ab8345aed07c80..5aa1adb4ba812e 100644 --- a/selfdrive/ui/tests/test_radar_monitor.py +++ b/selfdrive/ui/tests/test_radar_monitor.py @@ -5,6 +5,7 @@ ADDR_CAR_CONFIG, ADDR_SGU, ADDR_VIN_FEED, + ADDR_VIN_HOST, BoschRadarMonitor, decode_car_config, vin_mux_chars, @@ -41,6 +42,7 @@ def _tracks(*points): def test_sgu_and_alert_bits(): mon = BoschRadarMonitor() status = mon.update(0.0, [ + (ADDR_CAR_CONFIG, bytes.fromhex("4a85555300200010"), 129), (ADDR_SGU, _sgu(sgu=1), 1), (ADDR_ALERT, _alert(36, 41, 60), 1), ]) @@ -105,5 +107,26 @@ def test_moving_table_is_live(): def test_hw_fail_is_fault(): mon = BoschRadarMonitor() - status = mon.update(0.0, [(ADDR_SGU, _sgu(hw=1), 1)], None) + status = mon.update(0.0, [ + (ADDR_CAR_CONFIG, bytes.fromhex("4295555310001710"), 129), + (ADDR_SGU, _sgu(hw=1), 1), + ], None) assert status.health_label == "FAULT" + + +def test_wait_vin_until_host_stream_and_gtw(): + mon = BoschRadarMonitor() + status = mon.update(0.0, [], None) + assert status.health_label == "WAIT VIN" + + status = mon.update(0.1, [ + (ADDR_VIN_HOST, bytes([0, 1, 1, 0, 0, 0x20, 0x20, 0x20]), 192), + (ADDR_VIN_HOST, bytes([1, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20]), 192), + (ADDR_VIN_HOST, bytes([2, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20]), 192), + ], None) + assert status.vin_stream_complete is True + assert status.health_label == "WAIT GTW" + + status = mon.update(0.2, [(ADDR_CAR_CONFIG, bytes.fromhex("4295555310001710"), 129)], None) + assert status.gtw_live is True + assert status.health_label == "NO TRACKS" From 915f48dd381fffaaad60767ab388b1d2166983f6 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:19:38 +0000 Subject: [PATCH 13/30] ui: fit live radar HUD and modal on C4 without clipping C4 536x240 was using tici Button type (60px) and a 560x280 HUD rect. Use NAP chips, compact 16px buttons, and a HUD that never exceeds the screen. --- .../ui/mici/onroad/augmented_road_view.py | 10 +- selfdrive/ui/onroad/augmented_road_view.py | 10 +- selfdrive/ui/radar/preview_radar_ui.py | 16 +- selfdrive/ui/radar/radar_view.py | 540 ++++++++++++++---- 4 files changed, 441 insertions(+), 135 deletions(-) diff --git a/selfdrive/ui/mici/onroad/augmented_road_view.py b/selfdrive/ui/mici/onroad/augmented_road_view.py index 405efebca199a9..2c805b114942b3 100644 --- a/selfdrive/ui/mici/onroad/augmented_road_view.py +++ b/selfdrive/ui/mici/onroad/augmented_road_view.py @@ -9,7 +9,7 @@ from openpilot.selfdrive.ui.mici.onroad.driver_state import DriverStateRenderer from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer from openpilot.selfdrive.ui.mici.onroad.model_renderer import ModelRenderer -from openpilot.selfdrive.ui.radar.radar_view import RadarHudOverlay +from openpilot.selfdrive.ui.radar.radar_view import RadarHudOverlay, radar_hud_rect from openpilot.selfdrive.ui.mici.onroad.confidence_ball import ConfidenceBall from openpilot.selfdrive.ui.mici.onroad.cameraview import CameraView from openpilot.system.ui.lib.application import FontWeight, gui_app, MousePos, MouseEvent @@ -233,13 +233,7 @@ def _render(self, _): if ui_state.started: self._alert_renderer.render(self._content_rect) self._hud_renderer.render(self._content_rect) - radar_rect = rl.Rectangle( - self._content_rect.x + 8, - self._content_rect.y + self._content_rect.height - 148, - min(320, self._content_rect.width - 16), - 140, - ) - self._radar_hud.render(radar_rect) + self._radar_hud.render(radar_hud_rect(self._content_rect)) # Draw fake rounded border rl.draw_rectangle_rounded_lines_ex(self._content_rect, 0.2 * 1.02, 10, 50, rl.BLACK) diff --git a/selfdrive/ui/onroad/augmented_road_view.py b/selfdrive/ui/onroad/augmented_road_view.py index 448ab6b0536426..c15a8a78913909 100644 --- a/selfdrive/ui/onroad/augmented_road_view.py +++ b/selfdrive/ui/onroad/augmented_road_view.py @@ -9,7 +9,7 @@ from openpilot.selfdrive.ui.onroad.driver_state import DriverStateRenderer from openpilot.selfdrive.ui.onroad.hud_renderer import HudRenderer from openpilot.selfdrive.ui.onroad.model_renderer import ModelRenderer -from openpilot.selfdrive.ui.radar.radar_view import RadarHudOverlay +from openpilot.selfdrive.ui.radar.radar_view import RadarHudOverlay, radar_hud_rect from openpilot.selfdrive.ui.onroad.cameraview import CameraView from openpilot.system.ui.lib.application import gui_app from openpilot.common.transformations.camera import DEVICE_CAMERAS, DeviceCameraConfig, view_frame_from_device_frame @@ -88,13 +88,7 @@ def _render(self, rect): # Draw all UI overlays self.model_renderer.render(self._content_rect) self._hud_renderer.render(self._content_rect) - radar_rect = rl.Rectangle( - self._content_rect.x + 24, - self._content_rect.y + self._content_rect.height - 300, - 560, - 280, - ) - self._radar_hud.render(radar_rect) + self._radar_hud.render(radar_hud_rect(self._content_rect)) self.alert_renderer.render(self._content_rect) self.driver_state_renderer.render(self._content_rect) diff --git a/selfdrive/ui/radar/preview_radar_ui.py b/selfdrive/ui/radar/preview_radar_ui.py index f3e48cedae0367..8201851370a3d8 100644 --- a/selfdrive/ui/radar/preview_radar_ui.py +++ b/selfdrive/ui/radar/preview_radar_ui.py @@ -14,7 +14,7 @@ from dataclasses import replace from openpilot.selfdrive.ui.radar.bosch_status import BoschRadarStatus, RadarTrack -from openpilot.selfdrive.ui.radar.radar_view import RadarHudOverlay, RadarMonitorDialog +from openpilot.selfdrive.ui.radar.radar_view import RadarHudOverlay, RadarMonitorDialog, radar_hud_rect from openpilot.selfdrive.ui.ui_state import ui_state from openpilot.system.ui.lib.application import gui_app import pyray as rl @@ -39,6 +39,11 @@ def _status(label_tracks=True) -> BoschRadarStatus: epas_type=2, vin="5YJSA1E45FF108485", unique_raw=2, + gtw_live=True, + vin_stream_complete=True, + last_raw_age_s=0.4, + vin_f190="5YJSA1E45FF108485", + vin_chassis="5YJSA1H15EFP37440", ) @@ -53,10 +58,10 @@ def main() -> None: overlay = RadarHudOverlay() dialog = RadarMonitorDialog() + hud = radar_hud_rect(rl.Rectangle(0, 0, gui_app.width, gui_app.height)) rl.begin_drawing() rl.clear_background(rl.Color(30, 40, 50, 255)) - rl.draw_rectangle(0, 0, gui_app.width, 120, rl.Color(20, 20, 20, 255)) - overlay.render(rl.Rectangle(30, gui_app.height - 320, 560, 280)) + overlay.render(hud) rl.end_drawing() overlay_path = str(out / "radar_hud.png") rl.take_screenshot(overlay_path) @@ -77,10 +82,13 @@ def main() -> None: epas_type=0, vin="5YJSA1S11EFP54129", unique_raw=14, + last_raw_age_s=0.1, + vin_f190="5YJSA1S11EFP54129", + vin_chassis="5YJSA1S11EFP54129", ) rl.begin_drawing() rl.clear_background(rl.Color(30, 40, 50, 255)) - overlay.render(rl.Rectangle(30, gui_app.height - 320, 560, 280)) + overlay.render(hud) rl.end_drawing() live_path = str(out / "radar_hud_live.png") rl.take_screenshot(live_path) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index 287dbf76754527..e32f4016c9ef92 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -8,7 +8,7 @@ from __future__ import annotations -from dataclasses import replace +from dataclasses import dataclass, replace import pyray as rl @@ -20,13 +20,22 @@ RadarTrack, ) from openpilot.selfdrive.ui.ui_state import ui_state -from openpilot.system.ui.lib.application import gui_app, FontWeight +from openpilot.system.ui.lib.application import FontWeight, gui_app +from openpilot.system.ui.lib.text_measure import measure_text_cached from openpilot.system.ui.widgets import Widget from openpilot.system.ui.widgets.button import Button, ButtonStyle RANGE_M = 120.0 LATERAL_M = 8.0 +# 0x501 bits Jack actually uses to decide "wrong radar / wrong car" +ALERT_CHIP = { + "vinValidity": "VIN", + "xwdValidity": "XWD", + "radPositionMismatch": "POS", + "strRackMismatch": "RACK", +} + HEALTH_COLOR = { "LIVE": rl.Color(70, 200, 120, 255), "NO TRACKS": rl.Color(180, 180, 180, 255), @@ -40,28 +49,210 @@ "FAULT": rl.Color(226, 44, 44, 255), } -PANEL_BG = rl.Color(12, 14, 18, 210) -PANEL_BORDER = rl.Color(255, 255, 255, 40) +# NAP list_view / settings language +PANEL_BG = rl.Color(12, 14, 18, 230) +PANEL_BORDER = rl.Color(255, 255, 255, 70) ALIGN_FILL = rl.Color(70, 91, 234, 40) ALIGN_LINE = rl.Color(70, 91, 234, 160) TRACK_FILL = rl.Color(90, 200, 255, 230) TRACK_COAST = rl.Color(180, 180, 180, 200) LEAD_FILL = rl.Color(128, 216, 166, 255) TEXT = rl.Color(230, 230, 230, 255) -MUTED = rl.Color(160, 160, 160, 255) +MUTED = rl.Color(170, 170, 170, 255) # ITEM_TEXT_VALUE_COLOR +CHIP_MUTED = rl.Color(170, 170, 170, 255) +CHIP_FILL = rl.Color(57, 57, 57, 255) # LIST_ACTION +CHIP_ALERT = rl.Color(230, 120, 40, 255) +MISMATCH = rl.Color(230, 120, 40, 255) +MATCH = rl.Color(70, 200, 120, 255) +PRIMARY = rl.Color(70, 91, 234, 255) def health_color(label: str) -> rl.Color: return HEALTH_COLOR.get(label, MUTED) -def _draw_text(font, text: str, x: float, y: float, size: int, color: rl.Color): +def _draw_text(font, text: str, x: float, y: float, size: int, color: rl.Color) -> None: rl.draw_text_ex(font, text, rl.Vector2(x, y), size, 0, color) -def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True) -> None: +def _line_h(font, text: str, size: int, gap: int = 4) -> float: + return measure_text_cached(font, text or "Ag", size).y + gap + + +def _clean_vin(raw) -> str: + if raw is None: + return "" + if isinstance(raw, bytes): + raw = raw.decode("ascii", errors="ignore") + vin = "".join(ch for ch in str(raw).upper() if ch.isalnum()) + return vin if len(vin) == 17 else (vin if vin and vin != "." * 17 else "") + + +def decorate_status(status: BoschRadarStatus) -> BoschRadarStatus: + """Fill F190 (donor param) and chassis (CarParams) when the decoder left them empty.""" + f190 = _clean_vin(getattr(status, "vin_f190", "")) + chassis = _clean_vin(getattr(status, "vin_chassis", "")) + if not f190: + try: + raw = ui_state.params.get("NAPRadarDonorVin", return_default=True) or "" + f190 = _clean_vin(raw) + except Exception: + f190 = "" + if not chassis and getattr(ui_state, "CP", None) is not None: + try: + chassis = _clean_vin(getattr(ui_state.CP, "carVin", "") or "") + except Exception: + chassis = "" + if f190 != getattr(status, "vin_f190", "") or chassis != getattr(status, "vin_chassis", ""): + return replace(status, vin_f190=f190, vin_chassis=chassis) + return status + + +def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: + """On-road HUD that always fits inside `content`. + + Hidpi / tici (~2100x1020 content): 640x260 card, bottom-left. + C4 (536x240 screen, ~476x180 after 30px border): full remaining width, ~156 tall. + Never larger than the content rect. + """ + compact = content.height < 500 + if compact: + margin = 6.0 + w = max(0.0, content.width - margin * 2) + h = min(156.0, max(0.0, content.height - margin * 2)) + return rl.Rectangle(content.x + margin, content.y + content.height - h - margin, w, h) + margin_x, margin_y = 24.0, 16.0 + w = min(640.0, max(0.0, content.width - margin_x * 2)) + h = min(260.0, max(0.0, content.height - 24.0)) + return rl.Rectangle(content.x + margin_x, content.y + content.height - h - margin_y, w, h) + + +def _clamp_to_window(rect: rl.Rectangle) -> rl.Rectangle: + w_max = float(max(1, gui_app.width)) + h_max = float(max(1, gui_app.height)) + x = min(max(0.0, rect.x), w_max) + y = min(max(0.0, rect.y), h_max) + w = min(max(0.0, rect.width), w_max - x) + h = min(max(0.0, rect.height), h_max - y) + return rl.Rectangle(x, y, w, h) + + +def _chip_size(text: str, font_size: int) -> tuple[float, float]: + font = gui_app.font(FontWeight.BOLD) + sz = measure_text_cached(font, text, font_size) + pad_x = 6 if font_size < 20 else 12 + pad_y = 2 if font_size < 20 else 5 + return sz.x + pad_x * 2, sz.y + pad_y * 2 + + +def draw_chip(x: float, y: float, text: str, color: rl.Color, font_size: int, + fill: rl.Color | None = None) -> tuple[float, float]: + """NAP pill: LIST_ACTION fill, 1.5–2px stroke, bold label.""" + font = gui_app.font(FontWeight.BOLD) + sz = measure_text_cached(font, text, font_size) + pad_x = 6 if font_size < 20 else 12 + pad_y = 2 if font_size < 20 else 5 + w = sz.x + pad_x * 2 + h = sz.y + pad_y * 2 + rec = rl.Rectangle(x, y, w, h) + bg = fill if fill is not None else rl.Color(color.r, color.g, color.b, 48) + rl.draw_rectangle_rounded(rec, 0.45, 8, bg) + rl.draw_rectangle_rounded_lines_ex(rec, 0.45, 8, 1.5 if font_size < 20 else 2, color) + _draw_text(font, text, x + pad_x, y + pad_y, font_size, color) + return w, h + + +def _flow_chips(x: float, y: float, max_w: float, bottom: float, items: list[tuple[str, rl.Color, rl.Color | None]], + font_size: int, gap: float = 4) -> float: + """Wrap chips. Returns y after the last row (or y unchanged if nothing fits).""" + if not items: + return y + cx = x + row_h = 0.0 + started = False + for text, color, fill in items: + tw, th = _chip_size(text, font_size) + if cx + tw > x + max_w and cx > x: + cx = x + y += row_h + 3 + row_h = 0.0 + if y + th > bottom: + break + draw_chip(cx, y, text, color, font_size, fill=fill) + cx += tw + gap + row_h = max(row_h, th) + started = True + if started: + y += row_h + 4 + return y + + +def _lamp_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: + items = [] + if status.hw_fail: + items.append(("HWFail", HEALTH_COLOR["FAULT"], None)) + if status.sgu_fail: + items.append(("SGUFail", CHIP_ALERT, None)) + if status.dirty: + items.append(("dirty", MUTED, CHIP_FILL)) + if status.table_frozen: + items.append(("frozen", HEALTH_COLOR["FROZEN"], None)) + if status.radar_fault: + items.append(("radarFault", HEALTH_COLOR["FAULT"], None)) + if status.can_error: + items.append(("canError", HEALTH_COLOR["CAN"], None)) + return items + + +def _alert_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: + items = [] + named = set() + for key, short in ALERT_CHIP.items(): + if key in status.alerts: + items.append((short, CHIP_ALERT, None)) + named.add(key) + for name in status.alerts: + if name not in named: + items.append((name, MUTED, CHIP_FILL)) + return items + + +def _gtw_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: + items = [] + if status.awd is None and status.position is None and status.epas_type is None: + return items + if status.awd is not None: + items.append(("4WD" if status.awd else "2WD", TEXT, CHIP_FILL)) + if status.position is not None: + items.append((f"pos {status.position}", TEXT, CHIP_FILL)) + if status.epas_type is not None: + items.append((f"EPAS {status.epas_type}", TEXT, CHIP_FILL)) + return items + + +def _gate_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None]: + # silent-until-VIN-complete: host 0x560 mux must finish before panda talks + if not status.vin_stream_complete: + return "waiting", HEALTH_COLOR["WAIT VIN"], None + return "talking", MATCH, None + + +def _raw_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None]: + age = getattr(status, "last_raw_age_s", None) + if age is None: + label = f"310 {status.unique_raw}" + elif age < 10: + label = f"310 {status.unique_raw} {age:.1f}s" + else: + label = f"310 {status.unique_raw} {age:.0f}s" + frozenish = status.unique_raw <= 1 and status.table_frozen + return label, (HEALTH_COLOR["FROZEN"] if frozenish else MUTED), CHIP_FILL + + +def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True, + compact: bool = False) -> None: rl.draw_rectangle_rec(rect, rl.Color(8, 10, 14, 255)) - rl.draw_rectangle_lines_ex(rect, 2, PANEL_BORDER) + rl.draw_rectangle_lines_ex(rect, 1 if compact else 2, PANEL_BORDER) if rect.width < 8 or rect.height < 8: return @@ -76,10 +267,11 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: right, top = to_px(ALIGN_D_MAX, -ALIGN_Y_MAX) box = rl.Rectangle(min(left, right), min(top, bottom), abs(right - left), abs(bottom - top)) rl.draw_rectangle_rec(box, ALIGN_FILL) - rl.draw_rectangle_lines_ex(box, 2, ALIGN_LINE) + rl.draw_rectangle_lines_ex(box, 1 if compact else 2, ALIGN_LINE) car_x, car_y = to_px(0.0, 0.0) - rl.draw_rectangle(int(car_x - 6), int(car_y - 10), 12, 16, rl.Color(220, 220, 220, 255)) + cw, ch = (5, 8) if compact else (12, 16) + rl.draw_rectangle(int(car_x - cw / 2), int(car_y - ch + 2), cw, ch, rl.Color(220, 220, 220, 255)) closest = None for track in status.tracks: @@ -89,67 +281,88 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: for track in status.tracks: x, y = to_px(max(0.0, track.d_rel), track.y_rel) color = LEAD_FILL if track is closest else (TRACK_FILL if track.measured else TRACK_COAST) - radius = 7 if track is closest else 5 + radius = (4 if track is closest else 3) if compact else (7 if track is closest else 5) rl.draw_circle(int(x), int(y), radius, color) font = gui_app.font(FontWeight.NORMAL) - _draw_text(font, "0m", rect.x + 8, rect.y + rect.height - 28, 18, MUTED) - _draw_text(font, f"{int(RANGE_M)}m", rect.x + 8, rect.y + 6, 18, MUTED) + tick = 11 if compact else 18 + _draw_text(font, "0m", rect.x + 4, rect.y + rect.height - (14 if compact else 28), tick, MUTED) + _draw_text(font, f"{int(RANGE_M)}m", rect.x + 4, rect.y + 3, tick, MUTED) -def _status_lines(status: BoschRadarStatus) -> list[str]: - awd = "—" if status.awd is None else ("4WD" if status.awd else "2WD") - pos = "—" if status.position is None else str(status.position) - epas = "—" if status.epas_type is None else str(status.epas_type) - lamps = [] - if status.hw_fail: - lamps.append("HWFail") - if status.sgu_fail: - lamps.append("SGUFail") - if status.dirty: - lamps.append("dirty") - if status.table_frozen: - lamps.append("frozen") - if status.radar_fault: - lamps.append("radarFault") - if status.can_error: - lamps.append("canError") - lamp_text = " ".join(lamps) if lamps else "none" - alerts = ", ".join(status.alerts) if status.alerts else "none" - vin = status.vin if len(status.vin) == 17 else (status.vin or "—") - lines = [ - f"{status.health_label} {len(status.tracks)} tracks raw {status.unique_raw}", - f"lamps {lamp_text}", - ] - if len(alerts) <= 36: - lines.append(f"alerts {alerts}") - else: - lines.append("alerts") - chunk = "" - for name in status.alerts: - nxt = name if not chunk else chunk + ", " + name - if len(nxt) > 36: - if chunk: - lines.append(" " + chunk) - chunk = name - else: - chunk = nxt - if chunk: - lines.append(" " + chunk) - lines.append(f"GTW {awd} pos {pos} EPAS {epas}") - lines.append(f"VIN {vin}") - return lines - - -def draw_status_text(rect: rl.Rectangle, status: BoschRadarStatus, font_size: int = 28) -> None: +def _vin_value(status: BoschRadarStatus) -> str: + vin = getattr(status, "vin", "") or "" + return vin if len(vin) == 17 else (vin or "—") + + +def draw_vin_trio(x: float, y: float, max_w: float, bottom: float, status: BoschRadarStatus, + font_size: int) -> float: + """0x2B9 vs F190 vs chassis. Jack's spare / Ian donor mixups were real.""" + font = gui_app.font(FontWeight.MEDIUM) + bold = gui_app.font(FontWeight.BOLD) + rows = ( + ("2B9", _vin_value(status)), + ("F190", _clean_vin(getattr(status, "vin_f190", "")) or "—"), + ("CHS", _clean_vin(getattr(status, "vin_chassis", "")) or "—"), + ) + present = [v for _, v in rows if v != "—"] + mismatch = len(set(present)) > 1 + tag_w = measure_text_cached(bold, "F190", font_size).x + 6 + line = _line_h(font, "VIN", font_size, 1 if font_size < 16 else 3) + for tag, value in rows: + if y + line > bottom: + break + _draw_text(bold, tag, x, y, font_size, MUTED) + color = TEXT + suffix = "" + if value != "—" and mismatch: + others = [v for t, v in rows if t != tag and v != "—"] + if others and value not in others: + color = MISMATCH + suffix = " ≠" + elif others and all(value == o for o in others): + color = MATCH + label = value + suffix + size = font_size + while size >= 10 and measure_text_cached(font, label, size).x > max_w - tag_w: + size -= 1 + _draw_text(font, label, x + tag_w, y, size, color) + y += line + return y + + +def draw_status_panel(rect: rl.Rectangle, status: BoschRadarStatus, *, compact: bool, + font_size: int, show_health_chip: bool = True) -> float: + """Health + lamps + 0x501 + 0x2A9 + gate/310 + VIN trio. Returns y after last line.""" + if rect.width < 8 or rect.height < 8: + return rect.y + + x, y = rect.x, rect.y + max_w = rect.width + bottom = rect.y + rect.height + chip = font_size + body = font_size font = gui_app.font(FontWeight.MEDIUM) - y = rect.y - label = status.health_label - _draw_text(gui_app.font(FontWeight.BOLD), label, rect.x, y, font_size + 10, health_color(label)) - y += font_size + 18 - for line in _status_lines(status)[1:]: - _draw_text(font, line, rect.x, y, font_size, TEXT) - y += font_size + 8 + + if show_health_chip: + label = status.health_label + cw, ch = draw_chip(x, y, label, health_color(label), chip) + meta = f"{len(status.tracks)} trk" + mx = x + cw + 6 + if mx + measure_text_cached(font, meta, body).x <= x + max_w: + _draw_text(font, meta, mx, y + max(0, (ch - measure_text_cached(font, meta, body).y) / 2), body, MUTED) + y += ch + (3 if compact else 6) + + gate = _gate_chip(status) + raw = _raw_chip(status) + y = _flow_chips(x, y, max_w, bottom, [gate, raw], max(11, chip - 1)) + y = _flow_chips(x, y, max_w, bottom, _lamp_chips(status), max(11, chip - 1)) + y = _flow_chips(x, y, max_w, bottom, _alert_chips(status), max(11, chip - 1)) + y = _flow_chips(x, y, max_w, bottom, _gtw_chips(status), max(11, chip - 1)) + + if y + 14 <= bottom: + y = draw_vin_trio(x, y, max_w, bottom, status, body) + return y def _track_row(track: RadarTrack) -> str: @@ -157,23 +370,95 @@ def _track_row(track: RadarTrack) -> str: return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" +@dataclass(frozen=True) +class _DialogMetrics: + compact: bool + pad: int + title_size: int + body: int + chip: int + btn_h: int + btn_w: int + align_w: int + btn_font: int + btn_pad: int + btn_radius: int + header_h: int + footer_h: int + plot_frac: float + status_size: int + table_rows: int + + +def _dialog_metrics(rect: rl.Rectangle) -> _DialogMetrics: + compact = rect.height < 500 + if compact: + btn_h = 26 + return _DialogMetrics( + compact=True, + pad=6, + title_size=16, + body=12, + chip=12, + btn_h=btn_h, + btn_w=80, + align_w=80, + btn_font=15, + btn_pad=3, + btn_radius=8, + header_h=24, + footer_h=btn_h + 8, + plot_frac=0.32, + status_size=12, + table_rows=2, + ) + # Hidpi: NAP list_view BUTTON_FONT_SIZE=35, BUTTON_HEIGHT=100, ITEM 50/40 + btn_h = 80 + return _DialogMetrics( + compact=False, + pad=24, + title_size=40, + body=22, + chip=22, + btn_h=btn_h, + btn_w=240, + align_w=200, + btn_font=35, + btn_pad=16, + btn_radius=10, + header_h=88, + footer_h=btn_h + 20, + plot_frac=0.36, + status_size=22, + table_rows=8, + ) + + class RadarHudOverlay(Widget): """Compact on-road readout. Hidden unless NAPRadarHud is set.""" def _render(self, rect: rl.Rectangle): if not ui_state.radar_hud: return - status = ui_state.radar_status - panel = rect + status = decorate_status(ui_state.radar_status) + panel = _clamp_to_window(rect) + if panel.width < 8 or panel.height < 8: + return + compact = panel.height < 200 rl.draw_rectangle_rounded(panel, 0.08, 8, PANEL_BG) rl.draw_rectangle_rounded_lines_ex(panel, 0.08, 8, 2, health_color(status.health_label)) - pad = 8 if panel.height < 180 else 12 - plot_w = min(150, panel.width * 0.38) + pad = 6 if compact else 12 + plot_w = min(100 if compact else 160, panel.width * (0.28 if compact else 0.34)) plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) - draw_radar_plot(plot, status, align_box=False) - text = rl.Rectangle(plot.x + plot.width + 10, panel.y + pad, panel.width - plot.width - pad * 3, panel.height - pad * 2) - draw_status_text(text, status, font_size=18 if panel.height < 180 else 20) + draw_radar_plot(plot, status, align_box=False, compact=compact) + text = rl.Rectangle( + plot.x + plot.width + (6 if compact else 12), + panel.y + pad, + panel.width - plot.width - pad * 3, + panel.height - pad * 2, + ) + draw_status_panel(text, status, compact=compact, font_size=11 if compact else 18) class RadarMonitorDialog(Widget): @@ -181,9 +466,14 @@ class RadarMonitorDialog(Widget): def __init__(self): super().__init__() - self._close = Button("Close", click_callback=self._on_close, button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) + # Font size is retuned in _render for C4 vs hidpi. Close is pop_widget only. + self._close = Button("Close", click_callback=self._on_close, + font_size=35, text_padding=16, + button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) self._align_only = False - self._align_btn = Button("Align", click_callback=self._toggle_align, button_style=ButtonStyle.ACTION) + self._align_btn = Button("Align", click_callback=self._toggle_align, + font_size=35, text_padding=16, + button_style=ButtonStyle.ACTION) def _on_close(self): gui_app.pop_widget() @@ -191,8 +481,15 @@ def _on_close(self): def _toggle_align(self): self._align_only = not self._align_only + def _tune_buttons(self, m: _DialogMetrics) -> None: + for btn in (self._close, self._align_btn): + btn._label.set_font_size(m.btn_font) + btn._label._text_padding = m.btn_pad + btn._border_radius = m.btn_radius + self._align_btn.set_button_style(ButtonStyle.PRIMARY if self._align_only else ButtonStyle.ACTION) + def _render(self, rect: rl.Rectangle): - status = ui_state.radar_status + status = decorate_status(ui_state.radar_status) if self._align_only: tracks = tuple( t for t in status.tracks @@ -200,46 +497,59 @@ def _render(self, rect: rl.Rectangle): ) status = replace(status, tracks=tracks) - compact = rect.height < 500 - pad = 12 if compact else 30 - title_size = 28 if compact else 52 - body = 18 if compact else 26 - btn_h = 48 if compact else 90 - btn_w = 140 if compact else 280 - header_h = 44 if compact else 110 - footer_h = btn_h + (16 if compact else 40) - - rl.draw_rectangle_rec(rect, rl.Color(0, 0, 0, 230)) - _draw_text(gui_app.font(FontWeight.BOLD), "Live radar", rect.x + pad, rect.y + (8 if compact else 20), title_size, TEXT) - if not compact: - _draw_text(gui_app.font(FontWeight.MEDIUM), "openpilot stays running", rect.x + pad, rect.y + 78, 24, MUTED) - - plot_w = min(rect.width * (0.40 if compact else 0.42), 720) - plot = rl.Rectangle(rect.x + pad, rect.y + header_h, plot_w, rect.height - header_h - footer_h) - draw_radar_plot(plot, status, align_box=True) - - info_x = plot.x + plot.width + (12 if compact else 30) - info_w = rect.x + rect.width - info_x - pad - font_size = 18 if compact else 32 - draw_status_text(rl.Rectangle(info_x, plot.y, info_w, 160 if compact else 220), status, font_size=font_size) - - font = gui_app.font(FontWeight.MEDIUM) - y = plot.y + (190 if compact else 380) - if y + 40 < rect.y + rect.height - footer_h: - _draw_text(font, " ID dRel yRel vRel", info_x, y, body, MUTED) - y += body + 8 - rows = sorted(status.tracks, key=lambda t: t.d_rel)[: 4 if compact else 12] + m = _dialog_metrics(rect) + self._tune_buttons(m) + + # Opaque fill — alpha 230 left ghost glyphs from the previous pyray frame. + rl.draw_rectangle_rec(rect, rl.Color(0, 0, 0, 255)) + + title_font = gui_app.font(FontWeight.BOLD) + body_font = gui_app.font(FontWeight.MEDIUM) + _draw_text(title_font, "Live radar", rect.x + m.pad, rect.y + (3 if m.compact else 14), m.title_size, TEXT) + + chip_x = rect.x + m.pad + measure_text_cached(title_font, "Live radar", m.title_size).x + (8 if m.compact else 16) + chip_y = rect.y + (3 if m.compact else 18) + draw_chip(chip_x, chip_y, status.health_label, health_color(status.health_label), m.chip) + + if not m.compact: + _draw_text(body_font, "openpilot stays running", rect.x + m.pad, rect.y + 60, 20, MUTED) + + plot_w = min(rect.width * m.plot_frac, 168 if m.compact else 700) + plot_h = rect.height - m.header_h - m.footer_h + plot = rl.Rectangle(rect.x + m.pad, rect.y + m.header_h, plot_w, plot_h) + draw_radar_plot(plot, status, align_box=True, compact=m.compact) + + info_x = plot.x + plot.width + (8 if m.compact else 24) + info_w = rect.x + rect.width - info_x - m.pad + footer_y = rect.y + rect.height - m.footer_h + info = rl.Rectangle(info_x, plot.y, info_w, max(0, footer_y - plot.y - (4 if m.compact else 10))) + y = draw_status_panel(info, status, compact=m.compact, font_size=m.status_size, show_health_chip=False) + + # Track table sits strictly above the footer so Align never covers rows. + table_y = y + (3 if m.compact else 10) + table_bottom = footer_y - (2 if m.compact else 8) + if table_y + m.body < table_bottom and info_w > 40: + _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, m.body, MUTED) + table_y += _line_h(body_font, "dRel", m.body, 2 if m.compact else 5) + rows = sorted(status.tracks, key=lambda t: t.d_rel)[: m.table_rows] for track in rows: - if y + body > rect.y + rect.height - footer_h: + if table_y + m.body > table_bottom: break - _draw_text(font, _track_row(track), info_x, y, body, TEXT) - y += body + 6 + _draw_text(body_font, _track_row(track), info_x, table_y, m.body, TEXT) + table_y += _line_h(body_font, _track_row(track), m.body, 2 if m.compact else 4) if not rows: - _draw_text(font, "no published tracks", info_x, y, body, MUTED) - - btn_y = rect.y + rect.height - footer_h + (8 if compact else 20) - align_w = btn_w if compact else 220 - self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) - self._align_btn.render(rl.Rectangle(rect.x + pad + btn_w + 12, btn_y, align_w, btn_h)) - mode = "align 2.5–14.5m" if self._align_only else "all tracks" - _draw_text(font, mode, rect.x + pad + btn_w + align_w + 28, btn_y + btn_h * 0.28, body, MUTED) + empty = "no tracks in 2.5–14.5 m" if self._align_only else "no published tracks" + if table_y + m.body <= table_bottom: + _draw_text(body_font, empty, info_x, table_y, m.body, MUTED) + + btn_y = footer_y + (4 if m.compact else 10) + self._close.render(rl.Rectangle(rect.x + m.pad, btn_y, m.btn_w, m.btn_h)) + self._align_btn.render(rl.Rectangle(rect.x + m.pad + m.btn_w + (6 if m.compact else 14), btn_y, m.align_w, m.btn_h)) + + mode = "2.5–14.5 m" if self._align_only else "all tracks" + mode_color = PRIMARY if self._align_only else MUTED + mode_x = rect.x + m.pad + m.btn_w + m.align_w + (8 if m.compact else 18) + mode_y = btn_y + max(0, (m.btn_h - _chip_size(mode, m.body)[1]) / 2) + if mode_x + 20 < rect.x + rect.width - m.pad: + draw_chip(mode_x, mode_y, mode, mode_color, m.body, + fill=ALIGN_FILL if self._align_only else CHIP_FILL) From 0e27c20f82a12806d615d478a905a347411691d8 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:26:35 +0000 Subject: [PATCH 14/30] ui: live radar chips, VIN trio, and C4-safe HUD C4 536x240 modal keeps full Close/Align and the 2B9/F190/chassis VIN compare. On-road HUD scales to fit 536x240. Decoder tests unchanged. --- selfdrive/ui/radar/bosch_status.py | 5 + selfdrive/ui/radar/preview_radar_ui.py | 11 +- selfdrive/ui/radar/radar_view.py | 208 ++++++++++--------------- 3 files changed, 92 insertions(+), 132 deletions(-) diff --git a/selfdrive/ui/radar/bosch_status.py b/selfdrive/ui/radar/bosch_status.py index 3fb3efd767036f..4bdf7f3ebf73bd 100644 --- a/selfdrive/ui/radar/bosch_status.py +++ b/selfdrive/ui/radar/bosch_status.py @@ -105,6 +105,9 @@ class BoschRadarStatus: gtw_live: bool = False last_sgu_age_s: float | None = None last_tracks_age_s: float | None = None + last_raw_age_s: float | None = None + vin_f190: str = "" + vin_chassis: str = "" @property def health_label(self) -> str: @@ -226,6 +229,7 @@ def update(self, now: float, can_messages, live_tracks=None) -> BoschRadarStatus table_frozen = span >= FREEZE_HOLD_S - 1e-3 and same and bool(self._fingerprints[-1][1]) unique_raw = len({payload for _, payload in self._raw_seen}) + last_raw_age_s = None if not self._raw_seen else now - self._raw_seen[-1][0] vin = "".join(self._vin) if vin == "." * 17: vin = "" @@ -249,5 +253,6 @@ def update(self, now: float, can_messages, live_tracks=None) -> BoschRadarStatus gtw_live=self._gtw_live, last_sgu_age_s=None if self._last_sgu_t is None else now - self._last_sgu_t, last_tracks_age_s=None if self._last_tracks_t is None else now - self._last_tracks_t, + last_raw_age_s=last_raw_age_s, ) return self._status diff --git a/selfdrive/ui/radar/preview_radar_ui.py b/selfdrive/ui/radar/preview_radar_ui.py index 8201851370a3d8..6399d628f838ed 100644 --- a/selfdrive/ui/radar/preview_radar_ui.py +++ b/selfdrive/ui/radar/preview_radar_ui.py @@ -41,7 +41,7 @@ def _status(label_tracks=True) -> BoschRadarStatus: unique_raw=2, gtw_live=True, vin_stream_complete=True, - last_raw_age_s=0.4, + last_raw_age_s=0.08, vin_f190="5YJSA1E45FF108485", vin_chassis="5YJSA1H15EFP37440", ) @@ -57,10 +57,11 @@ def main() -> None: overlay = RadarHudOverlay() dialog = RadarMonitorDialog() - hud = radar_hud_rect(rl.Rectangle(0, 0, gui_app.width, gui_app.height)) + rl.begin_drawing() rl.clear_background(rl.Color(30, 40, 50, 255)) + rl.draw_rectangle(0, 0, gui_app.width, 120, rl.Color(20, 20, 20, 255)) overlay.render(hud) rl.end_drawing() overlay_path = str(out / "radar_hud.png") @@ -82,9 +83,9 @@ def main() -> None: epas_type=0, vin="5YJSA1S11EFP54129", unique_raw=14, - last_raw_age_s=0.1, - vin_f190="5YJSA1S11EFP54129", - vin_chassis="5YJSA1S11EFP54129", + last_raw_age_s=0.04, + vin_f190="5YJSA1E25FF106153", + vin_chassis="5YJSA1H13EFP20460", ) rl.begin_drawing() rl.clear_background(rl.Color(30, 40, 50, 255)) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index e32f4016c9ef92..a22cde76325bc6 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -28,7 +28,6 @@ RANGE_M = 120.0 LATERAL_M = 8.0 -# 0x501 bits Jack actually uses to decide "wrong radar / wrong car" ALERT_CHIP = { "vinValidity": "VIN", "xwdValidity": "XWD", @@ -49,7 +48,6 @@ "FAULT": rl.Color(226, 44, 44, 255), } -# NAP list_view / settings language PANEL_BG = rl.Color(12, 14, 18, 230) PANEL_BORDER = rl.Color(255, 255, 255, 70) ALIGN_FILL = rl.Color(70, 91, 234, 40) @@ -58,11 +56,9 @@ TRACK_COAST = rl.Color(180, 180, 180, 200) LEAD_FILL = rl.Color(128, 216, 166, 255) TEXT = rl.Color(230, 230, 230, 255) -MUTED = rl.Color(170, 170, 170, 255) # ITEM_TEXT_VALUE_COLOR -CHIP_MUTED = rl.Color(170, 170, 170, 255) -CHIP_FILL = rl.Color(57, 57, 57, 255) # LIST_ACTION +MUTED = rl.Color(170, 170, 170, 255) +CHIP_FILL = rl.Color(57, 57, 57, 255) CHIP_ALERT = rl.Color(230, 120, 40, 255) -MISMATCH = rl.Color(230, 120, 40, 255) MATCH = rl.Color(70, 200, 120, 255) PRIMARY = rl.Color(70, 91, 234, 255) @@ -82,25 +78,31 @@ def _line_h(font, text: str, size: int, gap: int = 4) -> float: def _clean_vin(raw) -> str: if raw is None: return "" - if isinstance(raw, bytes): + if isinstance(raw, (bytes, bytearray)): raw = raw.decode("ascii", errors="ignore") vin = "".join(ch for ch in str(raw).upper() if ch.isalnum()) - return vin if len(vin) == 17 else (vin if vin and vin != "." * 17 else "") + return vin if len(vin) == 17 else "" def decorate_status(status: BoschRadarStatus) -> BoschRadarStatus: - """Fill F190 (donor param) and chassis (CarParams) when the decoder left them empty.""" + """Fill F190 (donor / last F190 read) and chassis (CarParams) when empty.""" f190 = _clean_vin(getattr(status, "vin_f190", "")) chassis = _clean_vin(getattr(status, "vin_chassis", "")) if not f190: try: raw = ui_state.params.get("NAPRadarDonorVin", return_default=True) or "" f190 = _clean_vin(raw) + if not f190: + raw = ui_state.params.get("NAPRadarVinReadStatus", return_default=True) or "" + f190 = _clean_vin(raw) except Exception: f190 = "" - if not chassis and getattr(ui_state, "CP", None) is not None: + if not chassis: try: - chassis = _clean_vin(getattr(ui_state.CP, "carVin", "") or "") + if getattr(ui_state, "CP", None) is not None: + chassis = _clean_vin(getattr(ui_state.CP, "carVin", "") or "") + if not chassis: + chassis = _clean_vin(ui_state.params.get("CarVin")) except Exception: chassis = "" if f190 != getattr(status, "vin_f190", "") or chassis != getattr(status, "vin_chassis", ""): @@ -109,21 +111,16 @@ def decorate_status(status: BoschRadarStatus) -> BoschRadarStatus: def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: - """On-road HUD that always fits inside `content`. - - Hidpi / tici (~2100x1020 content): 640x260 card, bottom-left. - C4 (536x240 screen, ~476x180 after 30px border): full remaining width, ~156 tall. - Never larger than the content rect. - """ + """On-road HUD that always fits inside `content`. C4 536x240 must not overflow.""" compact = content.height < 500 if compact: margin = 6.0 w = max(0.0, content.width - margin * 2) - h = min(156.0, max(0.0, content.height - margin * 2)) + h = min(168.0, max(0.0, content.height - margin * 2)) return rl.Rectangle(content.x + margin, content.y + content.height - h - margin, w, h) margin_x, margin_y = 24.0, 16.0 - w = min(640.0, max(0.0, content.width - margin_x * 2)) - h = min(260.0, max(0.0, content.height - 24.0)) + w = min(720.0, max(0.0, content.width - margin_x * 2)) + h = min(280.0, max(0.0, content.height - 24.0)) return rl.Rectangle(content.x + margin_x, content.y + content.height - h - margin_y, w, h) @@ -140,18 +137,17 @@ def _clamp_to_window(rect: rl.Rectangle) -> rl.Rectangle: def _chip_size(text: str, font_size: int) -> tuple[float, float]: font = gui_app.font(FontWeight.BOLD) sz = measure_text_cached(font, text, font_size) - pad_x = 6 if font_size < 20 else 12 - pad_y = 2 if font_size < 20 else 5 + pad_x = 5 if font_size < 20 else 12 + pad_y = 1 if font_size < 20 else 5 return sz.x + pad_x * 2, sz.y + pad_y * 2 def draw_chip(x: float, y: float, text: str, color: rl.Color, font_size: int, fill: rl.Color | None = None) -> tuple[float, float]: - """NAP pill: LIST_ACTION fill, 1.5–2px stroke, bold label.""" font = gui_app.font(FontWeight.BOLD) sz = measure_text_cached(font, text, font_size) - pad_x = 6 if font_size < 20 else 12 - pad_y = 2 if font_size < 20 else 5 + pad_x = 5 if font_size < 20 else 12 + pad_y = 1 if font_size < 20 else 5 w = sz.x + pad_x * 2 h = sz.y + pad_y * 2 rec = rl.Rectangle(x, y, w, h) @@ -162,9 +158,9 @@ def draw_chip(x: float, y: float, text: str, color: rl.Color, font_size: int, return w, h -def _flow_chips(x: float, y: float, max_w: float, bottom: float, items: list[tuple[str, rl.Color, rl.Color | None]], +def _flow_chips(x: float, y: float, max_w: float, bottom: float, + items: list[tuple[str, rl.Color, rl.Color | None]], font_size: int, gap: float = 4) -> float: - """Wrap chips. Returns y after the last row (or y unchanged if nothing fits).""" if not items: return y cx = x @@ -174,7 +170,7 @@ def _flow_chips(x: float, y: float, max_w: float, bottom: float, items: list[tup tw, th = _chip_size(text, font_size) if cx + tw > x + max_w and cx > x: cx = x - y += row_h + 3 + y += row_h + 2 row_h = 0.0 if y + th > bottom: break @@ -183,23 +179,22 @@ def _flow_chips(x: float, y: float, max_w: float, bottom: float, items: list[tup row_h = max(row_h, th) started = True if started: - y += row_h + 4 + y += row_h + (2 if font_size < 16 else 5) return y def _lamp_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: items = [] - if status.hw_fail: + health = status.health_label + if status.hw_fail and health != "FAULT": items.append(("HWFail", HEALTH_COLOR["FAULT"], None)) if status.sgu_fail: items.append(("SGUFail", CHIP_ALERT, None)) if status.dirty: items.append(("dirty", MUTED, CHIP_FILL)) - if status.table_frozen: - items.append(("frozen", HEALTH_COLOR["FROZEN"], None)) - if status.radar_fault: + if status.radar_fault and health != "FAULT": items.append(("radarFault", HEALTH_COLOR["FAULT"], None)) - if status.can_error: + if status.can_error and health != "CAN": items.append(("canError", HEALTH_COLOR["CAN"], None)) return items @@ -231,7 +226,6 @@ def _gtw_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | def _gate_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None]: - # silent-until-VIN-complete: host 0x560 mux must finish before panda talks if not status.vin_stream_complete: return "waiting", HEALTH_COLOR["WAIT VIN"], None return "talking", MATCH, None @@ -245,7 +239,7 @@ def _raw_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None] label = f"310 {status.unique_raw} {age:.1f}s" else: label = f"310 {status.unique_raw} {age:.0f}s" - frozenish = status.unique_raw <= 1 and status.table_frozen + frozenish = status.unique_raw <= 1 and (status.table_frozen or status.unique_raw == 1) return label, (HEALTH_COLOR["FROZEN"] if frozenish else MUTED), CHIP_FILL @@ -253,7 +247,6 @@ def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: boo compact: bool = False) -> None: rl.draw_rectangle_rec(rect, rl.Color(8, 10, 14, 255)) rl.draw_rectangle_lines_ex(rect, 1 if compact else 2, PANEL_BORDER) - if rect.width < 8 or rect.height < 8: return @@ -262,6 +255,8 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: y = rect.y + rect.height * (1.0 - d_rel / RANGE_M) return x, y + rl.begin_scissor_mode(int(rect.x) + 1, int(rect.y) + 1, + max(1, int(rect.width) - 2), max(1, int(rect.height) - 2)) if align_box: left, bottom = to_px(ALIGN_D_MIN, ALIGN_Y_MAX) right, top = to_px(ALIGN_D_MAX, -ALIGN_Y_MAX) @@ -277,12 +272,12 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: for track in status.tracks: if closest is None or track.d_rel < closest.d_rel: closest = track - for track in status.tracks: - x, y = to_px(max(0.0, track.d_rel), track.y_rel) + x, y = to_px(max(0.0, min(RANGE_M, track.d_rel)), track.y_rel) color = LEAD_FILL if track is closest else (TRACK_FILL if track.measured else TRACK_COAST) radius = (4 if track is closest else 3) if compact else (7 if track is closest else 5) rl.draw_circle(int(x), int(y), radius, color) + rl.end_scissor_mode() font = gui_app.font(FontWeight.NORMAL) tick = 11 if compact else 18 @@ -292,34 +287,34 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: def _vin_value(status: BoschRadarStatus) -> str: vin = getattr(status, "vin", "") or "" - return vin if len(vin) == 17 else (vin or "—") + return vin if len(vin) == 17 else (vin or "--") def draw_vin_trio(x: float, y: float, max_w: float, bottom: float, status: BoschRadarStatus, font_size: int) -> float: - """0x2B9 vs F190 vs chassis. Jack's spare / Ian donor mixups were real.""" + """0x2B9 vs F190 vs chassis. Jack spare / Ian donor mixups were real.""" font = gui_app.font(FontWeight.MEDIUM) bold = gui_app.font(FontWeight.BOLD) rows = ( ("2B9", _vin_value(status)), - ("F190", _clean_vin(getattr(status, "vin_f190", "")) or "—"), - ("CHS", _clean_vin(getattr(status, "vin_chassis", "")) or "—"), + ("F190", _clean_vin(getattr(status, "vin_f190", "")) or "--"), + ("CHS", _clean_vin(getattr(status, "vin_chassis", "")) or "--"), ) - present = [v for _, v in rows if v != "—"] + present = [v for _, v in rows if v != "--"] mismatch = len(set(present)) > 1 tag_w = measure_text_cached(bold, "F190", font_size).x + 6 - line = _line_h(font, "VIN", font_size, 1 if font_size < 16 else 3) + line = _line_h(font, "VIN", font_size, 0 if font_size < 16 else 3) for tag, value in rows: if y + line > bottom: break _draw_text(bold, tag, x, y, font_size, MUTED) color = TEXT suffix = "" - if value != "—" and mismatch: - others = [v for t, v in rows if t != tag and v != "—"] + if value != "--" and mismatch: + others = [v for t, v in rows if t != tag and v != "--"] if others and value not in others: - color = MISMATCH - suffix = " ≠" + color = CHIP_ALERT + suffix = " !=" elif others and all(value == o for o in others): color = MATCH label = value + suffix @@ -333,35 +328,30 @@ def draw_vin_trio(x: float, y: float, max_w: float, bottom: float, status: Bosch def draw_status_panel(rect: rl.Rectangle, status: BoschRadarStatus, *, compact: bool, font_size: int, show_health_chip: bool = True) -> float: - """Health + lamps + 0x501 + 0x2A9 + gate/310 + VIN trio. Returns y after last line.""" if rect.width < 8 or rect.height < 8: return rect.y - x, y = rect.x, rect.y max_w = rect.width bottom = rect.y + rect.height - chip = font_size - body = font_size font = gui_app.font(FontWeight.MEDIUM) + chip = max(11, font_size) if show_health_chip: label = status.health_label cw, ch = draw_chip(x, y, label, health_color(label), chip) meta = f"{len(status.tracks)} trk" mx = x + cw + 6 - if mx + measure_text_cached(font, meta, body).x <= x + max_w: - _draw_text(font, meta, mx, y + max(0, (ch - measure_text_cached(font, meta, body).y) / 2), body, MUTED) - y += ch + (3 if compact else 6) - - gate = _gate_chip(status) - raw = _raw_chip(status) - y = _flow_chips(x, y, max_w, bottom, [gate, raw], max(11, chip - 1)) - y = _flow_chips(x, y, max_w, bottom, _lamp_chips(status), max(11, chip - 1)) - y = _flow_chips(x, y, max_w, bottom, _alert_chips(status), max(11, chip - 1)) - y = _flow_chips(x, y, max_w, bottom, _gtw_chips(status), max(11, chip - 1)) - - if y + 14 <= bottom: - y = draw_vin_trio(x, y, max_w, bottom, status, body) + if mx + measure_text_cached(font, meta, font_size).x <= x + max_w: + _draw_text(font, meta, mx, y + max(0, (ch - measure_text_cached(font, meta, font_size).y) / 2), + font_size, MUTED) + y += ch + (2 if compact else 6) + + y = _flow_chips(x, y, max_w, bottom, [_gate_chip(status), _raw_chip(status)], chip) + y = _flow_chips(x, y, max_w, bottom, _lamp_chips(status), chip) + y = _flow_chips(x, y, max_w, bottom, _alert_chips(status), chip) + y = _flow_chips(x, y, max_w, bottom, _gtw_chips(status), chip) + if y + 12 <= bottom: + y = draw_vin_trio(x, y, max_w, bottom, status, font_size) return y @@ -393,44 +383,17 @@ class _DialogMetrics: def _dialog_metrics(rect: rl.Rectangle) -> _DialogMetrics: compact = rect.height < 500 if compact: - btn_h = 26 + btn_h = 22 return _DialogMetrics( - compact=True, - pad=6, - title_size=16, - body=12, - chip=12, - btn_h=btn_h, - btn_w=80, - align_w=80, - btn_font=15, - btn_pad=3, - btn_radius=8, - header_h=24, - footer_h=btn_h + 8, - plot_frac=0.32, - status_size=12, - table_rows=2, + compact=True, pad=6, title_size=16, body=12, chip=12, + btn_h=btn_h, btn_w=78, align_w=78, btn_font=14, btn_pad=2, btn_radius=7, + header_h=22, footer_h=btn_h + 12, plot_frac=0.30, status_size=12, table_rows=1, ) - # Hidpi: NAP list_view BUTTON_FONT_SIZE=35, BUTTON_HEIGHT=100, ITEM 50/40 btn_h = 80 return _DialogMetrics( - compact=False, - pad=24, - title_size=40, - body=22, - chip=22, - btn_h=btn_h, - btn_w=240, - align_w=200, - btn_font=35, - btn_pad=16, - btn_radius=10, - header_h=88, - footer_h=btn_h + 20, - plot_frac=0.36, - status_size=22, - table_rows=8, + compact=False, pad=24, title_size=40, body=22, chip=22, + btn_h=btn_h, btn_w=240, align_w=200, btn_font=35, btn_pad=16, btn_radius=10, + header_h=88, footer_h=btn_h + 20, plot_frac=0.36, status_size=22, table_rows=8, ) @@ -447,13 +410,12 @@ def _render(self, rect: rl.Rectangle): compact = panel.height < 200 rl.draw_rectangle_rounded(panel, 0.08, 8, PANEL_BG) rl.draw_rectangle_rounded_lines_ex(panel, 0.08, 8, 2, health_color(status.health_label)) - - pad = 6 if compact else 12 - plot_w = min(100 if compact else 160, panel.width * (0.28 if compact else 0.34)) + pad = 5 if compact else 12 + plot_w = min(96 if compact else 160, panel.width * (0.26 if compact else 0.34)) plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) draw_radar_plot(plot, status, align_box=False, compact=compact) text = rl.Rectangle( - plot.x + plot.width + (6 if compact else 12), + plot.x + plot.width + (5 if compact else 12), panel.y + pad, panel.width - plot.width - pad * 3, panel.height - pad * 2, @@ -466,7 +428,6 @@ class RadarMonitorDialog(Widget): def __init__(self): super().__init__() - # Font size is retuned in _render for C4 vs hidpi. Close is pop_widget only. self._close = Button("Close", click_callback=self._on_close, font_size=35, text_padding=16, button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) @@ -499,35 +460,30 @@ def _render(self, rect: rl.Rectangle): m = _dialog_metrics(rect) self._tune_buttons(m) - - # Opaque fill — alpha 230 left ghost glyphs from the previous pyray frame. rl.draw_rectangle_rec(rect, rl.Color(0, 0, 0, 255)) title_font = gui_app.font(FontWeight.BOLD) body_font = gui_app.font(FontWeight.MEDIUM) - _draw_text(title_font, "Live radar", rect.x + m.pad, rect.y + (3 if m.compact else 14), m.title_size, TEXT) - + _draw_text(title_font, "Live radar", rect.x + m.pad, rect.y + (2 if m.compact else 14), m.title_size, TEXT) chip_x = rect.x + m.pad + measure_text_cached(title_font, "Live radar", m.title_size).x + (8 if m.compact else 16) - chip_y = rect.y + (3 if m.compact else 18) + chip_y = rect.y + (2 if m.compact else 18) draw_chip(chip_x, chip_y, status.health_label, health_color(status.health_label), m.chip) - if not m.compact: _draw_text(body_font, "openpilot stays running", rect.x + m.pad, rect.y + 60, 20, MUTED) - plot_w = min(rect.width * m.plot_frac, 168 if m.compact else 700) - plot_h = rect.height - m.header_h - m.footer_h - plot = rl.Rectangle(rect.x + m.pad, rect.y + m.header_h, plot_w, plot_h) + plot_w = min(rect.width * m.plot_frac, 156 if m.compact else 700) + plot = rl.Rectangle(rect.x + m.pad, rect.y + m.header_h, plot_w, + rect.height - m.header_h - m.footer_h) draw_radar_plot(plot, status, align_box=True, compact=m.compact) - info_x = plot.x + plot.width + (8 if m.compact else 24) + info_x = plot.x + plot.width + (6 if m.compact else 24) info_w = rect.x + rect.width - info_x - m.pad footer_y = rect.y + rect.height - m.footer_h - info = rl.Rectangle(info_x, plot.y, info_w, max(0, footer_y - plot.y - (4 if m.compact else 10))) + info = rl.Rectangle(info_x, plot.y, info_w, max(0, footer_y - plot.y - 2)) y = draw_status_panel(info, status, compact=m.compact, font_size=m.status_size, show_health_chip=False) - # Track table sits strictly above the footer so Align never covers rows. - table_y = y + (3 if m.compact else 10) - table_bottom = footer_y - (2 if m.compact else 8) + table_y = y + (2 if m.compact else 10) + table_bottom = footer_y - 2 if table_y + m.body < table_bottom and info_w > 40: _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, m.body, MUTED) table_y += _line_h(body_font, "dRel", m.body, 2 if m.compact else 5) @@ -538,18 +494,16 @@ def _render(self, rect: rl.Rectangle): _draw_text(body_font, _track_row(track), info_x, table_y, m.body, TEXT) table_y += _line_h(body_font, _track_row(track), m.body, 2 if m.compact else 4) if not rows: - empty = "no tracks in 2.5–14.5 m" if self._align_only else "no published tracks" + empty = "no tracks in 2.5-14.5 m" if self._align_only else "no published tracks" if table_y + m.body <= table_bottom: _draw_text(body_font, empty, info_x, table_y, m.body, MUTED) - btn_y = footer_y + (4 if m.compact else 10) + btn_y = footer_y + (5 if m.compact else 10) self._close.render(rl.Rectangle(rect.x + m.pad, btn_y, m.btn_w, m.btn_h)) - self._align_btn.render(rl.Rectangle(rect.x + m.pad + m.btn_w + (6 if m.compact else 14), btn_y, m.align_w, m.btn_h)) - - mode = "2.5–14.5 m" if self._align_only else "all tracks" - mode_color = PRIMARY if self._align_only else MUTED - mode_x = rect.x + m.pad + m.btn_w + m.align_w + (8 if m.compact else 18) + self._align_btn.render(rl.Rectangle(rect.x + m.pad + m.btn_w + 6, btn_y, m.align_w, m.btn_h)) + mode = "2.5-14.5 m" if self._align_only else "all tracks" + mode_x = rect.x + m.pad + m.btn_w + m.align_w + 8 mode_y = btn_y + max(0, (m.btn_h - _chip_size(mode, m.body)[1]) / 2) if mode_x + 20 < rect.x + rect.width - m.pad: - draw_chip(mode_x, mode_y, mode, mode_color, m.body, + draw_chip(mode_x, mode_y, mode, PRIMARY if self._align_only else MUTED, m.body, fill=ALIGN_FILL if self._align_only else CHIP_FILL) From 904645f98fc12a776139396336a1dcd71f48debb Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:26:51 +0000 Subject: [PATCH 15/30] ui: hidpi key-on chips; C4 is state plus Close only 3X shows LIVE/FROZEN/REJECT/FAULT, SGUFail/HWFail, talking/waiting, VIN/XWD/POS/RACK, 2WD/4WD pos EPAS, 2B9 vs F190 vs chassis, and raw/age vs liveTracks. C4 is a cut-down strip: state plus one or two reject/table bits and a full Close. No Align, no VIN dump, no table. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 628 ++++++++++++++++--------------- 1 file changed, 323 insertions(+), 305 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index a22cde76325bc6..e7f95bad1c85b4 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -4,11 +4,14 @@ pandad running. NAP's script runner killed the comma session instead. This dialog is a push_widget overlay: open while driving, close without reboot, no NAPScriptRunning. + +Hidpi 2160x1080 is the product: full key-on chips. +C4 536x240 is cut-down: state plus one or two reject/table bits and Close. """ from __future__ import annotations -from dataclasses import dataclass, replace +from dataclasses import replace import pyray as rl @@ -28,12 +31,21 @@ RANGE_M = 120.0 LATERAL_M = 8.0 -ALERT_CHIP = { - "vinValidity": "VIN", - "xwdValidity": "XWD", - "radPositionMismatch": "POS", - "strRackMismatch": "RACK", -} +# C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). +C4_HUD_W = 460.0 +C4_HUD_H = 44.0 +# Hidpi on-road panel: plot + full key-on chips. +HIDPI_HUD_W = 900.0 +HIDPI_HUD_H = 340.0 + +# 0x501 bits Jack uses to decide "wrong radar / wrong car" — product names, not DBC ids. +ALERT_CHIP = ( + ("vinValidity", "VIN"), + ("xwdValidity", "XWD"), + ("radPositionMismatch", "POS"), + ("strRackMismatch", "RACK"), +) +KEY_REJECT = tuple(k for k, _ in ALERT_CHIP) HEALTH_COLOR = { "LIVE": rl.Color(70, 200, 120, 255), @@ -55,12 +67,12 @@ TRACK_FILL = rl.Color(90, 200, 255, 230) TRACK_COAST = rl.Color(180, 180, 180, 200) LEAD_FILL = rl.Color(128, 216, 166, 255) -TEXT = rl.Color(230, 230, 230, 255) +TEXT = rl.Color(236, 236, 236, 255) MUTED = rl.Color(170, 170, 170, 255) +CHIP_MUTED = rl.Color(128, 128, 128, 255) CHIP_FILL = rl.Color(57, 57, 57, 255) -CHIP_ALERT = rl.Color(230, 120, 40, 255) -MATCH = rl.Color(70, 200, 120, 255) -PRIMARY = rl.Color(70, 91, 234, 255) +CHIP_ON_FILL = rl.Color(70, 40, 20, 230) +OK_FILL = rl.Color(20, 50, 32, 230) def health_color(label: str) -> rl.Color: @@ -75,52 +87,24 @@ def _line_h(font, text: str, size: int, gap: int = 4) -> float: return measure_text_cached(font, text or "Ag", size).y + gap -def _clean_vin(raw) -> str: - if raw is None: - return "" - if isinstance(raw, (bytes, bytearray)): - raw = raw.decode("ascii", errors="ignore") - vin = "".join(ch for ch in str(raw).upper() if ch.isalnum()) - return vin if len(vin) == 17 else "" - - -def decorate_status(status: BoschRadarStatus) -> BoschRadarStatus: - """Fill F190 (donor / last F190 read) and chassis (CarParams) when empty.""" - f190 = _clean_vin(getattr(status, "vin_f190", "")) - chassis = _clean_vin(getattr(status, "vin_chassis", "")) - if not f190: - try: - raw = ui_state.params.get("NAPRadarDonorVin", return_default=True) or "" - f190 = _clean_vin(raw) - if not f190: - raw = ui_state.params.get("NAPRadarVinReadStatus", return_default=True) or "" - f190 = _clean_vin(raw) - except Exception: - f190 = "" - if not chassis: - try: - if getattr(ui_state, "CP", None) is not None: - chassis = _clean_vin(getattr(ui_state.CP, "carVin", "") or "") - if not chassis: - chassis = _clean_vin(ui_state.params.get("CarVin")) - except Exception: - chassis = "" - if f190 != getattr(status, "vin_f190", "") or chassis != getattr(status, "vin_chassis", ""): - return replace(status, vin_f190=f190, vin_chassis=chassis) - return status +def is_c4_screen(rect: rl.Rectangle) -> bool: + return rect.width < 800 and rect.height < 500 def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: - """On-road HUD that always fits inside `content`. C4 536x240 must not overflow.""" - compact = content.height < 500 - if compact: - margin = 6.0 - w = max(0.0, content.width - margin * 2) - h = min(168.0, max(0.0, content.height - margin * 2)) + """On-road HUD that always fits inside `content`. + + C4 536x240 / content ~476x180: 460x44 status strip. + Hidpi 2160x1080 / content ~2100x1020: 900x340 chip panel. + """ + if is_c4_screen(content): + margin = 8.0 + w = min(C4_HUD_W, max(0.0, content.width - margin * 2)) + h = min(C4_HUD_H, max(0.0, content.height - margin)) return rl.Rectangle(content.x + margin, content.y + content.height - h - margin, w, h) - margin_x, margin_y = 24.0, 16.0 - w = min(720.0, max(0.0, content.width - margin_x * 2)) - h = min(280.0, max(0.0, content.height - 24.0)) + margin_x, margin_y = 24.0, 20.0 + w = min(HIDPI_HUD_W, max(0.0, content.width - margin_x * 2)) + h = min(HIDPI_HUD_H, max(0.0, content.height - 24.0)) return rl.Rectangle(content.x + margin_x, content.y + content.height - h - margin_y, w, h) @@ -134,11 +118,18 @@ def _clamp_to_window(rect: rl.Rectangle) -> rl.Rectangle: return rl.Rectangle(x, y, w, h) -def _chip_size(text: str, font_size: int) -> tuple[float, float]: +def _chip_pad(font_size: int) -> tuple[int, int]: + if font_size < 16: + return 6, 2 + if font_size < 22: + return 8, 3 + return 12, 5 + + +def chip_size(text: str, font_size: int) -> tuple[float, float]: font = gui_app.font(FontWeight.BOLD) sz = measure_text_cached(font, text, font_size) - pad_x = 5 if font_size < 20 else 12 - pad_y = 1 if font_size < 20 else 5 + pad_x, pad_y = _chip_pad(font_size) return sz.x + pad_x * 2, sz.y + pad_y * 2 @@ -146,101 +137,100 @@ def draw_chip(x: float, y: float, text: str, color: rl.Color, font_size: int, fill: rl.Color | None = None) -> tuple[float, float]: font = gui_app.font(FontWeight.BOLD) sz = measure_text_cached(font, text, font_size) - pad_x = 5 if font_size < 20 else 12 - pad_y = 1 if font_size < 20 else 5 + pad_x, pad_y = _chip_pad(font_size) w = sz.x + pad_x * 2 h = sz.y + pad_y * 2 rec = rl.Rectangle(x, y, w, h) bg = fill if fill is not None else rl.Color(color.r, color.g, color.b, 48) - rl.draw_rectangle_rounded(rec, 0.45, 8, bg) - rl.draw_rectangle_rounded_lines_ex(rec, 0.45, 8, 1.5 if font_size < 20 else 2, color) + rl.draw_rectangle_rounded(rec, 0.5, 8, bg) + rl.draw_rectangle_rounded_lines_ex(rec, 0.5, 8, 1.5 if font_size < 20 else 2, color) _draw_text(font, text, x + pad_x, y + pad_y, font_size, color) return w, h -def _flow_chips(x: float, y: float, max_w: float, bottom: float, - items: list[tuple[str, rl.Color, rl.Color | None]], - font_size: int, gap: float = 4) -> float: - if not items: - return y - cx = x +def draw_chip_row(x: float, y: float, max_w: float, chips: list[tuple[str, rl.Color, rl.Color | None]], + font_size: int, gap: float = 6) -> tuple[float, float]: + cx, cy = x, y row_h = 0.0 - started = False - for text, color, fill in items: - tw, th = _chip_size(text, font_size) + used_w = 0.0 + bottom = y + for text, color, fill in chips: + tw, th = chip_size(text, font_size) if cx + tw > x + max_w and cx > x: cx = x - y += row_h + 2 + cy += row_h + 4 row_h = 0.0 - if y + th > bottom: - break - draw_chip(cx, y, text, color, font_size, fill=fill) + if tw > max_w: + continue + draw_chip(cx, cy, text, color, font_size, fill=fill) cx += tw + gap row_h = max(row_h, th) - started = True - if started: - y += row_h + (2 if font_size < 16 else 5) - return y + used_w = max(used_w, cx - x) + bottom = cy + row_h + return used_w, max(0.0, bottom - y) + +def table_bit(status: BoschRadarStatus) -> str | None: + if status.table_frozen or status.unique_raw == 1: + return "frozen" + if status.unique_raw >= 2: + return "moving" + return None -def _lamp_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: - items = [] - health = status.health_label - if status.hw_fail and health != "FAULT": - items.append(("HWFail", HEALTH_COLOR["FAULT"], None)) - if status.sgu_fail: - items.append(("SGUFail", CHIP_ALERT, None)) - if status.dirty: - items.append(("dirty", MUTED, CHIP_FILL)) - if status.radar_fault and health != "FAULT": - items.append(("radarFault", HEALTH_COLOR["FAULT"], None)) - if status.can_error and health != "CAN": - items.append(("canError", HEALTH_COLOR["CAN"], None)) - return items - - -def _alert_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: - items = [] - named = set() - for key, short in ALERT_CHIP.items(): + +def link_label(status: BoschRadarStatus) -> str: + # silent-until-VIN-complete: host 0x560 mux must finish before panda talks + return "talking" if status.vin_stream_complete else "waiting" + + +def c4_extra_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color]]: + """One or two bits that matter on C4. No VIN trio, no 0x2A9 desk.""" + extras: list[tuple[str, rl.Color]] = [] + reason = None + for key, short in ALERT_CHIP: if key in status.alerts: - items.append((short, CHIP_ALERT, None)) - named.add(key) - for name in status.alerts: - if name not in named: - items.append((name, MUTED, CHIP_FILL)) - return items - - -def _gtw_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: - items = [] - if status.awd is None and status.position is None and status.epas_type is None: - return items - if status.awd is not None: - items.append(("4WD" if status.awd else "2WD", TEXT, CHIP_FILL)) - if status.position is not None: - items.append((f"pos {status.position}", TEXT, CHIP_FILL)) - if status.epas_type is not None: - items.append((f"EPAS {status.epas_type}", TEXT, CHIP_FILL)) - return items - - -def _gate_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None]: - if not status.vin_stream_complete: - return "waiting", HEALTH_COLOR["WAIT VIN"], None - return "talking", MATCH, None - - -def _raw_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None]: - age = getattr(status, "last_raw_age_s", None) - if age is None: - label = f"310 {status.unique_raw}" - elif age < 10: - label = f"310 {status.unique_raw} {age:.1f}s" - else: - label = f"310 {status.unique_raw} {age:.0f}s" - frozenish = status.unique_raw <= 1 and (status.table_frozen or status.unique_raw == 1) - return label, (HEALTH_COLOR["FROZEN"] if frozenish else MUTED), CHIP_FILL + reason = short + break + if reason is None and status.hw_fail: + reason = "HWFail" + elif reason is None and status.sgu_fail: + reason = "SGUFail" + elif reason is None and status.health_label in ("WAIT VIN", "WAIT GTW"): + reason = "waiting" + if reason: + extras.append((reason, health_color("REJECT" if reason in ("VIN", "XWD", "POS", "RACK") else status.health_label))) + bit = table_bit(status) + if bit: + extras.append((bit, health_color("FROZEN" if bit == "frozen" else "LIVE"))) + return extras[:2] + + +def _extract_vin(raw) -> str: + if raw is None: + return "" + if isinstance(raw, (bytes, bytearray)): + raw = raw.decode("ascii", "ignore") + token = "".join(ch for ch in str(raw).upper() if ch.isalnum()) + return token if len(token) == 17 else "" + + +def vin_refs(status: BoschRadarStatus) -> tuple[str, str, str]: + """0x2B9 feed vs F190 (radar EEPROM / donor param) vs chassis CarVin.""" + feed = status.vin if len(status.vin) == 17 else (status.vin or "") + f190 = _extract_vin(getattr(status, "vin_f190", "") or "") + chassis = _extract_vin(getattr(status, "vin_chassis", "") or "") + if not f190 or not chassis: + try: + if not f190: + raw = ui_state.params.get("NAPRadarDonorVin", return_default=True) or "" + f190 = _extract_vin(raw) + if not chassis and getattr(ui_state, "CP", None) is not None: + chassis = _extract_vin(getattr(ui_state.CP, "carVin", "") or "") + if not chassis: + chassis = _extract_vin(ui_state.params.get("CarVin")) + except Exception: + pass + return feed, f190, chassis def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True, @@ -255,8 +245,8 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: y = rect.y + rect.height * (1.0 - d_rel / RANGE_M) return x, y - rl.begin_scissor_mode(int(rect.x) + 1, int(rect.y) + 1, - max(1, int(rect.width) - 2), max(1, int(rect.height) - 2)) + rl.begin_scissor_mode(int(rect.x) + 1, int(rect.y) + 1, max(1, int(rect.width) - 2), max(1, int(rect.height) - 2)) + if align_box: left, bottom = to_px(ALIGN_D_MIN, ALIGN_Y_MAX) right, top = to_px(ALIGN_D_MAX, -ALIGN_Y_MAX) @@ -277,6 +267,7 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: color = LEAD_FILL if track is closest else (TRACK_FILL if track.measured else TRACK_COAST) radius = (4 if track is closest else 3) if compact else (7 if track is closest else 5) rl.draw_circle(int(x), int(y), radius, color) + rl.end_scissor_mode() font = gui_app.font(FontWeight.NORMAL) @@ -285,142 +276,141 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: _draw_text(font, f"{int(RANGE_M)}m", rect.x + 4, rect.y + 3, tick, MUTED) -def _vin_value(status: BoschRadarStatus) -> str: - vin = getattr(status, "vin", "") or "" - return vin if len(vin) == 17 else (vin or "--") - - -def draw_vin_trio(x: float, y: float, max_w: float, bottom: float, status: BoschRadarStatus, - font_size: int) -> float: - """0x2B9 vs F190 vs chassis. Jack spare / Ian donor mixups were real.""" - font = gui_app.font(FontWeight.MEDIUM) - bold = gui_app.font(FontWeight.BOLD) - rows = ( - ("2B9", _vin_value(status)), - ("F190", _clean_vin(getattr(status, "vin_f190", "")) or "--"), - ("CHS", _clean_vin(getattr(status, "vin_chassis", "")) or "--"), - ) - present = [v for _, v in rows if v != "--"] - mismatch = len(set(present)) > 1 - tag_w = measure_text_cached(bold, "F190", font_size).x + 6 - line = _line_h(font, "VIN", font_size, 0 if font_size < 16 else 3) - for tag, value in rows: - if y + line > bottom: - break - _draw_text(bold, tag, x, y, font_size, MUTED) - color = TEXT - suffix = "" - if value != "--" and mismatch: - others = [v for t, v in rows if t != tag and v != "--"] - if others and value not in others: - color = CHIP_ALERT - suffix = " !=" - elif others and all(value == o for o in others): - color = MATCH - label = value + suffix - size = font_size - while size >= 10 and measure_text_cached(font, label, size).x > max_w - tag_w: - size -= 1 - _draw_text(font, label, x + tag_w, y, size, color) - y += line - return y +def _track_row(track: RadarTrack) -> str: + flag = "m" if track.measured else "c" + return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" -def draw_status_panel(rect: rl.Rectangle, status: BoschRadarStatus, *, compact: bool, - font_size: int, show_health_chip: bool = True) -> float: +def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: + chips: list[tuple[str, rl.Color, rl.Color | None]] = [ + (status.health_label, health_color(status.health_label), None), + ] + for text, color in c4_extra_chips(status): + fill = CHIP_FILL if text in ("moving", "frozen", "waiting") else CHIP_ON_FILL + chips.append((text, color, fill)) + return chips + + +def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: + """Cut-down C4 HUD: state + at most two reject/table bits.""" + rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) + font_size = 13 + chips = _c4_chip_list(status) + max_h = 0.0 + for text, _, _ in chips: + _w, th = chip_size(text, font_size) + max_h = max(max_h, th) + pad = 6.0 + y = panel.y + max(pad, (panel.height - max_h) / 2) + draw_chip_row(panel.x + pad, y, panel.width - pad * 2, chips, font_size, gap=6) + + +def draw_hidpi_chips(rect: rl.Rectangle, status: BoschRadarStatus, font_size: int) -> float: + """Full key-on chips. Product names, not a wall of CAN ids.""" if rect.width < 8 or rect.height < 8: return rect.y + font = gui_app.font(FontWeight.MEDIUM) + label_size = max(14, font_size - 4) x, y = rect.x, rect.y max_w = rect.width bottom = rect.y + rect.height - font = gui_app.font(FontWeight.MEDIUM) - chip = max(11, font_size) - - if show_health_chip: - label = status.health_label - cw, ch = draw_chip(x, y, label, health_color(label), chip) - meta = f"{len(status.tracks)} trk" - mx = x + cw + 6 - if mx + measure_text_cached(font, meta, font_size).x <= x + max_w: - _draw_text(font, meta, mx, y + max(0, (ch - measure_text_cached(font, meta, font_size).y) / 2), - font_size, MUTED) - y += ch + (2 if compact else 6) - - y = _flow_chips(x, y, max_w, bottom, [_gate_chip(status), _raw_chip(status)], chip) - y = _flow_chips(x, y, max_w, bottom, _lamp_chips(status), chip) - y = _flow_chips(x, y, max_w, bottom, _alert_chips(status), chip) - y = _flow_chips(x, y, max_w, bottom, _gtw_chips(status), chip) - if y + 12 <= bottom: - y = draw_vin_trio(x, y, max_w, bottom, status, font_size) - return y - - -def _track_row(track: RadarTrack) -> str: - flag = "m" if track.measured else "c" - return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" + gap = 8 + def row(label: str, chips: list[tuple[str, rl.Color, rl.Color | None]]) -> None: + nonlocal y + if y + 20 > bottom: + return + lw = 0.0 + if label: + _draw_text(font, label, x, y + 4, label_size, MUTED) + lw = measure_text_cached(font, label, label_size).x + 10 + _, h = draw_chip_row(x + lw, y, max_w - lw, chips, font_size, gap=6) + y += max(h, _line_h(font, label or "Ag", label_size, 0)) + gap + + label = status.health_label + talking = link_label(status) + row("", [ + (label, health_color(label), None), + ("SGUFail", health_color("SGU") if status.sgu_fail else CHIP_MUTED, + CHIP_ON_FILL if status.sgu_fail else CHIP_FILL), + ("HWFail", health_color("FAULT") if status.hw_fail else CHIP_MUTED, + CHIP_ON_FILL if status.hw_fail else CHIP_FILL), + (talking, health_color("LIVE") if talking == "talking" else health_color("WAIT VIN"), + OK_FILL if talking == "talking" else CHIP_FILL), + ]) + + alert_chips = [] + for key, short in ALERT_CHIP: + on = key in status.alerts + alert_chips.append((short, health_color("REJECT") if on else CHIP_MUTED, CHIP_ON_FILL if on else CHIP_FILL)) + row("reject", alert_chips) + + awd = "4WD" if status.awd else ("2WD" if status.awd is False else "drive —") + pos = "—" if status.position is None else str(status.position) + epas = "—" if status.epas_type is None else str(status.epas_type) + row("drive", [ + (awd, TEXT, CHIP_FILL), + (f"pos {pos}", TEXT, CHIP_FILL), + (f"EPAS {epas}", TEXT, CHIP_FILL), + ]) + + feed, f190, chassis = vin_refs(status) + present = [v for v in (feed, f190, chassis) if v] + mismatch = len(set(present)) > 1 -@dataclass(frozen=True) -class _DialogMetrics: - compact: bool - pad: int - title_size: int - body: int - chip: int - btn_h: int - btn_w: int - align_w: int - btn_font: int - btn_pad: int - btn_radius: int - header_h: int - footer_h: int - plot_frac: float - status_size: int - table_rows: int - - -def _dialog_metrics(rect: rl.Rectangle) -> _DialogMetrics: - compact = rect.height < 500 - if compact: - btn_h = 22 - return _DialogMetrics( - compact=True, pad=6, title_size=16, body=12, chip=12, - btn_h=btn_h, btn_w=78, align_w=78, btn_font=14, btn_pad=2, btn_radius=7, - header_h=22, footer_h=btn_h + 12, plot_frac=0.30, status_size=12, table_rows=1, - ) - btn_h = 80 - return _DialogMetrics( - compact=False, pad=24, title_size=40, body=22, chip=22, - btn_h=btn_h, btn_w=240, align_w=200, btn_font=35, btn_pad=16, btn_radius=10, - header_h=88, footer_h=btn_h + 20, plot_frac=0.36, status_size=22, table_rows=8, + def vin_chip(tag: str, value: str) -> tuple[str, rl.Color, rl.Color | None]: + shown = value or "—" + bad = bool(value) and mismatch and value not in [v for v in present if v != value] + if value and mismatch and any(v != value for v in present): + bad = True + return (f"{tag} {shown}", health_color("REJECT") if bad else TEXT, CHIP_ON_FILL if bad else CHIP_FILL) + + row("VIN", [ + vin_chip("2B9", feed), + vin_chip("F190", f190), + vin_chip("CHS", chassis), + ]) + + age = "age —" if status.last_raw_age_s is None else ( + f"age {status.last_raw_age_s:.1f}s" if status.last_raw_age_s < 10 else f"age {status.last_raw_age_s:.0f}s" ) + bit = table_bit(status) + raw_chips: list[tuple[str, rl.Color, rl.Color | None]] = [ + (f"raw {status.unique_raw}", TEXT, CHIP_FILL), + (age, TEXT, CHIP_FILL), + (f"{len(status.tracks)} trk", TEXT, CHIP_FILL), + ] + if bit: + raw_chips.append((bit, health_color("FROZEN" if bit == "frozen" else "LIVE"), + CHIP_ON_FILL if bit == "frozen" else OK_FILL)) + row("table", raw_chips) + return y class RadarHudOverlay(Widget): - """Compact on-road readout. Hidden unless NAPRadarHud is set.""" + """On-road readout. Hidden unless NAPRadarHud is set.""" def _render(self, rect: rl.Rectangle): if not ui_state.radar_hud: return - status = decorate_status(ui_state.radar_status) + status = ui_state.radar_status panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - compact = panel.height < 200 - rl.draw_rectangle_rounded(panel, 0.08, 8, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.08, 8, 2, health_color(status.health_label)) - pad = 5 if compact else 12 - plot_w = min(96 if compact else 160, panel.width * (0.26 if compact else 0.34)) + if panel.height < 80: + draw_c4_strip(panel, status) + return + + rl.draw_rectangle_rounded(panel, 0.06, 8, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.06, 8, 2, health_color(status.health_label)) + pad = 14 + plot_w = min(220.0, panel.width * 0.28) plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) - draw_radar_plot(plot, status, align_box=False, compact=compact) - text = rl.Rectangle( - plot.x + plot.width + (5 if compact else 12), - panel.y + pad, - panel.width - plot.width - pad * 3, - panel.height - pad * 2, - ) - draw_status_panel(text, status, compact=compact, font_size=11 if compact else 18) + draw_radar_plot(plot, status, align_box=False, compact=False) + chips = rl.Rectangle(plot.x + plot.width + 14, panel.y + pad, + panel.width - plot.width - pad * 3, panel.height - pad * 2) + draw_hidpi_chips(chips, status, font_size=18) class RadarMonitorDialog(Widget): @@ -428,13 +418,11 @@ class RadarMonitorDialog(Widget): def __init__(self): super().__init__() - self._close = Button("Close", click_callback=self._on_close, - font_size=35, text_padding=16, - button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) + self._close = Button("Close", click_callback=self._on_close, font_size=35, + text_padding=16, button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) self._align_only = False - self._align_btn = Button("Align", click_callback=self._toggle_align, - font_size=35, text_padding=16, - button_style=ButtonStyle.ACTION) + self._align_btn = Button("Align", click_callback=self._toggle_align, font_size=35, + text_padding=16, button_style=ButtonStyle.ACTION) def _on_close(self): gui_app.pop_widget() @@ -442,68 +430,98 @@ def _on_close(self): def _toggle_align(self): self._align_only = not self._align_only - def _tune_buttons(self, m: _DialogMetrics) -> None: + def _tune_buttons(self, compact: bool) -> None: + font = 18 if compact else 35 + pad = 4 if compact else 16 + radius = 8 if compact else 10 for btn in (self._close, self._align_btn): - btn._label.set_font_size(m.btn_font) - btn._label._text_padding = m.btn_pad - btn._border_radius = m.btn_radius + btn._label.set_font_size(font) + btn._label._text_padding = pad + btn._border_radius = radius self._align_btn.set_button_style(ButtonStyle.PRIMARY if self._align_only else ButtonStyle.ACTION) def _render(self, rect: rl.Rectangle): - status = decorate_status(ui_state.radar_status) - if self._align_only: + status = ui_state.radar_status + compact = is_c4_screen(rect) + if self._align_only and not compact: tracks = tuple( t for t in status.tracks if ALIGN_D_MIN <= t.d_rel <= ALIGN_D_MAX and abs(t.y_rel) <= ALIGN_Y_MAX ) status = replace(status, tracks=tracks) - m = _dialog_metrics(rect) - self._tune_buttons(m) + self._tune_buttons(compact) rl.draw_rectangle_rec(rect, rl.Color(0, 0, 0, 255)) - + if compact: + self._render_c4(rect, status) + else: + self._render_hidpi(rect, status) + + def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: + """Cut-down 536x240 modal: title, state+bits, plot, Close. No Align, no VIN dump.""" + pad = 8 + title_size = 18 + btn_w, btn_h = 110, 36 + footer_h = btn_h + 10 + title_font = gui_app.font(FontWeight.BOLD) + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 6, title_size, TEXT) + chip_y = rect.y + 30 + draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 13, gap=6) + plot = rl.Rectangle(rect.x + pad, rect.y + 64, rect.width - pad * 2, rect.height - 64 - footer_h) + if plot.height > 24: + draw_radar_plot(plot, status, align_box=False, compact=True) + btn_y = rect.y + rect.height - footer_h + 4 + self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) + + def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: + pad = 28 + title_size = 42 + body = 22 + btn_h, btn_w, align_w = 80, 240, 200 + header_h = 92 + footer_h = btn_h + 24 title_font = gui_app.font(FontWeight.BOLD) body_font = gui_app.font(FontWeight.MEDIUM) - _draw_text(title_font, "Live radar", rect.x + m.pad, rect.y + (2 if m.compact else 14), m.title_size, TEXT) - chip_x = rect.x + m.pad + measure_text_cached(title_font, "Live radar", m.title_size).x + (8 if m.compact else 16) - chip_y = rect.y + (2 if m.compact else 18) - draw_chip(chip_x, chip_y, status.health_label, health_color(status.health_label), m.chip) - if not m.compact: - _draw_text(body_font, "openpilot stays running", rect.x + m.pad, rect.y + 60, 20, MUTED) - - plot_w = min(rect.width * m.plot_frac, 156 if m.compact else 700) - plot = rl.Rectangle(rect.x + m.pad, rect.y + m.header_h, plot_w, - rect.height - m.header_h - m.footer_h) - draw_radar_plot(plot, status, align_box=True, compact=m.compact) - - info_x = plot.x + plot.width + (6 if m.compact else 24) - info_w = rect.x + rect.width - info_x - m.pad - footer_y = rect.y + rect.height - m.footer_h - info = rl.Rectangle(info_x, plot.y, info_w, max(0, footer_y - plot.y - 2)) - y = draw_status_panel(info, status, compact=m.compact, font_size=m.status_size, show_health_chip=False) - - table_y = y + (2 if m.compact else 10) - table_bottom = footer_y - 2 - if table_y + m.body < table_bottom and info_w > 40: - _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, m.body, MUTED) - table_y += _line_h(body_font, "dRel", m.body, 2 if m.compact else 5) - rows = sorted(status.tracks, key=lambda t: t.d_rel)[: m.table_rows] + + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 16, title_size, TEXT) + chip_x = rect.x + pad + measure_text_cached(title_font, "Live radar", title_size).x + 16 + draw_chip(chip_x, rect.y + 20, status.health_label, health_color(status.health_label), 22) + _draw_text(body_font, "openpilot stays running", rect.x + pad, rect.y + 64, 20, MUTED) + + plot_w = min(rect.width * 0.34, 680) + plot = rl.Rectangle(rect.x + pad, rect.y + header_h, plot_w, rect.height - header_h - footer_h) + draw_radar_plot(plot, status, align_box=True, compact=False) + + info_x = plot.x + plot.width + 28 + info_w = rect.x + rect.width - info_x - pad + footer_y = rect.y + rect.height - footer_h + chips_h = min(280.0, max(80.0, (footer_y - plot.y) * 0.52)) + y = draw_hidpi_chips(rl.Rectangle(info_x, plot.y, info_w, chips_h), status, font_size=20) + + table_y = y + 12 + table_bottom = footer_y - 8 + if table_y + body < table_bottom and info_w > 40: + _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) + table_y += _line_h(body_font, "dRel", body, 6) + rows = sorted(status.tracks, key=lambda t: t.d_rel)[:8] for track in rows: - if table_y + m.body > table_bottom: + if table_y + body > table_bottom: break - _draw_text(body_font, _track_row(track), info_x, table_y, m.body, TEXT) - table_y += _line_h(body_font, _track_row(track), m.body, 2 if m.compact else 4) + _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) + table_y += _line_h(body_font, _track_row(track), body, 4) if not rows: - empty = "no tracks in 2.5-14.5 m" if self._align_only else "no published tracks" - if table_y + m.body <= table_bottom: - _draw_text(body_font, empty, info_x, table_y, m.body, MUTED) - - btn_y = footer_y + (5 if m.compact else 10) - self._close.render(rl.Rectangle(rect.x + m.pad, btn_y, m.btn_w, m.btn_h)) - self._align_btn.render(rl.Rectangle(rect.x + m.pad + m.btn_w + 6, btn_y, m.align_w, m.btn_h)) - mode = "2.5-14.5 m" if self._align_only else "all tracks" - mode_x = rect.x + m.pad + m.btn_w + m.align_w + 8 - mode_y = btn_y + max(0, (m.btn_h - _chip_size(mode, m.body)[1]) / 2) - if mode_x + 20 < rect.x + rect.width - m.pad: - draw_chip(mode_x, mode_y, mode, PRIMARY if self._align_only else MUTED, m.body, + empty = "no tracks in 2.5–14.5 m" if self._align_only else "no published tracks" + if table_y + body <= table_bottom: + _draw_text(body_font, empty, info_x, table_y, body, MUTED) + + btn_y = footer_y + 12 + self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) + self._align_btn.render(rl.Rectangle(rect.x + pad + btn_w + 14, btn_y, align_w, btn_h)) + mode = "2.5–14.5 m" if self._align_only else "all tracks" + mode_color = health_color("LIVE") if self._align_only else MUTED + mw, mh = chip_size(mode, body) + mode_x = rect.x + pad + btn_w + align_w + 20 + mode_y = btn_y + max(0, (btn_h - mh) / 2) + if mode_x + mw <= rect.x + rect.width - pad: + draw_chip(mode_x, mode_y, mode, mode_color, body, fill=ALIGN_FILL if self._align_only else CHIP_FILL) From 7e4f99c7fbbfa7e74f6b33cd67444d0e762f4d3d Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:27:50 +0000 Subject: [PATCH 16/30] ui: restore C4 Close+Align and VIN trio on live radar C4 536x240 must show full Close/Align glyphs and 2B9/F190/chassis. Do not strip the compact modal down to state+Close only. --- selfdrive/ui/radar/radar_view.py | 628 +++++++++++++++---------------- 1 file changed, 305 insertions(+), 323 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index e7f95bad1c85b4..a22cde76325bc6 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -4,14 +4,11 @@ pandad running. NAP's script runner killed the comma session instead. This dialog is a push_widget overlay: open while driving, close without reboot, no NAPScriptRunning. - -Hidpi 2160x1080 is the product: full key-on chips. -C4 536x240 is cut-down: state plus one or two reject/table bits and Close. """ from __future__ import annotations -from dataclasses import replace +from dataclasses import dataclass, replace import pyray as rl @@ -31,21 +28,12 @@ RANGE_M = 120.0 LATERAL_M = 8.0 -# C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). -C4_HUD_W = 460.0 -C4_HUD_H = 44.0 -# Hidpi on-road panel: plot + full key-on chips. -HIDPI_HUD_W = 900.0 -HIDPI_HUD_H = 340.0 - -# 0x501 bits Jack uses to decide "wrong radar / wrong car" — product names, not DBC ids. -ALERT_CHIP = ( - ("vinValidity", "VIN"), - ("xwdValidity", "XWD"), - ("radPositionMismatch", "POS"), - ("strRackMismatch", "RACK"), -) -KEY_REJECT = tuple(k for k, _ in ALERT_CHIP) +ALERT_CHIP = { + "vinValidity": "VIN", + "xwdValidity": "XWD", + "radPositionMismatch": "POS", + "strRackMismatch": "RACK", +} HEALTH_COLOR = { "LIVE": rl.Color(70, 200, 120, 255), @@ -67,12 +55,12 @@ TRACK_FILL = rl.Color(90, 200, 255, 230) TRACK_COAST = rl.Color(180, 180, 180, 200) LEAD_FILL = rl.Color(128, 216, 166, 255) -TEXT = rl.Color(236, 236, 236, 255) +TEXT = rl.Color(230, 230, 230, 255) MUTED = rl.Color(170, 170, 170, 255) -CHIP_MUTED = rl.Color(128, 128, 128, 255) CHIP_FILL = rl.Color(57, 57, 57, 255) -CHIP_ON_FILL = rl.Color(70, 40, 20, 230) -OK_FILL = rl.Color(20, 50, 32, 230) +CHIP_ALERT = rl.Color(230, 120, 40, 255) +MATCH = rl.Color(70, 200, 120, 255) +PRIMARY = rl.Color(70, 91, 234, 255) def health_color(label: str) -> rl.Color: @@ -87,24 +75,52 @@ def _line_h(font, text: str, size: int, gap: int = 4) -> float: return measure_text_cached(font, text or "Ag", size).y + gap -def is_c4_screen(rect: rl.Rectangle) -> bool: - return rect.width < 800 and rect.height < 500 +def _clean_vin(raw) -> str: + if raw is None: + return "" + if isinstance(raw, (bytes, bytearray)): + raw = raw.decode("ascii", errors="ignore") + vin = "".join(ch for ch in str(raw).upper() if ch.isalnum()) + return vin if len(vin) == 17 else "" + + +def decorate_status(status: BoschRadarStatus) -> BoschRadarStatus: + """Fill F190 (donor / last F190 read) and chassis (CarParams) when empty.""" + f190 = _clean_vin(getattr(status, "vin_f190", "")) + chassis = _clean_vin(getattr(status, "vin_chassis", "")) + if not f190: + try: + raw = ui_state.params.get("NAPRadarDonorVin", return_default=True) or "" + f190 = _clean_vin(raw) + if not f190: + raw = ui_state.params.get("NAPRadarVinReadStatus", return_default=True) or "" + f190 = _clean_vin(raw) + except Exception: + f190 = "" + if not chassis: + try: + if getattr(ui_state, "CP", None) is not None: + chassis = _clean_vin(getattr(ui_state.CP, "carVin", "") or "") + if not chassis: + chassis = _clean_vin(ui_state.params.get("CarVin")) + except Exception: + chassis = "" + if f190 != getattr(status, "vin_f190", "") or chassis != getattr(status, "vin_chassis", ""): + return replace(status, vin_f190=f190, vin_chassis=chassis) + return status def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: - """On-road HUD that always fits inside `content`. - - C4 536x240 / content ~476x180: 460x44 status strip. - Hidpi 2160x1080 / content ~2100x1020: 900x340 chip panel. - """ - if is_c4_screen(content): - margin = 8.0 - w = min(C4_HUD_W, max(0.0, content.width - margin * 2)) - h = min(C4_HUD_H, max(0.0, content.height - margin)) + """On-road HUD that always fits inside `content`. C4 536x240 must not overflow.""" + compact = content.height < 500 + if compact: + margin = 6.0 + w = max(0.0, content.width - margin * 2) + h = min(168.0, max(0.0, content.height - margin * 2)) return rl.Rectangle(content.x + margin, content.y + content.height - h - margin, w, h) - margin_x, margin_y = 24.0, 20.0 - w = min(HIDPI_HUD_W, max(0.0, content.width - margin_x * 2)) - h = min(HIDPI_HUD_H, max(0.0, content.height - 24.0)) + margin_x, margin_y = 24.0, 16.0 + w = min(720.0, max(0.0, content.width - margin_x * 2)) + h = min(280.0, max(0.0, content.height - 24.0)) return rl.Rectangle(content.x + margin_x, content.y + content.height - h - margin_y, w, h) @@ -118,18 +134,11 @@ def _clamp_to_window(rect: rl.Rectangle) -> rl.Rectangle: return rl.Rectangle(x, y, w, h) -def _chip_pad(font_size: int) -> tuple[int, int]: - if font_size < 16: - return 6, 2 - if font_size < 22: - return 8, 3 - return 12, 5 - - -def chip_size(text: str, font_size: int) -> tuple[float, float]: +def _chip_size(text: str, font_size: int) -> tuple[float, float]: font = gui_app.font(FontWeight.BOLD) sz = measure_text_cached(font, text, font_size) - pad_x, pad_y = _chip_pad(font_size) + pad_x = 5 if font_size < 20 else 12 + pad_y = 1 if font_size < 20 else 5 return sz.x + pad_x * 2, sz.y + pad_y * 2 @@ -137,100 +146,101 @@ def draw_chip(x: float, y: float, text: str, color: rl.Color, font_size: int, fill: rl.Color | None = None) -> tuple[float, float]: font = gui_app.font(FontWeight.BOLD) sz = measure_text_cached(font, text, font_size) - pad_x, pad_y = _chip_pad(font_size) + pad_x = 5 if font_size < 20 else 12 + pad_y = 1 if font_size < 20 else 5 w = sz.x + pad_x * 2 h = sz.y + pad_y * 2 rec = rl.Rectangle(x, y, w, h) bg = fill if fill is not None else rl.Color(color.r, color.g, color.b, 48) - rl.draw_rectangle_rounded(rec, 0.5, 8, bg) - rl.draw_rectangle_rounded_lines_ex(rec, 0.5, 8, 1.5 if font_size < 20 else 2, color) + rl.draw_rectangle_rounded(rec, 0.45, 8, bg) + rl.draw_rectangle_rounded_lines_ex(rec, 0.45, 8, 1.5 if font_size < 20 else 2, color) _draw_text(font, text, x + pad_x, y + pad_y, font_size, color) return w, h -def draw_chip_row(x: float, y: float, max_w: float, chips: list[tuple[str, rl.Color, rl.Color | None]], - font_size: int, gap: float = 6) -> tuple[float, float]: - cx, cy = x, y +def _flow_chips(x: float, y: float, max_w: float, bottom: float, + items: list[tuple[str, rl.Color, rl.Color | None]], + font_size: int, gap: float = 4) -> float: + if not items: + return y + cx = x row_h = 0.0 - used_w = 0.0 - bottom = y - for text, color, fill in chips: - tw, th = chip_size(text, font_size) + started = False + for text, color, fill in items: + tw, th = _chip_size(text, font_size) if cx + tw > x + max_w and cx > x: cx = x - cy += row_h + 4 + y += row_h + 2 row_h = 0.0 - if tw > max_w: - continue - draw_chip(cx, cy, text, color, font_size, fill=fill) + if y + th > bottom: + break + draw_chip(cx, y, text, color, font_size, fill=fill) cx += tw + gap row_h = max(row_h, th) - used_w = max(used_w, cx - x) - bottom = cy + row_h - return used_w, max(0.0, bottom - y) - - -def table_bit(status: BoschRadarStatus) -> str | None: - if status.table_frozen or status.unique_raw == 1: - return "frozen" - if status.unique_raw >= 2: - return "moving" - return None - - -def link_label(status: BoschRadarStatus) -> str: - # silent-until-VIN-complete: host 0x560 mux must finish before panda talks - return "talking" if status.vin_stream_complete else "waiting" + started = True + if started: + y += row_h + (2 if font_size < 16 else 5) + return y -def c4_extra_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color]]: - """One or two bits that matter on C4. No VIN trio, no 0x2A9 desk.""" - extras: list[tuple[str, rl.Color]] = [] - reason = None - for key, short in ALERT_CHIP: +def _lamp_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: + items = [] + health = status.health_label + if status.hw_fail and health != "FAULT": + items.append(("HWFail", HEALTH_COLOR["FAULT"], None)) + if status.sgu_fail: + items.append(("SGUFail", CHIP_ALERT, None)) + if status.dirty: + items.append(("dirty", MUTED, CHIP_FILL)) + if status.radar_fault and health != "FAULT": + items.append(("radarFault", HEALTH_COLOR["FAULT"], None)) + if status.can_error and health != "CAN": + items.append(("canError", HEALTH_COLOR["CAN"], None)) + return items + + +def _alert_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: + items = [] + named = set() + for key, short in ALERT_CHIP.items(): if key in status.alerts: - reason = short - break - if reason is None and status.hw_fail: - reason = "HWFail" - elif reason is None and status.sgu_fail: - reason = "SGUFail" - elif reason is None and status.health_label in ("WAIT VIN", "WAIT GTW"): - reason = "waiting" - if reason: - extras.append((reason, health_color("REJECT" if reason in ("VIN", "XWD", "POS", "RACK") else status.health_label))) - bit = table_bit(status) - if bit: - extras.append((bit, health_color("FROZEN" if bit == "frozen" else "LIVE"))) - return extras[:2] - - -def _extract_vin(raw) -> str: - if raw is None: - return "" - if isinstance(raw, (bytes, bytearray)): - raw = raw.decode("ascii", "ignore") - token = "".join(ch for ch in str(raw).upper() if ch.isalnum()) - return token if len(token) == 17 else "" - - -def vin_refs(status: BoschRadarStatus) -> tuple[str, str, str]: - """0x2B9 feed vs F190 (radar EEPROM / donor param) vs chassis CarVin.""" - feed = status.vin if len(status.vin) == 17 else (status.vin or "") - f190 = _extract_vin(getattr(status, "vin_f190", "") or "") - chassis = _extract_vin(getattr(status, "vin_chassis", "") or "") - if not f190 or not chassis: - try: - if not f190: - raw = ui_state.params.get("NAPRadarDonorVin", return_default=True) or "" - f190 = _extract_vin(raw) - if not chassis and getattr(ui_state, "CP", None) is not None: - chassis = _extract_vin(getattr(ui_state.CP, "carVin", "") or "") - if not chassis: - chassis = _extract_vin(ui_state.params.get("CarVin")) - except Exception: - pass - return feed, f190, chassis + items.append((short, CHIP_ALERT, None)) + named.add(key) + for name in status.alerts: + if name not in named: + items.append((name, MUTED, CHIP_FILL)) + return items + + +def _gtw_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: + items = [] + if status.awd is None and status.position is None and status.epas_type is None: + return items + if status.awd is not None: + items.append(("4WD" if status.awd else "2WD", TEXT, CHIP_FILL)) + if status.position is not None: + items.append((f"pos {status.position}", TEXT, CHIP_FILL)) + if status.epas_type is not None: + items.append((f"EPAS {status.epas_type}", TEXT, CHIP_FILL)) + return items + + +def _gate_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None]: + if not status.vin_stream_complete: + return "waiting", HEALTH_COLOR["WAIT VIN"], None + return "talking", MATCH, None + + +def _raw_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None]: + age = getattr(status, "last_raw_age_s", None) + if age is None: + label = f"310 {status.unique_raw}" + elif age < 10: + label = f"310 {status.unique_raw} {age:.1f}s" + else: + label = f"310 {status.unique_raw} {age:.0f}s" + frozenish = status.unique_raw <= 1 and (status.table_frozen or status.unique_raw == 1) + return label, (HEALTH_COLOR["FROZEN"] if frozenish else MUTED), CHIP_FILL def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True, @@ -245,8 +255,8 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: y = rect.y + rect.height * (1.0 - d_rel / RANGE_M) return x, y - rl.begin_scissor_mode(int(rect.x) + 1, int(rect.y) + 1, max(1, int(rect.width) - 2), max(1, int(rect.height) - 2)) - + rl.begin_scissor_mode(int(rect.x) + 1, int(rect.y) + 1, + max(1, int(rect.width) - 2), max(1, int(rect.height) - 2)) if align_box: left, bottom = to_px(ALIGN_D_MIN, ALIGN_Y_MAX) right, top = to_px(ALIGN_D_MAX, -ALIGN_Y_MAX) @@ -267,7 +277,6 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: color = LEAD_FILL if track is closest else (TRACK_FILL if track.measured else TRACK_COAST) radius = (4 if track is closest else 3) if compact else (7 if track is closest else 5) rl.draw_circle(int(x), int(y), radius, color) - rl.end_scissor_mode() font = gui_app.font(FontWeight.NORMAL) @@ -276,141 +285,142 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: _draw_text(font, f"{int(RANGE_M)}m", rect.x + 4, rect.y + 3, tick, MUTED) -def _track_row(track: RadarTrack) -> str: - flag = "m" if track.measured else "c" - return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" +def _vin_value(status: BoschRadarStatus) -> str: + vin = getattr(status, "vin", "") or "" + return vin if len(vin) == 17 else (vin or "--") -def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: - chips: list[tuple[str, rl.Color, rl.Color | None]] = [ - (status.health_label, health_color(status.health_label), None), - ] - for text, color in c4_extra_chips(status): - fill = CHIP_FILL if text in ("moving", "frozen", "waiting") else CHIP_ON_FILL - chips.append((text, color, fill)) - return chips - - -def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down C4 HUD: state + at most two reject/table bits.""" - rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) - font_size = 13 - chips = _c4_chip_list(status) - max_h = 0.0 - for text, _, _ in chips: - _w, th = chip_size(text, font_size) - max_h = max(max_h, th) - pad = 6.0 - y = panel.y + max(pad, (panel.height - max_h) / 2) - draw_chip_row(panel.x + pad, y, panel.width - pad * 2, chips, font_size, gap=6) - - -def draw_hidpi_chips(rect: rl.Rectangle, status: BoschRadarStatus, font_size: int) -> float: - """Full key-on chips. Product names, not a wall of CAN ids.""" +def draw_vin_trio(x: float, y: float, max_w: float, bottom: float, status: BoschRadarStatus, + font_size: int) -> float: + """0x2B9 vs F190 vs chassis. Jack spare / Ian donor mixups were real.""" + font = gui_app.font(FontWeight.MEDIUM) + bold = gui_app.font(FontWeight.BOLD) + rows = ( + ("2B9", _vin_value(status)), + ("F190", _clean_vin(getattr(status, "vin_f190", "")) or "--"), + ("CHS", _clean_vin(getattr(status, "vin_chassis", "")) or "--"), + ) + present = [v for _, v in rows if v != "--"] + mismatch = len(set(present)) > 1 + tag_w = measure_text_cached(bold, "F190", font_size).x + 6 + line = _line_h(font, "VIN", font_size, 0 if font_size < 16 else 3) + for tag, value in rows: + if y + line > bottom: + break + _draw_text(bold, tag, x, y, font_size, MUTED) + color = TEXT + suffix = "" + if value != "--" and mismatch: + others = [v for t, v in rows if t != tag and v != "--"] + if others and value not in others: + color = CHIP_ALERT + suffix = " !=" + elif others and all(value == o for o in others): + color = MATCH + label = value + suffix + size = font_size + while size >= 10 and measure_text_cached(font, label, size).x > max_w - tag_w: + size -= 1 + _draw_text(font, label, x + tag_w, y, size, color) + y += line + return y + + +def draw_status_panel(rect: rl.Rectangle, status: BoschRadarStatus, *, compact: bool, + font_size: int, show_health_chip: bool = True) -> float: if rect.width < 8 or rect.height < 8: return rect.y - font = gui_app.font(FontWeight.MEDIUM) - label_size = max(14, font_size - 4) x, y = rect.x, rect.y max_w = rect.width bottom = rect.y + rect.height - gap = 8 + font = gui_app.font(FontWeight.MEDIUM) + chip = max(11, font_size) + + if show_health_chip: + label = status.health_label + cw, ch = draw_chip(x, y, label, health_color(label), chip) + meta = f"{len(status.tracks)} trk" + mx = x + cw + 6 + if mx + measure_text_cached(font, meta, font_size).x <= x + max_w: + _draw_text(font, meta, mx, y + max(0, (ch - measure_text_cached(font, meta, font_size).y) / 2), + font_size, MUTED) + y += ch + (2 if compact else 6) + + y = _flow_chips(x, y, max_w, bottom, [_gate_chip(status), _raw_chip(status)], chip) + y = _flow_chips(x, y, max_w, bottom, _lamp_chips(status), chip) + y = _flow_chips(x, y, max_w, bottom, _alert_chips(status), chip) + y = _flow_chips(x, y, max_w, bottom, _gtw_chips(status), chip) + if y + 12 <= bottom: + y = draw_vin_trio(x, y, max_w, bottom, status, font_size) + return y - def row(label: str, chips: list[tuple[str, rl.Color, rl.Color | None]]) -> None: - nonlocal y - if y + 20 > bottom: - return - lw = 0.0 - if label: - _draw_text(font, label, x, y + 4, label_size, MUTED) - lw = measure_text_cached(font, label, label_size).x + 10 - _, h = draw_chip_row(x + lw, y, max_w - lw, chips, font_size, gap=6) - y += max(h, _line_h(font, label or "Ag", label_size, 0)) + gap - - label = status.health_label - talking = link_label(status) - row("", [ - (label, health_color(label), None), - ("SGUFail", health_color("SGU") if status.sgu_fail else CHIP_MUTED, - CHIP_ON_FILL if status.sgu_fail else CHIP_FILL), - ("HWFail", health_color("FAULT") if status.hw_fail else CHIP_MUTED, - CHIP_ON_FILL if status.hw_fail else CHIP_FILL), - (talking, health_color("LIVE") if talking == "talking" else health_color("WAIT VIN"), - OK_FILL if talking == "talking" else CHIP_FILL), - ]) - - alert_chips = [] - for key, short in ALERT_CHIP: - on = key in status.alerts - alert_chips.append((short, health_color("REJECT") if on else CHIP_MUTED, CHIP_ON_FILL if on else CHIP_FILL)) - row("reject", alert_chips) - - awd = "4WD" if status.awd else ("2WD" if status.awd is False else "drive —") - pos = "—" if status.position is None else str(status.position) - epas = "—" if status.epas_type is None else str(status.epas_type) - row("drive", [ - (awd, TEXT, CHIP_FILL), - (f"pos {pos}", TEXT, CHIP_FILL), - (f"EPAS {epas}", TEXT, CHIP_FILL), - ]) - - feed, f190, chassis = vin_refs(status) - present = [v for v in (feed, f190, chassis) if v] - mismatch = len(set(present)) > 1 - def vin_chip(tag: str, value: str) -> tuple[str, rl.Color, rl.Color | None]: - shown = value or "—" - bad = bool(value) and mismatch and value not in [v for v in present if v != value] - if value and mismatch and any(v != value for v in present): - bad = True - return (f"{tag} {shown}", health_color("REJECT") if bad else TEXT, CHIP_ON_FILL if bad else CHIP_FILL) - - row("VIN", [ - vin_chip("2B9", feed), - vin_chip("F190", f190), - vin_chip("CHS", chassis), - ]) - - age = "age —" if status.last_raw_age_s is None else ( - f"age {status.last_raw_age_s:.1f}s" if status.last_raw_age_s < 10 else f"age {status.last_raw_age_s:.0f}s" +def _track_row(track: RadarTrack) -> str: + flag = "m" if track.measured else "c" + return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" + + +@dataclass(frozen=True) +class _DialogMetrics: + compact: bool + pad: int + title_size: int + body: int + chip: int + btn_h: int + btn_w: int + align_w: int + btn_font: int + btn_pad: int + btn_radius: int + header_h: int + footer_h: int + plot_frac: float + status_size: int + table_rows: int + + +def _dialog_metrics(rect: rl.Rectangle) -> _DialogMetrics: + compact = rect.height < 500 + if compact: + btn_h = 22 + return _DialogMetrics( + compact=True, pad=6, title_size=16, body=12, chip=12, + btn_h=btn_h, btn_w=78, align_w=78, btn_font=14, btn_pad=2, btn_radius=7, + header_h=22, footer_h=btn_h + 12, plot_frac=0.30, status_size=12, table_rows=1, + ) + btn_h = 80 + return _DialogMetrics( + compact=False, pad=24, title_size=40, body=22, chip=22, + btn_h=btn_h, btn_w=240, align_w=200, btn_font=35, btn_pad=16, btn_radius=10, + header_h=88, footer_h=btn_h + 20, plot_frac=0.36, status_size=22, table_rows=8, ) - bit = table_bit(status) - raw_chips: list[tuple[str, rl.Color, rl.Color | None]] = [ - (f"raw {status.unique_raw}", TEXT, CHIP_FILL), - (age, TEXT, CHIP_FILL), - (f"{len(status.tracks)} trk", TEXT, CHIP_FILL), - ] - if bit: - raw_chips.append((bit, health_color("FROZEN" if bit == "frozen" else "LIVE"), - CHIP_ON_FILL if bit == "frozen" else OK_FILL)) - row("table", raw_chips) - return y class RadarHudOverlay(Widget): - """On-road readout. Hidden unless NAPRadarHud is set.""" + """Compact on-road readout. Hidden unless NAPRadarHud is set.""" def _render(self, rect: rl.Rectangle): if not ui_state.radar_hud: return - status = ui_state.radar_status + status = decorate_status(ui_state.radar_status) panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - if panel.height < 80: - draw_c4_strip(panel, status) - return - - rl.draw_rectangle_rounded(panel, 0.06, 8, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.06, 8, 2, health_color(status.health_label)) - pad = 14 - plot_w = min(220.0, panel.width * 0.28) + compact = panel.height < 200 + rl.draw_rectangle_rounded(panel, 0.08, 8, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.08, 8, 2, health_color(status.health_label)) + pad = 5 if compact else 12 + plot_w = min(96 if compact else 160, panel.width * (0.26 if compact else 0.34)) plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) - draw_radar_plot(plot, status, align_box=False, compact=False) - chips = rl.Rectangle(plot.x + plot.width + 14, panel.y + pad, - panel.width - plot.width - pad * 3, panel.height - pad * 2) - draw_hidpi_chips(chips, status, font_size=18) + draw_radar_plot(plot, status, align_box=False, compact=compact) + text = rl.Rectangle( + plot.x + plot.width + (5 if compact else 12), + panel.y + pad, + panel.width - plot.width - pad * 3, + panel.height - pad * 2, + ) + draw_status_panel(text, status, compact=compact, font_size=11 if compact else 18) class RadarMonitorDialog(Widget): @@ -418,11 +428,13 @@ class RadarMonitorDialog(Widget): def __init__(self): super().__init__() - self._close = Button("Close", click_callback=self._on_close, font_size=35, - text_padding=16, button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) + self._close = Button("Close", click_callback=self._on_close, + font_size=35, text_padding=16, + button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) self._align_only = False - self._align_btn = Button("Align", click_callback=self._toggle_align, font_size=35, - text_padding=16, button_style=ButtonStyle.ACTION) + self._align_btn = Button("Align", click_callback=self._toggle_align, + font_size=35, text_padding=16, + button_style=ButtonStyle.ACTION) def _on_close(self): gui_app.pop_widget() @@ -430,98 +442,68 @@ def _on_close(self): def _toggle_align(self): self._align_only = not self._align_only - def _tune_buttons(self, compact: bool) -> None: - font = 18 if compact else 35 - pad = 4 if compact else 16 - radius = 8 if compact else 10 + def _tune_buttons(self, m: _DialogMetrics) -> None: for btn in (self._close, self._align_btn): - btn._label.set_font_size(font) - btn._label._text_padding = pad - btn._border_radius = radius + btn._label.set_font_size(m.btn_font) + btn._label._text_padding = m.btn_pad + btn._border_radius = m.btn_radius self._align_btn.set_button_style(ButtonStyle.PRIMARY if self._align_only else ButtonStyle.ACTION) def _render(self, rect: rl.Rectangle): - status = ui_state.radar_status - compact = is_c4_screen(rect) - if self._align_only and not compact: + status = decorate_status(ui_state.radar_status) + if self._align_only: tracks = tuple( t for t in status.tracks if ALIGN_D_MIN <= t.d_rel <= ALIGN_D_MAX and abs(t.y_rel) <= ALIGN_Y_MAX ) status = replace(status, tracks=tracks) - self._tune_buttons(compact) + m = _dialog_metrics(rect) + self._tune_buttons(m) rl.draw_rectangle_rec(rect, rl.Color(0, 0, 0, 255)) - if compact: - self._render_c4(rect, status) - else: - self._render_hidpi(rect, status) - - def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down 536x240 modal: title, state+bits, plot, Close. No Align, no VIN dump.""" - pad = 8 - title_size = 18 - btn_w, btn_h = 110, 36 - footer_h = btn_h + 10 - title_font = gui_app.font(FontWeight.BOLD) - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 6, title_size, TEXT) - chip_y = rect.y + 30 - draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 13, gap=6) - plot = rl.Rectangle(rect.x + pad, rect.y + 64, rect.width - pad * 2, rect.height - 64 - footer_h) - if plot.height > 24: - draw_radar_plot(plot, status, align_box=False, compact=True) - btn_y = rect.y + rect.height - footer_h + 4 - self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) - - def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - pad = 28 - title_size = 42 - body = 22 - btn_h, btn_w, align_w = 80, 240, 200 - header_h = 92 - footer_h = btn_h + 24 + title_font = gui_app.font(FontWeight.BOLD) body_font = gui_app.font(FontWeight.MEDIUM) - - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 16, title_size, TEXT) - chip_x = rect.x + pad + measure_text_cached(title_font, "Live radar", title_size).x + 16 - draw_chip(chip_x, rect.y + 20, status.health_label, health_color(status.health_label), 22) - _draw_text(body_font, "openpilot stays running", rect.x + pad, rect.y + 64, 20, MUTED) - - plot_w = min(rect.width * 0.34, 680) - plot = rl.Rectangle(rect.x + pad, rect.y + header_h, plot_w, rect.height - header_h - footer_h) - draw_radar_plot(plot, status, align_box=True, compact=False) - - info_x = plot.x + plot.width + 28 - info_w = rect.x + rect.width - info_x - pad - footer_y = rect.y + rect.height - footer_h - chips_h = min(280.0, max(80.0, (footer_y - plot.y) * 0.52)) - y = draw_hidpi_chips(rl.Rectangle(info_x, plot.y, info_w, chips_h), status, font_size=20) - - table_y = y + 12 - table_bottom = footer_y - 8 - if table_y + body < table_bottom and info_w > 40: - _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) - table_y += _line_h(body_font, "dRel", body, 6) - rows = sorted(status.tracks, key=lambda t: t.d_rel)[:8] + _draw_text(title_font, "Live radar", rect.x + m.pad, rect.y + (2 if m.compact else 14), m.title_size, TEXT) + chip_x = rect.x + m.pad + measure_text_cached(title_font, "Live radar", m.title_size).x + (8 if m.compact else 16) + chip_y = rect.y + (2 if m.compact else 18) + draw_chip(chip_x, chip_y, status.health_label, health_color(status.health_label), m.chip) + if not m.compact: + _draw_text(body_font, "openpilot stays running", rect.x + m.pad, rect.y + 60, 20, MUTED) + + plot_w = min(rect.width * m.plot_frac, 156 if m.compact else 700) + plot = rl.Rectangle(rect.x + m.pad, rect.y + m.header_h, plot_w, + rect.height - m.header_h - m.footer_h) + draw_radar_plot(plot, status, align_box=True, compact=m.compact) + + info_x = plot.x + plot.width + (6 if m.compact else 24) + info_w = rect.x + rect.width - info_x - m.pad + footer_y = rect.y + rect.height - m.footer_h + info = rl.Rectangle(info_x, plot.y, info_w, max(0, footer_y - plot.y - 2)) + y = draw_status_panel(info, status, compact=m.compact, font_size=m.status_size, show_health_chip=False) + + table_y = y + (2 if m.compact else 10) + table_bottom = footer_y - 2 + if table_y + m.body < table_bottom and info_w > 40: + _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, m.body, MUTED) + table_y += _line_h(body_font, "dRel", m.body, 2 if m.compact else 5) + rows = sorted(status.tracks, key=lambda t: t.d_rel)[: m.table_rows] for track in rows: - if table_y + body > table_bottom: + if table_y + m.body > table_bottom: break - _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) - table_y += _line_h(body_font, _track_row(track), body, 4) + _draw_text(body_font, _track_row(track), info_x, table_y, m.body, TEXT) + table_y += _line_h(body_font, _track_row(track), m.body, 2 if m.compact else 4) if not rows: - empty = "no tracks in 2.5–14.5 m" if self._align_only else "no published tracks" - if table_y + body <= table_bottom: - _draw_text(body_font, empty, info_x, table_y, body, MUTED) - - btn_y = footer_y + 12 - self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) - self._align_btn.render(rl.Rectangle(rect.x + pad + btn_w + 14, btn_y, align_w, btn_h)) - mode = "2.5–14.5 m" if self._align_only else "all tracks" - mode_color = health_color("LIVE") if self._align_only else MUTED - mw, mh = chip_size(mode, body) - mode_x = rect.x + pad + btn_w + align_w + 20 - mode_y = btn_y + max(0, (btn_h - mh) / 2) - if mode_x + mw <= rect.x + rect.width - pad: - draw_chip(mode_x, mode_y, mode, mode_color, body, + empty = "no tracks in 2.5-14.5 m" if self._align_only else "no published tracks" + if table_y + m.body <= table_bottom: + _draw_text(body_font, empty, info_x, table_y, m.body, MUTED) + + btn_y = footer_y + (5 if m.compact else 10) + self._close.render(rl.Rectangle(rect.x + m.pad, btn_y, m.btn_w, m.btn_h)) + self._align_btn.render(rl.Rectangle(rect.x + m.pad + m.btn_w + 6, btn_y, m.align_w, m.btn_h)) + mode = "2.5-14.5 m" if self._align_only else "all tracks" + mode_x = rect.x + m.pad + m.btn_w + m.align_w + 8 + mode_y = btn_y + max(0, (m.btn_h - _chip_size(mode, m.body)[1]) / 2) + if mode_x + 20 < rect.x + rect.width - m.pad: + draw_chip(mode_x, mode_y, mode, PRIMARY if self._align_only else MUTED, m.body, fill=ALIGN_FILL if self._align_only else CHIP_FILL) From 3a37525f7d122a5814e8d40e9d03748cb6d769b4 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:33:13 +0000 Subject: [PATCH 17/30] ui: hidpi range rings and All tracks; keep C4 strip 3X overlay is 980x380 with colored 20/40/60/80 m rings and All tracks header-right. C4 stays state plus Close. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 645 ++++++++++++++++--------------- 1 file changed, 335 insertions(+), 310 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index a22cde76325bc6..43cb9f94abc308 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -4,11 +4,14 @@ pandad running. NAP's script runner killed the comma session instead. This dialog is a push_widget overlay: open while driving, close without reboot, no NAPScriptRunning. + +C4 (536x240) is a cut-down status strip: health plus one or two reject/table +bits. The full key-on chip set lives on hidpi / the 2160x1080 modal. """ from __future__ import annotations -from dataclasses import dataclass, replace +from dataclasses import replace import pyray as rl @@ -28,12 +31,14 @@ RANGE_M = 120.0 LATERAL_M = 8.0 -ALERT_CHIP = { - "vinValidity": "VIN", - "xwdValidity": "XWD", - "radPositionMismatch": "POS", - "strRackMismatch": "RACK", -} +# C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). +C4_HUD_W = 460.0 +C4_HUD_H = 44.0 +# Hidpi on-road panel: plot + full key-on chips. +HIDPI_HUD_W = 900.0 +HIDPI_HUD_H = 340.0 + +KEY_REJECT = ("vinValidity", "xwdValidity", "radPositionMismatch", "strRackMismatch") HEALTH_COLOR = { "LIVE": rl.Color(70, 200, 120, 255), @@ -57,10 +62,10 @@ LEAD_FILL = rl.Color(128, 216, 166, 255) TEXT = rl.Color(230, 230, 230, 255) MUTED = rl.Color(170, 170, 170, 255) +CHIP_MUTED = rl.Color(128, 128, 128, 255) CHIP_FILL = rl.Color(57, 57, 57, 255) -CHIP_ALERT = rl.Color(230, 120, 40, 255) -MATCH = rl.Color(70, 200, 120, 255) -PRIMARY = rl.Color(70, 91, 234, 255) +CHIP_ON_FILL = rl.Color(70, 40, 20, 230) +OK_FILL = rl.Color(20, 50, 32, 230) def health_color(label: str) -> rl.Color: @@ -75,52 +80,25 @@ def _line_h(font, text: str, size: int, gap: int = 4) -> float: return measure_text_cached(font, text or "Ag", size).y + gap -def _clean_vin(raw) -> str: - if raw is None: - return "" - if isinstance(raw, (bytes, bytearray)): - raw = raw.decode("ascii", errors="ignore") - vin = "".join(ch for ch in str(raw).upper() if ch.isalnum()) - return vin if len(vin) == 17 else "" - - -def decorate_status(status: BoschRadarStatus) -> BoschRadarStatus: - """Fill F190 (donor / last F190 read) and chassis (CarParams) when empty.""" - f190 = _clean_vin(getattr(status, "vin_f190", "")) - chassis = _clean_vin(getattr(status, "vin_chassis", "")) - if not f190: - try: - raw = ui_state.params.get("NAPRadarDonorVin", return_default=True) or "" - f190 = _clean_vin(raw) - if not f190: - raw = ui_state.params.get("NAPRadarVinReadStatus", return_default=True) or "" - f190 = _clean_vin(raw) - except Exception: - f190 = "" - if not chassis: - try: - if getattr(ui_state, "CP", None) is not None: - chassis = _clean_vin(getattr(ui_state.CP, "carVin", "") or "") - if not chassis: - chassis = _clean_vin(ui_state.params.get("CarVin")) - except Exception: - chassis = "" - if f190 != getattr(status, "vin_f190", "") or chassis != getattr(status, "vin_chassis", ""): - return replace(status, vin_f190=f190, vin_chassis=chassis) - return status +def is_c4_screen(rect: rl.Rectangle) -> bool: + """True for the 536x240 C4 window / content, not the hidpi 900x340 HUD card.""" + return rect.width < 800 and rect.height < 500 def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: - """On-road HUD that always fits inside `content`. C4 536x240 must not overflow.""" - compact = content.height < 500 - if compact: - margin = 6.0 - w = max(0.0, content.width - margin * 2) - h = min(168.0, max(0.0, content.height - margin * 2)) + """On-road HUD that always fits inside `content` with zero clipping. + + C4 536x240 / content ~476x180: 460x44 status strip. + Hidpi 2160x1080 / content ~2100x1020: 900x340 chip panel. + """ + if is_c4_screen(content): + margin = 8.0 + w = min(C4_HUD_W, max(0.0, content.width - margin * 2)) + h = min(C4_HUD_H, max(0.0, content.height - margin)) return rl.Rectangle(content.x + margin, content.y + content.height - h - margin, w, h) - margin_x, margin_y = 24.0, 16.0 - w = min(720.0, max(0.0, content.width - margin_x * 2)) - h = min(280.0, max(0.0, content.height - 24.0)) + margin_x, margin_y = 24.0, 20.0 + w = min(HIDPI_HUD_W, max(0.0, content.width - margin_x * 2)) + h = min(HIDPI_HUD_H, max(0.0, content.height - 24.0)) return rl.Rectangle(content.x + margin_x, content.y + content.height - h - margin_y, w, h) @@ -134,11 +112,18 @@ def _clamp_to_window(rect: rl.Rectangle) -> rl.Rectangle: return rl.Rectangle(x, y, w, h) -def _chip_size(text: str, font_size: int) -> tuple[float, float]: +def _chip_pad(font_size: int) -> tuple[int, int]: + if font_size < 16: + return 6, 2 + if font_size < 22: + return 8, 3 + return 14, 6 + + +def chip_size(text: str, font_size: int) -> tuple[float, float]: font = gui_app.font(FontWeight.BOLD) sz = measure_text_cached(font, text, font_size) - pad_x = 5 if font_size < 20 else 12 - pad_y = 1 if font_size < 20 else 5 + pad_x, pad_y = _chip_pad(font_size) return sz.x + pad_x * 2, sz.y + pad_y * 2 @@ -146,101 +131,86 @@ def draw_chip(x: float, y: float, text: str, color: rl.Color, font_size: int, fill: rl.Color | None = None) -> tuple[float, float]: font = gui_app.font(FontWeight.BOLD) sz = measure_text_cached(font, text, font_size) - pad_x = 5 if font_size < 20 else 12 - pad_y = 1 if font_size < 20 else 5 + pad_x, pad_y = _chip_pad(font_size) w = sz.x + pad_x * 2 h = sz.y + pad_y * 2 rec = rl.Rectangle(x, y, w, h) bg = fill if fill is not None else rl.Color(color.r, color.g, color.b, 48) - rl.draw_rectangle_rounded(rec, 0.45, 8, bg) - rl.draw_rectangle_rounded_lines_ex(rec, 0.45, 8, 1.5 if font_size < 20 else 2, color) + rl.draw_rectangle_rounded(rec, 0.5, 8, bg) + rl.draw_rectangle_rounded_lines_ex(rec, 0.5, 8, 1.5 if font_size < 20 else 2, color) _draw_text(font, text, x + pad_x, y + pad_y, font_size, color) return w, h -def _flow_chips(x: float, y: float, max_w: float, bottom: float, - items: list[tuple[str, rl.Color, rl.Color | None]], - font_size: int, gap: float = 4) -> float: - if not items: - return y - cx = x - row_h = 0.0 - started = False - for text, color, fill in items: - tw, th = _chip_size(text, font_size) - if cx + tw > x + max_w and cx > x: - cx = x - y += row_h + 2 - row_h = 0.0 - if y + th > bottom: - break - draw_chip(cx, y, text, color, font_size, fill=fill) - cx += tw + gap - row_h = max(row_h, th) - started = True - if started: - y += row_h + (2 if font_size < 16 else 5) - return y +def table_bit(status: BoschRadarStatus) -> str | None: + """Moving vs frozen from the 0x310 unique window (not liveTracks age).""" + if status.table_frozen or status.unique_raw == 1: + return "frozen" + if status.unique_raw >= 2: + return "moving" + return None + + +def c4_extra_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color]]: + """The one or two bits that matter on the C4 strip. No 0x501 dump, no VIN.""" + extras: list[tuple[str, rl.Color]] = [] + reason = next((name for name in KEY_REJECT if name in status.alerts), None) + if reason is None and status.health_label == "FAULT": + if status.hw_fail: + reason = "HWFail" + elif status.radar_fault: + reason = "radarFault" + if reason is None and status.health_label in ("WAIT VIN", "WAIT GTW"): + reason = "waiting" + if reason: + extras.append((reason, health_color("REJECT" if reason in KEY_REJECT else status.health_label))) + bit = table_bit(status) + if bit: + extras.append((bit, health_color("FROZEN" if bit == "frozen" else "LIVE"))) + return extras[:2] + + +def _extract_vin(raw) -> str: + if raw is None: + return "" + if isinstance(raw, (bytes, bytearray)): + raw = raw.decode("utf-8", "ignore") + token = "".join(ch for ch in str(raw).upper() if ch.isalnum()) + if len(token) == 17: + return token + for i in range(0, max(0, len(token) - 16)): + cand = token[i:i + 17] + if len(cand) == 17: + return cand + return "" + + +def vin_refs(status: BoschRadarStatus) -> tuple[str, str, str]: + """0x2B9 feed vs F190 (radar EEPROM) vs chassis CarVin.""" + feed = status.vin if len(status.vin) == 17 else (status.vin or "") + f190 = _extract_vin(getattr(status, "vin_f190", "") or "") + chassis = _extract_vin(getattr(status, "vin_chassis", "") or "") + if not f190 or not chassis: + try: + from openpilot.common.params import Params + p = Params() + if not chassis: + chassis = _extract_vin(p.get("CarVin")) + if not f190: + raw = "" + try: + from opendbc.car.tesla.preap.nap_params import NAPParamKeys + raw = p.get(NAPParamKeys.RADAR_VIN_READ_STATUS, return_default=True) or "" + except Exception: + raw = p.get("NAPRadarVinReadStatus", return_default=True) or "" + f190 = _extract_vin(raw) + except Exception: + pass + return feed, f190, chassis -def _lamp_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: - items = [] - health = status.health_label - if status.hw_fail and health != "FAULT": - items.append(("HWFail", HEALTH_COLOR["FAULT"], None)) - if status.sgu_fail: - items.append(("SGUFail", CHIP_ALERT, None)) - if status.dirty: - items.append(("dirty", MUTED, CHIP_FILL)) - if status.radar_fault and health != "FAULT": - items.append(("radarFault", HEALTH_COLOR["FAULT"], None)) - if status.can_error and health != "CAN": - items.append(("canError", HEALTH_COLOR["CAN"], None)) - return items - - -def _alert_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: - items = [] - named = set() - for key, short in ALERT_CHIP.items(): - if key in status.alerts: - items.append((short, CHIP_ALERT, None)) - named.add(key) - for name in status.alerts: - if name not in named: - items.append((name, MUTED, CHIP_FILL)) - return items - - -def _gtw_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: - items = [] - if status.awd is None and status.position is None and status.epas_type is None: - return items - if status.awd is not None: - items.append(("4WD" if status.awd else "2WD", TEXT, CHIP_FILL)) - if status.position is not None: - items.append((f"pos {status.position}", TEXT, CHIP_FILL)) - if status.epas_type is not None: - items.append((f"EPAS {status.epas_type}", TEXT, CHIP_FILL)) - return items - - -def _gate_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None]: - if not status.vin_stream_complete: - return "waiting", HEALTH_COLOR["WAIT VIN"], None - return "talking", MATCH, None - - -def _raw_chip(status: BoschRadarStatus) -> tuple[str, rl.Color, rl.Color | None]: - age = getattr(status, "last_raw_age_s", None) - if age is None: - label = f"310 {status.unique_raw}" - elif age < 10: - label = f"310 {status.unique_raw} {age:.1f}s" - else: - label = f"310 {status.unique_raw} {age:.0f}s" - frozenish = status.unique_raw <= 1 and (status.table_frozen or status.unique_raw == 1) - return label, (HEALTH_COLOR["FROZEN"] if frozenish else MUTED), CHIP_FILL +def link_label(status: BoschRadarStatus) -> str: + return "talking" if status.gtw_live else "waiting" def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True, @@ -255,8 +225,8 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: y = rect.y + rect.height * (1.0 - d_rel / RANGE_M) return x, y - rl.begin_scissor_mode(int(rect.x) + 1, int(rect.y) + 1, - max(1, int(rect.width) - 2), max(1, int(rect.height) - 2)) + rl.begin_scissor_mode(int(rect.x) + 1, int(rect.y) + 1, max(1, int(rect.width) - 2), max(1, int(rect.height) - 2)) + if align_box: left, bottom = to_px(ALIGN_D_MIN, ALIGN_Y_MAX) right, top = to_px(ALIGN_D_MAX, -ALIGN_Y_MAX) @@ -272,11 +242,13 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: for track in status.tracks: if closest is None or track.d_rel < closest.d_rel: closest = track + for track in status.tracks: x, y = to_px(max(0.0, min(RANGE_M, track.d_rel)), track.y_rel) color = LEAD_FILL if track is closest else (TRACK_FILL if track.measured else TRACK_COAST) radius = (4 if track is closest else 3) if compact else (7 if track is closest else 5) rl.draw_circle(int(x), int(y), radius, color) + rl.end_scissor_mode() font = gui_app.font(FontWeight.NORMAL) @@ -285,142 +257,164 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: _draw_text(font, f"{int(RANGE_M)}m", rect.x + 4, rect.y + 3, tick, MUTED) -def _vin_value(status: BoschRadarStatus) -> str: - vin = getattr(status, "vin", "") or "" - return vin if len(vin) == 17 else (vin or "--") +def draw_chip_row(x: float, y: float, max_w: float, chips: list[tuple[str, rl.Color, rl.Color | None]], + font_size: int, gap: float = 6) -> tuple[float, float]: + cx, cy = x, y + row_h = 0.0 + used_w = 0.0 + bottom = y + for text, color, fill in chips: + tw, th = chip_size(text, font_size) + if cx + tw > x + max_w and cx > x: + cx = x + cy += row_h + 4 + row_h = 0.0 + if tw > max_w: + continue + draw_chip(cx, cy, text, color, font_size, fill=fill) + cx += tw + gap + row_h = max(row_h, th) + used_w = max(used_w, cx - x) + bottom = cy + row_h + return used_w, max(0.0, bottom - y) -def draw_vin_trio(x: float, y: float, max_w: float, bottom: float, status: BoschRadarStatus, - font_size: int) -> float: - """0x2B9 vs F190 vs chassis. Jack spare / Ian donor mixups were real.""" - font = gui_app.font(FontWeight.MEDIUM) - bold = gui_app.font(FontWeight.BOLD) - rows = ( - ("2B9", _vin_value(status)), - ("F190", _clean_vin(getattr(status, "vin_f190", "")) or "--"), - ("CHS", _clean_vin(getattr(status, "vin_chassis", "")) or "--"), - ) - present = [v for _, v in rows if v != "--"] - mismatch = len(set(present)) > 1 - tag_w = measure_text_cached(bold, "F190", font_size).x + 6 - line = _line_h(font, "VIN", font_size, 0 if font_size < 16 else 3) - for tag, value in rows: - if y + line > bottom: - break - _draw_text(bold, tag, x, y, font_size, MUTED) - color = TEXT - suffix = "" - if value != "--" and mismatch: - others = [v for t, v in rows if t != tag and v != "--"] - if others and value not in others: - color = CHIP_ALERT - suffix = " !=" - elif others and all(value == o for o in others): - color = MATCH - label = value + suffix - size = font_size - while size >= 10 and measure_text_cached(font, label, size).x > max_w - tag_w: - size -= 1 - _draw_text(font, label, x + tag_w, y, size, color) - y += line - return y +def _track_row(track: RadarTrack) -> str: + flag = "m" if track.measured else "c" + return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" -def draw_status_panel(rect: rl.Rectangle, status: BoschRadarStatus, *, compact: bool, - font_size: int, show_health_chip: bool = True) -> float: +def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: + chips: list[tuple[str, rl.Color, rl.Color | None]] = [ + (status.health_label, health_color(status.health_label), None), + ] + for text, color in c4_extra_chips(status): + fill = CHIP_FILL if text in ("moving", "frozen", "waiting") else CHIP_ON_FILL + chips.append((text, color, fill)) + return chips + + +def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: + """Cut-down C4 HUD: state + at most two reject/table bits. No VIN, no 0x2A9.""" + rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) + font_size = 13 + chips = _c4_chip_list(status) + max_h = 0.0 + for text, _, _ in chips: + _w, th = chip_size(text, font_size) + max_h = max(max_h, th) + pad = 6.0 + y = panel.y + max(pad, (panel.height - max_h) / 2) + x = panel.x + pad + draw_chip_row(x, y, panel.width - pad * 2, chips, font_size, gap=6) + + +def draw_hidpi_chips(rect: rl.Rectangle, status: BoschRadarStatus, font_size: int) -> float: + """Full key-on chip set. Returns y after the last row.""" if rect.width < 8 or rect.height < 8: return rect.y + font = gui_app.font(FontWeight.MEDIUM) + label_size = max(14, font_size - 4) x, y = rect.x, rect.y max_w = rect.width bottom = rect.y + rect.height - font = gui_app.font(FontWeight.MEDIUM) - chip = max(11, font_size) - - if show_health_chip: - label = status.health_label - cw, ch = draw_chip(x, y, label, health_color(label), chip) - meta = f"{len(status.tracks)} trk" - mx = x + cw + 6 - if mx + measure_text_cached(font, meta, font_size).x <= x + max_w: - _draw_text(font, meta, mx, y + max(0, (ch - measure_text_cached(font, meta, font_size).y) / 2), - font_size, MUTED) - y += ch + (2 if compact else 6) - - y = _flow_chips(x, y, max_w, bottom, [_gate_chip(status), _raw_chip(status)], chip) - y = _flow_chips(x, y, max_w, bottom, _lamp_chips(status), chip) - y = _flow_chips(x, y, max_w, bottom, _alert_chips(status), chip) - y = _flow_chips(x, y, max_w, bottom, _gtw_chips(status), chip) - if y + 12 <= bottom: - y = draw_vin_trio(x, y, max_w, bottom, status, font_size) - return y - - -def _track_row(track: RadarTrack) -> str: - flag = "m" if track.measured else "c" - return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" + gap = 8 - -@dataclass(frozen=True) -class _DialogMetrics: - compact: bool - pad: int - title_size: int - body: int - chip: int - btn_h: int - btn_w: int - align_w: int - btn_font: int - btn_pad: int - btn_radius: int - header_h: int - footer_h: int - plot_frac: float - status_size: int - table_rows: int - - -def _dialog_metrics(rect: rl.Rectangle) -> _DialogMetrics: - compact = rect.height < 500 - if compact: - btn_h = 22 - return _DialogMetrics( - compact=True, pad=6, title_size=16, body=12, chip=12, - btn_h=btn_h, btn_w=78, align_w=78, btn_font=14, btn_pad=2, btn_radius=7, - header_h=22, footer_h=btn_h + 12, plot_frac=0.30, status_size=12, table_rows=1, - ) - btn_h = 80 - return _DialogMetrics( - compact=False, pad=24, title_size=40, body=22, chip=22, - btn_h=btn_h, btn_w=240, align_w=200, btn_font=35, btn_pad=16, btn_radius=10, - header_h=88, footer_h=btn_h + 20, plot_frac=0.36, status_size=22, table_rows=8, - ) + def row(label: str, chips: list[tuple[str, rl.Color, rl.Color | None]]) -> None: + nonlocal y + if y + 20 > bottom: + return + lw = 0.0 + if label: + _draw_text(font, label, x, y + 4, label_size, MUTED) + lw = measure_text_cached(font, label, label_size).x + 10 + _, h = draw_chip_row(x + lw, y, max_w - lw, chips, font_size, gap=6) + y += max(h, _line_h(font, label or "Ag", label_size, 0)) + gap + + label = status.health_label + row("", [ + (label, health_color(label), None), + ("SGUFail", health_color("SGU") if status.sgu_fail else CHIP_MUTED, + CHIP_ON_FILL if status.sgu_fail else CHIP_FILL), + ("HWFail", health_color("FAULT") if status.hw_fail else CHIP_MUTED, + CHIP_ON_FILL if status.hw_fail else CHIP_FILL), + (link_label(status), health_color("LIVE") if status.gtw_live else health_color("WAIT VIN"), + OK_FILL if status.gtw_live else CHIP_FILL), + ]) + + alert_chips: list[tuple[str, rl.Color, rl.Color | None]] = [] + for name in KEY_REJECT: + on = name in status.alerts + alert_chips.append((name, health_color("REJECT") if on else CHIP_MUTED, CHIP_ON_FILL if on else CHIP_FILL)) + for name in status.alerts: + if name not in KEY_REJECT: + alert_chips.append((name, health_color("SGU"), CHIP_ON_FILL)) + row("0x501", alert_chips) + + awd = "4WD" if status.awd else ("2WD" if status.awd is False else "drive —") + pos = "—" if status.position is None else str(status.position) + epas = "—" if status.epas_type is None else str(status.epas_type) + row("0x2A9", [ + (awd, TEXT, CHIP_FILL), + (f"pos {pos}", TEXT, CHIP_FILL), + (f"EPAS {epas}", TEXT, CHIP_FILL), + ]) + + feed, f190, chassis = vin_refs(status) + vins = [v for v in (feed, f190, chassis) if v] + mismatch = len(set(vins)) > 1 + vin_chips: list[tuple[str, rl.Color, rl.Color | None]] = [] + if feed: + bad = mismatch and bool(f190) and feed != f190 + vin_chips.append((f"0x2B9 {feed}", health_color("REJECT") if bad else TEXT, CHIP_ON_FILL if bad else CHIP_FILL)) + if f190: + bad = mismatch and bool(chassis) and f190 != chassis + vin_chips.append((f"F190 {f190}", health_color("REJECT") if bad else TEXT, CHIP_ON_FILL if bad else CHIP_FILL)) + if chassis: + vin_chips.append((f"chassis {chassis}", health_color("REJECT") if mismatch else TEXT, + CHIP_ON_FILL if mismatch else CHIP_FILL)) + if vin_chips: + row("VIN", vin_chips) + + age = "age —" if status.last_raw_age_s is None else f"age {status.last_raw_age_s:.2f}s" + bit = table_bit(status) + raw_chips: list[tuple[str, rl.Color, rl.Color | None]] = [ + (f"unique {status.unique_raw}", TEXT, CHIP_FILL), + (age, TEXT, CHIP_FILL), + (f"{len(status.tracks)} tracks", TEXT, CHIP_FILL), + ] + if bit: + raw_chips.append((bit, health_color("FROZEN" if bit == "frozen" else "LIVE"), + CHIP_ON_FILL if bit == "frozen" else OK_FILL)) + row("0x310", raw_chips) + return y class RadarHudOverlay(Widget): - """Compact on-road readout. Hidden unless NAPRadarHud is set.""" + """On-road readout. Hidden unless NAPRadarHud is set.""" def _render(self, rect: rl.Rectangle): if not ui_state.radar_hud: return - status = decorate_status(ui_state.radar_status) + status = ui_state.radar_status panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - compact = panel.height < 200 - rl.draw_rectangle_rounded(panel, 0.08, 8, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.08, 8, 2, health_color(status.health_label)) - pad = 5 if compact else 12 - plot_w = min(96 if compact else 160, panel.width * (0.26 if compact else 0.34)) + # Strip vs card is about the HUD rect, not the window. + if panel.height < 80: + draw_c4_strip(panel, status) + return + + rl.draw_rectangle_rounded(panel, 0.06, 8, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.06, 8, 2, health_color(status.health_label)) + pad = 12 + plot_w = min(220.0, panel.width * 0.28) plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) - draw_radar_plot(plot, status, align_box=False, compact=compact) - text = rl.Rectangle( - plot.x + plot.width + (5 if compact else 12), - panel.y + pad, - panel.width - plot.width - pad * 3, - panel.height - pad * 2, - ) - draw_status_panel(text, status, compact=compact, font_size=11 if compact else 18) + draw_radar_plot(plot, status, align_box=False, compact=False) + chips = rl.Rectangle(plot.x + plot.width + 14, panel.y + pad, + panel.width - plot.width - pad * 3, panel.height - pad * 2) + draw_hidpi_chips(chips, status, font_size=18) class RadarMonitorDialog(Widget): @@ -428,13 +422,14 @@ class RadarMonitorDialog(Widget): def __init__(self): super().__init__() - self._close = Button("Close", click_callback=self._on_close, - font_size=35, text_padding=16, - button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) + compact = not gui_app.big_ui() + font = 18 if compact else 48 + pad = 4 if compact else 20 + self._close = Button("Close", click_callback=self._on_close, font_size=font, + text_padding=pad, button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) self._align_only = False - self._align_btn = Button("Align", click_callback=self._toggle_align, - font_size=35, text_padding=16, - button_style=ButtonStyle.ACTION) + self._align_btn = Button("Align", click_callback=self._toggle_align, font_size=font, + text_padding=pad, button_style=ButtonStyle.ACTION) def _on_close(self): gui_app.pop_widget() @@ -442,15 +437,18 @@ def _on_close(self): def _toggle_align(self): self._align_only = not self._align_only - def _tune_buttons(self, m: _DialogMetrics) -> None: + def _tune_buttons(self, compact: bool) -> None: + font = 18 if compact else 48 + pad = 4 if compact else 20 + radius = 8 if compact else 10 for btn in (self._close, self._align_btn): - btn._label.set_font_size(m.btn_font) - btn._label._text_padding = m.btn_pad - btn._border_radius = m.btn_radius + btn._label.set_font_size(font) + btn._label._text_padding = pad + btn._border_radius = radius self._align_btn.set_button_style(ButtonStyle.PRIMARY if self._align_only else ButtonStyle.ACTION) def _render(self, rect: rl.Rectangle): - status = decorate_status(ui_state.radar_status) + status = ui_state.radar_status if self._align_only: tracks = tuple( t for t in status.tracks @@ -458,52 +456,79 @@ def _render(self, rect: rl.Rectangle): ) status = replace(status, tracks=tracks) - m = _dialog_metrics(rect) - self._tune_buttons(m) + compact = is_c4_screen(rect) + self._tune_buttons(compact) rl.draw_rectangle_rec(rect, rl.Color(0, 0, 0, 255)) - + if compact: + self._render_c4(rect, status) + else: + self._render_hidpi(rect, status) + + def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: + """Cut-down 536x240 modal: title, state+bits, plot, Close. No Align, no VIN dump.""" + pad = 8 + title_size = 18 + btn_w, btn_h = 100, 34 + footer_h = btn_h + 10 + title_font = gui_app.font(FontWeight.BOLD) + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 6, title_size, TEXT) + chip_y = rect.y + 30 + draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 13, gap=6) + plot = rl.Rectangle(rect.x + pad, rect.y + 64, rect.width - pad * 2, rect.height - 64 - footer_h) + if plot.height > 24: + draw_radar_plot(plot, status, align_box=False, compact=True) + btn_y = rect.y + rect.height - footer_h + 4 + self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) + + def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: + pad = 28 + title_size = 44 + body = 24 + btn_h, btn_w, align_w = 90, 280, 220 + header_h = 96 + footer_h = btn_h + 36 title_font = gui_app.font(FontWeight.BOLD) body_font = gui_app.font(FontWeight.MEDIUM) - _draw_text(title_font, "Live radar", rect.x + m.pad, rect.y + (2 if m.compact else 14), m.title_size, TEXT) - chip_x = rect.x + m.pad + measure_text_cached(title_font, "Live radar", m.title_size).x + (8 if m.compact else 16) - chip_y = rect.y + (2 if m.compact else 18) - draw_chip(chip_x, chip_y, status.health_label, health_color(status.health_label), m.chip) - if not m.compact: - _draw_text(body_font, "openpilot stays running", rect.x + m.pad, rect.y + 60, 20, MUTED) - - plot_w = min(rect.width * m.plot_frac, 156 if m.compact else 700) - plot = rl.Rectangle(rect.x + m.pad, rect.y + m.header_h, plot_w, - rect.height - m.header_h - m.footer_h) - draw_radar_plot(plot, status, align_box=True, compact=m.compact) - - info_x = plot.x + plot.width + (6 if m.compact else 24) - info_w = rect.x + rect.width - info_x - m.pad - footer_y = rect.y + rect.height - m.footer_h - info = rl.Rectangle(info_x, plot.y, info_w, max(0, footer_y - plot.y - 2)) - y = draw_status_panel(info, status, compact=m.compact, font_size=m.status_size, show_health_chip=False) - - table_y = y + (2 if m.compact else 10) - table_bottom = footer_y - 2 - if table_y + m.body < table_bottom and info_w > 40: - _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, m.body, MUTED) - table_y += _line_h(body_font, "dRel", m.body, 2 if m.compact else 5) - rows = sorted(status.tracks, key=lambda t: t.d_rel)[: m.table_rows] + + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 16, title_size, TEXT) + chip_x = rect.x + pad + measure_text_cached(title_font, "Live radar", title_size).x + 18 + draw_chip(chip_x, rect.y + 22, status.health_label, health_color(status.health_label), 26) + _draw_text(body_font, "openpilot stays running", rect.x + pad, rect.y + 66, 22, MUTED) + + plot_w = min(rect.width * 0.36, 720) + plot = rl.Rectangle(rect.x + pad, rect.y + header_h, plot_w, rect.height - header_h - footer_h) + draw_radar_plot(plot, status, align_box=True, compact=False) + + info_x = plot.x + plot.width + 28 + info_w = rect.x + rect.width - info_x - pad + footer_y = rect.y + rect.height - footer_h + chips_h = min(240.0, max(80.0, (footer_y - plot.y) * 0.55)) + y = draw_hidpi_chips(rl.Rectangle(info_x, plot.y, info_w, chips_h), status, font_size=20) + + table_y = y + 12 + table_bottom = footer_y - 8 + if table_y + body < table_bottom and info_w > 40: + _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) + table_y += _line_h(body_font, "dRel", body, 6) + rows = sorted(status.tracks, key=lambda t: t.d_rel)[:10] for track in rows: - if table_y + m.body > table_bottom: + if table_y + body > table_bottom: break - _draw_text(body_font, _track_row(track), info_x, table_y, m.body, TEXT) - table_y += _line_h(body_font, _track_row(track), m.body, 2 if m.compact else 4) + _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) + table_y += _line_h(body_font, _track_row(track), body, 4) if not rows: - empty = "no tracks in 2.5-14.5 m" if self._align_only else "no published tracks" - if table_y + m.body <= table_bottom: - _draw_text(body_font, empty, info_x, table_y, m.body, MUTED) - - btn_y = footer_y + (5 if m.compact else 10) - self._close.render(rl.Rectangle(rect.x + m.pad, btn_y, m.btn_w, m.btn_h)) - self._align_btn.render(rl.Rectangle(rect.x + m.pad + m.btn_w + 6, btn_y, m.align_w, m.btn_h)) - mode = "2.5-14.5 m" if self._align_only else "all tracks" - mode_x = rect.x + m.pad + m.btn_w + m.align_w + 8 - mode_y = btn_y + max(0, (m.btn_h - _chip_size(mode, m.body)[1]) / 2) - if mode_x + 20 < rect.x + rect.width - m.pad: - draw_chip(mode_x, mode_y, mode, PRIMARY if self._align_only else MUTED, m.body, + empty = "no tracks in 2.5–14.5 m" if self._align_only else "no published tracks" + if table_y + body <= table_bottom: + _draw_text(body_font, empty, info_x, table_y, body, MUTED) + + btn_y = footer_y + 16 + self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) + self._align_btn.render(rl.Rectangle(rect.x + pad + btn_w + 16, btn_y, align_w, btn_h)) + mode = "align 2.5–14.5m" if self._align_only else "all tracks" + mode_color = health_color("LIVE") if self._align_only else MUTED + mw, mh = chip_size(mode, body) + mode_x = rect.x + pad + btn_w + align_w + 24 + mode_y = btn_y + max(0, (btn_h - mh) / 2) + if mode_x + mw <= rect.x + rect.width - pad: + draw_chip(mode_x, mode_y, mode, mode_color, body, fill=ALIGN_FILL if self._align_only else CHIP_FILL) From b848fb30061930b06d1b40261879c6f4ce7c006a Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:41:44 +0000 Subject: [PATCH 18/30] ui: hidpi range rings and All tracks; C4 plot without full desk 3X overlay is 1100x400 with colored 20/40/60/80 m rings and All tracks header-right. C4 keeps a full-width bird-eye plot plus state/Close only. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 337 ++++++++++++++++++------------- 1 file changed, 199 insertions(+), 138 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index 43cb9f94abc308..8aab83a40b3353 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -5,13 +5,14 @@ This dialog is a push_widget overlay: open while driving, close without reboot, no NAPScriptRunning. -C4 (536x240) is a cut-down status strip: health plus one or two reject/table -bits. The full key-on chip set lives on hidpi / the 2160x1080 modal. +Hidpi 2160x1080 is the product: full key-on chips. +C4 536x240 is cut-down: state plus one or two reject/table bits and Close. """ from __future__ import annotations from dataclasses import replace +import math import pyray as rl @@ -31,14 +32,31 @@ RANGE_M = 120.0 LATERAL_M = 8.0 + +# Concentric dRel rings. Distinct colors so 20/40/60/80 m read at a glance. +RANGE_RINGS = ( + (20.0, rl.Color(72, 210, 160, 230)), # sea + (40.0, rl.Color(230, 190, 70, 230)), # gold + (60.0, rl.Color(235, 115, 95, 230)), # coral + (80.0, rl.Color(180, 120, 230, 230)), # orchid +) + + # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). C4_HUD_W = 460.0 C4_HUD_H = 44.0 # Hidpi on-road panel: plot + full key-on chips. -HIDPI_HUD_W = 900.0 -HIDPI_HUD_H = 340.0 - -KEY_REJECT = ("vinValidity", "xwdValidity", "radPositionMismatch", "strRackMismatch") +HIDPI_HUD_W = 980.0 +HIDPI_HUD_H = 380.0 + +# 0x501 bits Jack uses to decide "wrong radar / wrong car" — product names, not DBC ids. +ALERT_CHIP = ( + ("vinValidity", "VIN"), + ("xwdValidity", "XWD"), + ("radPositionMismatch", "POS"), + ("strRackMismatch", "RACK"), +) +KEY_REJECT = tuple(k for k, _ in ALERT_CHIP) HEALTH_COLOR = { "LIVE": rl.Color(70, 200, 120, 255), @@ -60,7 +78,7 @@ TRACK_FILL = rl.Color(90, 200, 255, 230) TRACK_COAST = rl.Color(180, 180, 180, 200) LEAD_FILL = rl.Color(128, 216, 166, 255) -TEXT = rl.Color(230, 230, 230, 255) +TEXT = rl.Color(236, 236, 236, 255) MUTED = rl.Color(170, 170, 170, 255) CHIP_MUTED = rl.Color(128, 128, 128, 255) CHIP_FILL = rl.Color(57, 57, 57, 255) @@ -81,15 +99,14 @@ def _line_h(font, text: str, size: int, gap: int = 4) -> float: def is_c4_screen(rect: rl.Rectangle) -> bool: - """True for the 536x240 C4 window / content, not the hidpi 900x340 HUD card.""" return rect.width < 800 and rect.height < 500 def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: - """On-road HUD that always fits inside `content` with zero clipping. + """On-road HUD that always fits inside `content`. C4 536x240 / content ~476x180: 460x44 status strip. - Hidpi 2160x1080 / content ~2100x1020: 900x340 chip panel. + Hidpi 2160x1080 / content ~2100x1020: 980x380 chip panel. """ if is_c4_screen(content): margin = 8.0 @@ -117,7 +134,7 @@ def _chip_pad(font_size: int) -> tuple[int, int]: return 6, 2 if font_size < 22: return 8, 3 - return 14, 6 + return 12, 5 def chip_size(text: str, font_size: int) -> tuple[float, float]: @@ -142,8 +159,29 @@ def draw_chip(x: float, y: float, text: str, color: rl.Color, font_size: int, return w, h +def draw_chip_row(x: float, y: float, max_w: float, chips: list[tuple[str, rl.Color, rl.Color | None]], + font_size: int, gap: float = 6) -> tuple[float, float]: + cx, cy = x, y + row_h = 0.0 + used_w = 0.0 + bottom = y + for text, color, fill in chips: + tw, th = chip_size(text, font_size) + if cx + tw > x + max_w and cx > x: + cx = x + cy += row_h + 4 + row_h = 0.0 + if tw > max_w: + continue + draw_chip(cx, cy, text, color, font_size, fill=fill) + cx += tw + gap + row_h = max(row_h, th) + used_w = max(used_w, cx - x) + bottom = cy + row_h + return used_w, max(0.0, bottom - y) + + def table_bit(status: BoschRadarStatus) -> str | None: - """Moving vs frozen from the 0x310 unique window (not liveTracks age).""" if status.table_frozen or status.unique_raw == 1: return "frozen" if status.unique_raw >= 2: @@ -151,19 +189,27 @@ def table_bit(status: BoschRadarStatus) -> str | None: return None +def link_label(status: BoschRadarStatus) -> str: + # silent-until-VIN-complete: host 0x560 mux must finish before panda talks + return "talking" if status.vin_stream_complete else "waiting" + + def c4_extra_chips(status: BoschRadarStatus) -> list[tuple[str, rl.Color]]: - """The one or two bits that matter on the C4 strip. No 0x501 dump, no VIN.""" + """One or two bits that matter on C4. No VIN trio, no 0x2A9 desk.""" extras: list[tuple[str, rl.Color]] = [] - reason = next((name for name in KEY_REJECT if name in status.alerts), None) - if reason is None and status.health_label == "FAULT": - if status.hw_fail: - reason = "HWFail" - elif status.radar_fault: - reason = "radarFault" - if reason is None and status.health_label in ("WAIT VIN", "WAIT GTW"): + reason = None + for key, short in ALERT_CHIP: + if key in status.alerts: + reason = short + break + if reason is None and status.hw_fail: + reason = "HWFail" + elif reason is None and status.sgu_fail: + reason = "SGUFail" + elif reason is None and status.health_label in ("WAIT VIN", "WAIT GTW"): reason = "waiting" if reason: - extras.append((reason, health_color("REJECT" if reason in KEY_REJECT else status.health_label))) + extras.append((reason, health_color("REJECT" if reason in ("VIN", "XWD", "POS", "RACK") else status.health_label))) bit = table_bit(status) if bit: extras.append((bit, health_color("FROZEN" if bit == "frozen" else "LIVE"))) @@ -174,43 +220,55 @@ def _extract_vin(raw) -> str: if raw is None: return "" if isinstance(raw, (bytes, bytearray)): - raw = raw.decode("utf-8", "ignore") + raw = raw.decode("ascii", "ignore") token = "".join(ch for ch in str(raw).upper() if ch.isalnum()) - if len(token) == 17: - return token - for i in range(0, max(0, len(token) - 16)): - cand = token[i:i + 17] - if len(cand) == 17: - return cand - return "" + return token if len(token) == 17 else "" def vin_refs(status: BoschRadarStatus) -> tuple[str, str, str]: - """0x2B9 feed vs F190 (radar EEPROM) vs chassis CarVin.""" + """0x2B9 feed vs F190 (radar EEPROM / donor param) vs chassis CarVin.""" feed = status.vin if len(status.vin) == 17 else (status.vin or "") f190 = _extract_vin(getattr(status, "vin_f190", "") or "") chassis = _extract_vin(getattr(status, "vin_chassis", "") or "") if not f190 or not chassis: try: - from openpilot.common.params import Params - p = Params() - if not chassis: - chassis = _extract_vin(p.get("CarVin")) if not f190: - raw = "" - try: - from opendbc.car.tesla.preap.nap_params import NAPParamKeys - raw = p.get(NAPParamKeys.RADAR_VIN_READ_STATUS, return_default=True) or "" - except Exception: - raw = p.get("NAPRadarVinReadStatus", return_default=True) or "" + raw = ui_state.params.get("NAPRadarDonorVin", return_default=True) or "" f190 = _extract_vin(raw) + if not chassis and getattr(ui_state, "CP", None) is not None: + chassis = _extract_vin(getattr(ui_state.CP, "carVin", "") or "") + if not chassis: + chassis = _extract_vin(ui_state.params.get("CarVin")) except Exception: pass return feed, f190, chassis -def link_label(status: BoschRadarStatus) -> str: - return "talking" if status.gtw_live else "waiting" + +def _draw_range_rings(rect: rl.Rectangle, to_px, compact: bool) -> None: + """Concentric range arcs centered on the car. Labels are hidpi-only.""" + if rect.height < 48: + return + car_x, car_y = to_px(0.0, 0.0) + n = 40 if compact else 80 + thick = 1.5 if compact else 2.5 + font = gui_app.font(FontWeight.NORMAL) + label_size = 14 + for r_m, color in RANGE_RINGS: + radius = (r_m / RANGE_M) * rect.height + if radius < 6: + continue + prev = None + for i in range(n + 1): + theta = math.pi * i / n + x = car_x + radius * math.cos(theta) + y = car_y - radius * math.sin(theta) + if prev is not None: + rl.draw_line_ex(rl.Vector2(prev[0], prev[1]), rl.Vector2(x, y), thick, color) + prev = (x, y) + if not compact: + lx, ly = to_px(r_m, 0.0) + _draw_text(font, f"{int(r_m)}m", lx + 8, ly - 12, label_size, color) def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True, @@ -234,6 +292,8 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: rl.draw_rectangle_rec(box, ALIGN_FILL) rl.draw_rectangle_lines_ex(box, 1 if compact else 2, ALIGN_LINE) + _draw_range_rings(rect, to_px, compact) + car_x, car_y = to_px(0.0, 0.0) cw, ch = (5, 8) if compact else (12, 16) rl.draw_rectangle(int(car_x - cw / 2), int(car_y - ch + 2), cw, ch, rl.Color(220, 220, 220, 255)) @@ -242,7 +302,6 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: for track in status.tracks: if closest is None or track.d_rel < closest.d_rel: closest = track - for track in status.tracks: x, y = to_px(max(0.0, min(RANGE_M, track.d_rel)), track.y_rel) color = LEAD_FILL if track is closest else (TRACK_FILL if track.measured else TRACK_COAST) @@ -257,28 +316,6 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: _draw_text(font, f"{int(RANGE_M)}m", rect.x + 4, rect.y + 3, tick, MUTED) -def draw_chip_row(x: float, y: float, max_w: float, chips: list[tuple[str, rl.Color, rl.Color | None]], - font_size: int, gap: float = 6) -> tuple[float, float]: - cx, cy = x, y - row_h = 0.0 - used_w = 0.0 - bottom = y - for text, color, fill in chips: - tw, th = chip_size(text, font_size) - if cx + tw > x + max_w and cx > x: - cx = x - cy += row_h + 4 - row_h = 0.0 - if tw > max_w: - continue - draw_chip(cx, cy, text, color, font_size, fill=fill) - cx += tw + gap - row_h = max(row_h, th) - used_w = max(used_w, cx - x) - bottom = cy + row_h - return used_w, max(0.0, bottom - y) - - def _track_row(track: RadarTrack) -> str: flag = "m" if track.measured else "c" return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" @@ -295,7 +332,7 @@ def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Colo def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down C4 HUD: state + at most two reject/table bits. No VIN, no 0x2A9.""" + """Cut-down C4 HUD: state + at most two reject/table bits.""" rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) font_size = 13 @@ -306,12 +343,11 @@ def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: max_h = max(max_h, th) pad = 6.0 y = panel.y + max(pad, (panel.height - max_h) / 2) - x = panel.x + pad - draw_chip_row(x, y, panel.width - pad * 2, chips, font_size, gap=6) + draw_chip_row(panel.x + pad, y, panel.width - pad * 2, chips, font_size, gap=6) def draw_hidpi_chips(rect: rl.Rectangle, status: BoschRadarStatus, font_size: int) -> float: - """Full key-on chip set. Returns y after the last row.""" + """Full key-on chips. Product names, not a wall of CAN ids.""" if rect.width < 8 or rect.height < 8: return rect.y font = gui_app.font(FontWeight.MEDIUM) @@ -333,61 +369,62 @@ def row(label: str, chips: list[tuple[str, rl.Color, rl.Color | None]]) -> None: y += max(h, _line_h(font, label or "Ag", label_size, 0)) + gap label = status.health_label + talking = link_label(status) row("", [ (label, health_color(label), None), ("SGUFail", health_color("SGU") if status.sgu_fail else CHIP_MUTED, CHIP_ON_FILL if status.sgu_fail else CHIP_FILL), ("HWFail", health_color("FAULT") if status.hw_fail else CHIP_MUTED, CHIP_ON_FILL if status.hw_fail else CHIP_FILL), - (link_label(status), health_color("LIVE") if status.gtw_live else health_color("WAIT VIN"), - OK_FILL if status.gtw_live else CHIP_FILL), + (talking, health_color("LIVE") if talking == "talking" else health_color("WAIT VIN"), + OK_FILL if talking == "talking" else CHIP_FILL), ]) - alert_chips: list[tuple[str, rl.Color, rl.Color | None]] = [] - for name in KEY_REJECT: - on = name in status.alerts - alert_chips.append((name, health_color("REJECT") if on else CHIP_MUTED, CHIP_ON_FILL if on else CHIP_FILL)) - for name in status.alerts: - if name not in KEY_REJECT: - alert_chips.append((name, health_color("SGU"), CHIP_ON_FILL)) - row("0x501", alert_chips) + alert_chips = [] + for key, short in ALERT_CHIP: + on = key in status.alerts + alert_chips.append((short, health_color("REJECT") if on else CHIP_MUTED, CHIP_ON_FILL if on else CHIP_FILL)) + row("reject", alert_chips) awd = "4WD" if status.awd else ("2WD" if status.awd is False else "drive —") pos = "—" if status.position is None else str(status.position) epas = "—" if status.epas_type is None else str(status.epas_type) - row("0x2A9", [ + row("drive", [ (awd, TEXT, CHIP_FILL), (f"pos {pos}", TEXT, CHIP_FILL), (f"EPAS {epas}", TEXT, CHIP_FILL), ]) feed, f190, chassis = vin_refs(status) - vins = [v for v in (feed, f190, chassis) if v] - mismatch = len(set(vins)) > 1 - vin_chips: list[tuple[str, rl.Color, rl.Color | None]] = [] - if feed: - bad = mismatch and bool(f190) and feed != f190 - vin_chips.append((f"0x2B9 {feed}", health_color("REJECT") if bad else TEXT, CHIP_ON_FILL if bad else CHIP_FILL)) - if f190: - bad = mismatch and bool(chassis) and f190 != chassis - vin_chips.append((f"F190 {f190}", health_color("REJECT") if bad else TEXT, CHIP_ON_FILL if bad else CHIP_FILL)) - if chassis: - vin_chips.append((f"chassis {chassis}", health_color("REJECT") if mismatch else TEXT, - CHIP_ON_FILL if mismatch else CHIP_FILL)) - if vin_chips: - row("VIN", vin_chips) - - age = "age —" if status.last_raw_age_s is None else f"age {status.last_raw_age_s:.2f}s" + present = [v for v in (feed, f190, chassis) if v] + mismatch = len(set(present)) > 1 + + def vin_chip(tag: str, value: str) -> tuple[str, rl.Color, rl.Color | None]: + shown = value or "—" + bad = bool(value) and mismatch and value not in [v for v in present if v != value] + if value and mismatch and any(v != value for v in present): + bad = True + return (f"{tag} {shown}", health_color("REJECT") if bad else TEXT, CHIP_ON_FILL if bad else CHIP_FILL) + + row("VIN", [ + vin_chip("2B9", feed), + vin_chip("F190", f190), + vin_chip("CHS", chassis), + ]) + + age = "age —" if status.last_raw_age_s is None else ( + f"age {status.last_raw_age_s:.1f}s" if status.last_raw_age_s < 10 else f"age {status.last_raw_age_s:.0f}s" + ) bit = table_bit(status) raw_chips: list[tuple[str, rl.Color, rl.Color | None]] = [ - (f"unique {status.unique_raw}", TEXT, CHIP_FILL), + (f"raw {status.unique_raw}", TEXT, CHIP_FILL), (age, TEXT, CHIP_FILL), - (f"{len(status.tracks)} tracks", TEXT, CHIP_FILL), + (f"{len(status.tracks)} trk", TEXT, CHIP_FILL), ] if bit: raw_chips.append((bit, health_color("FROZEN" if bit == "frozen" else "LIVE"), CHIP_ON_FILL if bit == "frozen" else OK_FILL)) - row("0x310", raw_chips) + row("table", raw_chips) return y @@ -401,14 +438,13 @@ def _render(self, rect: rl.Rectangle): panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - # Strip vs card is about the HUD rect, not the window. if panel.height < 80: draw_c4_strip(panel, status) return rl.draw_rectangle_rounded(panel, 0.06, 8, PANEL_BG) rl.draw_rectangle_rounded_lines_ex(panel, 0.06, 8, 2, health_color(status.health_label)) - pad = 12 + pad = 14 plot_w = min(220.0, panel.width * 0.28) plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) draw_radar_plot(plot, status, align_box=False, compact=False) @@ -422,14 +458,11 @@ class RadarMonitorDialog(Widget): def __init__(self): super().__init__() - compact = not gui_app.big_ui() - font = 18 if compact else 48 - pad = 4 if compact else 20 - self._close = Button("Close", click_callback=self._on_close, font_size=font, - text_padding=pad, button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) + self._close = Button("Close", click_callback=self._on_close, font_size=35, + text_padding=16, button_style=ButtonStyle.TRANSPARENT_WHITE_BORDER) self._align_only = False - self._align_btn = Button("Align", click_callback=self._toggle_align, font_size=font, - text_padding=pad, button_style=ButtonStyle.ACTION) + self._align_btn = Button("Align", click_callback=self._toggle_align, font_size=35, + text_padding=16, button_style=ButtonStyle.ACTION) def _on_close(self): gui_app.pop_widget() @@ -438,8 +471,8 @@ def _toggle_align(self): self._align_only = not self._align_only def _tune_buttons(self, compact: bool) -> None: - font = 18 if compact else 48 - pad = 4 if compact else 20 + font = 18 if compact else 35 + pad = 4 if compact else 16 radius = 8 if compact else 10 for btn in (self._close, self._align_btn): btn._label.set_font_size(font) @@ -449,14 +482,14 @@ def _tune_buttons(self, compact: bool) -> None: def _render(self, rect: rl.Rectangle): status = ui_state.radar_status - if self._align_only: + compact = is_c4_screen(rect) + if self._align_only and not compact: tracks = tuple( t for t in status.tracks if ALIGN_D_MIN <= t.d_rel <= ALIGN_D_MAX and abs(t.y_rel) <= ALIGN_Y_MAX ) status = replace(status, tracks=tracks) - compact = is_c4_screen(rect) self._tune_buttons(compact) rl.draw_rectangle_rec(rect, rl.Color(0, 0, 0, 255)) if compact: @@ -465,44 +498,80 @@ def _render(self, rect: rl.Rectangle): self._render_hidpi(rect, status) def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down 536x240 modal: title, state+bits, plot, Close. No Align, no VIN dump.""" + """Cut-down 536x240 modal: chips, small plot, All tracks table, Close. + No Align, no VIN dump, no full desk. + """ pad = 8 title_size = 18 - btn_w, btn_h = 100, 34 + body = 12 + btn_w, btn_h = 110, 36 footer_h = btn_h + 10 title_font = gui_app.font(FontWeight.BOLD) + body_font = gui_app.font(FontWeight.MEDIUM) _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 6, title_size, TEXT) chip_y = rect.y + 30 draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 13, gap=6) - plot = rl.Rectangle(rect.x + pad, rect.y + 64, rect.width - pad * 2, rect.height - 64 - footer_h) - if plot.height > 24: + + footer_y = rect.y + rect.height - footer_h + content_y = rect.y + 54 + content_h = max(0.0, footer_y - content_y - 2) + plot_w = min(rect.width * 0.32, 168.0) + plot = rl.Rectangle(rect.x + pad, content_y, plot_w, content_h) + if plot.height > 24 and plot.width > 24: draw_radar_plot(plot, status, align_box=False, compact=True) - btn_y = rect.y + rect.height - footer_h + 4 + + info_x = plot.x + plot.width + 8 + info_w = rect.x + rect.width - info_x - pad + table_y = content_y + table_bottom = footer_y - 2 + if info_w > 40 and table_y + body < table_bottom: + _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) + table_y += _line_h(body_font, "dRel", body, 2) + rows = sorted(status.tracks, key=lambda t: t.d_rel)[:6] + for track in rows: + if table_y + body > table_bottom: + break + _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) + table_y += _line_h(body_font, _track_row(track), body, 2) + if not rows: + empty = "no published tracks" + if table_y + body <= table_bottom: + _draw_text(body_font, empty, info_x, table_y, body, MUTED) + + btn_y = footer_y + 4 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: pad = 28 - title_size = 44 - body = 24 - btn_h, btn_w, align_w = 90, 280, 220 - header_h = 96 - footer_h = btn_h + 36 + title_size = 42 + body = 22 + btn_h, btn_w, align_w = 80, 240, 200 + header_h = 92 + footer_h = btn_h + 24 title_font = gui_app.font(FontWeight.BOLD) body_font = gui_app.font(FontWeight.MEDIUM) _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 16, title_size, TEXT) - chip_x = rect.x + pad + measure_text_cached(title_font, "Live radar", title_size).x + 18 - draw_chip(chip_x, rect.y + 22, status.health_label, health_color(status.health_label), 26) - _draw_text(body_font, "openpilot stays running", rect.x + pad, rect.y + 66, 22, MUTED) + chip_x = rect.x + pad + measure_text_cached(title_font, "Live radar", title_size).x + 16 + draw_chip(chip_x, rect.y + 20, status.health_label, health_color(status.health_label), 22) + _draw_text(body_font, "openpilot stays running", rect.x + pad, rect.y + 64, 20, MUTED) - plot_w = min(rect.width * 0.36, 720) + mode = "2.5–14.5 m" if self._align_only else "All tracks" + mode_color = health_color("LIVE") if self._align_only else MUTED + mw, mh = chip_size(mode, body) + mode_x = rect.x + rect.width - pad - mw + mode_y = rect.y + 20 + draw_chip(mode_x, mode_y, mode, mode_color, body, + fill=ALIGN_FILL if self._align_only else CHIP_FILL) + + plot_w = min(rect.width * 0.34, 680) plot = rl.Rectangle(rect.x + pad, rect.y + header_h, plot_w, rect.height - header_h - footer_h) draw_radar_plot(plot, status, align_box=True, compact=False) info_x = plot.x + plot.width + 28 info_w = rect.x + rect.width - info_x - pad footer_y = rect.y + rect.height - footer_h - chips_h = min(240.0, max(80.0, (footer_y - plot.y) * 0.55)) + chips_h = min(280.0, max(80.0, (footer_y - plot.y) * 0.52)) y = draw_hidpi_chips(rl.Rectangle(info_x, plot.y, info_w, chips_h), status, font_size=20) table_y = y + 12 @@ -510,7 +579,7 @@ def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: if table_y + body < table_bottom and info_w > 40: _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) table_y += _line_h(body_font, "dRel", body, 6) - rows = sorted(status.tracks, key=lambda t: t.d_rel)[:10] + rows = sorted(status.tracks, key=lambda t: t.d_rel)[:8] for track in rows: if table_y + body > table_bottom: break @@ -521,14 +590,6 @@ def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: if table_y + body <= table_bottom: _draw_text(body_font, empty, info_x, table_y, body, MUTED) - btn_y = footer_y + 16 + btn_y = footer_y + 12 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) - self._align_btn.render(rl.Rectangle(rect.x + pad + btn_w + 16, btn_y, align_w, btn_h)) - mode = "align 2.5–14.5m" if self._align_only else "all tracks" - mode_color = health_color("LIVE") if self._align_only else MUTED - mw, mh = chip_size(mode, body) - mode_x = rect.x + pad + btn_w + align_w + 24 - mode_y = btn_y + max(0, (btn_h - mh) / 2) - if mode_x + mw <= rect.x + rect.width - pad: - draw_chip(mode_x, mode_y, mode, mode_color, body, - fill=ALIGN_FILL if self._align_only else CHIP_FILL) + self._align_btn.render(rl.Rectangle(rect.x + pad + btn_w + 14, btn_y, align_w, btn_h)) From 1362eb1a392115be6428a35a4af7805724772f15 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:42:13 +0000 Subject: [PATCH 19/30] ui: C4 full-width plot; hidpi overlay 1100x400 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep 3X chips, colored 20/40/60/80 m rings, and All tracks top-right. C4 modal is plot + state/Close only — no Align, VIN trio, or table. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 99 ++++++++++++++------------------ 1 file changed, 42 insertions(+), 57 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index 8aab83a40b3353..955edf2ad129a8 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -43,11 +43,11 @@ # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). -C4_HUD_W = 460.0 -C4_HUD_H = 44.0 -# Hidpi on-road panel: plot + full key-on chips. -HIDPI_HUD_W = 980.0 -HIDPI_HUD_H = 380.0 +C4_HUD_W = 468.0 +C4_HUD_H = 112.0 +# Hidpi on-road panel: slightly bigger than 904's 900x340. +HIDPI_HUD_W = 1100.0 +HIDPI_HUD_H = 400.0 # 0x501 bits Jack uses to decide "wrong radar / wrong car" — product names, not DBC ids. ALERT_CHIP = ( @@ -73,8 +73,8 @@ PANEL_BG = rl.Color(12, 14, 18, 230) PANEL_BORDER = rl.Color(255, 255, 255, 70) -ALIGN_FILL = rl.Color(70, 91, 234, 40) -ALIGN_LINE = rl.Color(70, 91, 234, 160) +ALIGN_FILL = rl.Color(70, 91, 234, 60) +ALIGN_LINE = rl.Color(90, 110, 240, 200) TRACK_FILL = rl.Color(90, 200, 255, 230) TRACK_COAST = rl.Color(180, 180, 180, 200) LEAD_FILL = rl.Color(128, 216, 166, 255) @@ -105,8 +105,8 @@ def is_c4_screen(rect: rl.Rectangle) -> bool: def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: """On-road HUD that always fits inside `content`. - C4 536x240 / content ~476x180: 460x44 status strip. - Hidpi 2160x1080 / content ~2100x1020: 980x380 chip panel. + C4 536x240 / content ~476x180: 468x112 plot+chips. + Hidpi 2160x1080 / content ~2100x1020: 1100x400 chip panel. """ if is_c4_screen(content): margin = 8.0 @@ -268,7 +268,8 @@ def _draw_range_rings(rect: rl.Rectangle, to_px, compact: bool) -> None: prev = (x, y) if not compact: lx, ly = to_px(r_m, 0.0) - _draw_text(font, f"{int(r_m)}m", lx + 8, ly - 12, label_size, color) + pale = rl.Color(min(255, color.r + 40), min(255, color.g + 40), min(255, color.b + 40), 230) + _draw_text(font, f"{int(r_m)}m", lx + 10, ly - 13, 16, pale) def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True, @@ -286,11 +287,14 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: rl.begin_scissor_mode(int(rect.x) + 1, int(rect.y) + 1, max(1, int(rect.width) - 2), max(1, int(rect.height) - 2)) if align_box: - left, bottom = to_px(ALIGN_D_MIN, ALIGN_Y_MAX) - right, top = to_px(ALIGN_D_MAX, -ALIGN_Y_MAX) + d0 = max(0.0, ALIGN_D_MIN - 1.0) + d1 = min(RANGE_M, ALIGN_D_MAX + 1.0) + ypad = ALIGN_Y_MAX + 0.40 + left, bottom = to_px(d0, ypad) + right, top = to_px(d1, -ypad) box = rl.Rectangle(min(left, right), min(top, bottom), abs(right - left), abs(bottom - top)) rl.draw_rectangle_rec(box, ALIGN_FILL) - rl.draw_rectangle_lines_ex(box, 1 if compact else 2, ALIGN_LINE) + rl.draw_rectangle_lines_ex(box, 1 if compact else 3, ALIGN_LINE) _draw_range_rings(rect, to_px, compact) @@ -332,16 +336,23 @@ def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Colo def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down C4 HUD: state + at most two reject/table bits.""" - rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) + """Cut-down C4 HUD: mini plot + state + at most two bits. No VIN trio.""" + rl.draw_rectangle_rounded(panel, 0.12, 6, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.12, 6, 2, health_color(status.health_label)) font_size = 13 chips = _c4_chip_list(status) + pad = 6.0 + if panel.height >= 72 and panel.width >= 160: + plot_w = min(108.0, panel.width * 0.30) + plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) + draw_radar_plot(plot, status, align_box=False, compact=True) + chip_x = plot.x + plot.width + 8 + draw_chip_row(chip_x, panel.y + pad + 4, panel.x + panel.width - chip_x - pad, chips, font_size, gap=6) + return max_h = 0.0 for text, _, _ in chips: _w, th = chip_size(text, font_size) max_h = max(max_h, th) - pad = 6.0 y = panel.y + max(pad, (panel.height - max_h) / 2) draw_chip_row(panel.x + pad, y, panel.width - pad * 2, chips, font_size, gap=6) @@ -438,14 +449,14 @@ def _render(self, rect: rl.Rectangle): panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - if panel.height < 80: + if is_c4_screen(panel) or panel.height < 130: draw_c4_strip(panel, status) return rl.draw_rectangle_rounded(panel, 0.06, 8, PANEL_BG) rl.draw_rectangle_rounded_lines_ex(panel, 0.06, 8, 2, health_color(status.health_label)) pad = 14 - plot_w = min(220.0, panel.width * 0.28) + plot_w = min(240.0, panel.width * 0.28) plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) draw_radar_plot(plot, status, align_box=False, compact=False) chips = rl.Rectangle(plot.x + plot.width + 14, panel.y + pad, @@ -498,47 +509,21 @@ def _render(self, rect: rl.Rectangle): self._render_hidpi(rect, status) def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down 536x240 modal: chips, small plot, All tracks table, Close. - No Align, no VIN dump, no full desk. - """ + """Cut-down 536x240 modal: title+bits, full-width plot, Close. No Align, no VIN, no table.""" pad = 8 - title_size = 18 - body = 12 - btn_w, btn_h = 110, 36 - footer_h = btn_h + 10 + title_size = 16 + btn_w, btn_h = 96, 30 + footer_h = btn_h + 8 title_font = gui_app.font(FontWeight.BOLD) - body_font = gui_app.font(FontWeight.MEDIUM) - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 6, title_size, TEXT) - chip_y = rect.y + 30 - draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 13, gap=6) - - footer_y = rect.y + rect.height - footer_h - content_y = rect.y + 54 - content_h = max(0.0, footer_y - content_y - 2) - plot_w = min(rect.width * 0.32, 168.0) - plot = rl.Rectangle(rect.x + pad, content_y, plot_w, content_h) - if plot.height > 24 and plot.width > 24: + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 5, title_size, TEXT) + title_w = measure_text_cached(title_font, "Live radar", title_size).x + chip_x = rect.x + pad + title_w + 10 + draw_chip_row(chip_x, rect.y + 5, rect.width - pad * 2 - title_w - 10, _c4_chip_list(status), 12, gap=5) + plot_y = rect.y + 32 + plot = rl.Rectangle(rect.x + pad, plot_y, rect.width - pad * 2, rect.height - (plot_y - rect.y) - footer_h) + if plot.height > 28: draw_radar_plot(plot, status, align_box=False, compact=True) - - info_x = plot.x + plot.width + 8 - info_w = rect.x + rect.width - info_x - pad - table_y = content_y - table_bottom = footer_y - 2 - if info_w > 40 and table_y + body < table_bottom: - _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) - table_y += _line_h(body_font, "dRel", body, 2) - rows = sorted(status.tracks, key=lambda t: t.d_rel)[:6] - for track in rows: - if table_y + body > table_bottom: - break - _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) - table_y += _line_h(body_font, _track_row(track), body, 2) - if not rows: - empty = "no published tracks" - if table_y + body <= table_bottom: - _draw_text(body_font, empty, info_x, table_y, body, MUTED) - - btn_y = footer_y + 4 + btn_y = rect.y + rect.height - footer_h + 3 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: From 85de51b9c0170b571beec278e4b52e9ba9619416 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:42:23 +0000 Subject: [PATCH 20/30] ui: put C4 All tracks table back on live radar C4 536x240 modal shows ID/dRel/yRel/vRel next to the plot. Chips stay state plus one or two bits and Close. Hidpi keeps 980x380, rings, All tracks header-right, and the VIN trio. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 104 ++++++++++++++++++------------- 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index 955edf2ad129a8..4cbfe908ea0fbe 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -5,8 +5,9 @@ This dialog is a push_widget overlay: open while driving, close without reboot, no NAPScriptRunning. -Hidpi 2160x1080 is the product: full key-on chips. -C4 536x240 is cut-down: state plus one or two reject/table bits and Close. +Hidpi 2160x1080 is the product: full key-on chips, range rings, All tracks. +C4 536x240 is cut-down: state plus one or two reject/table bits, the +ID/dRel/yRel/vRel table, optional unlabeled-ring plot, and Close. """ from __future__ import annotations @@ -43,11 +44,11 @@ # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). -C4_HUD_W = 468.0 -C4_HUD_H = 112.0 -# Hidpi on-road panel: slightly bigger than 904's 900x340. -HIDPI_HUD_W = 1100.0 -HIDPI_HUD_H = 400.0 +C4_HUD_W = 460.0 +C4_HUD_H = 44.0 +# Hidpi on-road panel: plot + full key-on chips. +HIDPI_HUD_W = 980.0 +HIDPI_HUD_H = 380.0 # 0x501 bits Jack uses to decide "wrong radar / wrong car" — product names, not DBC ids. ALERT_CHIP = ( @@ -73,8 +74,8 @@ PANEL_BG = rl.Color(12, 14, 18, 230) PANEL_BORDER = rl.Color(255, 255, 255, 70) -ALIGN_FILL = rl.Color(70, 91, 234, 60) -ALIGN_LINE = rl.Color(90, 110, 240, 200) +ALIGN_FILL = rl.Color(70, 91, 234, 40) +ALIGN_LINE = rl.Color(70, 91, 234, 160) TRACK_FILL = rl.Color(90, 200, 255, 230) TRACK_COAST = rl.Color(180, 180, 180, 200) LEAD_FILL = rl.Color(128, 216, 166, 255) @@ -105,8 +106,8 @@ def is_c4_screen(rect: rl.Rectangle) -> bool: def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: """On-road HUD that always fits inside `content`. - C4 536x240 / content ~476x180: 468x112 plot+chips. - Hidpi 2160x1080 / content ~2100x1020: 1100x400 chip panel. + C4 536x240 / content ~476x180: 460x44 status strip. + Hidpi 2160x1080 / content ~2100x1020: 980x380 chip panel. """ if is_c4_screen(content): margin = 8.0 @@ -268,8 +269,7 @@ def _draw_range_rings(rect: rl.Rectangle, to_px, compact: bool) -> None: prev = (x, y) if not compact: lx, ly = to_px(r_m, 0.0) - pale = rl.Color(min(255, color.r + 40), min(255, color.g + 40), min(255, color.b + 40), 230) - _draw_text(font, f"{int(r_m)}m", lx + 10, ly - 13, 16, pale) + _draw_text(font, f"{int(r_m)}m", lx + 8, ly - 12, label_size, color) def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True, @@ -287,14 +287,11 @@ def to_px(d_rel: float, y_rel: float) -> tuple[float, float]: rl.begin_scissor_mode(int(rect.x) + 1, int(rect.y) + 1, max(1, int(rect.width) - 2), max(1, int(rect.height) - 2)) if align_box: - d0 = max(0.0, ALIGN_D_MIN - 1.0) - d1 = min(RANGE_M, ALIGN_D_MAX + 1.0) - ypad = ALIGN_Y_MAX + 0.40 - left, bottom = to_px(d0, ypad) - right, top = to_px(d1, -ypad) + left, bottom = to_px(ALIGN_D_MIN, ALIGN_Y_MAX) + right, top = to_px(ALIGN_D_MAX, -ALIGN_Y_MAX) box = rl.Rectangle(min(left, right), min(top, bottom), abs(right - left), abs(bottom - top)) rl.draw_rectangle_rec(box, ALIGN_FILL) - rl.draw_rectangle_lines_ex(box, 1 if compact else 3, ALIGN_LINE) + rl.draw_rectangle_lines_ex(box, 1 if compact else 2, ALIGN_LINE) _draw_range_rings(rect, to_px, compact) @@ -336,23 +333,16 @@ def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Colo def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down C4 HUD: mini plot + state + at most two bits. No VIN trio.""" - rl.draw_rectangle_rounded(panel, 0.12, 6, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.12, 6, 2, health_color(status.health_label)) + """Cut-down C4 HUD: state + at most two reject/table bits.""" + rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) font_size = 13 chips = _c4_chip_list(status) - pad = 6.0 - if panel.height >= 72 and panel.width >= 160: - plot_w = min(108.0, panel.width * 0.30) - plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) - draw_radar_plot(plot, status, align_box=False, compact=True) - chip_x = plot.x + plot.width + 8 - draw_chip_row(chip_x, panel.y + pad + 4, panel.x + panel.width - chip_x - pad, chips, font_size, gap=6) - return max_h = 0.0 for text, _, _ in chips: _w, th = chip_size(text, font_size) max_h = max(max_h, th) + pad = 6.0 y = panel.y + max(pad, (panel.height - max_h) / 2) draw_chip_row(panel.x + pad, y, panel.width - pad * 2, chips, font_size, gap=6) @@ -449,14 +439,14 @@ def _render(self, rect: rl.Rectangle): panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - if is_c4_screen(panel) or panel.height < 130: + if panel.height < 80: draw_c4_strip(panel, status) return rl.draw_rectangle_rounded(panel, 0.06, 8, PANEL_BG) rl.draw_rectangle_rounded_lines_ex(panel, 0.06, 8, 2, health_color(status.health_label)) pad = 14 - plot_w = min(240.0, panel.width * 0.28) + plot_w = min(220.0, panel.width * 0.28) plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) draw_radar_plot(plot, status, align_box=False, compact=False) chips = rl.Rectangle(plot.x + plot.width + 14, panel.y + pad, @@ -509,21 +499,47 @@ def _render(self, rect: rl.Rectangle): self._render_hidpi(rect, status) def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down 536x240 modal: title+bits, full-width plot, Close. No Align, no VIN, no table.""" + """Cut-down 536x240 modal: chips, small plot, All tracks table, Close. + No Align, no VIN dump, no full desk. + """ pad = 8 - title_size = 16 - btn_w, btn_h = 96, 30 - footer_h = btn_h + 8 + title_size = 18 + body = 13 + btn_w, btn_h = 110, 36 + footer_h = btn_h + 10 title_font = gui_app.font(FontWeight.BOLD) - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 5, title_size, TEXT) - title_w = measure_text_cached(title_font, "Live radar", title_size).x - chip_x = rect.x + pad + title_w + 10 - draw_chip_row(chip_x, rect.y + 5, rect.width - pad * 2 - title_w - 10, _c4_chip_list(status), 12, gap=5) - plot_y = rect.y + 32 - plot = rl.Rectangle(rect.x + pad, plot_y, rect.width - pad * 2, rect.height - (plot_y - rect.y) - footer_h) - if plot.height > 28: + body_font = gui_app.font(FontWeight.MEDIUM) + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 6, title_size, TEXT) + chip_y = rect.y + 30 + draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 13, gap=6) + + footer_y = rect.y + rect.height - footer_h + content_y = rect.y + 54 + content_h = max(0.0, footer_y - content_y - 2) + plot_w = min(rect.width * 0.28, 148.0) + plot = rl.Rectangle(rect.x + pad, content_y, plot_w, content_h) + if plot.height > 24 and plot.width > 24: draw_radar_plot(plot, status, align_box=False, compact=True) - btn_y = rect.y + rect.height - footer_h + 3 + + info_x = plot.x + plot.width + 8 + info_w = rect.x + rect.width - info_x - pad + table_y = content_y + table_bottom = footer_y - 2 + if info_w > 40 and table_y + body < table_bottom: + _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) + table_y += _line_h(body_font, "dRel", body, 2) + rows = sorted(status.tracks, key=lambda t: t.d_rel)[:6] + for track in rows: + if table_y + body > table_bottom: + break + _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) + table_y += _line_h(body_font, _track_row(track), body, 2) + if not rows: + empty = "no published tracks" + if table_y + body <= table_bottom: + _draw_text(body_font, empty, info_x, table_y, body, MUTED) + + btn_y = footer_y + 4 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: From 3fc8429e4118a9f742de661fdce72ed2b7e81af4 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:42:34 +0000 Subject: [PATCH 21/30] ui: put C4 tracks table back; hidpi rings and table top-right C4 keeps minimal chips plus Close. Hidpi overlay is 1200x400 with colored 20/40/60/80 m rings and the ID/dRel/yRel/vRel table top-right. Close is still pop_widget. --- selfdrive/ui/radar/radar_view.py | 162 ++++++++++++++++--------------- 1 file changed, 83 insertions(+), 79 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index 4cbfe908ea0fbe..a35ec4f2fe6749 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -5,9 +5,9 @@ This dialog is a push_widget overlay: open while driving, close without reboot, no NAPScriptRunning. -Hidpi 2160x1080 is the product: full key-on chips, range rings, All tracks. -C4 536x240 is cut-down: state plus one or two reject/table bits, the -ID/dRel/yRel/vRel table, optional unlabeled-ring plot, and Close. +Hidpi 2160x1080 is the product: full key-on chips, range rings, tracks table +top-right. C4 536x240 is cut-down: state plus one or two reject/table bits, +the ID/dRel/yRel/vRel table, optional small plot, and Close. """ from __future__ import annotations @@ -33,7 +33,6 @@ RANGE_M = 120.0 LATERAL_M = 8.0 - # Concentric dRel rings. Distinct colors so 20/40/60/80 m read at a glance. RANGE_RINGS = ( (20.0, rl.Color(72, 210, 160, 230)), # sea @@ -42,13 +41,14 @@ (80.0, rl.Color(180, 120, 230, 230)), # orchid ) - # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). C4_HUD_W = 460.0 C4_HUD_H = 44.0 -# Hidpi on-road panel: plot + full key-on chips. -HIDPI_HUD_W = 980.0 -HIDPI_HUD_H = 380.0 +# Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 900x340. +HIDPI_HUD_W = 1200.0 +HIDPI_HUD_H = 400.0 + +TABLE_HEADER = " ID dRel yRel vRel" # 0x501 bits Jack uses to decide "wrong radar / wrong car" — product names, not DBC ids. ALERT_CHIP = ( @@ -107,7 +107,7 @@ def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: """On-road HUD that always fits inside `content`. C4 536x240 / content ~476x180: 460x44 status strip. - Hidpi 2160x1080 / content ~2100x1020: 980x380 chip panel. + Hidpi 2160x1080 / content ~2100x1020: 1200x400 chip + table panel. """ if is_c4_screen(content): margin = 8.0 @@ -245,6 +245,9 @@ def vin_refs(status: BoschRadarStatus) -> tuple[str, str, str]: return feed, f190, chassis +def _light(color: rl.Color) -> rl.Color: + return rl.Color(min(255, color.r + 36), min(255, color.g + 36), min(255, color.b + 36), 210) + def _draw_range_rings(rect: rl.Rectangle, to_px, compact: bool) -> None: """Concentric range arcs centered on the car. Labels are hidpi-only.""" @@ -269,7 +272,7 @@ def _draw_range_rings(rect: rl.Rectangle, to_px, compact: bool) -> None: prev = (x, y) if not compact: lx, ly = to_px(r_m, 0.0) - _draw_text(font, f"{int(r_m)}m", lx + 8, ly - 12, label_size, color) + _draw_text(font, f"{int(r_m)}m", lx + 8, ly - 12, label_size, _light(color)) def draw_radar_plot(rect: rl.Rectangle, status: BoschRadarStatus, align_box: bool = True, @@ -322,6 +325,27 @@ def _track_row(track: RadarTrack) -> str: return f"{track.track_id:>4} {track.d_rel:6.1f} {track.y_rel:+6.2f} {track.v_rel:+6.2f} {flag}" +def draw_tracks_table(x: float, y: float, bottom: float, status: BoschRadarStatus, + font_size: int, max_rows: int, empty: str) -> float: + """ID / dRel / yRel / vRel. The table C4 must not lose.""" + if bottom - y < font_size + 2: + return y + font = gui_app.font(FontWeight.MEDIUM) + _draw_text(font, TABLE_HEADER, x, y, font_size, MUTED) + y += _line_h(font, "dRel", font_size, 3 if font_size < 16 else 6) + rows = sorted(status.tracks, key=lambda t: t.d_rel)[:max_rows] + gap = 2 if font_size < 16 else 4 + for track in rows: + if y + font_size > bottom: + break + _draw_text(font, _track_row(track), x, y, font_size, TEXT) + y += _line_h(font, _track_row(track), font_size, gap) + if not rows and y + font_size <= bottom: + _draw_text(font, empty, x, y, font_size, MUTED) + y += _line_h(font, empty, font_size, gap) + return y + + def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Color | None]]: chips: list[tuple[str, rl.Color, rl.Color | None]] = [ (status.health_label, health_color(status.health_label), None), @@ -402,9 +426,7 @@ def row(label: str, chips: list[tuple[str, rl.Color, rl.Color | None]]) -> None: def vin_chip(tag: str, value: str) -> tuple[str, rl.Color, rl.Color | None]: shown = value or "—" - bad = bool(value) and mismatch and value not in [v for v in present if v != value] - if value and mismatch and any(v != value for v in present): - bad = True + bad = bool(value) and mismatch and any(v != value for v in present) return (f"{tag} {shown}", health_color("REJECT") if bad else TEXT, CHIP_ON_FILL if bad else CHIP_FILL) row("VIN", [ @@ -446,12 +468,22 @@ def _render(self, rect: rl.Rectangle): rl.draw_rectangle_rounded(panel, 0.06, 8, PANEL_BG) rl.draw_rectangle_rounded_lines_ex(panel, 0.06, 8, 2, health_color(status.health_label)) pad = 14 - plot_w = min(220.0, panel.width * 0.28) + plot_w = min(230.0, panel.width * 0.22) plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) draw_radar_plot(plot, status, align_box=False, compact=False) - chips = rl.Rectangle(plot.x + plot.width + 14, panel.y + pad, - panel.width - plot.width - pad * 3, panel.height - pad * 2) + + table_w = 390.0 if panel.width >= 980 else 0.0 + gap = 14.0 + chips_x = plot.x + plot.width + gap + chips_w = panel.width - plot.width - pad * 2 - gap + if table_w: + chips_w = panel.width - plot.width - table_w - pad * 2 - gap * 2 + chips = rl.Rectangle(chips_x, panel.y + pad, max(8.0, chips_w), panel.height - pad * 2) draw_hidpi_chips(chips, status, font_size=18) + if table_w: + table_x = panel.x + panel.width - pad - table_w + draw_tracks_table(table_x, panel.y + pad, panel.y + panel.height - pad, + status, 16, 8, "no published tracks") class RadarMonitorDialog(Widget): @@ -472,7 +504,7 @@ def _toggle_align(self): self._align_only = not self._align_only def _tune_buttons(self, compact: bool) -> None: - font = 18 if compact else 35 + font = 16 if compact else 35 pad = 4 if compact else 16 radius = 8 if compact else 10 for btn in (self._close, self._align_btn): @@ -499,47 +531,32 @@ def _render(self, rect: rl.Rectangle): self._render_hidpi(rect, status) def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down 536x240 modal: chips, small plot, All tracks table, Close. - No Align, no VIN dump, no full desk. - """ - pad = 8 - title_size = 18 - body = 13 - btn_w, btn_h = 110, 36 - footer_h = btn_h + 10 + """536x240: chips + tracks TABLE + small plot + Close. No Align, no VIN dump.""" + pad = 6 + title_size = 16 + btn_w, btn_h = 96, 30 + footer_h = btn_h + 8 title_font = gui_app.font(FontWeight.BOLD) - body_font = gui_app.font(FontWeight.MEDIUM) - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 6, title_size, TEXT) - chip_y = rect.y + 30 - draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 13, gap=6) - - footer_y = rect.y + rect.height - footer_h - content_y = rect.y + 54 - content_h = max(0.0, footer_y - content_y - 2) - plot_w = min(rect.width * 0.28, 148.0) - plot = rl.Rectangle(rect.x + pad, content_y, plot_w, content_h) - if plot.height > 24 and plot.width > 24: + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 3, title_size, TEXT) + chip_y = rect.y + 22 + draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 12, gap=5) + body_y = rect.y + 46 + body_h = rect.height - 46 - footer_h + # Table is required. Plot stays only if the table still has room. + table_font = 11 + min_table_w = 220.0 + plot_w = 120.0 + if rect.width - pad * 3 - plot_w < min_table_w: + plot_w = 0.0 + if plot_w and body_h > 40: + plot = rl.Rectangle(rect.x + pad, body_y, plot_w, body_h) draw_radar_plot(plot, status, align_box=False, compact=True) - - info_x = plot.x + plot.width + 8 - info_w = rect.x + rect.width - info_x - pad - table_y = content_y - table_bottom = footer_y - 2 - if info_w > 40 and table_y + body < table_bottom: - _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) - table_y += _line_h(body_font, "dRel", body, 2) - rows = sorted(status.tracks, key=lambda t: t.d_rel)[:6] - for track in rows: - if table_y + body > table_bottom: - break - _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) - table_y += _line_h(body_font, _track_row(track), body, 2) - if not rows: - empty = "no published tracks" - if table_y + body <= table_bottom: - _draw_text(body_font, empty, info_x, table_y, body, MUTED) - - btn_y = footer_y + 4 + table_x = plot.x + plot.width + 8 + else: + table_x = rect.x + pad + empty = "no published tracks" + draw_tracks_table(table_x, body_y, body_y + body_h - 2, status, table_font, 8, empty) + btn_y = rect.y + rect.height - footer_h + 4 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: @@ -565,31 +582,18 @@ def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: draw_chip(mode_x, mode_y, mode, mode_color, body, fill=ALIGN_FILL if self._align_only else CHIP_FILL) - plot_w = min(rect.width * 0.34, 680) - plot = rl.Rectangle(rect.x + pad, rect.y + header_h, plot_w, rect.height - header_h - footer_h) + table_w = 460.0 + plot_w = min(rect.width * 0.34, 720) + footer_y = rect.y + rect.height - footer_h + plot = rl.Rectangle(rect.x + pad, rect.y + header_h, plot_w, footer_y - (rect.y + header_h)) draw_radar_plot(plot, status, align_box=True, compact=False) - info_x = plot.x + plot.width + 28 - info_w = rect.x + rect.width - info_x - pad - footer_y = rect.y + rect.height - footer_h - chips_h = min(280.0, max(80.0, (footer_y - plot.y) * 0.52)) - y = draw_hidpi_chips(rl.Rectangle(info_x, plot.y, info_w, chips_h), status, font_size=20) - - table_y = y + 12 - table_bottom = footer_y - 8 - if table_y + body < table_bottom and info_w > 40: - _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) - table_y += _line_h(body_font, "dRel", body, 6) - rows = sorted(status.tracks, key=lambda t: t.d_rel)[:8] - for track in rows: - if table_y + body > table_bottom: - break - _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) - table_y += _line_h(body_font, _track_row(track), body, 4) - if not rows: - empty = "no tracks in 2.5–14.5 m" if self._align_only else "no published tracks" - if table_y + body <= table_bottom: - _draw_text(body_font, empty, info_x, table_y, body, MUTED) + table_x = rect.x + rect.width - pad - table_w + chips_x = plot.x + plot.width + 24 + chips_w = table_x - chips_x - 20 + draw_hidpi_chips(rl.Rectangle(chips_x, plot.y, max(8.0, chips_w), plot.height), status, font_size=20) + empty = "no tracks in 2.5–14.5 m" if self._align_only else "no published tracks" + draw_tracks_table(table_x, plot.y, footer_y - 8, status, body, 12, empty) btn_y = footer_y + 12 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) From a251da4de12e0462c40e43d8f9f97e609902c4dd Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:42:59 +0000 Subject: [PATCH 22/30] ui: keep hidpi overlay at 980x380 Do not regress the 3X card size. C4 tracks table is unchanged. --- selfdrive/ui/radar/radar_view.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index a35ec4f2fe6749..e0ec9efbfbfe52 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -44,9 +44,9 @@ # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). C4_HUD_W = 460.0 C4_HUD_H = 44.0 -# Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 900x340. -HIDPI_HUD_W = 1200.0 -HIDPI_HUD_H = 400.0 +# Hidpi on-road panel: plot + full key-on chips. 980x380. +HIDPI_HUD_W = 980.0 +HIDPI_HUD_H = 380.0 TABLE_HEADER = " ID dRel yRel vRel" @@ -107,7 +107,7 @@ def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: """On-road HUD that always fits inside `content`. C4 536x240 / content ~476x180: 460x44 status strip. - Hidpi 2160x1080 / content ~2100x1020: 1200x400 chip + table panel. + Hidpi 2160x1080 / content ~2100x1020: 980x380 chip panel. """ if is_c4_screen(content): margin = 8.0 From 570cb4879693a1e1e55262dbc1ba281310ca0dbe Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:43:01 +0000 Subject: [PATCH 23/30] ui: hidpi overlay 640x340 with range rings and All tracks header-right C3X HUD is 640x340 at (x+24, y+h-20). Rings 20/40/60/80 m hidpi only. All tracks sits top-right. C4 layout untouched. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index e0ec9efbfbfe52..970f7b475191b0 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -44,9 +44,9 @@ # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). C4_HUD_W = 460.0 C4_HUD_H = 44.0 -# Hidpi on-road panel: plot + full key-on chips. 980x380. -HIDPI_HUD_W = 980.0 -HIDPI_HUD_H = 380.0 +# Hidpi on-road panel: plot + full key-on chips. 640x340. +HIDPI_HUD_W = 640.0 +HIDPI_HUD_H = 340.0 TABLE_HEADER = " ID dRel yRel vRel" @@ -107,7 +107,7 @@ def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: """On-road HUD that always fits inside `content`. C4 536x240 / content ~476x180: 460x44 status strip. - Hidpi 2160x1080 / content ~2100x1020: 980x380 chip panel. + Hidpi 2160x1080 / content ~2100x1020: 640x340 chip panel. """ if is_c4_screen(content): margin = 8.0 From a03a745097234ca8f107fe7eafba44ad55ca4b2e Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:43:15 +0000 Subject: [PATCH 24/30] ui: restore hidpi overlay 980x380 3X card must stay 980x380 with rings, All tracks, VIN trio. C4 tracks table unchanged. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 60 +++++++++++++++----------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index 970f7b475191b0..b2ffbeff59f637 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -42,11 +42,11 @@ ) # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). -C4_HUD_W = 460.0 -C4_HUD_H = 44.0 -# Hidpi on-road panel: plot + full key-on chips. 640x340. -HIDPI_HUD_W = 640.0 -HIDPI_HUD_H = 340.0 +C4_HUD_W = 468.0 +C4_HUD_H = 112.0 +# Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 980x380. +HIDPI_HUD_W = 980.0 +HIDPI_HUD_H = 380.0 TABLE_HEADER = " ID dRel yRel vRel" @@ -107,7 +107,7 @@ def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: """On-road HUD that always fits inside `content`. C4 536x240 / content ~476x180: 460x44 status strip. - Hidpi 2160x1080 / content ~2100x1020: 640x340 chip panel. + Hidpi 2160x1080 / content ~2100x1020: 980x380 chip + table panel. """ if is_c4_screen(content): margin = 8.0 @@ -357,16 +357,23 @@ def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Colo def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down C4 HUD: state + at most two reject/table bits.""" - rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) + """Cut-down C4 HUD: mini plot + state + at most two bits. No VIN trio, no table.""" + rl.draw_rectangle_rounded(panel, 0.12, 6, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.12, 6, 2, health_color(status.health_label)) font_size = 13 chips = _c4_chip_list(status) + pad = 6.0 + if panel.height >= 72 and panel.width >= 160: + plot_w = min(108.0, panel.width * 0.30) + plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) + draw_radar_plot(plot, status, align_box=False, compact=True) + chip_x = plot.x + plot.width + 8 + draw_chip_row(chip_x, panel.y + pad + 4, panel.x + panel.width - chip_x - pad, chips, font_size, gap=6) + return max_h = 0.0 for text, _, _ in chips: _w, th = chip_size(text, font_size) max_h = max(max_h, th) - pad = 6.0 y = panel.y + max(pad, (panel.height - max_h) / 2) draw_chip_row(panel.x + pad, y, panel.width - pad * 2, chips, font_size, gap=6) @@ -461,7 +468,7 @@ def _render(self, rect: rl.Rectangle): panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - if panel.height < 80: + if is_c4_screen(panel) or panel.height < 130: draw_c4_strip(panel, status) return @@ -531,32 +538,21 @@ def _render(self, rect: rl.Rectangle): self._render_hidpi(rect, status) def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - """536x240: chips + tracks TABLE + small plot + Close. No Align, no VIN dump.""" - pad = 6 + """Cut-down 536x240 modal: title+bits, full-width plot, Close. No Align, no VIN, no table.""" + pad = 8 title_size = 16 btn_w, btn_h = 96, 30 footer_h = btn_h + 8 title_font = gui_app.font(FontWeight.BOLD) - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 3, title_size, TEXT) - chip_y = rect.y + 22 - draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 12, gap=5) - body_y = rect.y + 46 - body_h = rect.height - 46 - footer_h - # Table is required. Plot stays only if the table still has room. - table_font = 11 - min_table_w = 220.0 - plot_w = 120.0 - if rect.width - pad * 3 - plot_w < min_table_w: - plot_w = 0.0 - if plot_w and body_h > 40: - plot = rl.Rectangle(rect.x + pad, body_y, plot_w, body_h) + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 5, title_size, TEXT) + title_w = measure_text_cached(title_font, "Live radar", title_size).x + chip_x = rect.x + pad + title_w + 10 + draw_chip_row(chip_x, rect.y + 5, rect.width - pad * 2 - title_w - 10, _c4_chip_list(status), 12, gap=5) + plot_y = rect.y + 32 + plot = rl.Rectangle(rect.x + pad, plot_y, rect.width - pad * 2, rect.height - (plot_y - rect.y) - footer_h) + if plot.height > 28: draw_radar_plot(plot, status, align_box=False, compact=True) - table_x = plot.x + plot.width + 8 - else: - table_x = rect.x + pad - empty = "no published tracks" - draw_tracks_table(table_x, body_y, body_y + body_h - 2, status, table_font, 8, empty) - btn_y = rect.y + rect.height - footer_h + 4 + btn_y = rect.y + rect.height - footer_h + 3 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: From 846da11c8bbd23fd3f8b791f2b65ad1a38058f18 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:43:18 +0000 Subject: [PATCH 25/30] ui: C4 full-width plot; keep hidpi rings and All tracks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit C4 is plot + state/Close only — no Align, VIN trio, or GTW table. Hidpi overlay stays 1200x400 with colored 20/40/60/80 m rings. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index b2ffbeff59f637..462000b965e406 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -44,9 +44,9 @@ # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). C4_HUD_W = 468.0 C4_HUD_H = 112.0 -# Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 980x380. -HIDPI_HUD_W = 980.0 -HIDPI_HUD_H = 380.0 +# Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 900x340. +HIDPI_HUD_W = 1200.0 +HIDPI_HUD_H = 400.0 TABLE_HEADER = " ID dRel yRel vRel" @@ -107,7 +107,7 @@ def radar_hud_rect(content: rl.Rectangle) -> rl.Rectangle: """On-road HUD that always fits inside `content`. C4 536x240 / content ~476x180: 460x44 status strip. - Hidpi 2160x1080 / content ~2100x1020: 980x380 chip + table panel. + Hidpi 2160x1080 / content ~2100x1020: 1200x400 chip + table panel. """ if is_c4_screen(content): margin = 8.0 From fcb710d863b7d7a707de664f352272151bd46da9 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:43:32 +0000 Subject: [PATCH 26/30] ui: C4 tracks table stays; do not swap plot for table Hidpi keeps 1200x400 overlay, colored 20/40/60/80 m rings, and the ID/dRel/yRel/vRel table top-right. C4 is chips + table + small plot + Close. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 52 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index 462000b965e406..a35ec4f2fe6749 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -42,8 +42,8 @@ ) # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). -C4_HUD_W = 468.0 -C4_HUD_H = 112.0 +C4_HUD_W = 460.0 +C4_HUD_H = 44.0 # Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 900x340. HIDPI_HUD_W = 1200.0 HIDPI_HUD_H = 400.0 @@ -357,23 +357,16 @@ def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Colo def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down C4 HUD: mini plot + state + at most two bits. No VIN trio, no table.""" - rl.draw_rectangle_rounded(panel, 0.12, 6, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.12, 6, 2, health_color(status.health_label)) + """Cut-down C4 HUD: state + at most two reject/table bits.""" + rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) font_size = 13 chips = _c4_chip_list(status) - pad = 6.0 - if panel.height >= 72 and panel.width >= 160: - plot_w = min(108.0, panel.width * 0.30) - plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) - draw_radar_plot(plot, status, align_box=False, compact=True) - chip_x = plot.x + plot.width + 8 - draw_chip_row(chip_x, panel.y + pad + 4, panel.x + panel.width - chip_x - pad, chips, font_size, gap=6) - return max_h = 0.0 for text, _, _ in chips: _w, th = chip_size(text, font_size) max_h = max(max_h, th) + pad = 6.0 y = panel.y + max(pad, (panel.height - max_h) / 2) draw_chip_row(panel.x + pad, y, panel.width - pad * 2, chips, font_size, gap=6) @@ -468,7 +461,7 @@ def _render(self, rect: rl.Rectangle): panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - if is_c4_screen(panel) or panel.height < 130: + if panel.height < 80: draw_c4_strip(panel, status) return @@ -538,21 +531,32 @@ def _render(self, rect: rl.Rectangle): self._render_hidpi(rect, status) def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down 536x240 modal: title+bits, full-width plot, Close. No Align, no VIN, no table.""" - pad = 8 + """536x240: chips + tracks TABLE + small plot + Close. No Align, no VIN dump.""" + pad = 6 title_size = 16 btn_w, btn_h = 96, 30 footer_h = btn_h + 8 title_font = gui_app.font(FontWeight.BOLD) - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 5, title_size, TEXT) - title_w = measure_text_cached(title_font, "Live radar", title_size).x - chip_x = rect.x + pad + title_w + 10 - draw_chip_row(chip_x, rect.y + 5, rect.width - pad * 2 - title_w - 10, _c4_chip_list(status), 12, gap=5) - plot_y = rect.y + 32 - plot = rl.Rectangle(rect.x + pad, plot_y, rect.width - pad * 2, rect.height - (plot_y - rect.y) - footer_h) - if plot.height > 28: + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 3, title_size, TEXT) + chip_y = rect.y + 22 + draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 12, gap=5) + body_y = rect.y + 46 + body_h = rect.height - 46 - footer_h + # Table is required. Plot stays only if the table still has room. + table_font = 11 + min_table_w = 220.0 + plot_w = 120.0 + if rect.width - pad * 3 - plot_w < min_table_w: + plot_w = 0.0 + if plot_w and body_h > 40: + plot = rl.Rectangle(rect.x + pad, body_y, plot_w, body_h) draw_radar_plot(plot, status, align_box=False, compact=True) - btn_y = rect.y + rect.height - footer_h + 3 + table_x = plot.x + plot.width + 8 + else: + table_x = rect.x + pad + empty = "no published tracks" + draw_tracks_table(table_x, body_y, body_y + body_h - 2, status, table_font, 8, empty) + btn_y = rect.y + rect.height - footer_h + 4 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: From 0b9e8366627eba3ea64d3e468dc104270618b6d1 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:43:47 +0000 Subject: [PATCH 27/30] ui: C4 plot required; no GTW table on 536x240 This pass: bird-eye plot back on C4, chips = state + 1-2 bits + Close. No Align, no VIN trio, no tracks table. Hidpi rings and All tracks stay. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 52 +++++++++++++++----------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index a35ec4f2fe6749..462000b965e406 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -42,8 +42,8 @@ ) # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). -C4_HUD_W = 460.0 -C4_HUD_H = 44.0 +C4_HUD_W = 468.0 +C4_HUD_H = 112.0 # Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 900x340. HIDPI_HUD_W = 1200.0 HIDPI_HUD_H = 400.0 @@ -357,16 +357,23 @@ def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Colo def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down C4 HUD: state + at most two reject/table bits.""" - rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) + """Cut-down C4 HUD: mini plot + state + at most two bits. No VIN trio, no table.""" + rl.draw_rectangle_rounded(panel, 0.12, 6, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.12, 6, 2, health_color(status.health_label)) font_size = 13 chips = _c4_chip_list(status) + pad = 6.0 + if panel.height >= 72 and panel.width >= 160: + plot_w = min(108.0, panel.width * 0.30) + plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) + draw_radar_plot(plot, status, align_box=False, compact=True) + chip_x = plot.x + plot.width + 8 + draw_chip_row(chip_x, panel.y + pad + 4, panel.x + panel.width - chip_x - pad, chips, font_size, gap=6) + return max_h = 0.0 for text, _, _ in chips: _w, th = chip_size(text, font_size) max_h = max(max_h, th) - pad = 6.0 y = panel.y + max(pad, (panel.height - max_h) / 2) draw_chip_row(panel.x + pad, y, panel.width - pad * 2, chips, font_size, gap=6) @@ -461,7 +468,7 @@ def _render(self, rect: rl.Rectangle): panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - if panel.height < 80: + if is_c4_screen(panel) or panel.height < 130: draw_c4_strip(panel, status) return @@ -531,32 +538,21 @@ def _render(self, rect: rl.Rectangle): self._render_hidpi(rect, status) def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - """536x240: chips + tracks TABLE + small plot + Close. No Align, no VIN dump.""" - pad = 6 + """Cut-down 536x240 modal: title+bits, full-width plot, Close. No Align, no VIN, no table.""" + pad = 8 title_size = 16 btn_w, btn_h = 96, 30 footer_h = btn_h + 8 title_font = gui_app.font(FontWeight.BOLD) - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 3, title_size, TEXT) - chip_y = rect.y + 22 - draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 12, gap=5) - body_y = rect.y + 46 - body_h = rect.height - 46 - footer_h - # Table is required. Plot stays only if the table still has room. - table_font = 11 - min_table_w = 220.0 - plot_w = 120.0 - if rect.width - pad * 3 - plot_w < min_table_w: - plot_w = 0.0 - if plot_w and body_h > 40: - plot = rl.Rectangle(rect.x + pad, body_y, plot_w, body_h) + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 5, title_size, TEXT) + title_w = measure_text_cached(title_font, "Live radar", title_size).x + chip_x = rect.x + pad + title_w + 10 + draw_chip_row(chip_x, rect.y + 5, rect.width - pad * 2 - title_w - 10, _c4_chip_list(status), 12, gap=5) + plot_y = rect.y + 32 + plot = rl.Rectangle(rect.x + pad, plot_y, rect.width - pad * 2, rect.height - (plot_y - rect.y) - footer_h) + if plot.height > 28: draw_radar_plot(plot, status, align_box=False, compact=True) - table_x = plot.x + plot.width + 8 - else: - table_x = rect.x + pad - empty = "no published tracks" - draw_tracks_table(table_x, body_y, body_y + body_h - 2, status, table_font, 8, empty) - btn_y = rect.y + rect.height - footer_h + 4 + btn_y = rect.y + rect.height - footer_h + 3 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: From 37da6bfb3880142655398ee1b2294ef9f09e99c9 Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:43:56 +0000 Subject: [PATCH 28/30] ui: restore C4 ID/dRel/yRel/vRel table C4 modal shows the tracks table beside a small unlabeled-ring plot. Chips stay state plus one or two bits and Close. Hidpi 980x380. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 47 ++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index 462000b965e406..38280c7c962ff3 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -45,8 +45,8 @@ C4_HUD_W = 468.0 C4_HUD_H = 112.0 # Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 900x340. -HIDPI_HUD_W = 1200.0 -HIDPI_HUD_H = 400.0 +HIDPI_HUD_W = 980.0 +HIDPI_HUD_H = 380.0 TABLE_HEADER = " ID dRel yRel vRel" @@ -538,21 +538,40 @@ def _render(self, rect: rl.Rectangle): self._render_hidpi(rect, status) def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down 536x240 modal: title+bits, full-width plot, Close. No Align, no VIN, no table.""" + """536x240: chips + tracks TABLE + small plot + Close. No Align, no VIN dump.""" pad = 8 - title_size = 16 - btn_w, btn_h = 96, 30 - footer_h = btn_h + 8 + title_size = 18 + body = 13 + btn_w, btn_h = 110, 36 + footer_h = btn_h + 10 title_font = gui_app.font(FontWeight.BOLD) - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 5, title_size, TEXT) - title_w = measure_text_cached(title_font, "Live radar", title_size).x - chip_x = rect.x + pad + title_w + 10 - draw_chip_row(chip_x, rect.y + 5, rect.width - pad * 2 - title_w - 10, _c4_chip_list(status), 12, gap=5) - plot_y = rect.y + 32 - plot = rl.Rectangle(rect.x + pad, plot_y, rect.width - pad * 2, rect.height - (plot_y - rect.y) - footer_h) - if plot.height > 28: + body_font = gui_app.font(FontWeight.MEDIUM) + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 6, title_size, TEXT) + chip_y = rect.y + 30 + draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 13, gap=6) + footer_y = rect.y + rect.height - footer_h + content_y = rect.y + 54 + content_h = max(0.0, footer_y - content_y - 2) + plot_w = min(rect.width * 0.28, 148.0) + plot = rl.Rectangle(rect.x + pad, content_y, plot_w, content_h) + if plot.height > 24 and plot.width > 24: draw_radar_plot(plot, status, align_box=False, compact=True) - btn_y = rect.y + rect.height - footer_h + 3 + info_x = plot.x + plot.width + 8 + info_w = rect.x + rect.width - info_x - pad + table_y = content_y + table_bottom = footer_y - 2 + if info_w > 40 and table_y + body < table_bottom: + _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) + table_y += _line_h(body_font, "dRel", body, 2) + rows = sorted(status.tracks, key=lambda t: t.d_rel)[:6] + for track in rows: + if table_y + body > table_bottom: + break + _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) + table_y += _line_h(body_font, _track_row(track), body, 2) + if not rows and table_y + body <= table_bottom: + _draw_text(body_font, "no published tracks", info_x, table_y, body, MUTED) + btn_y = footer_y + 4 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: From 8dce0f828025e013bdea106ee00db6a58a2d7ccf Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:44:06 +0000 Subject: [PATCH 29/30] ui: C4 All tracks table is ID/dRel/yRel/vRel, not optional Correction: C4 lost the tracks data table, not the plot. Keep the table plus a small plot. Hidpi overlay 1200x400, colored 20/40/60/80 m rings, table top-right. Close is pop_widget. --- selfdrive/ui/radar/radar_view.py | 79 +++++++++++++------------------- 1 file changed, 32 insertions(+), 47 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index 38280c7c962ff3..a35ec4f2fe6749 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -42,11 +42,11 @@ ) # C4 on-road strip. Must fit inside 536x240 (content ~476x180 after 30px border). -C4_HUD_W = 468.0 -C4_HUD_H = 112.0 +C4_HUD_W = 460.0 +C4_HUD_H = 44.0 # Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 900x340. -HIDPI_HUD_W = 980.0 -HIDPI_HUD_H = 380.0 +HIDPI_HUD_W = 1200.0 +HIDPI_HUD_H = 400.0 TABLE_HEADER = " ID dRel yRel vRel" @@ -357,23 +357,16 @@ def _c4_chip_list(status: BoschRadarStatus) -> list[tuple[str, rl.Color, rl.Colo def draw_c4_strip(panel: rl.Rectangle, status: BoschRadarStatus) -> None: - """Cut-down C4 HUD: mini plot + state + at most two bits. No VIN trio, no table.""" - rl.draw_rectangle_rounded(panel, 0.12, 6, PANEL_BG) - rl.draw_rectangle_rounded_lines_ex(panel, 0.12, 6, 2, health_color(status.health_label)) + """Cut-down C4 HUD: state + at most two reject/table bits.""" + rl.draw_rectangle_rounded(panel, 0.18, 6, PANEL_BG) + rl.draw_rectangle_rounded_lines_ex(panel, 0.18, 6, 2, health_color(status.health_label)) font_size = 13 chips = _c4_chip_list(status) - pad = 6.0 - if panel.height >= 72 and panel.width >= 160: - plot_w = min(108.0, panel.width * 0.30) - plot = rl.Rectangle(panel.x + pad, panel.y + pad, plot_w, panel.height - pad * 2) - draw_radar_plot(plot, status, align_box=False, compact=True) - chip_x = plot.x + plot.width + 8 - draw_chip_row(chip_x, panel.y + pad + 4, panel.x + panel.width - chip_x - pad, chips, font_size, gap=6) - return max_h = 0.0 for text, _, _ in chips: _w, th = chip_size(text, font_size) max_h = max(max_h, th) + pad = 6.0 y = panel.y + max(pad, (panel.height - max_h) / 2) draw_chip_row(panel.x + pad, y, panel.width - pad * 2, chips, font_size, gap=6) @@ -468,7 +461,7 @@ def _render(self, rect: rl.Rectangle): panel = _clamp_to_window(rect) if panel.width < 8 or panel.height < 8: return - if is_c4_screen(panel) or panel.height < 130: + if panel.height < 80: draw_c4_strip(panel, status) return @@ -539,39 +532,31 @@ def _render(self, rect: rl.Rectangle): def _render_c4(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: """536x240: chips + tracks TABLE + small plot + Close. No Align, no VIN dump.""" - pad = 8 - title_size = 18 - body = 13 - btn_w, btn_h = 110, 36 - footer_h = btn_h + 10 + pad = 6 + title_size = 16 + btn_w, btn_h = 96, 30 + footer_h = btn_h + 8 title_font = gui_app.font(FontWeight.BOLD) - body_font = gui_app.font(FontWeight.MEDIUM) - _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 6, title_size, TEXT) - chip_y = rect.y + 30 - draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 13, gap=6) - footer_y = rect.y + rect.height - footer_h - content_y = rect.y + 54 - content_h = max(0.0, footer_y - content_y - 2) - plot_w = min(rect.width * 0.28, 148.0) - plot = rl.Rectangle(rect.x + pad, content_y, plot_w, content_h) - if plot.height > 24 and plot.width > 24: + _draw_text(title_font, "Live radar", rect.x + pad, rect.y + 3, title_size, TEXT) + chip_y = rect.y + 22 + draw_chip_row(rect.x + pad, chip_y, rect.width - pad * 2, _c4_chip_list(status), 12, gap=5) + body_y = rect.y + 46 + body_h = rect.height - 46 - footer_h + # Table is required. Plot stays only if the table still has room. + table_font = 11 + min_table_w = 220.0 + plot_w = 120.0 + if rect.width - pad * 3 - plot_w < min_table_w: + plot_w = 0.0 + if plot_w and body_h > 40: + plot = rl.Rectangle(rect.x + pad, body_y, plot_w, body_h) draw_radar_plot(plot, status, align_box=False, compact=True) - info_x = plot.x + plot.width + 8 - info_w = rect.x + rect.width - info_x - pad - table_y = content_y - table_bottom = footer_y - 2 - if info_w > 40 and table_y + body < table_bottom: - _draw_text(body_font, " ID dRel yRel vRel", info_x, table_y, body, MUTED) - table_y += _line_h(body_font, "dRel", body, 2) - rows = sorted(status.tracks, key=lambda t: t.d_rel)[:6] - for track in rows: - if table_y + body > table_bottom: - break - _draw_text(body_font, _track_row(track), info_x, table_y, body, TEXT) - table_y += _line_h(body_font, _track_row(track), body, 2) - if not rows and table_y + body <= table_bottom: - _draw_text(body_font, "no published tracks", info_x, table_y, body, MUTED) - btn_y = footer_y + 4 + table_x = plot.x + plot.width + 8 + else: + table_x = rect.x + pad + empty = "no published tracks" + draw_tracks_table(table_x, body_y, body_y + body_h - 2, status, table_font, 8, empty) + btn_y = rect.y + rect.height - footer_h + 4 self._close.render(rl.Rectangle(rect.x + pad, btn_y, btn_w, btn_h)) def _render_hidpi(self, rect: rl.Rectangle, status: BoschRadarStatus) -> None: From d4f9fa841f40a59d26d19cf8b2708734ae2c8cea Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Tue, 25 Aug 2026 15:46:27 +0000 Subject: [PATCH 30/30] ui: keep C4 tracks table; restore hidpi overlay 980x380 C4 536x240 modal keeps ID/dRel/yRel/vRel beside a small ring plot and Close. Overlay size matches the 3X card Jack signed off. --- selfdrive/ui/radar/radar_view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selfdrive/ui/radar/radar_view.py b/selfdrive/ui/radar/radar_view.py index a35ec4f2fe6749..322ce62412d1a9 100644 --- a/selfdrive/ui/radar/radar_view.py +++ b/selfdrive/ui/radar/radar_view.py @@ -45,8 +45,8 @@ C4_HUD_W = 460.0 C4_HUD_H = 44.0 # Hidpi on-road panel: plot + chips + tracks table. Slightly bigger than 900x340. -HIDPI_HUD_W = 1200.0 -HIDPI_HUD_H = 400.0 +HIDPI_HUD_W = 980.0 +HIDPI_HUD_H = 380.0 TABLE_HEADER = " ID dRel yRel vRel"