fix: swallow Arduino boot-glitch frames after (re)connect#4
Merged
Conversation
Opening the serial port toggles DTR, which resets the Arduino. For ~1s while it boots, its pins float to garbage: analog pins read near max (every configured volume jumps to 100%) and button pins read HIGH (a fresh 0->1 edge fires Open -> a phantom "Open Spotify"). These frames are valid CSV, so the engine acted on them. It recurs randomly because any USB hiccup reconnects the session, re-resetting the board each time. - events.rs: add a 1s post-(re)connect settle window that mirrors frames to the UI but emits no commands and doesn't poison the edge-detection baseline; on the first good frame past the window, re-baseline buttons and re-sync slider volumes to the real physical positions. - protocol.rs: reject lines whose field count != FRAME_FIELDS so a corruption-merged line can't be processed as a misaligned frame (defense-in-depth); add a unit test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes two user-reported runtime bugs with a shared root cause, plus parser hardening.
Root cause
Opening the serial port toggles DTR, which resets the Arduino. For ~1s while it boots, its pins float to garbage — analog pins read near max and button pins read HIGH. Those frames are valid CSV, so the engine acted on them:
0→1edge → firesOpen→ phantom "Open Spotify"It recurs "randomly" because any USB hiccup reconnects the session, re-resetting the board each time.
Changes
events.rs— 1s post-(re)connect settle window: frames are mirrored to the UI but emit no commands and don't poison the edge-detection baseline. The first good frame past the window re-baselines buttons and re-syncs slider volumes to the real physical positions.protocol.rs— reject lines whose field count ≠FRAME_FIELDSso a corruption-merged line can't be processed as a misaligned frame (defense-in-depth). Added a unit test.Test
cargo test --bin slidr protocol::→ 4 passed (incl. newrejects_extra_fields)Note
The separate "console window on boot" report needs no code change here — already fixed on
mainby 89a3568; it just needs a rebuild/reinstall.🤖 Generated with Claude Code