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 = `

Widgets

{{ activeWidgets.length }} active
-

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.

@@ -443,7 +443,7 @@ export const ONROAD_LAYOUT_TEMPLATE = `
Camera
-

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 = `

Unlock {{ profile?.widgets[state.pipUnlockConfirm]?.label }}?

-

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?

diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout.js b/openpilot/starpilot/galaxy/web/js/onroad-layout.js index 96a19d0cc5..d9534554e1 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout.js @@ -21,7 +21,7 @@ export { layoutDocument, previewDocument, withDisplay, orderedWidgetIds, widgetP const previewVisibilityKey = projection => "gx-layout-preview-visibility-v2:" + (projection ? "starport" : "comma") const oldProjectionVisibilityKey = "gx-layout-preview-visibility-v2:android-auto" function loadPreviewVisibility(projection) { - const hidden = { large: {}, compact: {} } + const hidden = { large: {}, compact: projection ? {} : { pip_left: true } } try { const currentKey = previewVisibilityKey(projection) const raw = localStorage.getItem(currentKey) ?? (projection ? localStorage.getItem(oldProjectionVisibilityKey) : null) @@ -377,7 +377,8 @@ export const LayoutWidgetPreview = { - + + {{ widget.label }} diff --git a/openpilot/starpilot/galaxy/web/js/pip.js b/openpilot/starpilot/galaxy/web/js/pip.js index c8fa376007..535472a403 100644 --- a/openpilot/starpilot/galaxy/web/js/pip.js +++ b/openpilot/starpilot/galaxy/web/js/pip.js @@ -175,22 +175,22 @@ export const PipPage = { }, }, template: ` -
-

Blind Spot Camera & Preview

+
+

Adj Spot Camera & Preview

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.

-
+
Local saved settings are unavailable in preview.