Skip to content

Commit f0907a1

Browse files
Dynamic mapping boolean check
1 parent 0f50b57 commit f0907a1

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/joystick/hidapi/SDL_hidapi_sinput.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,20 @@ DeviceDynamicEncodingSetup(SDL_HIDAPI_Device *device)
387387
break;
388388
}
389389

390-
Uint16 version = analogIndex;
391-
version = version * SINPUT_TRIGGERSTYLE_MAX + triggerIndex;
392-
version = version * SINPUT_PADDLESTYLE_MAX + paddleIndex;
393-
version = version * SINPUT_METASTYLE_MAX + metaIndex;
394-
version = version * SINPUT_TOUCHSTYLE_MAX + touchIndex;
395-
version = version * SINPUT_MISCSTYLE_MAX + miscIndex;
390+
int version = analogIndex;
391+
version = version * (int) SINPUT_TRIGGERSTYLE_MAX + triggerIndex;
392+
version = version * (int)SINPUT_PADDLESTYLE_MAX + paddleIndex;
393+
version = version * (int)SINPUT_METASTYLE_MAX + metaIndex;
394+
version = version * (int)SINPUT_TOUCHSTYLE_MAX + touchIndex;
395+
version = version * (int)SINPUT_MISCSTYLE_MAX + miscIndex;
396396

397397
ctx->usage_masks[0] = mask[0];
398398
ctx->usage_masks[1] = mask[1];
399399
ctx->usage_masks[2] = mask[2];
400400
ctx->usage_masks[3] = mask[3];
401401

402+
version = SDL_clamp(version, 0, UINT16_MAX);
403+
402404
device->guid.data[12] = (Uint8)(version & 0xFF);
403405
device->guid.data[13] = (Uint8)(version >> 8);
404406
}
@@ -449,6 +451,7 @@ static void ProcessSDLFeaturesResponse(SDL_HIDAPI_Device *device, Uint8 *data)
449451
ctx->accelRange = EXTRACTUINT16(data, 8);
450452
ctx->gyroRange = EXTRACTUINT16(data, 10);
451453

454+
bool use_dynamic_mapping = false;
452455

453456
if ((device->product_id == USB_PRODUCT_HANDHELDLEGEND_SINPUT_GENERIC) && (device->vendor_id == USB_VENDOR_RASPBERRYPI)) {
454457
switch (ctx->sub_type) {
@@ -467,6 +470,7 @@ static void ProcessSDLFeaturesResponse(SDL_HIDAPI_Device *device, Uint8 *data)
467470
ctx->usage_masks[1] = data[13];
468471
ctx->usage_masks[2] = data[14];
469472
ctx->usage_masks[3] = data[15];
473+
use_dynamic_mapping = true;
470474
break;
471475
}
472476
} else {
@@ -508,7 +512,9 @@ static void ProcessSDLFeaturesResponse(SDL_HIDAPI_Device *device, Uint8 *data)
508512
ctx->gyroScale = CalculateGyroScale(ctx->gyroRange);
509513

510514
// Process dynamic controller info
511-
DeviceDynamicEncodingSetup(device);
515+
if (use_dynamic_mapping) {
516+
DeviceDynamicEncodingSetup(device);
517+
}
512518

513519
// Derive button count from mask
514520
for (Uint8 byte = 0; byte < 4; ++byte) {

0 commit comments

Comments
 (0)