Fixed rumble after Xbox controller initialization
authorSam Lantinga <slouken@libsdl.org>
Mon, 09 Dec 2019 16:52:11 -0800
changeset 13324b46a94bb2ab0
parent 13323 a8804daa1c3d
child 13325 45d6830f0b53
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
     1.1 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c	Mon Dec 09 13:54:05 2019 -0800
     1.2 +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c	Mon Dec 09 16:52:11 2019 -0800
     1.3 @@ -192,7 +192,7 @@
     1.4      Uint16 product_id = ctx->product_id;
     1.5  
     1.6      if (!IsBluetoothXboxOneController(vendor_id, product_id)) {
     1.7 -        int i;
     1.8 +        int i, j;
     1.9          Uint8 init_packet[USB_PACKET_LENGTH];
    1.10  
    1.11          for (i = 0; i < SDL_arraysize(xboxone_init_packets); ++i) {
    1.12 @@ -212,6 +212,16 @@
    1.13                  SDL_SetError("Couldn't write Xbox One initialization packet");
    1.14                  return SDL_FALSE;
    1.15              }
    1.16 +
    1.17 +            /* After the init we need to sync up the rumble sequence */
    1.18 +            if (packet->data == xboxone_fw2015_init) {
    1.19 +                for (j = 0; j < 255; ++j) {
    1.20 +                    if (hid_write(dev, xboxone_rumbleend_init, sizeof(xboxone_rumbleend_init)) != sizeof(xboxone_rumbleend_init)) {
    1.21 +                        SDL_SetError("Couldn't write Xbox One initialization packet");
    1.22 +                        return SDL_FALSE;
    1.23 +                    }
    1.24 +                }
    1.25 +            }
    1.26          }
    1.27      }
    1.28      return SDL_TRUE;
    1.29 @@ -227,7 +237,7 @@
    1.30          return SDL_FALSE;
    1.31      }
    1.32      if (vendor_id == 0x24c6 && product_id == 0x541a) {
    1.33 -        /* The PowerA Mini controller blocks while writing feature reports */
    1.34 +        /* The PowerA Mini controller, model 1240245-01, blocks while writing feature reports */
    1.35          return SDL_FALSE;
    1.36      }
    1.37  #endif