Skip to content

M0: touch-sync sensor-event bus (multi-device mesh sync) - #15

Merged
aphelps-claude-bot merged 6 commits into
mainfrom
touch-sync
Jun 18, 2026
Merged

aphelps-claude-bot merged 6 commits into
mainfrom
touch-sync

Conversation

@aphelps-claude-bot

Copy link
Copy Markdown
Collaborator

Summary

Bumps the WLED submodule to include the touch-sync usermod — the M0 prototype of the multi-device mesh-sync project (router-less shared sensor input across WLED devices). See todo_plans/multi-device-wled-mesh-sync-with-shared-touch-input.md.

All code lives in the submodule; this PR is the pointer bump.

Submodule PRs

Test plan

  • pio run -e ampworks — SUCCESS
  • pio run -e esp32dev — SUCCESS

Manual (hardware, pending):

  • Flash 3–5 devices (one AP + stations); local touch → distinct-hue ripple on all.
  • Validate UDP broadcast traverses the SoftAP between stations (top risk; plan runbook has fallbacks).

🤖 Generated with Claude Code

Points to aphelps/WLED@b801a746 — adds the touch-sync usermod (UDP cross-device
sensor-event bus) on top of the Touch Pond effect work.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

M0 touch-sync self-review

Reviewed the submodule change (aphelps/WLED#3): new usermods/ampworks/usermod_touch_sync.h (USERMOD_ID 56) plus the Touch Pond edits in ampworks.cpp. PR #15's own diff is only the submodule-pointer bump, so all findings are here in the body rather than as inline comments. Overall the M0 scope is met and the design is clean and forward-compatible; the items below are edge cases and coverage gaps to track, not blockers for the Wednesday prototype.

Findings

  • Rx ring buffer / effect-drain share mutable state without an explicit guard. usermod_touch_sync.h:pushRemoteEvent() mutates rxHead/rxTail/rxCount from the usermod loop(), while popRemoteEvent() (called from mode_touch_ripple during strip service) mutates rxTail/rxCount. On ESP32 both run on the same Arduino loop task, and loop() early-returns on strip.isUpdating(), so today they do not actually interleave — but that safety is implicit. A one-line comment in the class documenting the single-task assumption (and that it breaks if a future producer pushes from an ISR / ESP-NOW callback in M1/M3) would prevent a subtle regression later.

  • No dedup despite a seq field on the wire. usermod_touch_sync.h:receiveLoop() filters self-origin packets by deviceId, but ignores pkt.seq. UDP broadcast over WiFi can deliver the same datagram more than once (link-layer retransmit), and once the M3 relay tier exists a node will hear both direct and relayed copies — each currently spawns a duplicate remote wave. For M0 this is cosmetic; flagging because the seq field is already carried but unused, so the intended last-seen-per-sender dedup is a small add and worth doing before M1/M3 multiply the duplicates.

  • prevTouched edge state is not reset when the MPR121 disappears/reappears. In usermod_touch_sync.h:broadcastLocalEdges() the early return on !mpr->isSensorFound() leaves prevTouched frozen. If a sensor browns out mid-touch and recovers, the held electrode either never emits its release (consumers stuck "pressed" until next toggle) or emits a spurious edge. Resetting prevTouched = 0 on the sensor-lost path would make recovery deterministic.

  • Device-id derivation can collide at the target scale. usermod_touch_sync.h:deriveDeviceId() uses only the low 2 bytes of the STA MAC. Across the stated 20+ device fleet the birthday-paradox collision probability is non-trivial (~0.3% at 20 nodes, rising fast), and a collision makes two devices silently drop each other's events via the self-origin filter. The id config override mitigates this, but the runbook should call out assigning explicit ids for any deployment beyond a handful, or derive from more MAC bytes.

  • Oversized-packet bytes are silently truncated (acceptable, noting intent). receiveLoop() reads exactly sizeof(TouchSyncPacket) when sz >= sizeof(...); a longer datagram's trailing bytes are discarded when the next parsePacket() advances. This is fine for the current fixed layout, but since the header comment promises forward-compatibility for M1 sensor types, a future longer packet variant would lose its tail here — worth a comment that the reader assumes the M0 fixed size.

  • Suggested test: add a host-side check to the plan's ## Test Plan that injects crafted UDP packets at port 21330 from a laptop (valid packet → remote wave spawns; wrong magic / wrong version / undersized datagram → ignored, no crash; >RX_QUEUE_LEN=32 rapid packets → oldest overwritten, no overflow). The receive/parse/ring-overwrite path is the highest-risk new code and currently only the build (pio run -e ampworks) is automated.

  • Suggested post-merge check: verify on real hardware that UDP limited broadcast (255.255.255.255) actually traverses the ESP32 SoftAP between associated stations — this is already called out as the plan's top risk. Confirm station-to-station ripples (not just station↔AP) before relying on it Wednesday; if frames don't forward, fall back to subnet-directed broadcast or unicast-to-learned-peers as noted in the runbook.

Points to aphelps/WLED@7019b716 (generic header + per-sensor data struct;
all MPR121 sensors in one snapshot). Addresses CR on WLED#3.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of 02283fb — the only change on this parent PR since the last review is the WLED submodule pointer bump (b801a746 → 7019b716: the touch-sync wire-format redesign). The code change itself was re-reviewed on the submodule PR aphelps/WLED#3, where the CR was confirmed addressed. No parent-side findings.

Points to aphelps/WLED@a33d7c7d. Addresses the rename / .h-.cpp split / producer-edge
review on WLED#3.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of a3b6593 — parent-side change is the WLED submodule pointer bump (7019b716 → a33d7c7d: the sensor-sync rename, .h/.cpp split, and producer-side edge derivation). The code was re-reviewed on the submodule PR aphelps/WLED#3 (all three review items confirmed addressed; 4 minor findings tracked for the M1 task). No parent-side findings.

@aphelps-claude-bot
aphelps-claude-bot merged commit c11841d into main Jun 18, 2026
@aphelps-claude-bot
aphelps-claude-bot deleted the touch-sync branch June 18, 2026 20:30
aphelps-claude-bot added a commit that referenced this pull request Jul 30, 2026
ArduinoLibs bceedb3 (#10) -- four receive-path defects fixed, plus test/: the first
test infrastructure in that repo (45 assertions, each with a verified negative
control).
WLED cdfef9c0 (#15) -- bridge side: refuse to run on a failed socket alloc, scale the
receive timeout to the configured baud, surface timeouts on the info page, keep
rejected frames counted.

Both squash-merged, so this replaces the branch-tip pointers this PR opened with.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ
aphelps-claude-bot added a commit that referenced this pull request Jul 30, 2026
)

* bump submodules: RS485 receive-path fixes + first ArduinoLibs tests

ArduinoLibs 6d1de81 -- fixes the four receive-path defects found auditing the
vendored RS485_non_blocking (stale-packet re-delivery, unchecked malloc, no packet
timeout, length checks compiled out of release builds) and adds test/, the first test
infrastructure in that repo: an Arduino.h shim plus 28 assertions, each paired with a
negative control that confirms disabling the fix turns them red.
WLED 0cf79a01 -- bridge side: refuse to run on a failed socket alloc, and keep
rejected frames counted now that a NULL from getMsg() no longer means "bus empty".

Also extends `make test` to cover two suites it silently skipped: the new ArduinoLibs
receive-path tests, and the rs485_bridge wire-format tests, which had to be run by
hand and are now run on BOTH ABIs (native and -fpack-struct=1) since the point of most
of those assertions is that the two agree.

  make test  ->  ampworks sensor-sync + rs485_bridge (x2 ABIs) + ArduinoLibs + router

  aphelps/ArduinoLibs#10
  aphelps/WLED#15

Submodule PRs merge first; these pointers are re-pointed at the merged shas before
this lands.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* bump submodules: self-review fixes on the receive-path stack

ArduinoLibs 538a01b -- the packet timeout measured poll latency rather than wire
time, so with the check running before update() it could discard a frame whose
remaining bytes were already in the FIFO: a regression against pre-timeout behaviour,
not a pre-existing bug. Now checked after update(), plus a baud-derived timeout
(fixed 250 ms killed every full-size frame at 4800 baud), reachable NULL guards, and
uint16_t counters to keep the ATmega328 footprint down. Two of the new tests turned
out to pass with their fix disabled and are now deterministic; three uncovered paths
added. 45 assertions, up from 28.
WLED 2b5baa2c -- scale the timeout to the configured baud, surface timeouts on the
info page (the counter existed but nothing read it), and correct two comments that
still said the library's length checks are compiled out of release builds.

Makefile: test-bridge guards HMTL and ArduinoLibs too, not just WLED. It compiles
against headers from all three, so on a fresh clone with uninitialised submodules a
bare `make` failed with a confusing missing-header error from the compiler instead of
the "run ./setup.sh" message require_submodule exists to print.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

* re-point submodules at the merged receive-path commits

ArduinoLibs bceedb3 (#10) -- four receive-path defects fixed, plus test/: the first
test infrastructure in that repo (45 assertions, each with a verified negative
control).
WLED cdfef9c0 (#15) -- bridge side: refuse to run on a failed socket alloc, scale the
receive timeout to the configured baud, surface timeouts on the info page, keep
rejected frames counted.

Both squash-merged, so this replaces the branch-tip pointers this PR opened with.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

---------

Co-authored-by: aphelps-claude-bot <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
aphelps-claude-bot added a commit that referenced this pull request Jul 30, 2026
…rged main

The WLED gitlink was the only conflict. This branch pointed at c88a3c46, the tip of
the attach-protocol PR branch; that PR was squash-merged as 586c6136, and meanwhile
four RS485 pointer bumps landed on WLED_dev main. Resolved to 586c6136, which contains
BOTH workstreams -- socket-header packing (#14), the receive-path fixes (#15) and the
attach-protocol wire format (#13).

esp-now-router keeps this branch's 08bd6e2: main still records the initial commit, and
08bd6e2 is strictly newer (it also contains cfa6554, which is what the superseded #22
was advancing to).

Also fixes CLAUDE.md's submodule table, which still said custom work branches from
base-wled-16.0.1 -- that branch was renamed to main today and no longer exists, so the
instruction pointed at nothing.

Verified at the resolved pointers:
  * make test -- all suites green, and the esp-now-router tests now actually RUN.
    They were reporting "skipped: no tests/ at the pinned revision" because main
    records the router's initial commit; at 08bd6e2 the relay, election and attach
    suites all execute and pass. So this bump turns three silently-skipped suites into
    three real ones.
  * pio run -e ampworks and -e usermods both SUCCESS, with .pio/libdeps cleared first
    so the build could not read a stale cached copy of RS485Utils.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ
aphelps-claude-bot added a commit that referenced this pull request Aug 28, 2026
ArduinoLibs 002f6d7 -> ff2a367  (RFM95Socket, #16)
HMTL        c65f1a3 -> 0a5d7cd  (esp32_lora_gw DISABLE_LORA plumbing, #15)
WLED        8ea0be8 -> eb14ddb  (rs485_bridge framing-count caveat, #21)

The ArduinoLibs pointer deliberately lands on the commit that carries BOTH
the library and its test wiring, not just the library. The top-level
Makefile records why this matters: main once briefly pinned
esp-now-router at its README-only commit and the router suites vanished
from `make test` with no signal at all.

Verified on this exact tree rather than assumed:

  make test STRICT=1     green, and the ArduinoLibs section now names
                         rfm95_socket_test and rfm95_socket_test_quiet
                         (79 checks each) plus the rfm95-layout sweep
                         under both the host ABI and -fpack-struct=1.

  pio run -e ampworks     SUCCESS, after rm -rf .pio/libdeps/ampworks so
                          the path-based deps were re-copied rather than
                          read from a stale cache. This is the firmware
                          that ships, so it is confirmed rather than
                          reasoned about -- platformio.ini names each
                          ArduinoLibs dependency explicitly and does not
                          glob, so RFM95Socket is not pulled in here.

Co-authored-by: aphelps-claude-bot <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants