diff --git a/TODO.adoc b/TODO.adoc
index e79e765..adf642b 100644
--- a/TODO.adoc
+++ b/TODO.adoc
@@ -174,11 +174,22 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho
** [ ] Discover our esphome-canopen nodes over SDO (0x1008 name, 0x2001 entity types,
0x2000+0x10·N names/units/min/max, 0x1A00+n TPDO mapping): their entities decoded with no
`can.json`; 0x1008/0x1018 identity for any CANopen device
-** [ ] A configurable dashboard overlay over the map (like dashcams burn it in): widgets picked
- and placed per screen, each bound to a signal — speed, turn signals, brake, … — and one
- combined inclinometer (Pajero style, but one instrument, not three): compass heading, pitch
- and roll, all from the GNSS node (pitch/roll already in its TPDO1; the HMC5883L compass
- still to add to its firmware); GNSS course as the heading until then
+** [x] A node that stops its heartbeat (3 missed) is flagged: one journal line when it goes
+ silent and when it's back (`can: node 2 silent, last heartbeat …`), red in `/can.html`
+** [x] Dashboard overlay (Overlays → Live → Dashboard, `public/js/dashboard.js`): one combined
+ inclinometer (Pajero style, but one instrument, not three) — compass ring around a rear view
+ (roll) and a side view (pitch), amber past 20° roll / 25° pitch, red past 1.5× — and the
+ speed; widgets on/off per device. Heading: driving (≥ 1.5 m/s) the GNSS course from fixes
+ ≥ 5 m apart, standing still the compass (`imu.heading`), else the last course, dimmed
+*** [ ] Widgets placed per screen and bound to any signal — turn signals, brake, … once the
+ car's bridge puts them on the bus
+*** [x] The compass (HMC5883L on node 0x21, TPDO 0x221) as `imu.heading` + `mag.x/y/z` in
+ `can.json` — for orienting while standing; driving uses the GNSS course
+*** [ ] Tilt compensation (pitch/roll from the IMU) and hard-/soft-iron calibration of the
+ heading — ESPHome's is a plain `atan2(y, x)`; in the node, like the levelling
+*** [ ] IMU every 100–200 ms (the node reads it every 5 s today) and levelling done by the
+ node itself, set by an SDO write from a button in `/can.html` — design in home-gitops
+ `docs/canopen-nodes.adoc` ("Nulovanie náklonu a rýchlosť IMU")
=== 3D navigation mode
@@ -186,6 +197,35 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho
heading, pitched ~60°, smooth easing — the tracker's "Navigate" (see the Tablet-friendly
section); follows the MQTT tracker, not the browser's own GNSS control yet
** [ ] Real 3D relief from the raster-dem terrain and Liberty's `building-3d` extrusions while navigating
+* [ ] Full navigation (the car's main screen while driving; everything from our own Valhalla
+ tiles, no online service — Valhalla has OSM `maxspeed`, `traffic_signals` and turn lanes)
+** [x] Basics on the dashboard (`public/js/dashboard.js`): the speed limit as a sign and a red
+ warning over it (+3 km/h); on the route panel's route (≤ 50 m off it): the next limit
+ change and its distance, the distance to the next traffic signal, the next maneuver and
+ its lanes (from 1 km, the lanes to take highlighted). `/api/route` gains `speed_limits`
+ (km → limit, per change), `signals` ([lon, lat, km]) and `maneuvers[].lanes`
+ (`turn_lanes`), from the same `trace_attributes` pass as the countries; the route's
+ signals drawn on the map from z14. Off the route / with none: `POST /api/road`
+ (map-matched last fixes → the road's name and limit), every 4 s while moving
+** [ ] Speed limits that aren't on the edge: `maxspeed:conditional` (time, wet), variable
+ signs, `zone:maxspeed` defaults per country (Valhalla leaves untagged roads empty — show
+ the country's default by road class?), the vehicle's own limits (a camper > 3.5 t: 80/100)
+** [ ] Rerouting when off the route (> 50 m for a while): a new route from the position to the
+ remaining points
+** [ ] Turn-by-turn: the next maneuver big (arrow, distance, street), voice
+ (`speechSynthesis`), the route ahead highlighted / the driven part greyed
+** [ ] Lanes as proper arrows (SVG per direction bit, not Unicode) and only the lanes Valhalla
+ marks for the maneuver; through-lanes guidance before motorway exits
+** [ ] Traffic signals with no route: around the position (Valhalla `locate` or the offline
+ PBF), and only for the direction driven (`traffic_signals:direction`)
+** [ ] The "Navigate" follow mode for the CAN GNSS position (today the MQTT tracker and the
+ browser's GNSS control), the dashboard as part of the driving-mode UI
+** [ ] `locate()` scans the whole route each fix — a window around the last hit on long routes
+** [x] GNSS simulation for trying it without the car (`lib/maptool/gnss_sim.rb`, Dashboard
+ settings → "Simulate driving from the map center", `POST/DELETE /api/sim/gnss`): random
+ trips over our Valhalla (2–8 km each, one after another) at 90 % of the road's limit, a fix
+ a second into the same `gnss.*` signals / GNSS_LATEST as the node's (ignored meanwhile)
+*** [ ] Replay a library track (GPX/FIT with times) instead, at its own speed
* [ ] While following a planned route: the route ahead highlighted, distance to the next
maneuver from Valhalla's directions
diff --git a/app.rb b/app.rb
index 8924b9d..75a6da2 100644
--- a/app.rb
+++ b/app.rb
@@ -12,6 +12,7 @@ require_relative "lib/maptool/google_saved"
require_relative "lib/maptool/routing"
require_relative "lib/maptool/mqtt_client"
require_relative "lib/maptool/can"
+require_relative "lib/maptool/gnss_sim"
require_relative "lib/maptool/sync"
require "ipaddr"
require_relative "lib/maptool/live_store"
@@ -398,13 +399,16 @@ module Maptool
warn "can: #{CAN_CONFIG_PATH}: #{e.message} — CAN off"
[nil, nil]
end
+ # Simulated driving (lib/maptool/gnss_sim.rb) in place of the GNSS node.
+ GNSS_SIM = GnssSim.new(VALHALLA_URL)
+
if CAN_CONFIG && !test?
decoder = CAN_DECODER
CAN_CONFIG.fetch("interfaces", []).each do |interface|
Thread.new do
Can.listen(interface, decoder: decoder, store: CAN_STORE, start_nodes: CAN_CONFIG["nmt_start"]) do |values|
gnss = values.filter_map { |name, value| [name.delete_prefix("gnss.").to_sym, value] if name.start_with?("gnss.") }.to_h
- next if gnss.empty?
+ next if gnss.empty? || GNSS_SIM.running?
GNSS_LATEST_MUTEX.synchronize do
GNSS_LATEST.merge!(gnss)
@@ -654,6 +658,21 @@ module Maptool
halt 503, json(error: e.message)
end
+ # The road being driven ({"points": [[lon, lat], ...]}, the last few
+ # fixes): name and speed limit, for the dashboard. Open like /api/route.
+ post "/api/road" do
+ points = JSON.parse(request.body.read)["points"]
+ halt 400, json(error: "points must be a list of [lon, lat]") unless points.is_a?(Array) && points.all?(Array)
+
+ json Routing.road(VALHALLA_URL, points.last(10))
+ rescue JSON::ParserError
+ halt 400, json(error: "invalid JSON")
+ rescue Routing::RouteError => e
+ halt 422, json(error: e.message)
+ rescue Routing::Unavailable => e
+ halt 503, json(error: e.message)
+ end
+
# Where the vehicle profile gets in each of `minutes` from `center`
# ({"center": [lon, lat], "minutes": [30, 60]}). Open like /api/route.
post "/api/isochrone" do
@@ -1217,6 +1236,35 @@ module Maptool
json snapshot.merge(available: !CAN_CONFIG.nil?)
end
+ # The GNSS simulation: POST {"start": [lon, lat]} drives randomly from
+ # there, DELETE stops it, GET says whether it's on (and why it stopped).
+ get "/api/sim/gnss" do
+ require_login!
+ json running: GNSS_SIM.running?, error: GNSS_SIM.error
+ end
+
+ post "/api/sim/gnss" do
+ require_login!
+ lon, lat = JSON.parse(request.body.read)["start"]
+ halt 400, json(error: "start must be [lon, lat]") unless lon.is_a?(Numeric) && lat.is_a?(Numeric)
+
+ CAN_STORE.override_prefix = "gnss."
+ GNSS_SIM.start(lon, lat) do |fix|
+ CAN_STORE.put(fix.transform_keys { |key| "gnss.#{key}" })
+ GNSS_LATEST_MUTEX.synchronize { GNSS_LATEST.merge!(fix, received_at: Time.now.to_f) }
+ end
+ json running: true
+ rescue JSON::ParserError
+ halt 400, json(error: "invalid JSON")
+ end
+
+ delete "/api/sim/gnss" do
+ require_login!
+ GNSS_SIM.stop
+ CAN_STORE.override_prefix = nil
+ json running: false
+ end
+
get "/api/live" do
require_login!
json LIVE_STORE.snapshot.merge(available: !MQTT_URL.empty?)
diff --git a/docs/deployment.adoc b/docs/deployment.adoc
index b38dbf4..8959980 100644
--- a/docs/deployment.adoc
+++ b/docs/deployment.adoc
@@ -244,10 +244,17 @@ same node) isn't in the firmware yet:
{ "name": "gnss.satellites", "id": "0x4A1", "byte": 6, "type": "u8", "scale": 1.0039370078740157, "invalid": 255 },
{ "name": "imu.pitch", "id": "0x2A1", "byte": 0, "type": "u16", "scale": 0.005493331705679495, "offset": -180, "invalid": 65535, "unit": "°" },
{ "name": "imu.roll", "id": "0x2A1", "byte": 2, "type": "u16", "scale": 0.005493331705679495, "offset": -180, "invalid": 65535, "unit": "°" },
- { "name": "imu.temperature", "id": "0x2A1", "byte": 4, "type": "u16", "scale": 0.0025177770317697684, "offset": -40, "invalid": 65535, "unit": "°C" } ] }
+ { "name": "imu.temperature", "id": "0x2A1", "byte": 4, "type": "u16", "scale": 0.0025177770317697684, "offset": -40, "invalid": 65535, "unit": "°C" },
+ { "name": "mag.x", "id": "0x221", "byte": 0, "type": "u16", "scale": 0.006103701895199438, "offset": -200, "invalid": 65535, "unit": "µT" },
+ { "name": "mag.y", "id": "0x221", "byte": 2, "type": "u16", "scale": 0.006103701895199438, "offset": -200, "invalid": 65535, "unit": "µT" },
+ { "name": "mag.z", "id": "0x221", "byte": 4, "type": "u16", "scale": 0.006103701895199438, "offset": -200, "invalid": 65535, "unit": "µT" },
+ { "name": "imu.heading", "id": "0x221", "byte": 6, "type": "u16", "scale": 0.005493331705679495, "invalid": 65535, "unit": "°" } ] }
----
-Speed's scale also converts km/h to m/s (`300 / 65534 / 3.6`). The node
+Speed's scale also converts km/h to m/s (`300 / 65534 / 3.6`). 0x221 is
+the HMC5883L (TPDO 4 → `0x200 + node`): the field ±200 µT and ESPHome's
+heading 0..360°, plain `atan2(y, x)` — no tilt compensation or hard-iron
+calibration yet, so only roughly right standing level. The node
goes operational by itself, so no `nmt_start`.
=== Map data (one way)
diff --git a/lib/maptool/gnss_sim.rb b/lib/maptool/gnss_sim.rb
new file mode 100644
index 0000000..7021a92
--- /dev/null
+++ b/lib/maptool/gnss_sim.rb
@@ -0,0 +1,100 @@
+require_relative "routing"
+
+module Maptool
+ # Simulated driving, to try the dashboard and navigation without the car:
+ # from a start point it routes (our Valhalla) to a random point 2–8 km
+ # away and drives there at the road's speed limit, a fix a second, then
+ # on to the next random point. Its fixes go where the GNSS node's do
+ # (app.rb: the CAN store's gnss.* signals and GNSS_LATEST), the node's own
+ # are ignored meanwhile.
+ class GnssSim
+ TICK_S = 1.0
+ DEST_KM = (2.0..8.0)
+ NO_LIMIT_KMH = 50 # an untagged road
+ UNLIMITED_KMH = 130
+ LIMIT_SHARE = 0.9 # drives a bit under the limit
+
+ attr_reader :error
+
+ def initialize(valhalla_url, vehicle: { id: "car" }, random: Random.new, sleep: ->(s) { Kernel.sleep(s) })
+ @valhalla_url = valhalla_url
+ @vehicle = vehicle
+ @random = random
+ @sleep = sleep
+ @thread = nil
+ @mutex = Mutex.new
+ end
+
+ def running?
+ @mutex.synchronize { @thread&.alive? || false }
+ end
+
+ # Drives from [lon, lat] until stopped; each fix to the block:
+ # { lat:, lon:, speed: m/s, satellites:, hdop: }.
+ def start(lon, lat, &on_fix)
+ stop
+ @error = nil
+ @mutex.synchronize do
+ @thread = Thread.new do
+ position = [Float(lon), Float(lat)]
+ loop { position = drive(position, &on_fix) }
+ rescue StandardError => e
+ @error = e.message
+ warn "gnss sim: #{e.message}"
+ end
+ end
+ end
+
+ def stop
+ thread = @mutex.synchronize { @thread.tap { @thread = nil } }
+ thread&.kill&.join
+ end
+
+ # One random trip from position; returns where it ended.
+ def drive(position, &on_fix)
+ route = random_route(position)
+ coords = route[:geometry][:coordinates]
+ km = [0.0]
+ coords.each_cons(2) { |a, b| km << km.last + self.class.meters(a, b) / 1000 }
+ limits = route[:properties][:speed_limits] || [[0.0, nil]]
+ at = 0.0
+ i = 1
+ while i < coords.size
+ kmh = speed_kmh(limits.reverse.find { |start, _| start <= at }&.last)
+ at += kmh / 3600 * TICK_S
+ i += 1 while i < coords.size - 1 && km[i] < at
+ t = km[i] > km[i - 1] ? ((at - km[i - 1]) / (km[i] - km[i - 1])).clamp(0.0, 1.0) : 1.0
+ lon, lat = coords[i - 1].zip(coords[i]).map { |a, b| a + (b - a) * t }
+ on_fix&.call(lat: lat, lon: lon, speed: kmh / 3.6, satellites: 12, hdop: 0.8)
+ break if i == coords.size - 1 && t >= 1
+
+ @sleep.call(TICK_S)
+ end
+ coords.last
+ end
+
+ def speed_kmh(limit)
+ (limit == "unlimited" ? UNLIMITED_KMH : limit || NO_LIMIT_KMH) * LIMIT_SHARE
+ end
+
+ # A route to a random point DEST_KM away; a few tries (a lake, no road there).
+ def random_route(position)
+ last = nil
+ 5.times do
+ bearing = @random.rand * 2 * Math::PI
+ distance = @random.rand(DEST_KM) * 1000
+ lon, lat = position
+ dest = [lon + distance * Math.sin(bearing) / (111_320 * Math.cos(lat * Math::PI / 180)), lat + distance * Math.cos(bearing) / 111_320]
+ route = Routing.route(@valhalla_url, [position, dest], @vehicle)
+ return route if route[:geometry][:coordinates].size >= 2
+ rescue Routing::RouteError => e
+ last = e
+ end
+ raise Routing::RouteError, "no route from #{position.map { |v| v.round(5) }.join(', ')}: #{last&.message}"
+ end
+
+ def self.meters((lon1, lat1), (lon2, lat2))
+ Math.hypot((lon2 - lon1) * Math.cos((lat1 + lat2) / 2 * Math::PI / 180), lat2 - lat1) * 111_320
+ end
+ end
+end
diff --git a/lib/maptool/routing.rb b/lib/maptool/routing.rb
index d27fe63..55c25c7 100644
--- a/lib/maptool/routing.rb
+++ b/lib/maptool/routing.rb
@@ -246,27 +246,39 @@ module Maptool
costing, options = costing(vehicle, avoid)
data = valhalla(valhalla_url, "/route",
locations: locations.map { |lon, lat| { lon: Float(lon), lat: Float(lat) } },
- costing: costing, costing_options: { costing => options }, units: "kilometers")
+ costing: costing, costing_options: { costing => options }, units: "kilometers", turn_lanes: true)
legs = data["trip"]["legs"]
+ along = (along_route(valhalla_url, legs, costing, options) if %w[auto truck].include?(costing)) || {}
{ type: "Feature",
geometry: { type: "LineString", coordinates: legs.flat_map { |leg| decode_polyline(leg["shape"]) } },
properties: { kind: "route", costing: costing, distance_km: data["trip"]["summary"]["length"],
- time_s: data["trip"]["summary"]["time"],
- countries: (countries(valhalla_url, legs, costing, options) if %w[auto truck].include?(costing)),
- maneuvers: legs.flat_map { |leg| leg["maneuvers"].map { |m| { text: m["instruction"], km: m["length"] } } } } }
+ time_s: data["trip"]["summary"]["time"], countries: along[:countries],
+ speed_limits: along[:speed_limits], signals: along[:signals],
+ # lanes: Valhalla's [{directions:, valid:, active:}] bitmasks, at junctions that have them
+ maneuvers: legs.flat_map { |leg| leg["maneuvers"].map { |m| { text: m["instruction"], km: m["length"], lanes: m["lanes"] }.compact } } } }
rescue ArgumentError, TypeError
raise RouteError, "invalid coordinates"
end
- # [{ code: "AT", km:, motorway_km:, toll_km: }, ...] in route order, from
- # Valhalla's per-edge attributes. nil if that lookup fails: it's extra.
- def self.countries(valhalla_url, legs, costing, options)
+ # From Valhalla's per-edge attributes along the route:
+ # countries: [{ code: "AT", km:, motorway_km:, toll_km: }, ...] in route
+ # order (vignettes, tolls);
+ # speed_limits: [[km from the start, km/h | "unlimited" | nil], ...], an
+ # entry where the limit changes (nil: not tagged);
+ # signals: [[lon, lat, km from the start], ...], the traffic signals.
+ # nil if that lookup fails: it's extra.
+ def self.along_route(valhalla_url, legs, costing, options)
totals = {}
+ limits = []
+ signals = []
+ km = 0.0
legs.each do |leg|
+ shape = decode_polyline(leg["shape"])
data = valhalla(valhalla_url, "/trace_attributes",
encoded_polyline: leg["shape"], shape_match: "edge_walk", costing: costing,
costing_options: { costing => options },
- filters: { attributes: %w[edge.length edge.road_class edge.toll node.admin_index admin.country_code], action: "include" })
+ filters: { attributes: %w[edge.length edge.road_class edge.toll edge.speed_limit edge.end_shape_index
+ node.admin_index node.traffic_signal admin.country_code], action: "include" })
codes = data["admins"].map { |admin| admin["country_code"] }
data["edges"].each do |edge|
code = codes[edge.dig("end_node", "admin_index").to_i] || "?"
@@ -274,13 +286,41 @@ module Maptool
row[:km] += edge["length"]
row[:motorway_km] += edge["length"] if edge["road_class"] == "motorway"
row[:toll_km] += edge["length"] if edge["toll"]
+ limit = speed_limit(edge["speed_limit"])
+ limits << [km.round(3), limit] if limits.empty? || limits.last[1] != limit
+ km += edge["length"]
+ point = shape[edge["end_shape_index"].to_i] if edge.dig("end_node", "traffic_signal")
+ signals << [*point, km.round(3)] if point
end
end
- totals.values.each { |row| row.transform_values! { |v| v.is_a?(Float) ? v.round(1) : v } }
+ { countries: totals.values.each { |row| row.transform_values! { |v| v.is_a?(Float) ? v.round(1) : v } },
+ speed_limits: limits, signals: signals }
rescue RouteError, Unavailable, Net::ReadTimeout, NoMethodError, TypeError
nil
end
- private_class_method :countries
+ private_class_method :along_route
+
+ # Valhalla's speed_limit: km/h, "unlimited" (a German Autobahn), else nil
+ # (0 or missing = not tagged).
+ def self.speed_limit(value)
+ value == "unlimited" || (value.is_a?(Integer) && value.positive?) ? value : nil
+ end
+
+ # The road at the end of a short trace ([[lon, lat], ...] oldest first,
+ # the last few fixes) for driving without a route: its name, class and
+ # speed limit. Map-matched, so the road actually driven, not just the
+ # nearest one (a bridge over the motorway).
+ def self.road(valhalla_url, points)
+ raise RouteError, "at least two points are needed" if points.size < 2
+
+ data = valhalla(valhalla_url, "/trace_attributes",
+ shape: points.map { |lon, lat| { lon: Float(lon), lat: Float(lat) } }, costing: "auto", shape_match: "map_snap",
+ filters: { attributes: %w[edge.names edge.road_class edge.speed_limit], action: "include" })
+ edge = data["edges"]&.last or raise RouteError, "no road here"
+ { name: edge["names"]&.first, road_class: edge["road_class"], speed_limit: speed_limit(edge["speed_limit"]) }
+ rescue ArgumentError, TypeError
+ raise RouteError, "invalid coordinates"
+ end
ISOCHRONE_MAX_MINUTES = 240 # Valhalla's own default limit
diff --git a/public/css/style.css b/public/css/style.css
index af91dfc..5038394 100644
--- a/public/css/style.css
+++ b/public/css/style.css
@@ -3284,3 +3284,66 @@ html.night .maplibregl-marker {
.gpx-panel__action[hidden] {
display: none;
}
+
+/* The car's dashboard over the map (public/js/dashboard.js). */
+.dash-card {
+ position: absolute;
+ right: 12px;
+ bottom: 36px;
+ z-index: 3;
+ padding: 8px;
+ border-radius: 12px;
+ background: #fff;
+ box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
+ text-align: center;
+ pointer-events: none;
+}
+
+.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: #f6f6f4; stroke: #bbb; stroke-width: 2; }
+.dash-ring line { stroke: #555; stroke-width: 2; }
+.dash-ring text { font-size: 14px; font-weight: 600; }
+.dash-ring .dash-n { fill: #c62828; }
+.dash-lubber { fill: #c62828; }
+.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-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-speed { font-size: 14px; color: #555; }
+.dash-speed span { font-size: 34px; font-weight: 700; color: #222; font-variant-numeric: tabular-nums; }
+
+/* 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-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;
+}
+.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-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-lanes span { min-width: 22px; padding: 1px 3px; border-radius: 4px; background: #eee; color: #999; text-align: center; font-size: 16px; }
+.dash-lanes .dash-lane--go { background: #1d6fdc; color: #fff; }
+.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; }
diff --git a/public/js/dashboard.js b/public/js/dashboard.js
new file mode 100644
index 0000000..75e7258
--- /dev/null
+++ b/public/js/dashboard.js
@@ -0,0 +1,324 @@
+import { isLoggedIn } from "/js/auth.js";
+import { onRouteChanged } 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
+// view (roll) and a side view (pitch) — and the speed. Which widgets show
+// is per device (localStorage); levelling is the node's own (its offsets,
+// set from /can.html). Turn signals / brake: when they're on the bus.
+// Heading: driving, the GNSS course (from consecutive fixes); standing
+// still, the compass (imu.heading, once the node sends it) — else the
+// last course stays, dimmed.
+const SIGNALS = { pitch: "imu.pitch", roll: "imu.roll", heading: "imu.heading", speed: "gnss.speed", lat: "gnss.lat", lon: "gnss.lon" };
+const MOVING_MS = 1.5; // m/s: above this the GNSS course counts
+const COURSE_MIN_M = 5; // fixes closer than this: too noisy for a course
+const POLL_MS = 500;
+const STALE_S = 5; // older signal: shown as missing
+const WARN = { roll: 20, pitch: 25 }; // ° — amber past these, red past 1.5×
+const STORE_KEY = "maptool.dashboard";
+// Navigation (the speed limit, what's ahead): along the route panel's route
+// while on it (its speed_limits / signals / maneuvers from /api/route),
+// else the limit of the road being driven (POST /api/road, map-matched).
+const OVER_KMH = 3; // over the limit by more than this: warning
+const ON_ROUTE_M = 50; // farther from the route line: off it
+const ROAD_EVERY_MS = 4000; // /api/road at most this often, only while moving
+const TRACE_STEP_M = 10; // fixes kept for /api/road at least this far apart
+const LANES_AHEAD_M = 1000; // the next maneuver's lanes from this close
+const DEFAULT_WIDGETS = { inclinometer: true, speed: true, navigation: true };
+
+const load = () => {
+ try { const saved = JSON.parse(localStorage.getItem(STORE_KEY)) || {}; return { ...saved, widgets: { ...DEFAULT_WIDGETS, ...saved.widgets } }; }
+ catch { return { widgets: { ...DEFAULT_WIDGETS } }; }
+};
+
+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`);
+// Valhalla's lane direction bits → arrows
+const LANE_ARROWS = [[2, "↑"], [16, "↖"], [8, "←"], [4, "↙"], [32, "↗"], [64, "→"], [128, "↘"], [256, "↶"], [512, "⇤"], [1024, "⇥"]];
+const laneArrows = (bits) => LANE_ARROWS.filter(([bit]) => bits & bit).map(([, arrow]) => arrow).join("") || "↑";
+
+// A route prepared for "where am I on it": km at every vertex, maneuvers' start km.
+function prepareRoute(route) {
+ if (!route?.properties?.speed_limits) return null;
+ const coords = route.geometry.coordinates;
+ const km = [0];
+ for (let i = 1; i < coords.length; i++) km.push(km[i - 1] + meters(coords[i - 1], coords[i]) / 1000);
+ let start = 0;
+ const maneuvers = route.properties.maneuvers.map((m) => { const at = start; start += m.km; return { ...m, at }; });
+ return { coords, km, limits: route.properties.speed_limits, signals: route.properties.signals || [], maneuvers };
+}
+
+// Nearest point on the route: [km along it, meters off it].
+// ponytail: scans every segment each fix — a window around the last hit if long routes get slow.
+function locate(route, position) {
+ let best = [0, Infinity];
+ const { coords, km } = route;
+ const cos = Math.cos(position[1] * RAD);
+ for (let i = 1; i < coords.length; i++) {
+ const [ax, ay] = [coords[i - 1][0] * cos, coords[i - 1][1]];
+ const [bx, by] = [coords[i][0] * cos, coords[i][1]];
+ const [px, py] = [position[0] * cos, position[1]];
+ const len2 = (bx - ax) ** 2 + (by - ay) ** 2;
+ const t = len2 ? Math.max(0, Math.min(1, ((px - ax) * (bx - ax) + (py - ay) * (by - ay)) / len2)) : 0;
+ const off = Math.hypot(px - (ax + t * (bx - ax)), py - (ay + t * (by - ay))) * 111320;
+ if (off < best[1]) best = [km[i - 1] + t * (km[i] - km[i - 1]), off];
+ }
+ return best;
+}
+
+const ticks = Array.from({ length: 36 }, (_, i) => {
+ const a = i * 10;
+ const long = a % 30 === 0;
+ return `