Skip to content

Commit f8c7790

Browse files
committed
Use motor sequence ID 0 in the HIDAPI GIP driver
Using a 0 sequence number is always allowed and avoids having to synchronize sequence numbers with the controller (and potentially confusing other things talking to the controller) Also fixes occasional long running rumble at controller connection.
1 parent 33e5f48 commit f8c7790

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

src/joystick/hidapi/SDL_hidapi_gip.c

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ typedef struct GIP_Metadata
393393
Uint16 version_minor;
394394

395395
GIP_DeviceMetadata device;
396-
396+
397397
Uint8 num_messages;
398398
GIP_MessageMetadata *message_metadata;
399399
} GIP_Metadata;
@@ -575,6 +575,7 @@ static bool GIP_SupportsVendorMessage(GIP_Device *device, Uint8 command, bool up
575575
static Uint8 GIP_SequenceNext(GIP_Device *device, Uint8 command, bool system)
576576
{
577577
Uint8 seq;
578+
578579
if (system) {
579580
switch (command) {
580581
case GIP_CMD_SECURITY:
@@ -603,6 +604,11 @@ static Uint8 GIP_SequenceNext(GIP_Device *device, Uint8 command, bool system)
603604
break;
604605
}
605606
} else {
607+
if (command == GIP_CMD_DIRECT_MOTOR) {
608+
// The motor sequence number is optional and always works with 0
609+
return 0;
610+
}
611+
606612
seq = device->seq_vendor++;
607613
if (!seq) {
608614
seq = device->seq_vendor++;
@@ -792,7 +798,7 @@ static bool GIP_ParseDeviceMetadata(GIP_Metadata *metadata, const Uint8 *bytes,
792798

793799
for (i = 0; i < count; i++) {
794800
Uint8 message = bytes[buffer_offset + 1 + i];
795-
device->in_system_messages[message >> 5] |= 1u << (message & 0x1F);
801+
device->in_system_messages[message >> 5] |= 1u << (message & 0x1F);
796802
}
797803
}
798804

@@ -809,7 +815,7 @@ static bool GIP_ParseDeviceMetadata(GIP_Metadata *metadata, const Uint8 *bytes,
809815

810816
for (i = 0; i < count; i++) {
811817
Uint8 message = bytes[buffer_offset + 1 + i];
812-
device->out_system_messages[message >> 5] |= 1u << (message & 0x1F);
818+
device->out_system_messages[message >> 5] |= 1u << (message & 0x1F);
813819
}
814820
}
815821

@@ -1122,7 +1128,7 @@ static bool GIP_SendInitSequence(GIP_Device *device)
11221128

11231129
static bool GIP_EnsureMetadata(GIP_Device *device)
11241130
{
1125-
1131+
11261132
switch (device->got_metadata) {
11271133
case GIP_METADATA_GOT:
11281134
case GIP_METADATA_FAKED:
@@ -1147,8 +1153,6 @@ static bool GIP_EnsureMetadata(GIP_Device *device)
11471153

11481154
static bool GIP_SetMetadataDefaults(GIP_Device *device)
11491155
{
1150-
int seq;
1151-
11521156
/* Some decent default settings */
11531157
device->features |= GIP_FEATURE_MOTOR_CONTROL;
11541158
device->device_type = GIP_TYPE_GAMEPAD;
@@ -1164,23 +1168,6 @@ static bool GIP_SetMetadataDefaults(GIP_Device *device)
11641168
GIP_SendQueryFirmware(device, 2);
11651169
}
11661170

1167-
if (device->features & GIP_FEATURE_MOTOR_CONTROL) {
1168-
for (seq = 1; seq < 0x100; seq++) {
1169-
Uint8 message[9] = {0};
1170-
1171-
/* Try all sequence numbers to reset it to 1 */
1172-
GIP_SendRawMessage(device,
1173-
GIP_CMD_DIRECT_MOTOR,
1174-
0,
1175-
(Uint8) seq,
1176-
message,
1177-
sizeof(message),
1178-
true,
1179-
NULL,
1180-
NULL);
1181-
}
1182-
}
1183-
11841171
device->got_metadata = GIP_METADATA_FAKED;
11851172
device->hello_deadline = 0;
11861173
return HIDAPI_JoystickConnected(device->device, NULL);
@@ -1512,7 +1499,7 @@ static bool GIP_HandleCommandGuideButtonStatus(
15121499
if (!joystick) {
15131500
return false;
15141501
}
1515-
if (bytes[1] == VK_LWIN) {
1502+
if (bytes[1] == VK_LWIN) {
15161503
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (bytes[0] & 0x01) != 0);
15171504
}
15181505

@@ -1815,7 +1802,7 @@ static bool GIP_HandleLLInputReport(
18151802
(bytes[device->paddle_offset] & 0x08) != 0);
18161803
}
18171804
}
1818-
1805+
18191806
if ((device->features & GIP_FEATURE_CONSOLE_FUNCTION_MAP) && num_bytes >= 32) {
18201807
int function_map_offset = -1;
18211808
if (device->features & GIP_FEATURE_DYNAMIC_LATENCY_INPUT) {
@@ -2057,7 +2044,7 @@ static int GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_byt
20572044
device->fragment_data = NULL;
20582045
}
20592046
device->fragment_message = 0;
2060-
}
2047+
}
20612048
fragment_offset += header.length;
20622049
device->fragment_offset = (Uint16) fragment_offset;
20632050
}

0 commit comments

Comments
 (0)