Skip to content

Use motor sequence ID 0 in the HIDAPI GIP driver #12940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions src/joystick/hidapi/SDL_hidapi_gip.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ typedef struct GIP_Metadata
Uint16 version_minor;

GIP_DeviceMetadata device;

Uint8 num_messages;
GIP_MessageMetadata *message_metadata;
} GIP_Metadata;
Expand Down Expand Up @@ -575,6 +575,11 @@ static bool GIP_SupportsVendorMessage(GIP_Device *device, Uint8 command, bool up
static Uint8 GIP_SequenceNext(GIP_Device *device, Uint8 command, bool system)
{
Uint8 seq;

if (command == GIP_CMD_DIRECT_MOTOR) {
// The motor sequence is optional and always works with 0
return 0;
}
if (system) {
switch (command) {
case GIP_CMD_SECURITY:
Expand Down Expand Up @@ -792,7 +797,7 @@ static bool GIP_ParseDeviceMetadata(GIP_Metadata *metadata, const Uint8 *bytes,

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

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

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

Expand Down Expand Up @@ -1122,7 +1127,7 @@ static bool GIP_SendInitSequence(GIP_Device *device)

static bool GIP_EnsureMetadata(GIP_Device *device)
{

switch (device->got_metadata) {
case GIP_METADATA_GOT:
case GIP_METADATA_FAKED:
Expand All @@ -1147,8 +1152,6 @@ static bool GIP_EnsureMetadata(GIP_Device *device)

static bool GIP_SetMetadataDefaults(GIP_Device *device)
{
int seq;

/* Some decent default settings */
device->features |= GIP_FEATURE_MOTOR_CONTROL;
device->device_type = GIP_TYPE_GAMEPAD;
Expand All @@ -1164,23 +1167,6 @@ static bool GIP_SetMetadataDefaults(GIP_Device *device)
GIP_SendQueryFirmware(device, 2);
}

if (device->features & GIP_FEATURE_MOTOR_CONTROL) {
for (seq = 1; seq < 0x100; seq++) {
Uint8 message[9] = {0};

/* Try all sequence numbers to reset it to 1 */
GIP_SendRawMessage(device,
GIP_CMD_DIRECT_MOTOR,
0,
(Uint8) seq,
message,
sizeof(message),
true,
NULL,
NULL);
}
}

device->got_metadata = GIP_METADATA_FAKED;
device->hello_deadline = 0;
return HIDAPI_JoystickConnected(device->device, NULL);
Expand Down Expand Up @@ -1512,7 +1498,7 @@ static bool GIP_HandleCommandGuideButtonStatus(
if (!joystick) {
return false;
}
if (bytes[1] == VK_LWIN) {
if (bytes[1] == VK_LWIN) {
SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE, (bytes[0] & 0x01) != 0);
}

Expand Down Expand Up @@ -1815,7 +1801,7 @@ static bool GIP_HandleLLInputReport(
(bytes[device->paddle_offset] & 0x08) != 0);
}
}

if ((device->features & GIP_FEATURE_CONSOLE_FUNCTION_MAP) && num_bytes >= 32) {
int function_map_offset = -1;
if (device->features & GIP_FEATURE_DYNAMIC_LATENCY_INPUT) {
Expand Down Expand Up @@ -2057,7 +2043,7 @@ static int GIP_ReceivePacket(GIP_Device *device, const Uint8 *bytes, int num_byt
device->fragment_data = NULL;
}
device->fragment_message = 0;
}
}
fragment_offset += header.length;
device->fragment_offset = (Uint16) fragment_offset;
}
Expand Down
Loading