Keypads as channels and bindings, the PDMs' way (lib/maptool/keypad.rb): can.json's keypads (a Blink Marine PKP by its protocol, or any signals as inputs) give channels pad.K1, pad.E3, pad.E3 press; the drive profile's bindings give each a screen action, a knob action (zoom, pan, rows), another in an open menu and its LED colour, sent back to the PKP. Outputs (lib/maptool/outputs.rb): relay modules (simulated, no current measured), a binding's output with toggle/on/off/hold/pulse, hold off when the keypad goes silent, the state re-sent every 100 ms; /sim.html switches them by hand. CANopen TIME from maptool while no other node sends it (lib/maptool/can_time.rb), shown in /can.html
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-04 16:14:39 +01:00
1 parent bf90f4cf23
commit 38fb06853e
14 files changed
+785 -24

No files matched your search

+67
View File
@@ -353,6 +353,73 @@ No tilt compensation or hard-iron calibration yet, so only roughly right
standing level. The node goes operational by itself, so no `nmt_start`.
Sensor16/8: `value = wire * (max - min) / (2^n - 2) + min`, all ones unknown.
Keypads for drive mode (`lib/maptool/keypad.rb`), the way PDMs do it: a
device's keys and knobs become named channels, and the screen profile's
`"bindings"` say what each one does (`public/drive/road.json`) — nothing
in the server knows what a key is for.
----
"keypads": [
{ "name": "pad", "protocol": "pkp", "node": 20, "keys": 8, "heartbeat_node": 32,
"inputs": { "E1": "XIAO STM32C5.Encoder 1", "E1 press": "XIAO STM32C5.Encoder Button 1",
"E2": "XIAO STM32C5.Encoder 2", "E3": "XIAO STM32C5.Encoder 3",
"E3 press": "XIAO STM32C5.Encoder Button 3" } } ]
----
`name` prefixes its channels (`pad.K1`, `pad.E3`, `pad.E3 press`).
`"protocol": "pkp"` — a Blink Marine PKP CANopen keypad, or ours speaking
its protocol (home-gitops `docs/canopen-nodes.adoc`): K1… come from its
TPDO1 (`0x180+node`, a bit each, `keys` of them) with no signals, and its
key LEDs take colours. Without it a keypad is just `inputs`: channel → any
signal, can.json's own or a discovered node's (as `/can.html` names them);
a channel starting with E is a knob (a free-turning counter mod 256 — set
its bit in the 8Encoder's "Encoder Relative Modes", entity 7, e.g. by an
`actions` SDO write), anything else a key. `heartbeat_node`: whose
heartbeat says it's there (a real PKP has it off; ours is the XIAO's own
node 0x20, the one with the knobs) — default `node`. The PKP waits for
NMT Start: `"nmt_start": true`.
A binding in the profile: `{ "input": "pad.K5", "action": "menu", "menu":
"close", "led": "cyan", "led_on": "green" }` — `action` a screen key's
(`trip`, `zoomIn`, `follow`, …) or a knob's (`zoom`, `panX`, `panY`,
`rows`), `menu` what it does while a menu is open (`rows`, `enter`,
`close`, or any action), `led` the key LED's colour (red green blue yellow
cyan magenta white), `led_on` while its screen key is on. `GET
/api/keypad?since=<seq>` is a long poll of the channels' events, `PUT
/api/keypad/leds` (`{"keypad": "pad", "on": {"K1": "cyan"}, "blink": {}}`)
sets a PKP's key LEDs.
Outputs (`lib/maptool/outputs.rb`): relay modules on the bus, maptool the
controller, nothing measured (no current, no feedback). A binding with an
`output` in place of an `action` drives one channel:
----
"outputs": [ { "name": "relays", "node": 48, "channels": 8, "simulated": true,
"labels": { "1": "Lights", "2": "Winch in" } } ]
----
`{ "input": "pad.E2 press", "output": "relays.1", "mode": "hold", "led":
"red" }` — `mode`: `toggle` (default), `on`, `off`, `hold` (on while held;
off when let go or when the keypad's heartbeat is gone), `pulse` (on for
`pulse_s`, 1 s by default). A PKP key bound to an output shows `led` (red
by default) while it's on, whatever the screen says. The module's
protocol is ours (after LD's native CAN control): RPDO1 `0x200+node`, a
bit per channel (byte 0 channels 1–8, byte 1 9–16), the whole state sent
on every change and every 100 ms; the module is to switch everything off
after 2 s without a frame. `"simulated": true` sends nothing, the state
only lives in the server — `/sim.html` shows the relays and switches
them by hand. `GET /api/outputs`, `POST /api/outputs/<module>/<n>` (`{"on":
true}`, empty toggles). An output in the profile that this car's can.json
hasn't is skipped.
CANopen TIME (`lib/maptool/can_time.rb`): maptool sends the TIME object
(`0x100`, CiA 301 TIME_OF_DAY, UTC: ms after midnight + days since
1984-01-01) once a second, but only while no other node does — once the
GNSS node sends it (esphome-canopen has no TIME yet), maptool stays quiet
until it's been silent 3 s. Nothing goes out while the Pi's clock is
unset (before 2025). `"time": false` in can.json turns it off; `/can.html`
shows who's sending it.
The node sends no course: `App.gnss_update` (where every fix lands, the
node's and the GNSS simulation's) works it out from the fix ≥ 5 m back
while moving ≥ 1.5 m/s and keeps the last one standing still, so