From 82d2c357c3048a2f9cea304f8785635fe121350b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 9 Dec 2019 16:52:11 -0800 Subject: [PATCH] Fixed rumble after Xbox controller initialization When we initialize the controller it has an internal rumble sequence number, and if our rumble sequence number doesn't match that, rumble won't happen. To fix that we cycle through the range of sequence numbers, and at some point we'll match up with the controller's sequence number and it'll roll forward until it matches our next rumble sequence number. --- src/joystick/hidapi/SDL_hidapi_xboxone.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapi_xboxone.c b/src/joystick/hidapi/SDL_hidapi_xboxone.c index 230fe64471119..11bbbc6c9abff 100644 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c @@ -192,7 +192,7 @@ SendControllerInit(hid_device *dev, SDL_DriverXboxOne_Context *ctx) Uint16 product_id = ctx->product_id; if (!IsBluetoothXboxOneController(vendor_id, product_id)) { - int i; + int i, j; Uint8 init_packet[USB_PACKET_LENGTH]; for (i = 0; i < SDL_arraysize(xboxone_init_packets); ++i) { @@ -212,6 +212,16 @@ SendControllerInit(hid_device *dev, SDL_DriverXboxOne_Context *ctx) SDL_SetError("Couldn't write Xbox One initialization packet"); return SDL_FALSE; } + + /* After the init we need to sync up the rumble sequence */ + if (packet->data == xboxone_fw2015_init) { + for (j = 0; j < 255; ++j) { + if (hid_write(dev, xboxone_rumbleend_init, sizeof(xboxone_rumbleend_init)) != sizeof(xboxone_rumbleend_init)) { + SDL_SetError("Couldn't write Xbox One initialization packet"); + return SDL_FALSE; + } + } + } } } return SDL_TRUE; @@ -227,7 +237,7 @@ HIDAPI_DriverXboxOne_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint return SDL_FALSE; } if (vendor_id == 0x24c6 && product_id == 0x541a) { - /* The PowerA Mini controller blocks while writing feature reports */ + /* The PowerA Mini controller, model 1240245-01, blocks while writing feature reports */ return SDL_FALSE; } #endif