src/joystick/hidapi/SDL_hidapi_xboxone.c
changeset 13324 b46a94bb2ab0
parent 13323 a8804daa1c3d
child 13330 c88765bcf1da
equal deleted inserted replaced
13323:a8804daa1c3d 13324:b46a94bb2ab0
   190 {
   190 {
   191     Uint16 vendor_id = ctx->vendor_id;
   191     Uint16 vendor_id = ctx->vendor_id;
   192     Uint16 product_id = ctx->product_id;
   192     Uint16 product_id = ctx->product_id;
   193 
   193 
   194     if (!IsBluetoothXboxOneController(vendor_id, product_id)) {
   194     if (!IsBluetoothXboxOneController(vendor_id, product_id)) {
   195         int i;
   195         int i, j;
   196         Uint8 init_packet[USB_PACKET_LENGTH];
   196         Uint8 init_packet[USB_PACKET_LENGTH];
   197 
   197 
   198         for (i = 0; i < SDL_arraysize(xboxone_init_packets); ++i) {
   198         for (i = 0; i < SDL_arraysize(xboxone_init_packets); ++i) {
   199             const SDL_DriverXboxOne_InitPacket *packet = &xboxone_init_packets[i];
   199             const SDL_DriverXboxOne_InitPacket *packet = &xboxone_init_packets[i];
   200 
   200 
   210             init_packet[2] = ctx->sequence++;
   210             init_packet[2] = ctx->sequence++;
   211             if (hid_write(dev, init_packet, packet->size) != packet->size) {
   211             if (hid_write(dev, init_packet, packet->size) != packet->size) {
   212                 SDL_SetError("Couldn't write Xbox One initialization packet");
   212                 SDL_SetError("Couldn't write Xbox One initialization packet");
   213                 return SDL_FALSE;
   213                 return SDL_FALSE;
   214             }
   214             }
       
   215 
       
   216             /* After the init we need to sync up the rumble sequence */
       
   217             if (packet->data == xboxone_fw2015_init) {
       
   218                 for (j = 0; j < 255; ++j) {
       
   219                     if (hid_write(dev, xboxone_rumbleend_init, sizeof(xboxone_rumbleend_init)) != sizeof(xboxone_rumbleend_init)) {
       
   220                         SDL_SetError("Couldn't write Xbox One initialization packet");
       
   221                         return SDL_FALSE;
       
   222                     }
       
   223                 }
       
   224             }
   215         }
   225         }
   216     }
   226     }
   217     return SDL_TRUE;
   227     return SDL_TRUE;
   218 }
   228 }
   219 
   229 
   225     if (IsBluetoothXboxOneController(vendor_id, product_id)) {
   235     if (IsBluetoothXboxOneController(vendor_id, product_id)) {
   226         /* We can't do rumble on this device, hid_write() fails, so don't try to open it here */
   236         /* We can't do rumble on this device, hid_write() fails, so don't try to open it here */
   227         return SDL_FALSE;
   237         return SDL_FALSE;
   228     }
   238     }
   229     if (vendor_id == 0x24c6 && product_id == 0x541a) {
   239     if (vendor_id == 0x24c6 && product_id == 0x541a) {
   230         /* The PowerA Mini controller blocks while writing feature reports */
   240         /* The PowerA Mini controller, model 1240245-01, blocks while writing feature reports */
   231         return SDL_FALSE;
   241         return SDL_FALSE;
   232     }
   242     }
   233 #endif
   243 #endif
   234     return (SDL_GetJoystickGameControllerType(vendor_id, product_id, name) == SDL_CONTROLLER_TYPE_XBOXONE);
   244     return (SDL_GetJoystickGameControllerType(vendor_id, product_id, name) == SDL_CONTROLLER_TYPE_XBOXONE);
   235 }
   245 }