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
+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() {
|
||||
|
||||
Reference in new issue
Block a user