Skip to content

Commit 2b0b794

Browse files
mitchellcairnsslouken
authored andcommitted
SInput Generic Types
- Implements 'handheld' flag to indicate whether the SInput device is a gamepad or handheld (ROG Ally etc) - Implements generic mapping fallback along with face style setting ability
1 parent d983a89 commit 2b0b794

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

src/joystick/SDL_gamepad.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,8 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_GUID guid)
799799
// This controller has no guide button
800800
SDL_strlcat(mapping_string, "a:b1,b:b0,back:b4,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b3,y:b2,hint:!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,", sizeof(mapping_string));
801801
} else if (SDL_IsJoystickSInputController(vendor, product)) {
802-
Uint8 face_style = (guid.data[15] & 0xF0) >> 4;
803-
Uint8 u_id = guid.data[15] & 0x0F;
802+
Uint8 face_style = (guid.data[15] & 0xE0) >> 5;
803+
Uint8 sinput_id = guid.data[15] & 0x1F;
804804

805805
switch (product) {
806806
case USB_PRODUCT_HANDHELDLEGEND_PROGCC:
@@ -814,14 +814,13 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_GUID guid)
814814
break;
815815

816816
case USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC:
817-
switch (u_id) {
818-
case 1:
819-
// SuperGamepad+ Map
820-
SDL_strlcat(mapping_string, "a:b1,b:b0,back:b7,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,rightshoulder:b5,start:b6,x:b3,y:b2,", sizeof(mapping_string));
821-
break;
817+
// Apply mapping profile for type
818+
switch (sinput_id) {
822819
default:
823-
// Unknown mapping
824-
return NULL;
820+
case 0:
821+
// Default Fully Exposed Mapping
822+
SDL_strlcat(mapping_string, "b:b0,a:b1,y:b2,x:b3,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftstick:b4,rightstick:b5,leftshoulder:b6,rightshoulder:b7,lefttrigger:b8,righttrigger:b9,paddle1:b10,paddle2:b11,start:b12,back:b13,guide:b14,misc1:b15,paddle3:b16,paddle4:b17,touchpad:b18,misc2:b19,misc3:b20,misc4:b21,misc5:b22,misc6:b23", sizeof(mapping_string));
823+
break;
825824
}
826825

827826
// Apply face style

src/joystick/hidapi/SDL_hidapi_sinput.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ typedef struct
200200
bool right_analog_trigger_supported;
201201
bool dpad_supported;
202202
bool touchpad_supported;
203+
bool is_handheld;
203204

204205
Uint8 touchpad_count; // 2 touchpads maximum
205206
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)
255256
ctx->touchpad_supported = (data[3] & 0x01) != 0;
256257
ctx->joystick_rgb_supported = (data[3] & 0x02) != 0;
257258

259+
ctx->is_handheld = (data[3] & 0x04) != 0;
260+
258261
SDL_GamepadType type = SDL_GAMEPAD_TYPE_UNKNOWN;
259262
type = (SDL_GamepadType)SDL_clamp(data[4], SDL_GAMEPAD_TYPE_UNKNOWN, SDL_GAMEPAD_TYPE_COUNT);
260263
device->type = type;
261264

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
264267
device->guid.data[15] = data[5];
265268

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);
272270

273271
ctx->polling_rate_ms = data[6];
274272

275273
ctx->accelRange = EXTRACTUINT16(data, 8);
276274
ctx->gyroRange = EXTRACTUINT16(data, 10);
277275

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)) {
281277

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
285282

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];
288297

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+
}
291308

292309
// Derive button count from mask
293310
for (Uint8 byte = 0; byte < 4; ++byte) {
@@ -449,11 +466,6 @@ static bool HIDAPI_DriverSInput_InitDevice(SDL_HIDAPI_Device *device)
449466
case USB_PRODUCT_HANDHELDLEGEND_PROGCC:
450467
HIDAPI_SetDeviceName(device, "HHL ProGCC");
451468
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;
457469
default:
458470
// Use the USB product name
459471
break;

0 commit comments

Comments
 (0)