Drive keys (canvas GridKeys): a screen key's "key" in the profile clicks it (F1 F2 F3 / F5 − + 3 F T N; "keypad" K1–K8 / E3 kept for the keypad), the menus' own buttons too (1 2 3 the scopes / presets, H hide all / all off); in an open menu ↑ ↓ move the row (the keypad's encoder will send the same arrows), Enter its first button, Space its eye, + adds it, ⌫ up a folder, Esc closes. The key in each button's corner and the row in purple with ⏎ ␣ +, from the first key pressed on (a touch-only screen stays clean)
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-12-03 12:27:45 +01:00
1 parent d39e3b5edd
commit 1ee79fff66
6 files changed
+128 -18

No files matched your search

+3
View File
@@ -426,6 +426,9 @@ are in home-gitops `docs/canopen-nodes.adoc` ("Inšpirácia: Garmin Tread / zūm
actions in `data/can.json` — pan, zoom ±, add a point (the position into the library or the actions in `data/can.json` — pan, zoom ±, add a point (the position into the library or the
trip), mark a place, switch views (navigation / overview / dashboard), mute / volume, the trip), mark a place, switch views (navigation / overview / dashboard), mute / volume, the
trip's next stop, night mode; a long press for a second action, the keypad's LEDs showing state trip's next stop, night mode; a long press for a second action, the keypad's LEDs showing state
** [x] Drive mode keys from the keyboard (profile `key`, labels in the corners, ↑ ↓ / Enter / Space / + / Esc in a menu)
** [ ] The keypad's keys and encoder (as ↑ ↓) from the bus into the same keys; its heartbeat switches the labels to `keypad`, gone 5 s back
** [ ] The switch (auto / keyboard / keypad) and the key mapping in our diagnostics
* [ ] A virtual switch panel for the PDM node (like Garmin's PowerSwitch: tiles with icon, * [ ] A virtual switch panel for the PDM node (like Garmin's PowerSwitch: tiles with icon,
label, state and current, groups) + rules: by speed, sun/time of day, geofence (the trip's label, state and current, groups) + rules: by speed, sun/time of day, geofence (the trip's
camp), ignition and battery voltage camp), ignition and battery voltage
+10
View File
@@ -310,6 +310,16 @@ value | action | km}`; widgets `maneuver`, `field`, `status`,
`elevation`, `compass`, `key`); once the editor exists it saves to `elevation`, `compass`, `key`); once the editor exists it saves to
`data/` and the file is the default. `data/` and the file is the default.
*Keys* (artboard GridKeys): a `key` cell's `key` is the keyboard key
that clicks it (the uConsole has no touch), `keypad` the CAN keypad's;
the menus' own buttons carry theirs (1 2 3, H). In an open menu ↑ ↓
move the row (the keypad's encoder sends the same arrows), Enter its
first button, Space its eye, + adds it, ⌫ up a folder, Esc closes.
Every bound button shows its key in the corner, from the first key
pressed on. Still to do: the keypad's keys from the bus, its heartbeat
switching the labels to the keypad by itself, and the switch (auto /
keyboard / keypad) and the mapping in our diagnostics.
*Terrain* (artboard GridTerrain): the inclinometer only off-road — on *Terrain* (artboard GridTerrain): the inclinometer only off-road — on
the road its cells show the elevation ahead. A 7 × 8 panel like a menu, the road its cells show the elevation ahead. A 7 × 8 panel like a menu,
the map 9 × 8: roll (a rear view) and pitch (a side view), each with the map 9 × 8: roll (a rear view) and pitch (a side view), each with
+29
View File
@@ -4714,3 +4714,32 @@ html.driving .dash-card { display: none; } /* the grid's cells and its Terrain v
.drive-terrain__reset { grid-area: 8 / 4 / 9 / 6; } .drive-terrain__reset { grid-area: 8 / 4 / 9 / 6; }
.drive-terrain__road { grid-area: 8 / 6 / 9 / 8; } .drive-terrain__road { grid-area: 8 / 6 / 9 / 8; }
.drive-panel button.drive-terrain__level--armed { background: var(--inst-caution); color: #000; } .drive-panel button.drive-terrain__level--armed { background: var(--inst-caution); color: #000; }
/* Drive keys (canvas GridKeys): the key that does a button in its corner, the
row ↑ ↓ are on in purple with its keys (⏎ the first button, ␣ the eye, + add);
shown from the first key pressed on (html.drive-keys, driving.js) */
html.driving.drive-keys [data-key],
html.driving.drive-keys .drive-focus { position: relative; }
html.driving.drive-keys [data-key]::after,
html.driving.drive-keys .drive-focus--main::after,
html.driving.drive-keys .drive-focus.drive-panel__eye::after,
html.driving.drive-keys .drive-focus.drive-panel__add::after {
content: attr(data-label);
position: absolute;
top: calc(4px * var(--s, 1));
right: calc(5px * var(--s, 1));
padding: 0 calc(4px * var(--s, 1));
border: 1px solid currentColor;
border-radius: 4px;
color: var(--drive-muted);
font-size: calc(11px * var(--s, 1));
font-weight: 700;
line-height: 1.3;
letter-spacing: 0;
text-transform: none;
pointer-events: none;
}
html.driving.drive-keys .drive-focus { outline: 3px solid #b45bd0; outline-offset: -3px; }
html.driving.drive-keys .drive-focus--main::after { content: "⏎"; color: #b45bd0; }
html.driving.drive-keys .drive-focus.drive-panel__eye::after { content: "␣"; color: #b45bd0; }
html.driving.drive-keys .drive-focus.drive-panel__add::after { content: "+"; color: #b45bd0; }
+11 -11
View File
@@ -20,16 +20,16 @@
{ "area": "5 / 14 / 6 / 17", "widget": "field", "value": "toEnd" }, { "area": "5 / 14 / 6 / 17", "widget": "field", "value": "toEnd" },
{ "area": "6 / 14 / 9 / 17", "widget": "elevation", "km": 10 }, { "area": "6 / 14 / 9 / 17", "widget": "elevation", "km": 10 },
{ "area": "9 / 14 / 10 / 17", "widget": "compass" }, { "area": "9 / 14 / 10 / 17", "widget": "compass" },
{ "area": "10 / 1 / 11 / 3", "widget": "key", "action": "trip" }, { "area": "10 / 1 / 11 / 3", "widget": "key", "action": "trip", "key": "F1", "keypad": "K1" },
{ "area": "10 / 3 / 11 / 5", "widget": "key", "action": "points" }, { "area": "10 / 3 / 11 / 5", "widget": "key", "action": "points", "key": "F2", "keypad": "K2" },
{ "area": "10 / 5 / 11 / 7", "widget": "key", "action": "layers" }, { "area": "10 / 5 / 11 / 7", "widget": "key", "action": "layers", "key": "F3", "keypad": "K3" },
{ "area": "10 / 7 / 11 / 9", "widget": "key", "action": "search" }, { "area": "10 / 7 / 11 / 9", "widget": "key", "action": "search", "key": "/", "keypad": "K4" },
{ "area": "10 / 9 / 11 / 11", "widget": "key", "action": "menu" }, { "area": "10 / 9 / 11 / 11", "widget": "key", "action": "menu", "key": "F5", "keypad": "K5" },
{ "area": "10 / 11 / 11 / 12", "widget": "key", "action": "zoomOut" }, { "area": "10 / 11 / 11 / 12", "widget": "key", "action": "zoomOut", "key": "-", "keypad": "E3 ⟲" },
{ "area": "10 / 12 / 11 / 13", "widget": "key", "action": "zoomIn" }, { "area": "10 / 12 / 11 / 13", "widget": "key", "action": "zoomIn", "key": "+", "keypad": "E3 ⟳" },
{ "area": "10 / 13 / 11 / 14", "widget": "key", "action": "pitch" }, { "area": "10 / 13 / 11 / 14", "widget": "key", "action": "pitch", "key": "3", "keypad": "K6" },
{ "area": "10 / 14 / 11 / 15", "widget": "key", "action": "follow" }, { "area": "10 / 14 / 11 / 15", "widget": "key", "action": "follow", "key": "f", "keypad": "E3 ⏎" },
{ "area": "10 / 15 / 11 / 16", "widget": "key", "action": "terrain" }, { "area": "10 / 15 / 11 / 16", "widget": "key", "action": "terrain", "key": "t", "keypad": "K7" },
{ "area": "10 / 16 / 11 / 17", "widget": "key", "action": "palette" } { "area": "10 / 16 / 11 / 17", "widget": "key", "action": "palette", "key": "n", "keypad": "K8" }
] ]
} }
+13 -6
View File
@@ -30,6 +30,13 @@ export function cellButton(cls, html, title, action) {
return el; return el;
} }
// A hardware key for a button: pressed, it clicks it; its label in the corner (driving.js, the keys)
export function bindKey(el, key) {
el.dataset.key = key;
el.dataset.label = key === "-" ? "−" : key.length === 1 ? key.toUpperCase() : key;
return el;
}
export const emptyRow = (text) => Object.assign(document.createElement("p"), { className: "drive-panel__empty", textContent: text }); export const emptyRow = (text) => Object.assign(document.createElement("p"), { className: "drive-panel__empty", textContent: text });
function panel(cls, label, inner) { function panel(cls, label, inner) {
@@ -56,7 +63,7 @@ export function pointsMenu(ctx) {
<div class="drive-points__bar"></div> <div class="drive-points__bar"></div>
<div class="drive-panel__list drive-points__list"></div> <div class="drive-panel__list drive-points__list"></div>
<div class="drive-panel__foot"></div> <div class="drive-panel__foot"></div>
<button type="button" class="drive-panel__wide" data-action="hide-all">Hide all</button>`); <button type="button" class="drive-panel__wide" data-action="hide-all" data-key="h" data-label="H">Hide all</button>`);
const input = el.querySelector("input"); const input = el.querySelector("input");
const bar = el.querySelector(".drive-points__bar"); const bar = el.querySelector(".drive-points__bar");
const list = el.querySelector(".drive-points__list"); const list = el.querySelector(".drive-points__list");
@@ -189,8 +196,8 @@ export function pointsMenu(ctx) {
el.querySelector(".drive-panel__note").textContent = "folders"; el.querySelector(".drive-panel__note").textContent = "folders";
renderFolder(); renderFolder();
} else { } else {
bar.replaceChildren(...[["near", "Near the car"], ["ahead", "Ahead"], ["shown", "Shown"]].map(([id, label]) => { bar.replaceChildren(...[["near", "Near the car"], ["ahead", "Ahead"], ["shown", "Shown"]].map(([id, label], i) => {
const chip = cellButton("scope", label, label, () => { scope = id; render(); }); const chip = bindKey(cellButton("scope", label, label, () => { scope = id; render(); }), String(i + 1));
chip.setAttribute("aria-pressed", String(scope === id)); chip.setAttribute("aria-pressed", String(scope === id));
return chip; return chip;
}), cellButton("mode", `<span class="drive-key__icon">▣</span><span class="drive-key__label">Folders</span>`, "Folders", () => { scope = "folder"; input.value = ""; render(); })); }), cellButton("mode", `<span class="drive-key__icon">▣</span><span class="drive-key__label">Folders</span>`, "Folders", () => { scope = "folder"; input.value = ""; render(); }));
@@ -223,7 +230,7 @@ export function layersMenu(ctx) {
<div class="drive-layers__source"></div> <div class="drive-layers__source"></div>
<div class="drive-panel__list drive-layers__list"></div> <div class="drive-panel__list drive-layers__list"></div>
<div class="drive-panel__foot"></div> <div class="drive-panel__foot"></div>
<button type="button" class="drive-panel__wide" data-action="all-off">All off</button>`); <button type="button" class="drive-panel__wide" data-action="all-off" data-key="h" data-label="H">All off</button>`);
const list = el.querySelector(".drive-layers__list"); const list = el.querySelector(".drive-layers__list");
let order = []; let order = [];
let keeping = false; let keeping = false;
@@ -251,7 +258,7 @@ export function layersMenu(ctx) {
if (el.hidden) return; if (el.hidden) return;
const presets = loadPresets(); const presets = loadPresets();
const current = presetOn(presets); const current = presetOn(presets);
el.querySelector(".drive-layers__presets").replaceChildren(...PRESETS.map(([id, icon, label]) => { el.querySelector(".drive-layers__presets").replaceChildren(...PRESETS.map(([id, icon, label], i) => {
const b = cellButton("preset", `<span class="drive-key__icon">${icon}</span><span class="drive-key__label">${keeping ? `Save as ${label}` : label}</span>`, label, () => { const b = cellButton("preset", `<span class="drive-key__icon">${icon}</span><span class="drive-key__label">${keeping ? `Save as ${label}` : label}</span>`, label, () => {
if (keeping) { if (keeping) {
presets[id] = layers().filter((l) => l.toggle.checked).map((l) => l.name); presets[id] = layers().filter((l) => l.toggle.checked).map((l) => l.name);
@@ -263,7 +270,7 @@ export function layersMenu(ctx) {
render(); render();
}); });
b.setAttribute("aria-pressed", String(!keeping && current === id)); b.setAttribute("aria-pressed", String(!keeping && current === id));
return b; return bindKey(b, String(i + 1));
}), (() => { }), (() => {
const keep = cellButton("mode", `<span class="drive-key__icon">${keeping ? "✕" : "+"}</span><span class="drive-key__label">${keeping ? "Cancel" : "Keep"}</span>`, const keep = cellButton("mode", `<span class="drive-key__icon">${keeping ? "✕" : "+"}</span><span class="drive-key__label">${keeping ? "Cancel" : "Keep"}</span>`,
keeping ? "Cancel" : "Keep what is on as a preset", () => { keeping = !keeping; render(); }); keeping ? "Cancel" : "Keep what is on as a preset", () => { keeping = !keeping; render(); });
+62 -1
View File
@@ -5,7 +5,7 @@ import { formatDuration } from "/js/route.js";
import { isLoggedIn } from "/js/auth.js"; import { isLoggedIn } from "/js/auth.js";
import { watchDashboard, maneuverSvg, distance } from "/js/dashboard.js"; import { watchDashboard, maneuverSvg, distance } from "/js/dashboard.js";
import { formatSunInfo } from "/js/sun.js"; import { formatSunInfo } from "/js/sun.js";
import { pointsMenu, layersMenu, terrainMenu, elevationHtml, cellButton, emptyRow as empty, escapeHtml } from "/js/drive_menus.js"; import { pointsMenu, layersMenu, terrainMenu, 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 // 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 // panels"; the Design canvas' Grid) — the page becomes cells, the map one
@@ -250,6 +250,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
} }
if (panel !== tripPanel && results) backToStops(); // the pins go with the search if (panel !== tripPanel && results) backToStops(); // the pins go with the search
openPanel = panel; openPanel = panel;
row = 0;
tripPanel.hidden = panel !== tripPanel; tripPanel.hidden = panel !== tripPanel;
menuPanel.hidden = panel !== menuPanel; menuPanel.hidden = panel !== menuPanel;
for (const menu of menus) { for (const menu of menus) {
@@ -374,6 +375,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
el.disabled = NOT_YET.has(cell.action) || !keyAction[cell.action]; el.disabled = NOT_YET.has(cell.action) || !keyAction[cell.action];
el.addEventListener("click", () => keyAction[cell.action]?.()); el.addEventListener("click", () => keyAction[cell.action]?.());
if (cell.action === "zoomIn" || cell.action === "zoomOut") el.classList.add("drive-key--big"); if (cell.action === "zoomIn" || cell.action === "zoomOut") el.classList.add("drive-key--big");
if (cell.key) bindKey(el, cell.key); // "keypad" too, for when the keypad is on the bus
} else { } else {
el = document.createElement("div"); el = document.createElement("div");
} }
@@ -546,6 +548,65 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
map.resize(); // the grid came or went map.resize(); // the grid came or went
} }
toggle.addEventListener("click", () => set(!document.documentElement.classList.contains("driving"))); toggle.addEventListener("click", () => set(!document.documentElement.classList.contains("driving")));
// Keys (canvas GridKeys): a screen key's "key" in the profile clicks it, a
// menu's [data-key] buttons too (1 2 3, H); in an open menu ↑ ↓ move the row
// (the keypad's encoder will send the same arrows), Enter its first button,
// Space its eye, + adds it, ⌫ up a folder, Esc closes. The labels in the
// corners show from the first key pressed on, so a touch-only screen stays clean.
// ponytail: keyboard only; the keypad's keys and its heartbeat switching the
// labels to "keypad" wait for the keypad on the bus (and the diagnostics' mapping)
const KEYS_SEEN = "maptool.driveKeys";
let row = 0;
try { if (localStorage.getItem(KEYS_SEEN)) document.documentElement.classList.add("drive-keys"); } catch { /* nothing kept */ }
const norm = (k) => (k.length === 1 ? k.toLowerCase() : k);
const visible = (b) => b.offsetParent && !b.disabled;
const rowsOf = (panel) => {
const rows = new Map();
for (const b of panel.querySelectorAll("button:not(.drive-panel__close)")) {
if (!visible(b)) continue;
const top = Math.round(b.getBoundingClientRect().top);
rows.set(top, [...(rows.get(top) || []), b]);
}
return [...rows].sort((a, b) => a[0] - b[0]).map(([, r]) => r);
};
const markRow = (scroll) => {
for (const b of document.querySelectorAll(".drive-focus")) b.classList.remove("drive-focus", "drive-focus--main");
if (!openPanel || !document.documentElement.classList.contains("drive-keys")) return [];
const rows = rowsOf(openPanel);
row = Math.max(0, Math.min(row, rows.length - 1));
const current = rows[row] || [];
for (const b of current) b.classList.add("drive-focus");
current[0]?.classList.add("drive-focus--main");
if (scroll) current[0]?.scrollIntoView({ block: "nearest" });
return current;
};
let marking = 0; // the menus re-render their rows: the highlight follows, once a frame
new MutationObserver(() => { marking ||= requestAnimationFrame(() => { marking = 0; markRow(false); }); }).observe(app, { childList: true, subtree: true });
document.addEventListener("keydown", (e) => {
if (!document.documentElement.classList.contains("driving") || e.ctrlKey || e.altKey || e.metaKey) return;
const key = norm(e.key);
const move = key === "ArrowUp" ? -1 : key === "ArrowDown" ? 1 : 0;
if (e.target.matches?.("input, textarea, select")) {
if (key === "Escape" || move) e.target.blur(); else return; // typing a search
}
if (!document.documentElement.classList.contains("drive-keys")) {
document.documentElement.classList.add("drive-keys");
try { localStorage.setItem(KEYS_SEEN, "1"); } catch { /* private window: not kept */ }
}
const current = markRow(false);
const press = (b) => (b && visible(b) ? (b.click(), true) : false);
const bound = (scope) => [...(scope?.querySelectorAll("[data-key]") || [])].find((b) => norm(b.dataset.key) === key && visible(b));
let done = false;
if (key === "Escape") done = !!openPanel && (open(null), true);
else if (openPanel && move) { row += move; markRow(true); done = true; }
else if (openPanel && key === "Enter") done = press(current[0]);
else if (openPanel && key === " ") done = press(current.find((b) => b.classList.contains("drive-panel__eye")));
else if (openPanel && key === "Backspace") done = press(openPanel.querySelector(".drive-panel__up"));
if (!done && openPanel && key === "+") done = press(current.find((b) => b.classList.contains("drive-panel__add")));
if (!done) done = press(bound(openPanel) || bound(app));
if (done) e.preventDefault(); // F1, F5, / are the browser's otherwise
});
let saved = null; let saved = null;
try { saved = localStorage.getItem(KEY); } catch { /* nothing kept */ } try { saved = localStorage.getItem(KEY); } catch { /* nothing kept */ }
set(saved === "on"); set(saved === "on");