@@ -233,18 +233,18 @@ static inline float CalculateAccelScale(uint16_t g_range)
233
233
return SDL_STANDARD_GRAVITY / (32768.0f / (float )g_range );
234
234
}
235
235
236
- static void ProcessSDLFeaturesResponse (SDL_HIDAPI_Device * device , Uint8 * data )
236
+ static bool ProcessSDLFeaturesResponse (SDL_HIDAPI_Device * device , Uint8 * data )
237
237
{
238
238
SDL_DriverSInput_Context * ctx = (SDL_DriverSInput_Context * )device -> context ;
239
239
240
240
// Obtain protocol version
241
241
ctx -> protocol_version = EXTRACTUINT16 (data , 0 );
242
- Uint8 * fflags = data + 2 ;
243
- Uint8 * buttons = data + 12 ;
244
-
242
+
245
243
//
246
244
// Unpack feature flags into context
247
245
//
246
+ Uint8 * fflags = data + 2 ;
247
+ Uint8 * buttons = data + 12 ;
248
248
ctx -> rumble_supported = (fflags [0 ] & 0x01 ) != 0 ;
249
249
ctx -> player_leds_supported = (fflags [0 ] & 0x02 ) != 0 ;
250
250
ctx -> accelerometer_supported = (fflags [0 ] & 0x04 ) != 0 ;
@@ -272,17 +272,25 @@ static void ProcessSDLFeaturesResponse(SDL_HIDAPI_Device *device, Uint8 *data)
272
272
device -> guid .data [15 ] = data [5 ];
273
273
ctx -> sub_type = (data [5 ] & 0x1F );
274
274
275
- #if defined(DEBUG_SINPUT_INIT )
276
- SDL_Log ("SInput Face Style: %d" , (data [5 ] & 0xE0 ) >> 5 );
277
- SDL_Log ("SInput Sub-type: %d" , (data [5 ] & 0x1F ));
278
- #endif
275
+ // Get and validate touchpad parameters
276
+ ctx -> touchpad_count = data [16 ];
277
+ ctx -> touchpad_finger_count = data [17 ];
279
278
280
279
//
281
280
// IMU Info
282
281
//
283
282
ctx -> polling_rate_ms = data [6 ];
284
283
ctx -> accelRange = EXTRACTUINT16 (data , 8 );
285
284
ctx -> gyroRange = EXTRACTUINT16 (data , 10 );
285
+ ctx -> accelScale = CalculateAccelScale (ctx -> accelRange );
286
+ ctx -> gyroScale = CalculateGyroScale (ctx -> gyroRange );
287
+
288
+ // Get device Serial - MAC address
289
+ Uint8 * serial = data + 18 ;
290
+ char serial_str [18 ];
291
+ (void )SDL_snprintf (serial_str , sizeof (serial_str ), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x" ,
292
+ serial [0 ], serial [1 ], serial [2 ], data [3 ], data [4 ], data [5 ]);
293
+ HIDAPI_SetDeviceSerial (device , serial_str );
286
294
287
295
//
288
296
// Get mappings based on SDL subtype and assert that they match.
@@ -418,32 +426,15 @@ static void ProcessSDLFeaturesResponse(SDL_HIDAPI_Device *device, Uint8 *data)
418
426
}
419
427
420
428
#if defined(DEBUG_SINPUT_INIT )
429
+ SDL_Log ("SInput Face Style: %d" , (device -> guid .data [15 ] & 0xE0 ) >> 5 );
430
+ SDL_Log ("SInput Sub-type: %d" , (device -> guid .data [15 ] & 0x1F ));
421
431
SDL_Log ("Buttons count: %d" , ctx -> buttons_count );
422
- #endif
423
-
424
- // Get and validate touchpad parameters
425
- ctx -> touchpad_count = data [16 ];
426
- ctx -> touchpad_finger_count = data [17 ];
427
-
428
- // Get device Serial - MAC address
429
- char serial [18 ];
430
- (void )SDL_snprintf (serial , sizeof (serial ), "%.2x-%.2x-%.2x-%.2x-%.2x-%.2x" ,
431
- data [18 ], data [19 ], data [20 ], data [21 ], data [22 ], data [23 ]);
432
- #if defined(DEBUG_SINPUT_INIT )
433
432
SDL_Log ("Serial num: %s" , serial );
434
- #endif
435
- HIDAPI_SetDeviceSerial (device , serial );
436
-
437
- #if defined(DEBUG_SINPUT_INIT )
438
433
SDL_Log ("Accelerometer Range: %d" , ctx -> accelRange );
439
- #endif
440
-
441
- #if defined(DEBUG_SINPUT_INIT )
442
434
SDL_Log ("Gyro Range: %d" , ctx -> gyroRange );
443
435
#endif
444
436
445
- ctx -> accelScale = CalculateAccelScale (ctx -> accelRange );
446
- ctx -> gyroScale = CalculateGyroScale (ctx -> gyroRange );
437
+ return true;
447
438
}
448
439
449
440
static bool RetrieveSDLFeatures (SDL_HIDAPI_Device * device )
@@ -487,11 +478,7 @@ static bool RetrieveSDLFeatures(SDL_HIDAPI_Device *device)
487
478
#endif
488
479
489
480
if ((read == USB_PACKET_LENGTH ) && (data [0 ] == SINPUT_DEVICE_REPORT_ID_INPUT_CMDDAT ) && (data [1 ] == SINPUT_DEVICE_COMMAND_FEATURES )) {
490
- ProcessSDLFeaturesResponse (device , & (data [SINPUT_REPORT_IDX_COMMAND_RESPONSE_BULK ]));
491
- #if defined(DEBUG_SINPUT_INIT )
492
- SDL_Log ("Received SInput SDL Features command response" );
493
- #endif
494
- return true;
481
+ return ProcessSDLFeaturesResponse (device , & (data [SINPUT_REPORT_IDX_COMMAND_RESPONSE_BULK ]));
495
482
}
496
483
}
497
484
0 commit comments