Drive as the Design canvas' Grid: the page as 16 × 10 cells from a screen profile (public/drive/road.json, {area, widget, …} per cell, to be edited in the app later), the map 13 × 8 with nothing over it; the manoeuvre, speed, limit, altitude, time, sun, status (online, rec), next stop with km / ETA to it and to the end, the route's elevation of the next 10 km, a compass; keys Trip, Points, Layers, Search, Menu, − + 3D Follow, Terrain, day/dusk/night. A menu opens in the right 7 × 8 as cells of its own and the map narrows to 9 × 8 (drive_menus.js): Trip and Search as GridTrip / GridSearch (a stop a row, ✓ ↑ ↓ ✕ a cell each; results with their pins on the map); Points as GridPoints (the library nearest the car — /api/search with no words and a center lists every saved feature nearest first — along the route ahead, shown, or one folder at a time; an eye per row, + a point as a stop); Layers as GridLayers (the On the map panel's own switches and Online | Offline, presets Road / Off-road / Overnight, + Keep); Terrain as GridTerrain (roll / pitch dials with the max held, climb and side slope ahead from the DEM, the next 2 km, Level here = can.json's levelling action in two taps), on by itself on an unpaved surface (/api/road now gives Valhalla's surface) or past 10° for 10 s, back after 2 km of paved road, automatic / by hand in the Menu. The dashboard polls for the grid without its overlay; the old drive bar and floating buttons gone
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-03 10:47:40 +01:00
1 parent 285af64a65
commit f73badd107
14 files changed
+1253 -277

No files matched your search

+45 -13
View File
@@ -49,7 +49,7 @@ const load = () => {
const RAD = Math.PI / 180;
// meters between two [lon, lat] (equirectangular: fine at these distances)
const meters = ([lon1, lat1], [lon2, lat2]) => Math.hypot((lon2 - lon1) * Math.cos(((lat1 + lat2) / 2) * RAD), lat2 - lat1) * 111320;
const distance = (m) => (m >= 1000 ? `${(m / 1000).toFixed(1)} km` : `${Math.round(m / 10) * 10} m`);
export const distance = (m) => (m >= 1000 ? `${(m / 1000).toFixed(1)} km` : `${Math.round(m / 10) * 10} m`);
const esc = (text) => String(text ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
// An arrow from the bottom center turning by `angle` (° from straight on),
@@ -66,7 +66,7 @@ const uturnPath = (cls) => `<path class="${cls}" d="M14 30 V14 A5 5 0 0 0 4 14 V
// "uturn", "arrive", "roundabout" drawn their own way.
const MANEUVER_ANGLES = { 1: 0, 2: 45, 3: -45, 7: 0, 8: 0, 9: 45, 10: 90, 11: 135, 14: -135, 15: -90, 16: -45, 17: 0, 18: 45, 19: -45,
20: 45, 21: -45, 22: 0, 23: 30, 24: -30, 25: 0, 37: 30, 38: -30 };
function maneuverSvg(type) {
export function maneuverSvg(type) {
let body;
if (type === 12 || type === 13) body = uturnPath("dash-banner__arrow");
else if (type >= 4 && type <= 6) body = `<path class="dash-banner__arrow" d="M8 30 V4 M8 5 H19 L16 9 L19 13 H8"/>`; // a flag: arriving
@@ -163,8 +163,19 @@ const INCLINOMETER = `
<text x="35" y="60" class="dash-caption">pitch</text>
</svg>`;
// The driving grid (driving.js) reads the dashboard: watchDashboard(cb)
// polls the bus while it's on, the overlay's card or not, and hands each
// poll's state to cb; watchDashboard(null) stops that.
let instance = null;
export function watchDashboard(callback) {
if (!instance || !isLoggedIn()) return; // /api/can wants a login
instance._watch = callback;
if (callback && !instance._timer) instance._poll();
}
export class DashboardControl {
constructor(map) {
instance = this;
this._map = map;
this._settings = load();
this._timer = null;
@@ -348,13 +359,15 @@ export class DashboardControl {
this._map.getContainer().appendChild(this._banner);
this._status.hidden = false;
this._status.textContent = "Connecting…";
this._poll();
if (!this._timer) this._poll();
}
_disable() {
this._progress(null);
clearTimeout(this._timer);
this._timer = null;
if (!this._watch) {
this._progress(null);
clearTimeout(this._timer);
this._timer = null;
}
this._card?.remove();
this._card = null;
this._banner?.remove();
@@ -363,6 +376,8 @@ export class DashboardControl {
}
async _poll() {
if (this._busy) return; // the grid and the card both asked
this._busy = true;
try {
const response = await fetch("/api/can", { cache: "no-store" });
if (!response.ok) throw new Error(`HTTP ${response.status}`);
@@ -375,6 +390,7 @@ export class DashboardControl {
}));
this._updateCourse(this._values);
this._simRunning = !!data.simulated; // /sim.html runs it
this._actions = data.actions || []; // can.json's SDO actions (levelling), POST /api/can/actions/<n>
if (this._simRunning) await this._simulateTerrain();
this._navigate();
this._status.textContent = this._simRunning ? "Simulated GNSS" : data.available ? "" : "CAN is off on this server";
@@ -385,7 +401,25 @@ export class DashboardControl {
this._status.textContent = `Can't reach the server: ${e.message}`;
}
this._render();
if (this._card) this._timer = setTimeout(() => this._poll(), POLL_MS);
this._busy = false;
this._watch?.(this.state());
this._timer = this._card || this._watch ? setTimeout(() => this._poll(), POLL_MS) : null;
}
// What the driving grid shows: the signals, the navigation, the heading
// ({ deg, live }), the road's surface (off a route, /api/road), the CAN
// actions, and the km along the route (null off it).
state() {
return { values: this._values, nav: this._nav, heading: this._heading(), simulated: !!this._simRunning, actions: this._actions || [],
surface: this._road?.surface ?? null, course: this._course, atKm: this._route && this._offFixes < OFF_ROUTE_FIXES ? this._lastAt : null };
}
// Driving, the GNSS course; standing, the compass — else the last of either, not live.
_heading() {
const v = this._values;
const moving = v.speed != null && v.speed >= MOVING_MS;
const deg = moving ? this._course ?? v.heading : v.heading ?? this._course;
return deg == null ? null : { deg: (deg + 360) % 360, live: moving ? this._course != null : v.heading != null };
}
_render() {
@@ -414,12 +448,10 @@ export class DashboardControl {
text.textContent = value == null ? "—" : `${value > 0 ? "+" : ""}${Math.round(value)}°`;
text.setAttribute("class", `dash-value dash-${key}-value ${severity(key, value)}`);
}
const moving = v.speed != null && v.speed >= MOVING_MS;
const heading = moving ? this._course ?? v.heading : v.heading ?? this._course;
const live = heading != null && (moving ? this._course != null : v.heading != null);
svg.querySelector(".dash-ring").setAttribute("transform", `rotate(${heading == null ? 0 : -heading})`);
svg.querySelector(".dash-ring").style.opacity = heading == null ? 0.3 : live ? 1 : 0.55;
svg.querySelector(".dash-heading").textContent = heading == null ? "" : `${Math.round((heading + 360) % 360)}°`;
const heading = this._heading();
svg.querySelector(".dash-ring").setAttribute("transform", `rotate(${heading ? -heading.deg : 0})`);
svg.querySelector(".dash-ring").style.opacity = !heading ? 0.3 : heading.live ? 1 : 0.55;
svg.querySelector(".dash-heading").textContent = heading ? `${Math.round(heading.deg)}°` : "";
speed.querySelector("span").textContent = v.speed == null ? "—" : Math.round(v.speed * 3.6);
}