diff --git a/openpilot/starpilot/galaxy/setting_descriptions.py b/openpilot/starpilot/galaxy/setting_descriptions.py index f2604b2170..0c2a4534f8 100644 --- a/openpilot/starpilot/galaxy/setting_descriptions.py +++ b/openpilot/starpilot/galaxy/setting_descriptions.py @@ -162,10 +162,10 @@ DESCRIPTIONS = { 'EngageVolume': 'Sets the engagement-chime volume.', 'DisengageVolume': 'Sets the disengagement-alert volume.', 'PromptVolume': 'Sets the volume of general prompts.', - 'PIPPreviewEnabled': 'Shows the configured blind-spot camera preview when fresh camera frames are available.', - 'PIPPreviewShowOnBlinker': 'Shows the blind-spot camera preview while a turn signal is on.', - 'PIPPreviewShowOnBSM': 'Shows the blind-spot camera preview during a blind-spot warning.', - 'PIPPreviewInvert': 'Mirrors the blind-spot camera crop horizontally.', + 'PIPPreviewEnabled': 'Shows the configured Adj Spot Camera preview when fresh camera frames are available.', + 'PIPPreviewShowOnBlinker': 'Shows the Adj Spot Camera preview while a turn signal is on.', + 'PIPPreviewShowOnBSM': 'Shows the Adj Spot Camera preview during a blind-spot warning.', + 'PIPPreviewInvert': 'Mirrors the Adj Spot Camera crop horizontally.', 'pip:mask:size': 'Sets the size of each camera-image crop shown in the preview.', 'pip:mask:editor': 'Edits the source-image crop for the vehicle left and right camera views.', 'pip:reset': 'Restores the default source-image camera crops.', diff --git a/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs b/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs index 63438fd995..7dca87bd5d 100644 --- a/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs +++ b/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs @@ -1,4 +1,5 @@ import assert from "node:assert/strict" +import { compile } from "../web/vendor/vue/vue.esm-browser.js" import * as documentHelpers from "../web/js/onroad-layout-document.js" import * as layoutModule from "../web/js/onroad-layout.js" import { ONROAD_LAYOUT_TEMPLATE } from "../web/js/onroad-layout-template.js" @@ -54,7 +55,7 @@ export function snapshot() { metadata.roadColorFields = [{ id: 'path', label: 'Path', default: '#30FF9CFF' }, { id: 'pathEdge', label: 'Path edges', default: '#00FF40FF' }, { id: 'laneLines', label: 'Lane lines', default: '#FFFFFFFF' }] metadata.profiles.compact.widgets.speed_limit.visualInsetTop = 32 - const document = { version: 16, roadColors: { large: {}, compact: {} }, widgetColors: { large: {}, compact: {} }, palette: Object.fromEntries(metadata.paletteFields.map((field) => [field.id, field.default])), + const document = { version: 17, roadColors: { large: {}, compact: {} }, widgetColors: { large: {}, compact: {} }, palette: Object.fromEntries(metadata.paletteFields.map((field) => [field.id, field.default])), layouts: Object.fromEntries(Object.entries(metadata.profiles).map(([id, profile]) => [id, Object.fromEntries(Object.entries(profile.widgets).map(([key, definition]) => [key, { ...definition.default, ...(definition.resizable ? { size: definition.resizable.default } : {}) }]))])) } @@ -364,6 +365,11 @@ try { Object.defineProperty(globalThis, "localStorage", { configurable: true, value: { getItem: key => preferences.get(key) ?? null, setItem: (key, value) => preferences.set(key, value) } }) + assert.equal(editor().vm.state.hiddenPreviewWidgets.compact.pip_left, true) + assert.equal(OnroadLayoutPage.setup({ projection: true }).state.hiddenPreviewWidgets.compact.pip_left, undefined) + preferences.set("gx-layout-preview-visibility-v2:comma", JSON.stringify({ compact: { pip_left: false } })) + assert.equal(editor().vm.state.hiddenPreviewWidgets.compact.pip_left, false) + preferences.delete("gx-layout-preview-visibility-v2:comma") const preference = editor().vm assert.equal(preference.state.snapEnabled, true) preference.toggleSnap() @@ -1386,11 +1392,11 @@ console.log("Ford rear fog: make visibility, saved placement and strict metadata assert.equal(clampPlacement(profile, 'speed_limit', 330, 16, sample.document.layouts.compact).x, 320) } -// The device writes version 16 once the speed limit actions widget is folded into the sign. +// The device writes version 17 with full-panel C4 side cameras. { const sample = snapshot() assert.equal(validDocument(sample.document, sample.metadata), true) - sample.document.version = 15 + sample.document.version = 16 assert.equal(validDocument(sample.document, sample.metadata), false) } @@ -1403,3 +1409,45 @@ for (const invalidOffset of [true, null, "1", NaN, Infinity, -5.1, 5.1]) { assert.equal(validDocument(document, speedAdjustment.metadata), false) } assert.ok(SETTINGS_SECTIONS.find(section => section.id === "developer").pages.includes("developer")) + + +// C4 has one locked camera widget covering the road panel. +{ + const sample = snapshot() + const profile = sample.metadata.profiles.compact + for (const side of ["left"]) { + const id = `pip_${side}` + profile.widgets[id] = widget("Adj Spot Camera", "pip_camera", 476, 240, 0, 0) + sample.document.layouts.compact[id] = { x: 0, y: 0, enabled: side === "left" } + assert.deepEqual(clampPlacement(profile, id, 300, 100, sample.document.layouts.compact), { x: 0, y: 0 }) + assert.deepEqual(documentHelpers.widgetSize(profile.widgets[id], sample.document.layouts.compact[id]), [476, 240]) + } + assert.equal(validDocument(sample.document, sample.metadata), true) + const vm = editor().vm + vm.state.data = sample; vm.state.draft = copy(sample.document); vm.state.profile = "compact" + assert.deepEqual(vm.cameraIds, ["pip_left"]) + assert.deepEqual(vm.lockedCameraIds, ["pip_left"]) + const original = copy(vm.state.draft) + assert.equal(vm.previewHidden("pip_left"), true) + assert.equal(vm.renderWidgets.some(widget => widget.id === "pip_left"), false) + vm.togglePreviewVisibility("pip_left") + assert.equal(vm.previewHidden("pip_left"), false) + assert.equal(vm.renderWidgets.some(widget => widget.id === "pip_left"), true) + assert.deepEqual(vm.state.draft, original) + assert.equal(vm.dirty, false) +} + + +// The actual Vue preview uses the same device-specific silhouettes as onroad. +{ + const render = compile(LayoutWidgetPreview.template, { decodeEntities: value => value.replaceAll("&", "&") }) + const nodes = vnode => [vnode, ...(Array.isArray(vnode.children) ? vnode.children.flatMap(nodes) : [])] + for (const [profile, width, height, shape] of [["large", 600, 600, "circle"], ["compact", 476, 240, "rect"]]) { + const tree = render({ widget: widget("Adj Spot Camera", "pip_camera", width, height, 0, 0), + palette: {}, sprite: null, native: false, profile }, []) + const camera = nodes(tree).find(node => node.type === shape) + assert.ok(camera, `${profile} renders a ${shape}`) + assert.equal(nodes(tree).some(node => node.type === (shape === "rect" ? "circle" : "rect")), false) + if (shape === "rect") assert.deepEqual([camera.props.width, camera.props.height, camera.props.rx], [476, 240, 52.8]) + } +} diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js b/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js index 523046fb32..109141ced7 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js @@ -145,7 +145,7 @@ export const PROJECTION_DISPLAY_SWITCHES = ["blindSpotBorder", "signalBorder", " export function validDocument(document, metadata) { if (!object(document)) return false const profiles = metadata?.projection === true ? ["large"] : PROFILES - if (!keysEqual(document, ["version", "palette", "layouts", "widgetColors", "roadColors", ...(Object.hasOwn(document, "widgetOrder") ? ["widgetOrder"] : []), ...(Object.hasOwn(document, "speedSources") ? ["speedSources"] : []), ...(Object.hasOwn(document, "speedSourcesCard") ? ["speedSourcesCard"] : []), ...(Object.hasOwn(document, "speedAlign") ? ["speedAlign"] : []), ...(Object.hasOwn(document, "clock24Hour") ? ["clock24Hour"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "reduceMotion") ? ["reduceMotion"] : []), ...(Object.hasOwn(document, "showMaxSpeed") ? ["showMaxSpeed"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "speedDisplayOffset") ? ["speedDisplayOffset"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "display") ? ["display"] : []), ...(metadata?.projection === true && Object.hasOwn(document, "largeUiGammaTrial") ? ["largeUiGammaTrial"] : []), ...(metadata?.projection === true ? PROJECTION_DISPLAY_SWITCHES.filter(key => Object.hasOwn(document, key)) : []), ...(metadata?.projection === true && Object.hasOwn(document, "leadInfo") ? ["leadInfo"] : [])]) || (metadata?.projection === true ? document.version !== 8 : document.version !== 16) || + if (!keysEqual(document, ["version", "palette", "layouts", "widgetColors", "roadColors", ...(Object.hasOwn(document, "widgetOrder") ? ["widgetOrder"] : []), ...(Object.hasOwn(document, "speedSources") ? ["speedSources"] : []), ...(Object.hasOwn(document, "speedSourcesCard") ? ["speedSourcesCard"] : []), ...(Object.hasOwn(document, "speedAlign") ? ["speedAlign"] : []), ...(Object.hasOwn(document, "clock24Hour") ? ["clock24Hour"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "reduceMotion") ? ["reduceMotion"] : []), ...(Object.hasOwn(document, "showMaxSpeed") ? ["showMaxSpeed"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "speedDisplayOffset") ? ["speedDisplayOffset"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "display") ? ["display"] : []), ...(metadata?.projection === true && Object.hasOwn(document, "largeUiGammaTrial") ? ["largeUiGammaTrial"] : []), ...(metadata?.projection === true ? PROJECTION_DISPLAY_SWITCHES.filter(key => Object.hasOwn(document, key)) : []), ...(metadata?.projection === true && Object.hasOwn(document, "leadInfo") ? ["leadInfo"] : [])]) || (metadata?.projection === true ? document.version !== 8 : document.version !== 17) || (Object.hasOwn(document, "speedSources") && typeof document.speedSources !== "boolean") || (Object.hasOwn(document, "speedSourcesCard") && typeof document.speedSourcesCard !== "boolean") || (Object.hasOwn(document, "speedAlign") && !SPEED_ALIGNMENTS.includes(document.speedAlign)) || diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js index b91f49b552..336de621b9 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js @@ -207,7 +207,7 @@ export const ONROAD_LAYOUT_TEMPLATE = `
Tap a widget to edit it.
Drag ⠿ to reorder. The top row is in front, and alerts stay above all widgets. Each side camera can be locked to the front; unlock it to move widgets above.
The eyes follow the chosen scene. Choose General edit to arrange every enabled widget. Hiding a widget with the eye affects only this scene's preview.
+Tap a widget to edit it.
Drag ⠿ to reorder. The top row is in front, and alerts stay above all widgets. Each Adj Spot Camera can be locked to the front; unlock it to move widgets above.
The eyes follow the chosen scene. Choose General edit to arrange every enabled widget. Hiding a widget with the eye affects only this scene's preview.
Add a left or right blind-spot camera widget to enable this option.
+Add a left or right Adj Spot Camera widget to enable this option.
The large UI road-camera color effect on StarPort (not shown in the preview).
@@ -471,7 +471,7 @@ export const ONROAD_LAYOUT_TEMPLATE = `Warning: moving other widgets on top of this side camera may block your view of the blind-spot camera. Are you sure?
Warning: moving other widgets on top of this Adj Spot Camera may block your view of the Adj Spot Camera. Are you sure?
Shows a close-up of the cabin window as you drive. Whether it appears on your turn signal or when a car is in your blind spot depends on your settings. Choose which window each side covers and how much to zoom in.
Drag a circle onto the cabin window you want to watch. Both crops share one size.
{{ state.cameraWarming ? "Warming up the camera · about 10 seconds…" : state.imageName ? "Snapshot ready" : "Take a cabin snapshot while parked." }}
diff --git a/openpilot/starpilot/galaxy/web/js/settings.js b/openpilot/starpilot/galaxy/web/js/settings.js index 1900f9922b..d3267d5f87 100644 --- a/openpilot/starpilot/galaxy/web/js/settings.js +++ b/openpilot/starpilot/galaxy/web/js/settings.js @@ -34,7 +34,7 @@ export const SETTINGS_SECTIONS = Object.freeze([ ]) // Crop numeric rows and the inline editor row are controlled from the dedicated -// Blind Spot Camera page; they stay writable through the settings API for the +// Adj Spot Camera page; they stay writable through the settings API for the // widget/VASM editor but must not surface in the generic toggles list. export const isPipCropRow = (row) => ["Visual camera crop editor", "Camera crop size", "Restore default camera crop"].includes(row.label) || /^Vehicle (left|right) crop/.test(row.label || "") @@ -51,7 +51,7 @@ const SECTION_LINKS = { { label: "Display", page: "display", value: "Adjust screen brightness and display timing" }, { label: "Driving Screen Widgets, Colors & Layout", page: "ui_layout" }, { label: "Quick Select", page: "favorites" }, - { label: "Blind Spot Camera & Preview", page: "pip" }, + { label: "Adj Spot Camera & Preview", page: "pip" }, ], } diff --git a/openpilot/starpilot/replay/render.py b/openpilot/starpilot/replay/render.py index 98af28b368..cea648a29e 100644 --- a/openpilot/starpilot/replay/render.py +++ b/openpilot/starpilot/replay/render.py @@ -317,7 +317,7 @@ class Compositor: from openpilot.starpilot.ui.pip_render import PiPRenderer self.pip_saved = read_pip(ui_state.params) self.pip_stream = ReplayCameraStream(ui_state) - self.pip = PiPRenderer('bubble', self.pip_stream, frame_availability=PassiveAvailability()) + self.pip = PiPRenderer('curved' if self.profile == 'compact' else 'bubble', self.pip_stream, frame_availability=PassiveAvailability()) self.resources.callback(lambda: self.pip.close()) self._new_view() self.resources.callback(lambda: self.view.close()) @@ -443,15 +443,19 @@ class Compositor: signals = Signals(car is not None, bool(car.leftBlinker) if car else False, bool(car.rightBlinker) if car else False, bool(car.leftBlindspot) if car else False, bool(car.rightBlindspot) if car else False) positions = {} - for side, key in zip(('left', 'right'), CAMERA_WIDGETS, strict=True): + for side, key in zip(('left', 'right'), CAMERA_WIDGETS if self.profile == 'large' else ('pip_left', 'pip_left'), strict=True): position = placement(state.customization, self.profile, key) if position['enabled']: width, height = widget_size(state.customization, self.profile, key) positions[side] = Rect(position['x'], position['y'], width, height) + if submit is not None and self.profile == 'compact': + submit_widget = submit + def submit(_key, draw): + submit_widget('pip_left', draw) status = self.pip.render(rect, saved.mask, signals, enabled=self.cabin, on_blinker=saved.on_blinker, on_bsm=saved.on_bsm, invert=saved.invert, now=now / 1e9, placements=positions, submit=submit) if not self.cabin or status not in ('rendered', 'inactive'): - self.fonts.draw('RECORDED SIDE CAMERA UNAVAILABLE', FontRole.MEDIUM, 18 if self.profile == 'compact' else 25, + self.fonts.draw('RECORDED ADJ SPOT CAMERA UNAVAILABLE', FontRole.MEDIUM, 18 if self.profile == 'compact' else 25, 18 if self.profile == 'compact' else rect.x + 30, 180 if self.profile == 'compact' else rect.y + rect.height - 62, self.rl.Color(245, 200, 155, 255)) @@ -517,7 +521,7 @@ class Compositor: self.pip_stream._client = pip_client self.pip_stream.release_retired() self.pip_stream.reset() - self.pip = PiPRenderer('bubble', self.pip_stream, frame_availability=PassiveAvailability()) + self.pip = PiPRenderer('curved' if self.profile == 'compact' else 'bubble', self.pip_stream, frame_availability=PassiveAvailability()) self.view.close() self.adapter = RuntimeSnapshotAdapter(self.ui) self._new_view() diff --git a/openpilot/starpilot/replay/tests/test_render.py b/openpilot/starpilot/replay/tests/test_render.py index c1c6e0d43e..6d89dfd872 100644 --- a/openpilot/starpilot/replay/tests/test_render.py +++ b/openpilot/starpilot/replay/tests/test_render.py @@ -574,12 +574,14 @@ def test_published_readiness_survives_buffering_but_rejects_seeks_and_old_epochs assert sleeps == [.01] * len(times) # Native playback keeps its original idle wait. +@pytest.mark.parametrize('profile', ('compact', 'large')) @pytest.mark.parametrize('matching_frame', (False, True)) @pytest.mark.parametrize('streams,expected_streams', (({0, 2}, [0, 2]), ([2, 0], [2, 0]))) -def test_epoch_reset_preserves_native_camera_stream_and_eligible_paused_frame(monkeypatch, matching_frame, streams, expected_streams): +def test_epoch_reset_preserves_native_camera_stream_and_eligible_paused_frame(monkeypatch, matching_frame, streams, expected_streams, profile): monkeypatch.setattr('openpilot.starpilot.ui.runtime_snapshot.RuntimeSnapshotAdapter', Mock()) monkeypatch.setattr('openpilot.starpilot.ui.pip_render.PiPRenderer', Mock()) core: Any = object.__new__(Compositor) + core.profile = profile client = Mock(frame_id=5 if matching_frame else 4, timestamp_sof=9_000_000_000, timestamp_eof=9_010_000_000) client.is_connected.return_value = True frame = SimpleNamespace(frame_id=5) @@ -607,6 +609,8 @@ def test_epoch_reset_preserves_native_camera_stream_and_eligible_paused_frame(mo _offroad_transition_callbacks=callbacks) core.render_receipts = {'modelV2': 1} core.reset_epoch(3) + from openpilot.starpilot.ui.pip_render import PiPRenderer + assert PiPRenderer.call_args.args[0] == ('curved' if profile == 'compact' else 'bubble') for callback in callbacks: callback() assert core.render_receipts == {} diff --git a/openpilot/starpilot/ui/layout_preview_renderer.py b/openpilot/starpilot/ui/layout_preview_renderer.py index d9f6ef7767..77f5e22966 100644 --- a/openpilot/starpilot/ui/layout_preview_renderer.py +++ b/openpilot/starpilot/ui/layout_preview_renderer.py @@ -18,7 +18,7 @@ from openpilot.starpilot.ui.raylib import rl from openpilot.starpilot.ui.layout_preview_transport import SCENES, validate_preview_document from openpilot.starpilot.ui.developer_preview import OnroadVisualPreview -from openpilot.starpilot.ui.onroad_customization import (CAMERA_WIDGETS, PROFILES, ROAD_BASE_WIDTH, RUNTIME_PREVIEW_WIDGETS, fit_to_road, placement, +from openpilot.starpilot.ui.onroad_customization import (camera_widgets, PROFILES, ROAD_BASE_WIDTH, RUNTIME_PREVIEW_WIDGETS, fit_to_road, placement, validate_document, widget_size) from openpilot.starpilot.ui.onroad_widget_style import draw_widget_frame from openpilot.starpilot.curve_speed.status import CurveObservation @@ -276,17 +276,21 @@ class _Canvas: if submit is None: self._render_side_cameras(state) return - for key in CAMERA_WIDGETS: + for key in camera_widgets(self.profile): submit(key, lambda key=key: self._render_side_cameras(state, only=key)) def _render_side_cameras(self, state: OnroadState, only=None) -> None: - for key in CAMERA_WIDGETS: + for key in camera_widgets(self.profile): if only is not None and key != only: continue position = placement(state.customization, self.profile, key) if not position["enabled"]: continue widget = PROFILES[str(self.profile)]["widgets"][key] + if self.profile == Profile.COMPACT: + target = rl.Rectangle(position["x"], position["y"], widget["width"], widget["height"]) + rl.draw_rectangle_rounded(target, 0.44, 16, rl.Color(21, 44, 57, 90)) + continue radius = widget["width"] / 2 shift = state.viewport_width - 1860 if self.profile == Profile.LARGE and key == "pip_right" and self.viewport is None else 0 center = rl.Vector2(position["x"] + shift + radius, position["y"] + radius) diff --git a/openpilot/starpilot/ui/onroad_customization.py b/openpilot/starpilot/ui/onroad_customization.py index dad8bf882a..34921b5666 100644 --- a/openpilot/starpilot/ui/onroad_customization.py +++ b/openpilot/starpilot/ui/onroad_customization.py @@ -152,13 +152,19 @@ for _index, (_key, _label) in enumerate(zip(RAIL_WIDGETS, ("Model confidence", " # Keep layouts saved before camera widgets valid when the registry grows. CAMERALESS_WIDGETS = {profile: set(data["widgets"]) for profile, data in PROFILES.items()} CAMERA_WIDGETS = ("pip_left", "pip_right") -for _profile, (_size, _margin) in {"large": (600, 24), "compact": (80, 16)}.items(): + + +def camera_widgets(profile): + return CAMERA_WIDGETS[:1] if str(profile) == "compact" else CAMERA_WIDGETS + + +for _profile, (_width, _height, _margin) in {"large": (600, 600, 24), "compact": (476, 240, 0)}.items(): _bounds = PROFILES[_profile]["bounds"] - for _side, _key in zip(("left", "right"), CAMERA_WIDGETS, strict=True): - _x = _bounds["x"] + (_margin if _side == "left" else _bounds["width"] - _margin - _size) - _y = _bounds["y"] + _bounds["height"] - _margin - _size + for _side, _key in zip(("left", "right"), camera_widgets(_profile), strict=False): + _x = _bounds["x"] + (_margin if _side == "left" else _bounds["width"] - _margin - _width) + _y = _bounds["y"] + _bounds["height"] - _margin - _height PROFILES[_profile]["widgets"][_key] = { - **_widget(f"PiP {_side} side camera", "pip_camera", _size, _size, _x, _y), "layer": "underlay"} + **_widget((f"Adj Spot Camera {_side.title()}" if _profile == "large" else "Adj Spot Camera"), "pip_camera", _width, _height, _x, _y), "layer": "underlay"} MODE_WIDGET = "driving_mode_descriptions" for _profile, _geometry in {"large": (580, 68, 640, 344), "compact": (168, 44, 154, 0)}.items(): @@ -372,7 +378,7 @@ DEFAULT_WIDGET_ORDER = { STOPPED_TIMER_WIDGET, NAV_CARD_WIDGET, JETLINK_WIDGET, SIGNAL_WIDGET, UNIDEN_WIDGET, "rear_fog", "pip_left", "pip_right"), "compact": ("speed_limit", "max_speed", "steering_wheel", "torque_bar", "driver_monitor", *RAIL_WIDGETS, MODE_WIDGET, CLOCK_WIDGET, WEATHER_WIDGET, - STOPPED_TIMER_WIDGET, NAV_CARD_WIDGET, "rear_fog", "pip_left", "pip_right"), + STOPPED_TIMER_WIDGET, NAV_CARD_WIDGET, "rear_fog", "pip_left"), } @@ -427,7 +433,7 @@ def customization_metadata(): def default_document(): - return {"version": 16, "clock24Hour": False, "reduceMotion": False, "palette": dict(PALETTE), "roadColors": {profile: {} for profile in PROFILES}, + return {"version": 17, "clock24Hour": False, "reduceMotion": False, "palette": dict(PALETTE), "roadColors": {profile: {} for profile in PROFILES}, "widgetColors": {profile: {} for profile in PROFILES}, "layouts": { profile: {key: {**widget["default"], **({"size": WIDGET_SIZES[key][profile][1]} if key in WIDGET_SIZES else {})} for key, widget in data["widgets"].items()} @@ -509,7 +515,7 @@ def migrate_confirmation_layout(layout, profile, widgets, bounds, *, extra_heigh def validate_document(value): - if type(value) is not dict or type(value.get("version")) is not int or value["version"] not in range(1, 17): + if type(value) is not dict or type(value.get("version")) is not int or value["version"] not in range(1, 18): raise ValueError("Invalid customization version") if value["version"] < 16: # Version 16 folded the separate speed limit actions widget into the speed limit sign. @@ -521,6 +527,23 @@ def validate_document(value): if type(value.get("widgetOrder")) is dict: value["widgetOrder"] = {profile: [key for key in order if key != "speed_limit_actions"] if type(order) is list else order for profile, order in value["widgetOrder"].items()} + # C4 has one shared camera panel; accept the old pair without changing C3. + compact = value.get("layouts", {}).get("compact") if type(value.get("layouts")) is dict else None + if type(compact) is dict and "pip_right" in compact: + value = copy.deepcopy(value) + compact = value["layouts"]["compact"] + right = compact.pop("pip_right") + left = compact.get("pip_left") + if any(type(item) is not dict or set(item) != {"x", "y", "enabled"} or type(item["enabled"]) is not bool or + any(type(item[axis]) not in (int, float) or not math.isfinite(item[axis]) for axis in ("x", "y")) for item in (left, right)): + raise ValueError("Invalid legacy camera placement") + left["enabled"] = left["enabled"] or right["enabled"] + colors = value.get("widgetColors", {}).get("compact") if type(value.get("widgetColors")) is dict else None + if type(colors) is dict and colors.get("pip_right") == {}: + colors.pop("pip_right") + order = value.get("widgetOrder", {}).get("compact") if type(value.get("widgetOrder")) is dict else None + if type(order) is list: + value["widgetOrder"]["compact"] = [key for key in order if key != "pip_right"] fields = {"version", "palette", "layouts"} | ({"widgetColors"} if value["version"] >= 2 else set()) if value["version"] >= 3: fields.add("roadColors") @@ -587,13 +610,14 @@ def validate_document(value): type(legacy["enabled"]) is not bool or any(type(legacy[axis]) not in (int, float) or not math.isfinite(legacy[axis]) for axis in ("x", "y"))): raise ValueError("Invalid legacy camera placement") - for side, key in enumerate(CAMERA_WIDGETS): + for side, key in enumerate(camera_widgets(profile)): widget = PROFILES[profile]["widgets"][key] position = dict(widget["default"]) if legacy is not None: bounds = widget_bounds(profile, key) + shift = side * widget["width"] if profile == "large" else 0 position.update(enabled=legacy["enabled"], - x=max(bounds["x"], min(legacy["x"], bounds["x"] + bounds["width"] - 2 * widget["width"])) + side * widget["width"], + x=max(bounds["x"], min(legacy["x"], bounds["x"] + bounds["width"] - 2 * widget["width"])) + shift, y=max(bounds["y"], min(legacy["y"], bounds["y"] + bounds["height"] - widget["height"]))) layouts[profile][key] = position layouts = copy.deepcopy(layouts) @@ -670,6 +694,14 @@ def validate_document(value): bounds = data['bounds'] if legacy_signal: _fit_legacy_signal(placement, bounds) + if value["version"] < 17 and profile == "compact" and key in CAMERA_WIDGETS and type(placement) is dict: + # Move the legacy 80px widget into the shared C4 panel. + if any(type(placement.get(axis)) not in (int, float) or not math.isfinite(placement[axis]) for axis in ("x", "y")): + raise ValueError("Invalid widget position") + if key in value["layouts"][profile] and not (0 <= placement["x"] <= bounds["width"] - 80 and + 0 <= placement["y"] <= bounds["height"] - 80): + raise ValueError("Invalid legacy camera position") + placement = layout[key] = {**placement, "x": 0, "y": 0} if (key == JETLINK_WIDGET and type(placement) is dict and type(placement.get('y')) in (int, float) and math.isfinite(placement['y']) and bounds['y'] + bounds['height'] - JETLINK_SIZE[1] < placement['y'] <= bounds['y'] + bounds['height'] - 84): diff --git a/openpilot/starpilot/ui/pip_owner.py b/openpilot/starpilot/ui/pip_owner.py index 164ef4e620..1e80923594 100644 --- a/openpilot/starpilot/ui/pip_owner.py +++ b/openpilot/starpilot/ui/pip_owner.py @@ -24,7 +24,7 @@ RESET = "pip:reset" EDITOR = "pip:mask:editor" FORMAT_PREFIX = "pip:format:" MASK_PREFIX = "pip:mask:" -LABELS = {ENABLED: "Use blind spot camera", BLINKER: "Show on turn signal", +LABELS = {ENABLED: "Use Adj Spot Camera", BLINKER: "Show on turn signal", BSM: "Show on blind spot warning", INVERT: "Mirror camera crop"} @@ -230,7 +230,7 @@ class PiPOwner: reason="" if live else "Open the live crop preview while parked to check the camera.")) defaults = dict.fromkeys(BOOL_KEYS, 'Off') rows = [replace(row, default_value=defaults[row.key]) if row.key in defaults else row for row in rows] - return FeatureSettingsState(page="pip", title="Blind Spot Camera & Preview", + return FeatureSettingsState(page="pip", title="Adj Spot Camera & Preview", subtitle="Choose when to show the camera and adjust its crop from the live preview. " + "Resolution follows the camera automatically.", rows=tuple(rows), parked=parked) diff --git a/openpilot/starpilot/ui/preview_shell.py b/openpilot/starpilot/ui/preview_shell.py index 134d54637d..fda95f5738 100644 --- a/openpilot/starpilot/ui/preview_shell.py +++ b/openpilot/starpilot/ui/preview_shell.py @@ -122,7 +122,7 @@ def reference_feature_scene(scene: str) -> tuple[Destination, str, FeatureSettin elif scene == "settings_pip": rows = (boolean("pip:enabled", "On"), boolean("pip:blinker", "Off"), number, reset, FeatureRow("", "Camera availability", "No fresh cabin frame", reason="Check the live crop preview while parked")) - destination, field, page, title = Destination.APPEARANCE, "appearance", "pip", "Blind Spot Camera & Preview" + destination, field, page, title = Destination.APPEARANCE, "appearance", "pip", "Adj Spot Camera & Preview" else: rows = (boolean("enabled_off", "Off"), boolean("enabled_on", "On"), boolean("disabled_off", "Off", available=False), boolean("disabled_on", "On", available=False), diff --git a/openpilot/starpilot/ui/runtime_app.py b/openpilot/starpilot/ui/runtime_app.py index 71b92dd5e1..d042c53f62 100644 --- a/openpilot/starpilot/ui/runtime_app.py +++ b/openpilot/starpilot/ui/runtime_app.py @@ -170,7 +170,7 @@ class StarShellSession(TeslaSpeedActions): self.network_layer = network_layer self.settings_layer = settings_layer self.fonts = BitmapFonts(profile, Path(font_dir) if font_dir else default_font_directory()) - self.pip_renderer = PiPRenderer("bubble") + self.pip_renderer = PiPRenderer("curved" if profile == Profile.COMPACT else "bubble") self.pip_warning = PiPWarningSource() self._pip_saved = None self._vasm_saved = None @@ -905,7 +905,7 @@ class StarShellSession(TeslaSpeedActions): self.pip_renderer.deactivate() return camera_positions = {} - for side, key in zip(("left", "right"), CAMERA_WIDGETS, strict=True): + for side, key in zip(("left", "right"), CAMERA_WIDGETS if self.profile == Profile.LARGE else ("pip_left", "pip_left"), strict=True): position = placement(state.customization, self.profile, key) if position["enabled"]: width, height = widget_size(state.customization, self.profile, key) @@ -913,9 +913,11 @@ class StarShellSession(TeslaSpeedActions): camera_positions[side] = Rect(position["x"] + shift, position["y"], width, height) status = self.pip_renderer.render(rect, saved.mask, signals, enabled=True, on_blinker=saved.on_blinker, on_bsm=saved.on_bsm, invert=saved.invert, - placements=camera_positions, **({"submit": submit} if submit is not None else {})) + placements=camera_positions, + **({"submit": (lambda _key, draw: submit("pip_left", draw)) if self.profile == Profile.COMPACT else submit} + if submit is not None else {})) if status not in ("rendered", "inactive") and state.alert.size == AlertSize.NONE: - self.fonts.draw("SIDE CAMERA UNAVAILABLE", FontRole.MEDIUM, + self.fonts.draw("ADJ SPOT CAMERA UNAVAILABLE", FontRole.MEDIUM, 18 if self.profile == Profile.COMPACT else 25, 18 if self.profile == Profile.COMPACT else rect.x + 30, 180 if self.profile == Profile.COMPACT else rect.y + rect.height - 62, diff --git a/openpilot/starpilot/ui/tests/test_covered_camera.py b/openpilot/starpilot/ui/tests/test_covered_camera.py index 2fe9254fe7..69c8914728 100644 --- a/openpilot/starpilot/ui/tests/test_covered_camera.py +++ b/openpilot/starpilot/ui/tests/test_covered_camera.py @@ -287,3 +287,9 @@ def test_large_shell_forwards_the_saved_camera_and_temporary_reverse(monkeypatch session.view.camera_layer(rl.Rectangle(0, 0, 2160, 1080), state) kwargs = camera.render_camera_model_layer.call_args.kwargs assert kwargs['camera_view'] is choice and kwargs['reverse_driver'] is reverse + + +@pytest.mark.parametrize('profile,shape', [(runtime_app.Profile.COMPACT, 'curved'), (runtime_app.Profile.LARGE, 'bubble')]) +def test_side_camera_shape_follows_device_profile(lifecycle, monkeypatch, request, profile, shape): + make_session(monkeypatch, request, profile, Mock()) + runtime_app.PiPRenderer.assert_called_once_with(shape) diff --git a/openpilot/starpilot/ui/tests/test_dinish_speed.py b/openpilot/starpilot/ui/tests/test_dinish_speed.py index b8b66af165..1af599e435 100644 --- a/openpilot/starpilot/ui/tests/test_dinish_speed.py +++ b/openpilot/starpilot/ui/tests/test_dinish_speed.py @@ -751,7 +751,7 @@ def test_v5_geometry_migrates_the_card(): doc['layouts']['large']['cruise_limits'].update(x=1550, y=638) doc['layouts']['large']['speed_limit_actions'] = {'x': 1550, 'y': 954, 'enabled': True} migrated = validate_document(doc) - assert migrated['version'] == 16 + assert migrated['version'] == 17 assert migrated['layouts']['large']['cruise_limits'] == default_document()['layouts']['large']['cruise_limits'] assert 'speed_limit_actions' not in migrated['layouts']['large'] assert migrated['speedSources'] is True diff --git a/openpilot/starpilot/ui/tests/test_layout_preview_renderer.py b/openpilot/starpilot/ui/tests/test_layout_preview_renderer.py index d12442b2e1..4cd499c906 100644 --- a/openpilot/starpilot/ui/tests/test_layout_preview_renderer.py +++ b/openpilot/starpilot/ui/tests/test_layout_preview_renderer.py @@ -319,15 +319,22 @@ if __name__ == "__main__": unittest.main() -def test_native_preview_draws_independent_camera_circles_without_camera_input(): +def test_native_preview_matches_camera_geometry_without_camera_input(): for profile, width in ((Profile.COMPACT, 536), (Profile.LARGE, 1860), (Profile.LARGE, 2160)): canvas = _Canvas.__new__(_Canvas) canvas.profile, canvas.viewport = profile, None document = default_document() state = replace(sample_state('engaged', document), viewport_width=width) with patch('openpilot.starpilot.ui.layout_preview_renderer.rl.draw_circle_v') as circle, \ - patch('openpilot.starpilot.ui.layout_preview_renderer.rl.draw_ring') as ring: + patch('openpilot.starpilot.ui.layout_preview_renderer.rl.draw_ring') as ring, \ + patch('openpilot.starpilot.ui.layout_preview_renderer.rl.draw_rectangle_rounded') as panel: canvas._render_side_cameras(state) + if profile == Profile.COMPACT: + assert panel.call_count == 1 + assert circle.call_count == ring.call_count == 0 + target = panel.call_args.args[0] + assert (target.x, target.y, target.width, target.height) == (0, 0, 476, 240) + continue assert circle.call_count == ring.call_count == 2 right_center, radius = circle.call_args.args[:2] assert right_center.x + radius == (width - 54 if profile == Profile.LARGE else 460) diff --git a/openpilot/starpilot/ui/tests/test_onroad_customization.py b/openpilot/starpilot/ui/tests/test_onroad_customization.py index d2b5a3afba..872c13fe15 100644 --- a/openpilot/starpilot/ui/tests/test_onroad_customization.py +++ b/openpilot/starpilot/ui/tests/test_onroad_customization.py @@ -13,7 +13,7 @@ import pytest from openpilot.starpilot.ui.appearance_preferences import OnroadAppearance from openpilot.starpilot.ui.onroad_customization import ( CLOCK_WIDGET, DEFAULT_WIDGET_ORDER, MAX_BYTES, STOPPED_TIMER_WIDGET, customization_metadata, default_document, offset, read_customization, - validate_document, decode_document, widget_palette, rgba, widget_size) + validate_document, camera_widgets, decode_document, widget_palette, rgba, widget_size) from openpilot.starpilot.ui.onroad_compact_widgets import CompactHudRenderer from openpilot.starpilot.ui.onroad_large_widgets import CurrentSpeedHud, UnifiedSpeedWidget, SteeringWheelWidget from openpilot.starpilot.ui.onroad_state import ( @@ -69,7 +69,7 @@ def test_v12_portrait_upgrade_preserves_preferences_and_is_idempotent(): before = copy.deepcopy(old) updated = validate_document(old) expected = copy.deepcopy(old) - expected['version'] = 16 + expected['version'] = 17 expected['layouts']['compact']['speed_limit'].update(x=320, y=16) assert old == before and updated == expected assert validate_document(updated) == updated @@ -120,7 +120,7 @@ def test_v13_notice_upgrade_preserves_preferences_and_only_moves_a_conflicting_s before = copy.deepcopy(old) updated = validate_document(old) expected = copy.deepcopy(old) - expected['version'] = 16 + expected['version'] = 17 expected['layouts']['compact']['speed_limit']['y'] = min(sign_y, 16) assert old == before and updated == expected assert validate_document(updated) == updated @@ -206,7 +206,7 @@ def test_v7_speed_layout_migration_is_bounded_non_mutating_and_idempotent(): original = copy.deepcopy(document) migrated = validate_document(document) assert document == original - assert migrated['version'] == 16 and validate_document(migrated) == migrated + assert migrated['version'] == 17 and validate_document(migrated) == migrated assert migrated['layouts']['large']['cruise_limits']['x'] == 1391 assert migrated['layouts']['large']['current_speed'] == original['layouts']['large']['current_speed'] assert migrated['layouts']['large']['cem_gauge'] == {'x': 56, 'y': 536, 'enabled': True} @@ -235,7 +235,7 @@ def test_v8_restores_only_compact_speed_defaults_and_preserves_customizations(cu original = copy.deepcopy(document) migrated = validate_document(document) assert document == original - assert migrated['version'] == 16 and validate_document(migrated) == migrated + assert migrated['version'] == 17 and validate_document(migrated) == migrated assert migrated['layouts']['large'] == document['layouts']['large'] assert migrated['widgetColors'] == document['widgetColors'] assert migrated['widgetOrder'] == document['widgetOrder'] @@ -274,7 +274,7 @@ def test_v8_layout_without_rails_preserves_customizations(): original = copy.deepcopy(document) migrated = validate_document(document) assert document == original - assert migrated['version'] == 16 and validate_document(migrated) == migrated + assert migrated['version'] == 17 and validate_document(migrated) == migrated assert migrated['layouts']['large'] == original['layouts']['large'] assert migrated['layouts']['compact']['speed_limit'] == default_document()['layouts']['compact']['speed_limit'] assert migrated['palette'] == original['palette'] @@ -387,7 +387,7 @@ def test_v3_layout_migrates_wheel_size_without_changing_saved_placement_or_color for profile in ("large", "compact"): del document["layouts"][profile]["steering_wheel"]["size"] migrated = validate_document(document) - assert migrated["version"] == 16 + assert migrated["version"] == 17 assert migrated["palette"] == document["palette"] assert migrated["layouts"]["large"]["steering_wheel"] == {"x": 1300, "y": 100, "enabled": False, "size": 192} assert migrated["layouts"]["compact"]["steering_wheel"] == {"x": 90, "y": 130, "enabled": True, "size": 50} @@ -425,7 +425,7 @@ def test_pre_action_saved_layout_migrates_without_losing_positions_or_palette(re def test_duplicate_key_cannot_apply_otherwise_valid_placement(): document = default_document() document["layouts"]["large"]["current_speed"]["x"] = 100 - raw = json.dumps(document).replace('"version": 16', '"version": 11, "version": 11').encode() + raw = json.dumps(document).replace('"version": 17', '"version": 11, "version": 11').encode() with patch("openpilot.starpilot.ui.onroad_customization.read_saved", return_value=(raw, True)): assert read_customization(Mock()) == default_document() @@ -440,7 +440,7 @@ def test_v9_large_sign_migration_preserves_customizations_and_clamps_bottom_edge before = deepcopy(old) updated = validate_document(old) assert old == before - assert updated['version'] == 16 + assert updated['version'] == 17 assert updated['layouts']['large']['cruise_limits']['y'] == default_document()['layouts']['large']['cruise_limits']['y'] assert updated['layouts']['compact'] == before['layouts']['compact'] assert validate_document(updated) == updated @@ -680,7 +680,7 @@ def test_v1_palette_positions_and_visibility_migrate_without_mutating_source(): original = copy.deepcopy(old) result = decode_document(json.dumps(old).encode()) assert old == original - assert result['version'] == 16 + assert result['version'] == 17 assert result['palette'] == old['palette'] for profile, layout in old['layouts'].items(): for key, position in layout.items(): @@ -836,28 +836,30 @@ def test_overlapping_sign_stays_visible_and_chooser_keeps_exact_input(): @pytest.mark.parametrize('profile', ['large', 'compact']) -def test_pip_circles_are_independent_widgets_and_migrate_old_camera_pair(profile): +def test_pip_widgets_match_device_geometry_and_migrate_old_camera_pair(profile): import copy document = default_document() metadata = customization_metadata()['profiles'][profile]['widgets'] assert 'vasm' not in metadata - for key in ('pip_left', 'pip_right'): + for key in camera_widgets(profile): assert metadata[key]['kind'] == 'pip_camera' - assert metadata[key]['width'] == metadata[key]['height'] - right = copy.deepcopy(document['layouts'][profile]['pip_right']) + assert metadata[key]['label'] == (f"Adj Spot Camera {key.removeprefix('pip_').title()}" if profile == 'large' else 'Adj Spot Camera') + assert (metadata[key]['width'], metadata[key]['height']) == ((600, 600) if profile == 'large' else (476, 240)) + right = copy.deepcopy(document['layouts']['large']['pip_right']) document['layouts'][profile]['pip_left']['enabled'] = False - assert validate_document(document)['layouts'][profile]['pip_right'] == right + assert validate_document(document)['layouts']['large']['pip_right'] == right legacy = copy.deepcopy(document) for name, layout in legacy['layouts'].items(): layout.pop('pip_left') - layout.pop('pip_right') + layout.pop('pip_right', None) layout['vasm'] = {'x': 1200 if name == 'large' else 300, 'y': 650 if name == 'large' else 30, 'enabled': False} migrated = validate_document(legacy) for name, layout in migrated['layouts'].items(): assert 'vasm' not in layout - assert not layout['pip_left']['enabled'] and not layout['pip_right']['enabled'] - assert layout['pip_left']['x'] <= layout['pip_right']['x'] + assert all(not layout[key]['enabled'] for key in camera_widgets(name)) + if name == 'large': + assert layout['pip_left']['x'] <= layout['pip_right']['x'] assert layout['current_speed' if name == 'large' else 'max_speed'] == document['layouts'][name]['current_speed' if name == 'large' else 'max_speed'] assert validate_document(migrated) == migrated @@ -1053,3 +1055,18 @@ def test_compact_navigation_upgrade_preserves_saved_layout_and_order(): assert upgraded['layouts']['compact']['nav_card'] == default_document()['layouts']['compact']['nav_card'] assert upgraded['widgetOrder']['compact'] == older['widgetOrder']['compact'] + ['nav_card'] assert {k: v for k, v in upgraded['layouts']['compact'].items() if k != 'nav_card'} == older['layouts']['compact'] + + +def test_c4_camera_upgrade_preserves_visibility_and_other_widgets(): + document = default_document() + document["version"] = 16 + document["layouts"]["compact"]["pip_left"].update(x=16, y=144, enabled=False) + document["layouts"]["compact"]["pip_right"] = {"x": 380, "y": 144, "enabled": True} + document["widgetColors"]["compact"]["pip_right"] = {} + document["widgetOrder"] = {profile: list(widgets) for profile, widgets in document["layouts"].items()} + migrated = validate_document(document) + assert migrated["layouts"]["compact"]["pip_left"] == {"x": 0, "y": 0, "enabled": True} + assert "pip_right" not in migrated["layouts"]["compact"] + assert migrated["layouts"]["large"] == document["layouts"]["large"] + assert migrated["layouts"]["compact"]["max_speed"] == document["layouts"]["compact"]["max_speed"] + assert validate_document(migrated) == migrated diff --git a/openpilot/starpilot/ui/tests/test_pip_settings.py b/openpilot/starpilot/ui/tests/test_pip_settings.py index 83c0532e90..198abe0bf1 100644 --- a/openpilot/starpilot/ui/tests/test_pip_settings.py +++ b/openpilot/starpilot/ui/tests/test_pip_settings.py @@ -45,7 +45,7 @@ class PiPSettingsTests(unittest.TestCase): from openpilot.starpilot.ui.onroad_customization import PARAM_KEY, default_document, read_customization document = default_document() document["layouts"]["large"]["pip_left"]["enabled"] = False - document["layouts"]["compact"]["pip_right"]["enabled"] = False + document["layouts"]["compact"]["pip_left"]["enabled"] = False layout = Path(self.params.get_param_path(PARAM_KEY)) layout.write_bytes(json.dumps(document).encode()) from openpilot.starpilot.system.starport.projection_layout import (ProjectionLayoutSource, decode_layout_for_viewport, @@ -61,7 +61,7 @@ class PiPSettingsTests(unittest.TestCase): self.assertTrue(self.owner.apply(action)) saved = read_customization(self.params) self.assertTrue(all(saved["layouts"][profile][key]["enabled"] - for profile in ("large", "compact") for key in ("pip_left", "pip_right"))) + for profile in ("large", "compact") for key in (("pip_left", "pip_right") if profile == "large" else ("pip_left",)))) projected = decode_layout_for_viewport(projection_path.read_bytes(), viewport) self.assertTrue(projected["widgets"]["pip_left"]["enabled"] and projected["widgets"]["pip_right"]["enabled"]) # A camera removed while PiP is on stays removed; turning PiP off does not touch the layout. @@ -111,7 +111,7 @@ class PiPSettingsTests(unittest.TestCase): path = Path(self.params.get_param_path(MASK)) path.write_bytes(original) page = self.owner.snapshot(include_editor=True) - self.assertEqual(page.title, 'Blind Spot Camera & Preview') + self.assertEqual(page.title, 'Adj Spot Camera & Preview') self.assertFalse(any(row.key.startswith(FORMAT_PREFIX) for row in page.rows)) self.assertEqual(path.read_bytes(), original) editor, source = self.owner.editor_with_source() @@ -237,7 +237,7 @@ class PiPSettingsTests(unittest.TestCase): session._pip_request_epoch = 0 session.input = Mock() session._unavailable = Mock() - link = FeatureRow("", "Blind Spot Camera", "", page="pip", available=True) + link = FeatureRow("", "Adj Spot Camera", "", page="pip", available=True) session._appearance_ui(FeatureUiAction("open", link)) self.assertEqual(session.appearance_page, "appearance") session.appearance_page = "pip" @@ -312,7 +312,7 @@ class PiPSettingsTests(unittest.TestCase): patch.object(appearance_compact.gui_app, "texture", return_value=None): appearance_compact.AppearanceCompact(Session()).entry_button().click() parent = shown[-1] - self.assertFalse(any(item.label == "blind spot camera" for item in parent.items)) + self.assertFalse(any(item.label == "Adj Spot Camera" for item in parent.items)) appearance_compact.AppearanceCompact(Session()).open("pip") child = shown[-1] next(item for item in child.items if item.label == "show on turn signal").click() diff --git a/openpilot/starpilot/ui/tests/test_pip_sidecam.py b/openpilot/starpilot/ui/tests/test_pip_sidecam.py index c730b556be..dba3bcdd97 100644 --- a/openpilot/starpilot/ui/tests/test_pip_sidecam.py +++ b/openpilot/starpilot/ui/tests/test_pip_sidecam.py @@ -814,3 +814,28 @@ def test_white_balance_switch_follows_saved_choice(monkeypatch): FakeParams.value = False assert switch.enabled(0.5) assert not switch.enabled(1.5) + + +def test_c4_shell_passes_full_panel_placements_and_saved_triggers(): + from openpilot.starpilot.ui.runtime_app import StarShellSession + from openpilot.starpilot.ui.presentation import Profile + shell = StarShellSession.__new__(StarShellSession) + shell.profile = Profile.COMPACT + shell._pip_saved = SimpleNamespace(enabled=True, mask=starting_mask(1928, 1208), invert=True, + on_blinker=False, on_bsm=True) + shell._pip_signals_cache = Signals(True, False, False, True, False) + shell.pip_renderer = Mock() + shell.pip_renderer.render.return_value = "rendered" + document = default_document() + state = SimpleNamespace(customization=document) + shell._render_pip(Rect(0, 0, 476, 240), state) + options = shell.pip_renderer.render.call_args.kwargs + assert options["placements"] == {"left": Rect(0, 0, 476, 240), "right": Rect(0, 0, 476, 240)} + assert options["on_blinker"] is False and options["on_bsm"] is True and options["invert"] is True + submit, draw = Mock(), Mock() + shell._render_pip(Rect(0, 0, 476, 240), state, submit=submit) + shell.pip_renderer.render.call_args.kwargs["submit"]("pip_right", draw) + submit.assert_called_once_with("pip_left", draw) + document["layouts"]["compact"]["pip_left"]["enabled"] = False + shell._render_pip(Rect(0, 0, 476, 240), state) + assert shell.pip_renderer.render.call_args.kwargs["placements"] == {} diff --git a/openpilot/starpilot/ui/tests/test_slc_confirmation.py b/openpilot/starpilot/ui/tests/test_slc_confirmation.py index 3137dc6e99..f06380aefa 100644 --- a/openpilot/starpilot/ui/tests/test_slc_confirmation.py +++ b/openpilot/starpilot/ui/tests/test_slc_confirmation.py @@ -156,7 +156,7 @@ def test_new_layouts_reject_torque_overlap_and_legacy_migration_is_targeted(prof original = deepcopy(doc) migrated = validate_document(doc) assert doc == original - assert migrated['version'] == 16 + assert migrated['version'] == 17 assert migrated['palette'] == doc['palette'] assert migrated['layouts']['large']['current_speed'] == doc['layouts']['large']['current_speed'] assert migrated['layouts'][str(profile)][owner]['y'] == default_document()['layouts'][str(profile)][owner]['y'] diff --git a/openpilot/starpilot/ui/tests/test_speed_stack.py b/openpilot/starpilot/ui/tests/test_speed_stack.py index 0aaff6fae8..84ae672d36 100644 --- a/openpilot/starpilot/ui/tests/test_speed_stack.py +++ b/openpilot/starpilot/ui/tests/test_speed_stack.py @@ -48,7 +48,7 @@ def test_v4_migration_preserves_settings_and_clamps_only_enlarged_widgets(): doc['layouts']['large']['cruise_limits'].update(x=1654, y=75) old_speed = dict(doc['layouts']['large']['current_speed']) migrated = validate_document(doc) - assert migrated['version'] == 16 + assert migrated['version'] == 17 assert migrated['layouts']['large']['cruise_limits']['x'] == 1391 assert migrated['layouts']['large']['current_speed'] == old_speed assert migrated['speedSources'] is True