Skip to content

Commit 01b649e

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 ab12b7c commit 01b649e

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

src/joystick/hidapi/SDL_hidapi_gip.c

Lines changed: 12 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,11 @@ 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+
579+
if (command == GIP_CMD_DIRECT_MOTOR) {
580+
// The motor sequence is optional and always works with 0
581+
return 0;
582+
}
578583
if (system) {
579584
switch (command) {
580585
case GIP_CMD_SECURITY:
@@ -792,7 +797,7 @@ static bool GIP_ParseDeviceMetadata(GIP_Metadata *metadata, const Uint8 *bytes,
792797

793798
for (i = 0; i < count; i++) {
794799
Uint8 message = bytes[buffer_offset + 1 + i];
795-
device->in_system_messages[message >> 5] |= 1u << (message & 0x1F);
800+
device->in_system_messages[message >> 5] |= 1u << (message & 0x1F);
796801
}
797802
}
798803

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

810815
for (i = 0; i < count; i++) {
811816
Uint8 message = bytes[buffer_offset + 1 + i];
812-
device->out_system_messages[message >> 5] |= 1u << (message & 0x1F);
817+
device->out_system_messages[message >> 5] |= 1u << (message & 0x1F);
813818
}
814819
}
815820

@@ -1122,7 +1127,7 @@ static bool GIP_SendInitSequence(GIP_Device *device)
11221127

11231128
static bool GIP_EnsureMetadata(GIP_Device *device)
11241129
{
1125-
1130+
11261131
switch (device->got_metadata) {
11271132
case GIP_METADATA_GOT:
11281133
case GIP_METADATA_FAKED:
@@ -1147,8 +1152,6 @@ static bool GIP_EnsureMetadata(GIP_Device *device)
11471152

11481153
static bool GIP_SetMetadataDefaults(GIP_Device *device)
11491154
{
1150-
int seq;
1151-
11521155
/* Some decent default settings */
11531156
device->features |= GIP_FEATURE_MOTOR_CONTROL;
11541157
device->device_type = GIP_TYPE_GAMEPAD;
@@ -1164,23 +1167,6 @@ static bool GIP_SetMetadataDefaults(GIP_Device *device)
11641167
GIP_SendQueryFirmware(device, 2);
11651168
}
11661169

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-
11841170
device->got_metadata = GIP_METADATA_FAKED;
11851171
device->hello_deadline = 0;
11861172
return HIDAPI_JoystickConnected(device->device, NULL);
@@ -1512,7 +1498,7 @@ static bool GIP_HandleCommandGuideButtonStatus(
15121498
if (!joystick) {
15131499
return false;
15141500
}
1515-
if (bytes[1] == VK_LWIN) {
1501+
if (bytes[1] == VK_LWIN) {
15161502
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (bytes[0] & 0x01) != 0);
15171503
}
15181504

@@ -1815,7 +1801,7 @@ static bool GIP_HandleLLInputReport(
18151801
(bytes[device->paddle_offset] & 0x08) != 0);
18161802
}
18171803
}
1818-
1804+
18191805
if ((device->features & GIP_FEATURE_CONSOLE_FUNCTION_MAP) && num_bytes >= 32) {
18201806
int function_map_offset = -1;
18211807
if (device->features & GIP_FEATURE_DYNAMIC_LATENCY_INPUT) {
@@ -2057,7 +2043,7 @@ static int GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_byt
20572043
device->fragment_data = NULL;
20582044
}
20592045
device->fragment_message = 0;
2060-
}
2046+
}
20612047
fragment_offset += header.length;
20622048
device->fragment_offset = (Uint16) fragment_offset;
20632049
}

0 commit comments

Comments
 (0)