Skip to content

Fix Switch controller initialization race condition#188

Merged
GaryOderNichts merged 3 commits intoGaryOderNichts:mainfrom
mitchellcairns:patch-1
Aug 24, 2025
Merged

Fix Switch controller initialization race condition#188
GaryOderNichts merged 3 commits intoGaryOderNichts:mainfrom
mitchellcairns:patch-1

Conversation

@mitchellcairns
Copy link
Contributor

Switch controllers require ACK responses between initialization commands to process them correctly. The previous implementation sent setPlayerLeds(), setVibration(), and readSpiFlash() commands in rapid succession without waiting for acknowledgments, causing race conditions.

Changes:

  • Restructured command sequence to wait for each ACK before sending next command
  • setPlayerLeds() now triggers setVibration() on ACK
  • setVibration() now triggers calibration reads on ACK
  • Ensures proper controller state before attempting calibration data reads

Switch controllers require ACK responses between initialization commands to
process them correctly. The previous implementation sent setPlayerLeds(),
setVibration(), and readSpiFlash() commands in rapid succession without
waiting for acknowledgments, causing race conditions.

Changes:
- Restructured command sequence to wait for each ACK before sending next command
- setPlayerLeds() now triggers setVibration() on ACK
- setVibration() now triggers calibration reads on ACK
- Ensures proper controller state before attempting calibration data reads
Copy link
Owner

@GaryOderNichts GaryOderNichts left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! So far I haven't noticed any issues during initialization, but that change definitely seems better.
Sending rumble commands also doesn't wait for an ACK at the moment, I wonder if that's related to #29 and #60/

Remove Extra Spaces
- Add early return for command response containing LED set command ACK
@GaryOderNichts GaryOderNichts merged commit 79751cd into GaryOderNichts:main Aug 24, 2025
1 check passed
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