Nodes describe themselves: an SDO client (Can::Sdo) reads each esphome-canopen node's TPDOs and entities (type, name, unit, range) on its first heartbeat, cached by the TPDO layout hash, decoded with no hand-written signals — can.json keeps aliases (with unit conversion) and foreign devices; design doc (NPS planning, cockpit instruments, Unigrid band) with color tokens, the dashboard in cockpit colors; starting the simulation turns the GNSS follow on, the GNSS position an arrow by its course
This commit is contained in:
1 parent
ce290f2162
commit
e92f01db12
12 files changed
+713
-76
No files matched your search
+49
-32
@@ -3,6 +3,16 @@
|
||||
:root {
|
||||
--accent: #546619;
|
||||
--accent-bg: #e1e5cf;
|
||||
/* The Unigrid black band (topbar) — also the instruments' bezel. */
|
||||
--band: #1a1a1a;
|
||||
/* Instruments (the driving view), one meaning per color — docs/design.adoc. */
|
||||
--inst-text: #f2f2f2;
|
||||
--inst-muted: #9aa0a6;
|
||||
--inst-ok: #3ccf4e;
|
||||
--inst-caution: #ffb300;
|
||||
--inst-warning: #ff3b30;
|
||||
--inst-active: #e040fb; /* magenta: the route / waypoint / lane being followed */
|
||||
--inst-selected: #00d5ff; /* cyan: a value set by hand */
|
||||
}
|
||||
|
||||
html, body {
|
||||
@@ -35,7 +45,7 @@ html, body {
|
||||
align-items: center;
|
||||
height: 44px;
|
||||
padding: 0 16px;
|
||||
background: #1a1a1a;
|
||||
background: var(--band);
|
||||
}
|
||||
|
||||
.topbar__brand {
|
||||
@@ -3192,6 +3202,7 @@ html.night {
|
||||
}
|
||||
|
||||
html.night .topbar,
|
||||
html.night .dash-card,
|
||||
html.night img,
|
||||
html.night #map canvas,
|
||||
html.night .maplibregl-marker {
|
||||
@@ -3299,7 +3310,9 @@ html.night .maplibregl-marker {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* The car's dashboard over the map (public/js/dashboard.js). */
|
||||
/* The car's dashboard over the map (public/js/dashboard.js), in the
|
||||
cockpit style (docs/design.adoc): the black band as a see-through bezel,
|
||||
light values, colors only for meaning. */
|
||||
.dash-card {
|
||||
position: absolute;
|
||||
right: 12px;
|
||||
@@ -3307,65 +3320,69 @@ html.night .maplibregl-marker {
|
||||
z-index: 3;
|
||||
padding: 8px;
|
||||
border-radius: 12px;
|
||||
background: rgb(255 255 255 / var(--dash-alpha, 0.45));
|
||||
background: rgb(26 26 26 / var(--dash-alpha, 0.45));
|
||||
backdrop-filter: blur(2px);
|
||||
box-shadow: 0 1px 6px rgb(0 0 0 / calc(var(--dash-alpha, 0.45) * 0.5));
|
||||
box-shadow: 0 1px 6px rgb(0 0 0 / calc(var(--dash-alpha, 0.45) * 0.6));
|
||||
color: var(--inst-text);
|
||||
text-align: center;
|
||||
pointer-events: none;
|
||||
/* readable over the map whatever the background */
|
||||
text-shadow: 0 0 3px #fff, 0 0 3px #fff;
|
||||
/* readable over a light map whatever the bezel's opacity */
|
||||
text-shadow: 0 0 3px #000, 0 0 3px #000;
|
||||
font-family: system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.dash-incl {
|
||||
display: block;
|
||||
width: 190px;
|
||||
height: 190px;
|
||||
font-family: system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.dash-incl text { text-anchor: middle; dominant-baseline: middle; fill: #222; }
|
||||
.dash-face { fill: rgb(246 246 244 / var(--dash-alpha, 0.45)); stroke: #999; stroke-width: 2; }
|
||||
.dash-incl text { paint-order: stroke; stroke: #fff; stroke-width: 3px; }
|
||||
.dash-ring line { stroke: #555; stroke-width: 2; }
|
||||
.dash-incl text { text-anchor: middle; dominant-baseline: middle; fill: var(--inst-text); paint-order: stroke; stroke: #000; stroke-width: 3px; }
|
||||
.dash-face { fill: rgb(0 0 0 / calc(var(--dash-alpha, 0.45) * 0.5)); stroke: var(--inst-muted); stroke-width: 2; }
|
||||
.dash-ring line { stroke: var(--inst-muted); stroke-width: 2; }
|
||||
.dash-ring text { font-size: 14px; font-weight: 600; }
|
||||
.dash-ring .dash-n { fill: #c62828; }
|
||||
.dash-lubber { fill: #c62828; }
|
||||
.dash-ring .dash-n { fill: var(--inst-warning); }
|
||||
.dash-lubber { fill: var(--inst-active); }
|
||||
.dash-heading { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
|
||||
.dash-ground { stroke: #999; stroke-width: 1.5; stroke-dasharray: 3 3; }
|
||||
.dash-car { fill: #37474f; }
|
||||
.dash-wheel { fill: #111; }
|
||||
.dash-ground { stroke: var(--inst-muted); stroke-width: 1.5; stroke-dasharray: 3 3; }
|
||||
.dash-car { fill: var(--inst-text); }
|
||||
.dash-wheel { fill: var(--inst-muted); }
|
||||
.dash-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
|
||||
.dash-caption { font-size: 10px; fill: #777 !important; text-transform: uppercase; letter-spacing: 0.05em; }
|
||||
.dash-incl .dash-warn { fill: #ef6c00; }
|
||||
.dash-incl .dash-bad { fill: #c62828; }
|
||||
.dash-caption { font-size: 10px; fill: var(--inst-muted) !important; text-transform: uppercase; letter-spacing: 0.05em; }
|
||||
.dash-incl .dash-warn { fill: var(--inst-caution); }
|
||||
.dash-incl .dash-bad { fill: var(--inst-warning); }
|
||||
|
||||
.dash-speed { font-size: 14px; color: #555; }
|
||||
.dash-speed span { font-size: 34px; font-weight: 700; color: #222; font-variant-numeric: tabular-nums; }
|
||||
.dash-speed { font-size: 12px; color: var(--inst-muted); text-transform: uppercase; letter-spacing: 0.05em; }
|
||||
.dash-speed span { font-size: 34px; font-weight: 700; color: var(--inst-text); font-variant-numeric: tabular-nums; letter-spacing: 0; }
|
||||
|
||||
/* Navigation on the dashboard: the speed limit sign and what's ahead. */
|
||||
.dash-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; text-align: left; font-size: 13px; color: #333; }
|
||||
.dash-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; text-align: left; font-size: 13px; }
|
||||
/* a road sign stays a road sign: white disc, red ring, black figures */
|
||||
.dash-limit {
|
||||
display: inline-flex; align-items: center; justify-content: center; flex: none;
|
||||
width: 56px; height: 56px; box-sizing: border-box; border: 7px solid #d32f2f; border-radius: 50%;
|
||||
background: #fff; color: #111; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
|
||||
background: #fff; color: #111; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; text-shadow: none;
|
||||
}
|
||||
.dash-limit[hidden] { display: none; }
|
||||
.dash-limit--small { width: 26px; height: 26px; border-width: 3px; font-size: 11px; vertical-align: middle; }
|
||||
/* no limit (Autobahn): the white sign with the black slash */
|
||||
.dash-limit--none { border: 2px solid #111; background: linear-gradient(135deg, transparent 45%, #111 45% 55%, transparent 55%), #fff; }
|
||||
.dash-ahead > div { margin: 2px 0; white-space: nowrap; }
|
||||
.dash-maneuver { max-width: 220px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
|
||||
.dash-maneuver { max-width: 220px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; color: var(--inst-active); }
|
||||
.dash-signal {
|
||||
display: inline-block; width: 8px; height: 20px; vertical-align: middle; border-radius: 3px; background:
|
||||
radial-gradient(circle at 50% 17%, #e53935 2.5px, transparent 3px), radial-gradient(circle at 50% 50%, #fbc02d 2.5px, transparent 3px),
|
||||
radial-gradient(circle at 50% 83%, #43a047 2.5px, transparent 3px), #222;
|
||||
}
|
||||
.dash-lanes { display: flex; gap: 3px; }
|
||||
.dash-card--over { box-shadow: 0 0 0 4px #d32f2f, 0 1px 6px rgba(0, 0, 0, 0.25); }
|
||||
.dash-card--over .dash-speed span { color: #d32f2f; }
|
||||
.dash-lanes svg.dash-lane { width: 26px; height: 34px; border-radius: 4px; background: #eee; }
|
||||
.dash-lane__arrow { fill: none; stroke: #aaa; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.dash-lane--go { background: #1d6fdc !important; }
|
||||
.dash-lane--go .dash-lane__arrow { stroke: #cfe0f7; }
|
||||
.dash-lane--go .dash-lane__take { stroke: #fff; stroke-width: 3; }
|
||||
.dash-offroute { color: #c62828; font-weight: 600; }
|
||||
.dash-card--over { box-shadow: 0 0 0 4px var(--inst-warning), 0 1px 6px rgba(0, 0, 0, 0.25); }
|
||||
.dash-card--over .dash-speed span { color: var(--inst-warning); }
|
||||
.dash-lanes svg.dash-lane { width: 26px; height: 34px; border-radius: 4px; background: rgb(0 0 0 / 0.45); border: 1px solid var(--inst-muted); box-sizing: border-box; }
|
||||
.dash-lane__arrow { fill: none; stroke: var(--inst-muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.dash-lane--go { border-color: var(--inst-active) !important; }
|
||||
.dash-lane--go .dash-lane__arrow { stroke: var(--inst-text); }
|
||||
.dash-lane--go .dash-lane__take { stroke: var(--inst-active); stroke-width: 3; }
|
||||
.dash-offroute { color: var(--inst-caution); font-weight: 600; }
|
||||
/* The GNSS position once it has a course: an arrow, not the dot. */
|
||||
.gnss-marker--arrow { width: 26px; height: 26px; border: none; border-radius: 0; background: none; box-shadow: none; filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.5)); }
|
||||
.gnss-marker--arrow svg { display: block; }
|
||||
@@ -1,5 +1,5 @@
|
||||
import { isLoggedIn } from "/js/auth.js";
|
||||
import { onRouteChanged, requestReroute } from "/js/panels.js";
|
||||
import { onRouteChanged, requestReroute, requestGnssFollow } from "/js/panels.js";
|
||||
|
||||
// The car's dashboard over the map, off the CAN signals (GET /api/can,
|
||||
// names from data/can.json): one inclinometer — compass ring around a rear
|
||||
@@ -251,17 +251,17 @@ export class DashboardControl {
|
||||
}
|
||||
|
||||
// GNSS simulation on the server (POST/DELETE /api/sim/gnss): random
|
||||
// driving from a random place in the offline countries, the map jumping
|
||||
// there with the first fix; on = true / false, null = just read the state.
|
||||
// driving from a random place in the offline countries, the GNSS control
|
||||
// turned on to follow it; on = true / false, null = just read the state.
|
||||
async _simulate(on) {
|
||||
const options = on === true ? { method: "POST", headers: { "Content-Type": "application/json" }, body: "{}" }
|
||||
: on === false ? { method: "DELETE" } : {};
|
||||
this._jumpToFix = on === true;
|
||||
try {
|
||||
const response = await fetch("/api/sim/gnss", options);
|
||||
const state = await response.json();
|
||||
if (!response.ok) throw new Error(state.error || `HTTP ${response.status}`);
|
||||
this._simRunning = state.running;
|
||||
if (on === true && state.running) requestGnssFollow(); // the map follows the simulated position
|
||||
this._simStatus.hidden = !state.error;
|
||||
this._simStatus.textContent = state.error ? `Simulation stopped: ${state.error}` : "";
|
||||
} catch (e) {
|
||||
@@ -305,10 +305,6 @@ export class DashboardControl {
|
||||
// Date has 1 s resolution: +1 so a fresh value isn't "stale"
|
||||
return [key, s && now - s.at < STALE_S + 1 ? s.value : null];
|
||||
}));
|
||||
if (this._jumpToFix && this._simRunning && this._values.lat != null) {
|
||||
this._jumpToFix = false;
|
||||
this._map.jumpTo({ center: [this._values.lon, this._values.lat], zoom: Math.max(this._map.getZoom(), 15) });
|
||||
}
|
||||
this._updateCourse(this._values);
|
||||
this._navigate();
|
||||
this._status.textContent = this._simRunning ? "Simulated GNSS" : data.available ? "" : "CAN is off on this server";
|
||||
|
||||
+22
-1
@@ -1,9 +1,13 @@
|
||||
import { Marker } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||
import { GNSS_ICON } from "/js/icons.js";
|
||||
import { isLoggedIn } from "/js/auth.js";
|
||||
import { onGnssFollow } from "/js/panels.js";
|
||||
|
||||
const POSITION_URL = "/api/gnss/position";
|
||||
const POLL_INTERVAL_MS = 1500;
|
||||
const JUMP_M = 1000; // farther than this from the marker: jump there, not glide (a new simulation)
|
||||
// The position as an arrow, turned by the course once there is one.
|
||||
const ARROW = `<svg viewBox="0 0 24 24" width="26" height="26"><path d="M12 2 L20 21 L12 16.5 L4 21 Z" fill="#2a9d8f" stroke="#fff" stroke-width="2" stroke-linejoin="round"/></svg>`;
|
||||
|
||||
// A sidebar icon that polls /api/gnss/position (the car's receiver, fed
|
||||
// server-side into GNSS_LATEST in app.rb) and shows the fix as a
|
||||
@@ -27,6 +31,11 @@ export function followPosition(map, lngLat, heading, speed, duration) {
|
||||
});
|
||||
}
|
||||
|
||||
// Meters between a MapLibre LngLat and [lon, lat] (equirectangular).
|
||||
function distanceM({ lng, lat }, [lon2, lat2]) {
|
||||
return Math.hypot((lon2 - lng) * Math.cos((lat * Math.PI) / 180), lat2 - lat) * 111320;
|
||||
}
|
||||
|
||||
// The marker moved to lngLat the same way: a linear glide over duration ms.
|
||||
function glideMarker(marker, lngLat, duration) {
|
||||
cancelAnimationFrame(marker._glide);
|
||||
@@ -71,6 +80,7 @@ export class GnssControl {
|
||||
this._flyout = this._container.querySelector(".sidebar-flyout");
|
||||
this._status = this._container.querySelector(".gnss-control__status");
|
||||
this._icon.addEventListener("click", () => this._setEnabled(!this._enabled));
|
||||
onGnssFollow(() => !this._enabled && !this._container.hidden && this._setEnabled(true));
|
||||
|
||||
// GET /api/gnss/position itself requires login too (app.rb) — hidden
|
||||
// here rather than shown and failing on click, same reasoning as
|
||||
@@ -128,6 +138,8 @@ export class GnssControl {
|
||||
// flyTo (with its zoom swoop) only for the first fix, since that's the
|
||||
// one jumping from wherever the map already was; easeTo for later
|
||||
// updates, a plain follow rather than repeating that swoop every poll.
|
||||
const far = this._marker && distanceM(this._marker.getLngLat(), lngLat) > JUMP_M;
|
||||
if (far) this._removeMarker();
|
||||
if (!this._marker) {
|
||||
const el = document.createElement("div");
|
||||
el.className = "gnss-marker";
|
||||
@@ -135,12 +147,21 @@ export class GnssControl {
|
||||
// style's sources/layers, so — unlike the radar/GPX layers — this
|
||||
// survives map.setStyle() (switching Online/Offline) with no extra
|
||||
// re-add handling needed.
|
||||
this._marker = new Marker({ element: el }).setLngLat(lngLat).addTo(this._map);
|
||||
this._marker = new Marker({ element: el, rotationAlignment: "map", pitchAlignment: "map" }).setLngLat(lngLat).addTo(this._map);
|
||||
this._map.flyTo({ center: lngLat, zoom: Math.max(this._map.getZoom(), 15) });
|
||||
} else {
|
||||
glideMarker(this._marker, lngLat, POLL_INTERVAL_MS);
|
||||
followPosition(this._map, lngLat, data.track, data.speed, POLL_INTERVAL_MS);
|
||||
}
|
||||
// an arrow turned by the course, once there is one (a dot until then)
|
||||
if (Number.isFinite(data.track)) {
|
||||
const el = this._marker.getElement();
|
||||
if (!el.classList.contains("gnss-marker--arrow")) {
|
||||
el.classList.add("gnss-marker--arrow");
|
||||
el.innerHTML = ARROW;
|
||||
}
|
||||
this._marker.setRotation(data.track);
|
||||
}
|
||||
}
|
||||
|
||||
_removeMarker() {
|
||||
|
||||
@@ -135,6 +135,18 @@ export function onReroute(callback) {
|
||||
document.addEventListener(REROUTE_EVENT, (event) => callback(event.detail));
|
||||
}
|
||||
|
||||
// Something that moves the GNSS position (the simulation) wants the map
|
||||
// to follow it: the GNSS control turns itself on.
|
||||
const GNSS_FOLLOW_EVENT = "gnss-follow";
|
||||
|
||||
export function requestGnssFollow() {
|
||||
document.dispatchEvent(new CustomEvent(GNSS_FOLLOW_EVENT));
|
||||
}
|
||||
|
||||
export function onGnssFollow(callback) {
|
||||
document.addEventListener(GNSS_FOLLOW_EVENT, callback);
|
||||
}
|
||||
|
||||
export function onRouteChanged(callback) {
|
||||
document.addEventListener(ROUTE_CHANGED_EVENT, (event) => callback(event.detail));
|
||||
return currentRoute;
|
||||
|
||||
Reference in new issue
Block a user