src/joystick/hidapi/SDL_hidapi_ps4.c
changeset 12163 dd056c76593a
parent 12120 0131b11bd03f
child 12165 c7e321efcbab
equal deleted inserted replaced
12162:03a4f7b4ec77 12163:dd056c76593a
   105 
   105 
   106 typedef struct {
   106 typedef struct {
   107     SDL_bool is_dongle;
   107     SDL_bool is_dongle;
   108     SDL_bool is_bluetooth;
   108     SDL_bool is_bluetooth;
   109     SDL_bool audio_supported;
   109     SDL_bool audio_supported;
       
   110     SDL_bool rumble_supported;
   110     Uint8 volume;
   111     Uint8 volume;
   111     Uint32 last_volume_check;
   112     Uint32 last_volume_check;
   112     Uint32 rumble_expiration;
   113     Uint32 rumble_expiration;
   113     PS4StatePacket_t last_state;
   114     PS4StatePacket_t last_state;
   114 } SDL_DriverPS4_Context;
   115 } SDL_DriverPS4_Context;
   295     if (vendor_id == SONY_USB_VID &&
   296     if (vendor_id == SONY_USB_VID &&
   296         (product_id == SONY_DS4_SLIM_PID || product_id == SONY_DS4_DONGLE_PID )) {
   297         (product_id == SONY_DS4_SLIM_PID || product_id == SONY_DS4_DONGLE_PID )) {
   297         ctx->audio_supported = SDL_TRUE;
   298         ctx->audio_supported = SDL_TRUE;
   298     }
   299     }
   299 
   300 
       
   301     if (ctx->is_bluetooth) {
       
   302         ctx->rumble_supported = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, SDL_FALSE);
       
   303     } else {
       
   304         ctx->rumble_supported = SDL_TRUE;
       
   305     }
       
   306 
   300     /* Initialize LED and effect state */
   307     /* Initialize LED and effect state */
   301     HIDAPI_DriverPS4_Rumble(joystick, dev, ctx, 0, 0, 0);
   308     HIDAPI_DriverPS4_Rumble(joystick, dev, ctx, 0, 0, 0);
   302 
   309 
   303     /* Initialize the joystick capabilities */
   310     /* Initialize the joystick capabilities */
   304     joystick->nbuttons = SDL_CONTROLLER_BUTTON_MAX;
   311     joystick->nbuttons = SDL_CONTROLLER_BUTTON_MAX;
   313 {
   320 {
   314     SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)context;
   321     SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)context;
   315     DS4EffectsState_t *effects;
   322     DS4EffectsState_t *effects;
   316     Uint8 data[78];
   323     Uint8 data[78];
   317     int report_size, offset;
   324     int report_size, offset;
       
   325 
       
   326     if (!ctx->rumble_supported) {
       
   327         return SDL_Unsupported();
       
   328     }
   318 
   329 
   319     /* In order to send rumble, we have to send a complete effect packet */
   330     /* In order to send rumble, we have to send a complete effect packet */
   320     SDL_memset(data, 0, sizeof(data));
   331     SDL_memset(data, 0, sizeof(data));
   321 
   332 
   322     if (ctx->is_bluetooth) {
   333     if (ctx->is_bluetooth) {
   515         if (SDL_TICKS_PASSED(now, ctx->rumble_expiration)) {
   526         if (SDL_TICKS_PASSED(now, ctx->rumble_expiration)) {
   516             HIDAPI_DriverPS4_Rumble(joystick, dev, context, 0, 0, 0);
   527             HIDAPI_DriverPS4_Rumble(joystick, dev, context, 0, 0, 0);
   517         }
   528         }
   518     }
   529     }
   519 
   530 
   520 	return (size >= 0);
   531     return (size >= 0);
   521 }
   532 }
   522 
   533 
   523 static void
   534 static void
   524 HIDAPI_DriverPS4_Quit(SDL_Joystick *joystick, hid_device *dev, void *context)
   535 HIDAPI_DriverPS4_Quit(SDL_Joystick *joystick, hid_device *dev, void *context)
   525 {
   536 {