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

@@ -31,6 +31,7 @@ static char *path[2]; // the HID paths hd_pair_find sa
static PlatMutex dev_lock = PLAT_MUTEX_INIT; // guards dev[] and number[], and is held across a write
static SDL_hid_device *dev[2];
static unsigned number[2]; // the next report's number, per device
static volatile int32_t ended; // hd_pair_end ran: hd_pair_write, under dev_lock, writes nothing
int hd_pair_find(void) {
char *found[2] = {NULL, NULL};
@@ -71,6 +72,11 @@ static int write_side(int s, const uint8_t v[RUMBLE_HD_SIDE]) {
int hd_pair_write(const uint8_t data[RUMBLE_HD_DATA]) {
int ok = 1;
plat_mutex_lock(&dev_lock);
if (__atomic_load_n(&ended, __ATOMIC_ACQUIRE)) { // under the write's lock: no stop between this and the write
plat_mutex_unlock(&dev_lock);
SDL_SetError("HD rumble has ended");
return 0;
}
if (!dev[0] || !dev[1]) {
close_devices();
char *p[2];
@@ -111,3 +117,8 @@ void hd_pair_close(int neutral, unsigned wait_ms) {
close_devices();
plat_mutex_unlock(&dev_lock);
}
void hd_pair_end(unsigned wait_ms) {
__atomic_store_n(&ended, 1, __ATOMIC_RELEASE); // before the lock: a write that holds it now is the last one
hd_pair_close(1, wait_ms);
}