Switches in drive mode, after the Design canvas' GridSwitches: Menu → Switches (only when /api/outputs answers), 3×3 tiles per page with the output's name, On / Off / Flashing / level, the key and mode driving it and its LED colour line, a group per module, All off, More ▸, a tap toggles. The status pill above the car (pypilot's note in SidePanel): ● REC while the trip is recorded, estimated / no fix, hidden when all is well
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-12-04 21:45:04 +01:00
1 parent 82a728e024
commit 88fa2d27a3
5 files changed
+162 -5

No files matched your search

+3 -1
View File
@@ -127,6 +127,7 @@ plan from — the server does the heavy lifting. The UI is built for a mouse tod
stays (the inclinometer all along) / by hand; the surface in its head. The limit as a sign
in the speed field (the next one under it), the speed red past it. Still to do: the surface while
on a route (along the route's edges), the lanes in the manoeuvre cell, the profile served from `data/` once the editor exists
** [x] The status pill above the car (2026-12-04, pypilot's note in the canvas' SidePanel): ● REC while the trip is recorded, estimated (a tunnel) / no fix; hidden when all is well (`gnss.js` `_showTag`)
** [ ] Softkeys: the CAN keypad's labels on the screen edge next to its keys (G1000 style)
** [x] The Trip menu beside the map, not over it (Android Auto's side panel, seen again in
signalk-pypilot-newui): the map narrower, its buttons kept, its center (follow, crosshair,
@@ -473,7 +474,8 @@ are in home-gitops `docs/canopen-nodes.adoc` ("Inšpirácia: Garmin Tread / zūm
** [x] Keypads as channels and bindings, the PDMs' way (2026-12-04, `lib/maptool/keypad.rb`): can.json's `"keypads"` (a PKP by its protocol, or any signals as `inputs`) give channels `pad.K1`, `pad.E3`, `pad.E3 press`; the screen profile's `"bindings"` give each an action (a screen key, zoom, pan, rows), another in an open menu, its LED colour and the colour while on. A keypad's heartbeat labels the screen keys with its channels (back after 5 s without it), a line under them in the LED colour. Not tried on the real node yet
*** [x] Outputs (2026-12-04, `lib/maptool/outputs.rb`): can.json's relay modules (simulated for now, no current measured), a binding's `output` with Toggle / On / Off / Hold / Pulse, Hold off when the keypad goes silent, the state re-sent every 100 ms (the module's 2 s watchdog), the key LED while on; `/sim.html` switches them by hand. Not tried on a real module
*** [x] Positions, strobe and dimmer (2026-12-04): a key steps through outputs (a knob up and down), blinking with a period, a knob's level by a step (a dimmable module: a byte per channel); in /keypad.html and /sim.html. Nothing real behind them yet
*** [ ] Interlocks and conditions (speed, ignition), long press, switch tiles on the screen (docs/design.adoc, the canvas' GridSwitches / GridBinding)
*** [x] Switch tiles on the screen (2026-12-04, the canvas' GridSwitches): Menu → Switches (only when `/api/outputs` answers), 3×3 tiles per page (name, On / Off / Flashing / level, the key and mode driving it, its LED colour line), a group per module, All off, More ▸; a tap toggles (`switchesMenu` in `drive_menus.js`)
*** [ ] Interlocks and conditions (speed, ignition), long press
** [x] CANopen TIME from maptool while no node sends it (2026-12-04, `lib/maptool/can_time.rb`); the GNSS node takes over once esphome-canopen has TIME
*** [ ] A knob's hold (the eye), the focused row's badges in keypad mode, the knobs' LEDs (8Encoder colours over SDO)
** [x] The key mapping in our diagnostics (2026-12-04, `/keypad.html`, the canvas' GridBinding): pick a key or knob (or press it), what it drives, mode, menu, LEDs; saved per car in `data/drive/bindings.json`. Not yet: interlocks, conditions, long press; drive mode picks a change up only on reload
+37 -1
View File
@@ -4937,12 +4937,16 @@ html.driving #app,
.drive-points__bar,
.drive-layers__presets,
.drive-layers__source,
.drive-switches__tiles,
.drive-switches__groups,
.drive-rec__days { gap: 0; background: var(--drive-ground); }
.drive-cell,
.drive-panel__cell,
.drive-panel__empty,
.drive-rec__day,
.drive-panel > :not(.drive-trip__stops, .drive-trip__results, .drive-panel__list, .drive-points__bar, .drive-layers__presets, .drive-layers__source, .drive-rec__days) {
.drive-switches__tiles > *,
.drive-switches__groups > *,
.drive-panel > :not(.drive-trip__stops, .drive-trip__results, .drive-panel__list, .drive-points__bar, .drive-layers__presets, .drive-layers__source, .drive-rec__days, .drive-switches__tiles, .drive-switches__groups) {
margin: var(--drive-half-gap);
border-radius: var(--drive-radius);
}
@@ -4956,6 +4960,10 @@ html.driving.drive-keypad [data-led] { box-shadow: inset 0 calc(-4px * var(--s,
[data-led="cyan"] { --led: #22c3d6; }
[data-led="white"] { --led: #e8e6df; }
[data-led="yellow"] { --led: #f0a020; }
[data-led="red"] { --led: #e8453a; }
[data-led="green"] { --led: #34b545; }
[data-led="blue"] { --led: #3b82f6; }
[data-led="magenta"] { --led: #b45bd0; }
.drive-rec__cutrow { flex: none; height: calc(var(--cell, 80px) / 2); display: flex; align-items: center; gap: 10px; padding-left: 28px; background: var(--band); color: var(--drive-muted); font-size: calc(14px * var(--s, 1)); }
.drive-rec__cutrow span:nth-child(2) { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drive-panel .drive-rec__cutrow button { height: 100%; padding: 0 16px; background: none; border-left: 1px solid var(--drive-line); font-size: calc(14px * var(--s, 1)); font-weight: 700; }
@@ -5035,3 +5043,31 @@ rect.drive-level__none { fill: var(--band-fg); } text.drive-level__none { fill:
.drive-panel button.drive-level__zero,
.drive-panel button.drive-level__under,
.drive-panel button.drive-level__terrain { font-size: calc(16px * var(--s, 1)); font-weight: 700; }
/* Switches (drive_menus.js, the canvas' GridSwitches): tiles 3 × 3 in the
menu's first six columns, the modules down the seventh, All off / More
below; a tile's line is its key's LED colour, full when it's on. */
.drive-switches__tiles { grid-area: 2 / 1 / -2 / 7; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--drive-line); }
.drive-panel button.drive-switches__tile { position: relative; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; padding: 10px 12px 16px; text-align: left; font-size: inherit; min-width: 0; overflow: hidden; }
.drive-panel button.drive-switches__tile[aria-pressed="true"] { background: color-mix(in srgb, var(--led, var(--drive-key-on)) 18%, var(--band)); }
.drive-switches__tile::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 6px; height: 4px; border-radius: 2px; background: var(--led); opacity: 0.35; }
.drive-switches__tile[aria-pressed="true"]::after { opacity: 1; }
.drive-switches__top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: auto; }
.drive-switches__icon { font-size: calc(26px * var(--s, 1)); line-height: 1; color: var(--drive-muted); }
.drive-switches__tile[aria-pressed="true"] .drive-switches__icon { color: var(--led, var(--band-fg)); }
.drive-switches__key { font-size: calc(11px * var(--s, 1)); font-weight: 700; letter-spacing: 0.06em; color: var(--drive-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70%; }
.drive-switches__name { font-size: calc(17px * var(--s, 1)); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drive-switches__state { font-size: calc(13px * var(--s, 1)); color: var(--drive-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drive-switches__tile[aria-pressed="true"] .drive-switches__state { color: var(--band-fg); }
.drive-switches__mode { font-size: calc(11px * var(--s, 1)); color: var(--drive-muted); text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drive-switches__groups { grid-area: 2 / 7 / -2 / 8; display: flex; flex-direction: column; gap: 1px; background: var(--drive-line); }
.drive-panel .drive-switches__groups button { flex: 1; border: none; background: var(--band); color: var(--band-fg); font-size: calc(13px * var(--s, 1)); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; writing-mode: vertical-rl; transform: rotate(180deg); }
.drive-panel .drive-switches__groups button[aria-pressed="true"] { background: var(--drive-key-on); color: #fff; }
.drive-switches__off { grid-area: -2 / 1 / -1 / 4; }
.drive-switches__page { grid-area: -2 / 4 / -1 / 8; }
.drive-panel button.drive-switches__off, .drive-panel button.drive-switches__page { font-size: calc(17px * var(--s, 1)); font-weight: 700; }
/* the status pill above the car (gnss.js _showTag) */
.gnss-tag { display: flex; gap: 6px; padding: 2px 8px; border-radius: 999px; background: rgb(0 0 0 / 0.75); color: #fbbf24; font: 600 11px/1.4 system-ui, sans-serif; white-space: nowrap; pointer-events: none; }
.gnss-tag:empty { display: none; }
.gnss-tag__rec { color: #f87171; }
+96
View File
@@ -924,3 +924,99 @@ export function todayMenu(ctx) {
ctx.routePanel?.onStopsChanged(() => render());
return { el, render, opened: () => { page = 0; render(); } };
}
// Switches (the Design canvas' GridSwitches): can.json's outputs as tiles —
// state, mode, the key that drives it and a line in its LED colour; a tap
// switches it (POST /api/outputs/<module>/<n>, a strobe stops). Groups are
// the modules; nine tiles a page. Polled while open (GET /api/outputs).
const LED = { red: "#e8453a", green: "#34b545", blue: "#3b82f6", yellow: "#f0a020", cyan: "#22c3d6", magenta: "#b45bd0", white: "#e8e6df" };
const TILES = 9;
export function switchesMenu(ctx) {
const el = panel("drive-switches", "Switches", `
<div class="drive-switches__tiles"></div>
<div class="drive-switches__groups"></div>
<button type="button" class="drive-switches__off" data-action="off">All off</button>
<button type="button" class="drive-switches__page" data-action="page"></button>`);
let data = null;
let group = null; // a module's name, null = all
let page = 0;
let timer = null;
const outputsOf = (b) => b.outputs || (b.output ? [b.output] : []);
const short = (input) => input.slice(input.indexOf(".") + 1).replace(/ press$/, " ⏎");
function tiles() {
return data.modules.filter((m) => !group || m.name === group).flatMap((m) => m.channels.map((c) => {
const output = `${m.name}.${c.n}`;
const bound = data.bindings.filter((b) => outputsOf(b).includes(output));
return { m, c, output, bound };
}));
}
function render() {
if (el.hidden || !data) return;
const all = tiles();
const pages = Math.max(1, Math.ceil(all.length / TILES));
page = Math.min(page, pages - 1);
const on = data.modules.reduce((n, m) => n + m.channels.filter((c) => c.on).length, 0);
el.querySelector(".drive-panel__note").textContent = `${on} on${data.modules.every((m) => m.simulated) ? " · simulated" : ""}`;
el.querySelector(".drive-switches__tiles").replaceChildren(...all.slice(page * TILES, page * TILES + TILES).map(({ m, c, output, bound }) => {
const b = bound[0];
const tile = document.createElement("button");
tile.type = "button";
tile.className = "drive-switches__tile";
tile.setAttribute("aria-pressed", String(!!c.on));
tile.style.setProperty("--led", LED[b?.led] || (b ? LED.red : "transparent"));
const state = c.strobe ? "Flashing" : c.on ? `On${c.level != null ? ` · ${Math.round(c.level)} %` : ""}` : `Off${c.level != null ? ` · ${Math.round(c.level)} %` : ""}`;
const mode = bound.map((x) => x.mode || "toggle").filter((x, i, a) => a.indexOf(x) === i).join(" · ");
tile.innerHTML = `<span class="drive-switches__top"><span class="drive-switches__icon" aria-hidden="true">⏻</span><span class="drive-switches__key"></span></span>
<span class="drive-switches__name"></span><span class="drive-switches__state"></span><span class="drive-switches__mode"></span>`;
tile.querySelector(".drive-switches__key").textContent = bound.map((x) => short(x.input)).join(" · ");
tile.querySelector(".drive-switches__name").textContent = c.label || output;
tile.querySelector(".drive-switches__state").textContent = state;
tile.querySelector(".drive-switches__mode").textContent = mode || (c.label ? output : "");
tile.title = `${output}${c.label ? ` · ${c.label}` : ""}`;
tile.addEventListener("click", () => send(`/api/outputs/${encodeURIComponent(m.name)}/${c.n}`));
return tile;
}));
const groups = data.modules.length > 1 ? [null, ...data.modules.map((m) => m.name)] : [];
el.querySelector(".drive-switches__groups").replaceChildren(...groups.map((name) => {
const g = document.createElement("button");
g.type = "button";
g.textContent = name ?? "All";
g.setAttribute("aria-pressed", String(group === name));
g.addEventListener("click", () => { group = name; page = 0; render(); });
return g;
}));
const pageButton = el.querySelector('[data-action="page"]');
pageButton.hidden = pages < 2;
pageButton.textContent = `More ▸ ${page + 1}/${pages}`;
el.querySelector('[data-action="off"]').disabled = !on;
}
async function load() {
try {
const r = await fetch("/api/outputs", { cache: "no-store" });
data = r.ok ? await r.json() : null;
} catch { /* offline for a moment: the last state stays */ }
render();
}
async function send(url, body) {
await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: body && JSON.stringify(body) }).catch(() => {});
load();
}
el.querySelector(".drive-panel__close").addEventListener("click", ctx.close);
el.querySelector('[data-action="page"]').addEventListener("click", () => { page++; if (page * TILES >= tiles().length) page = 0; render(); });
el.querySelector('[data-action="off"]').addEventListener("click", async () => {
const on = data.modules.flatMap((m) => m.channels.filter((c) => c.on).map((c) => `/api/outputs/${encodeURIComponent(m.name)}/${c.n}`));
await Promise.all(on.map((url) => fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: '{"on":false}' }).catch(() => {})));
load();
});
return {
el, render,
// whether this server has outputs at all (the Menu's row shows then)
available: () => fetch("/api/outputs", { cache: "no-store" }).then((r) => r.ok).catch(() => false),
opened: () => { page = 0; load(); clearInterval(timer); timer = setInterval(load, 1000); },
closed: () => clearInterval(timer),
};
}
+8 -3
View File
@@ -7,7 +7,7 @@ import { watchDashboard, maneuverSvg, laneSvg, distance, VOICE_KEY } from "/js/d
import { SPEED_LIMITS, COUNTRY_NAMES, isHeavy, motorwayPayment } from "/js/speed_limits.js";
import { currentVehicle, onVehicle } from "/js/panels.js";
import { formatSunInfo } from "/js/sun.js";
import { pointsMenu, layersMenu, terrainMenu, levelMenu, recordingMenu, todayMenu, elevationHtml, cellButton, bindKey, emptyRow as empty, escapeHtml } from "/js/drive_menus.js";
import { pointsMenu, layersMenu, terrainMenu, levelMenu, recordingMenu, todayMenu, switchesMenu, elevationHtml, cellButton, bindKey, emptyRow as empty, escapeHtml } from "/js/drive_menus.js";
// Driving mode: the grid of docs/design.adoc ("Layout: a grid, not floating
// panels"; the Design canvas' Grid) — the page becomes cells, the map one
@@ -109,6 +109,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
menuPanel.innerHTML = `<div class="drive-panel__head">Menu</div>
<button type="button" class="drive-panel__close" aria-label="Close">✕</button>
<button type="button" class="drive-menu__row" data-action="today">Today ▸ <small>the stops left, tonight, the weather, the day's notes</small></button>
<button type="button" class="drive-menu__row" data-action="switches" hidden>Switches ▸ <small>the relays and lights, what drives them</small></button>
<button type="button" class="drive-menu__row" data-action="overview">The whole route <small>the follow pauses</small></button>
<button type="button" class="drive-menu__row" data-action="terrain-auto"></button>
<button type="button" class="drive-menu__row" data-action="voice"></button>
@@ -150,6 +151,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
renderProfile();
menuPanel.querySelector('[data-action="overview"]').addEventListener("click", overview);
menuPanel.querySelector('[data-action="today"]').addEventListener("click", () => open(today.el));
menuPanel.querySelector('[data-action="switches"]').addEventListener("click", () => open(switches.el));
menuPanel.querySelector('[data-action="leave"]').addEventListener("click", () => set(false));
const crosshair = document.createElement("div");
crosshair.className = "drive-crosshair";
@@ -260,7 +262,9 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
endTrip: () => endTrip(),
});
const today = todayMenu(menuCtx);
const menus = [points, layers, terrain, level, recording, today];
const switches = switchesMenu(menuCtx);
switches.available().then((yes) => { menuPanel.querySelector('[data-action="switches"]').hidden = !yes; });
const menus = [points, layers, terrain, level, recording, today, switches];
let offRoad = false;
let tiltSince = null;
let pavedM = 0;
@@ -356,6 +360,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
logButton.classList.toggle("drive-trip__log--on", !!log?.active);
logState.textContent = log?.active ? `● ${log.folder.replace(/^Trips\//, "")} · ${(log.distance_m / 1000).toFixed(1)} km` : "Not recording";
logState.classList.toggle("drive-trip__log-text--on", !!log?.active);
document.documentElement.classList.toggle("trip-rec", !!log?.active);
};
const endTrip = async () => {
if (!log?.active || !window.confirm(`End the trip "${log.folder}"? Its track stays in the library.`)) return;
@@ -381,7 +386,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
logState.textContent = "Log in to record";
}
map.getContainer().append(crosshair);
app.append(tripPanel, menuPanel, points.el, layers.el, terrain.el, level.el, recording.el, today.el);
app.append(tripPanel, menuPanel, points.el, layers.el, terrain.el, level.el, recording.el, today.el, switches.el);
// --- the grid's cells ---------------------------------------------------
+18
View File
@@ -245,9 +245,27 @@ export class GnssControl {
this._marker.setRotation(data.track);
}
this._marker.getElement().classList.toggle("gnss-marker--estimated", !!data.estimated);
this._showTag(lngLat, data);
}
// The status pill above the car (pypilot's note in the Design canvas' SidePanel): REC while
// drive mode records the trip (it sets .trip-rec on <html>), estimated / no fix; none when all is well
_showTag(lngLat, data) {
const rec = document.documentElement.classList.contains("trip-rec");
const fix = data.estimated ? "estimated" : data.mode >= 2 ? "" : "no fix";
if (!rec && !fix) return this._tag?.getElement().replaceChildren();
if (!this._tag) {
const el = document.createElement("div");
el.className = "gnss-tag";
this._tag = new Marker({ element: el, anchor: "bottom", offset: [0, -16] }).setLngLat(lngLat).addTo(this._map);
}
glideMarker(this._tag, lngLat, POLL_INTERVAL_MS);
this._tag.getElement().innerHTML = (rec ? `<span class="gnss-tag__rec">● REC</span>` : "") + (fix ? `<span>${fix}</span>` : "");
}
_removeMarker() {
this._tag?.remove();
this._tag = null;
if (this._marker) {
this._marker.remove();
this._marker = null;