@@ -200,6 +200,7 @@ typedef struct
200
200
bool right_analog_trigger_supported ;
201
201
bool dpad_supported ;
202
202
bool touchpad_supported ;
203
+ bool is_handheld ;
203
204
204
205
Uint8 touchpad_count ; // 2 touchpads maximum
205
206
Uint8 touchpad_finger_count ; // 2 fingers for one touchpad, or 1 per touchpad (2 max)
@@ -255,39 +256,55 @@ static void ProcessSDLFeaturesResponse(SDL_HIDAPI_Device *device, Uint8 *data)
255
256
ctx -> touchpad_supported = (data [3 ] & 0x01 ) != 0 ;
256
257
ctx -> joystick_rgb_supported = (data [3 ] & 0x02 ) != 0 ;
257
258
259
+ ctx -> is_handheld = (data [3 ] & 0x04 ) != 0 ;
260
+
258
261
SDL_GamepadType type = SDL_GAMEPAD_TYPE_UNKNOWN ;
259
262
type = (SDL_GamepadType )SDL_clamp (data [4 ], SDL_GAMEPAD_TYPE_UNKNOWN , SDL_GAMEPAD_TYPE_COUNT );
260
263
device -> type = type ;
261
264
262
- // The 4 MSB represent a button layout style SDL_GamepadFaceStyle
263
- // The 4 LSB represent a device sub-type
265
+ // The 3 MSB represent a button layout style SDL_GamepadFaceStyle
266
+ // The 5 LSB represent a device sub-type
264
267
device -> guid .data [15 ] = data [5 ];
265
268
266
- #if defined(DEBUG_SINPUT_INIT )
267
- SDL_Log ("SInput Face Style: %d" , (data [5 ] & 0xF0 ) >> 4 );
268
- SDL_Log ("SInput Sub-type: %d" , (data [5 ] & 0xF ));
269
- #endif
270
-
271
- ctx -> sub_type = (data [5 ] & 0xF );
269
+ ctx -> sub_type = (data [5 ] & 0x1F );
272
270
273
271
ctx -> polling_rate_ms = data [6 ];
274
272
275
273
ctx -> accelRange = EXTRACTUINT16 (data , 8 );
276
274
ctx -> gyroRange = EXTRACTUINT16 (data , 10 );
277
275
278
- // Masks in LSB to MSB
279
- // South, East, West, North, DUp, DDown, DLeft, DRight
280
- ctx -> usage_masks [0 ] = data [12 ];
276
+ if ((device -> product_id == USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC ) && (device -> vendor_id == USB_VENDOR_RASPBERRYPI )) {
281
277
282
- // Stick Left, Stick Right, L Shoulder, R Shoulder,
283
- // L Trigger, R Trigger, L Paddle 1, R Paddle 1
284
- ctx -> usage_masks [1 ] = data [13 ];
278
+ #if defined(DEBUG_SINPUT_INIT )
279
+ SDL_Log ("SInput Face Style: %d" , (data [5 ] & 0xE0 ) >> 5 );
280
+ SDL_Log ("SInput Sub-type: %d" , (data [5 ] & 0x1F ));
281
+ #endif
285
282
286
- // Start, Back, Guide, Capture, L Paddle 2, R Paddle 2, Touchpad L, Touchpad R
287
- ctx -> usage_masks [2 ] = data [14 ];
283
+ switch (ctx -> sub_type ) {
284
+ // Default generic device, exposes all buttons
285
+ default :
286
+ case 0 :
287
+ ctx -> usage_masks [0 ] = 0xFF ;
288
+ ctx -> usage_masks [1 ] = 0xFF ;
289
+ ctx -> usage_masks [2 ] = 0xFF ;
290
+ ctx -> usage_masks [3 ] = 0xFF ;
291
+ break ;
292
+ }
293
+ } else {
294
+ // Masks in LSB to MSB
295
+ // South, East, West, North, DUp, DDown, DLeft, DRight
296
+ ctx -> usage_masks [0 ] = data [12 ];
288
297
289
- // Power, Misc 4 to 10
290
- ctx -> usage_masks [3 ] = data [15 ];
298
+ // Stick Left, Stick Right, L Shoulder, R Shoulder,
299
+ // L Trigger, R Trigger, L Paddle 1, R Paddle 1
300
+ ctx -> usage_masks [1 ] = data [13 ];
301
+
302
+ // Start, Back, Guide, Capture, L Paddle 2, R Paddle 2, Touchpad L, Touchpad R
303
+ ctx -> usage_masks [2 ] = data [14 ];
304
+
305
+ // Power, Misc 4 to 10
306
+ ctx -> usage_masks [3 ] = data [15 ];
307
+ }
291
308
292
309
// Derive button count from mask
293
310
for (Uint8 byte = 0 ; byte < 4 ; ++ byte ) {
@@ -449,11 +466,6 @@ static bool HIDAPI_DriverSInput_InitDevice(SDL_HIDAPI_Device *device)
449
466
case USB_PRODUCT_HANDHELDLEGEND_PROGCC :
450
467
HIDAPI_SetDeviceName (device , "HHL ProGCC" );
451
468
break ;
452
- case USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC :
453
- if (ctx -> sub_type == SINPUT_GENERIC_SUBTYPE_SUPERGAMEPADPLUS ) {
454
- HIDAPI_SetDeviceName (device , "HHL SuperGamepad+" );
455
- }
456
- break ;
457
469
default :
458
470
// Use the USB product name
459
471
break ;
0 commit comments