Keep a late HD rumble report from opening a Joy-Con pair again after the stop.

hd_tick picks a report under the locks and writes it to the pair after letting them go. When input_rumble_hd_stop
wrote the neutral value and closed the pair in between, that write opened the two devices again and left the
Joy-Con vibrating after the exit. The stop now ends the pair (hd_pair_end), and hd_pair_write checks that under the
lock it holds for the write, so nothing is written after the stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 06:02:58 -05:00
parent d59488d308
commit b399d8f15c
3 changed files with 21 additions and 4 deletions

View File

@@ -10,10 +10,14 @@
int hd_pair_find(void);
// Writes one rumble report to each Joy-Con: the left half of data to the left one, the right half to the right one.
// The first call after hd_pair_find opens the two devices. 0 when a device could not be opened or written (both are
// closed then, and SDL's error text says why). Blocks for as long as the writes take: the HD rumble thread only.
// closed then, and SDL's error text says why), and after hd_pair_end. Blocks for as long as the writes take: the HD
// rumble thread only.
int hd_pair_write(const uint8_t data[RUMBLE_HD_DATA]);
// 1 while the two devices are open.
int hd_pair_is_open(void);
// Writes the neutral value to both Joy-Con, when neutral is set, and closes them. wait_ms: how long to wait for a
// write that is still running on another thread before giving up (the process is ending); 0 waits for it.
void hd_pair_close(int neutral, unsigned wait_ms);
// The process is ending (input.c input_rumble_hd_stop): hd_pair_close(1, wait_ms), and hd_pair_write writes nothing
// from here on, so a report the HD thread chose before the stop cannot open the two devices again after it.
void hd_pair_end(unsigned wait_ms);