Browse Source

joystick: Several minor GIP fixes

This mostly fixes stylistic issues, but also fixes an issue with some
controllers where an erroneous check would clear the DLI flag, offsetting the
share button index so it wouldn't work.
Vicki Pfau 2 months ago
parent
commit
4cd889cb13
1 changed files with 16 additions and 17 deletions
  1. 16 17
      src/joystick/hidapi/SDL_hidapi_gip.c

+ 16 - 17
src/joystick/hidapi/SDL_hidapi_gip.c

@@ -809,7 +809,7 @@ static void GIP_MetadataFree(GIP_Metadata *metadata)
     SDL_memset(metadata, 0, sizeof(*metadata));
     SDL_memset(metadata, 0, sizeof(*metadata));
 }
 }
 
 
-static bool GIP_ParseDeviceMetadata(GIP_Metadata *metadata, const Uint8 *bytes, int num_bytes, int* offset)
+static bool GIP_ParseDeviceMetadata(GIP_Metadata *metadata, const Uint8 *bytes, int num_bytes, int *offset)
 {
 {
     GIP_DeviceMetadata *device = &metadata->device;
     GIP_DeviceMetadata *device = &metadata->device;
     int buffer_offset;
     int buffer_offset;
@@ -956,7 +956,7 @@ static bool GIP_ParseDeviceMetadata(GIP_Metadata *metadata, const Uint8 *bytes,
     return true;
     return true;
 }
 }
 
 
-static bool GIP_ParseMessageMetadata(GIP_MessageMetadata *metadata, const Uint8 *bytes, int num_bytes, int* offset)
+static bool GIP_ParseMessageMetadata(GIP_MessageMetadata *metadata, const Uint8 *bytes, int num_bytes, int *offset)
 {
 {
     Uint16 length;
     Uint16 length;
 
 
@@ -1095,7 +1095,8 @@ static bool GIP_Acknowledge(
         NULL);
         NULL);
 }
 }
 
 
-static bool GIP_FragmentFailed(GIP_Attachment *attachment, const GIP_Header *header) {
+static bool GIP_FragmentFailed(GIP_Attachment *attachment, const GIP_Header *header)
+{
     attachment->fragment_retries++;
     attachment->fragment_retries++;
     if (attachment->fragment_retries > 8) {
     if (attachment->fragment_retries > 8) {
         if (attachment->fragment_data) {
         if (attachment->fragment_data) {
@@ -1120,14 +1121,11 @@ static bool GIP_EnableEliteButtons(GIP_Attachment *attachment) {
          */
          */
         static const Uint8 enable_raw_report[] = { 7, 0 };
         static const Uint8 enable_raw_report[] = { 7, 0 };
 
 
-        if (!GIP_SendVendorMessage(attachment,
+        return GIP_SendVendorMessage(attachment,
             GIP_SL_ELITE_CONFIG,
             GIP_SL_ELITE_CONFIG,
             0,
             0,
             enable_raw_report,
             enable_raw_report,
-            sizeof(enable_raw_report)))
-        {
-            return false;
-        }
+            sizeof(enable_raw_report));
     }
     }
 
 
     return true;
     return true;
@@ -1565,10 +1563,10 @@ static bool GIP_HandleCommandMetadataRespose(
             "GIP: Controller was missing expected GUID. This controller probably won't work on an actual Xbox.");
             "GIP: Controller was missing expected GUID. This controller probably won't work on an actual Xbox.");
     }
     }
 
 
-    if ((attachment->features & GIP_CMD_GUIDE_COLOR) &&
+    if ((attachment->features & GIP_FEATURE_GUIDE_COLOR) &&
         !GIP_SupportsVendorMessage(attachment, GIP_CMD_GUIDE_COLOR, false))
         !GIP_SupportsVendorMessage(attachment, GIP_CMD_GUIDE_COLOR, false))
     {
     {
-        attachment->features &= ~GIP_CMD_GUIDE_COLOR;
+        attachment->features &= ~GIP_FEATURE_GUIDE_COLOR;
     }
     }
 
 
     GIP_HandleQuirks(attachment);
     GIP_HandleQuirks(attachment);
@@ -1661,9 +1659,9 @@ static bool GIP_HandleCommandFirmware(
             } else {
             } else {
                 attachment->paddle_format = GIP_PADDLES_XBE2;
                 attachment->paddle_format = GIP_PADDLES_XBE2;
             }
             }
+            return GIP_EnableEliteButtons(attachment);
         }
         }
-
-        return GIP_EnableEliteButtons(attachment);
+        return true;
     } else {
     } else {
         SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Firmware message");
         SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, "GIP: Unimplemented Firmware message");
 
 
@@ -1715,7 +1713,6 @@ static bool GIP_HandleCommandRawReport(
     return true;
     return true;
 }
 }
 
 
-
 static bool GIP_HandleCommandHidReport(
 static bool GIP_HandleCommandHidReport(
     GIP_Attachment *attachment,
     GIP_Attachment *attachment,
     const GIP_Header *header,
     const GIP_Header *header,
@@ -1886,8 +1883,6 @@ static void GIP_HandleNavigationReport(
         } else {
         } else {
             SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((bytes[1] & 0x10) != 0));
             SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER, ((bytes[1] & 0x10) != 0));
             SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((bytes[1] & 0x20) != 0));
             SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER, ((bytes[1] & 0x20) != 0));
-            SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((bytes[1] & 0x40) != 0));
-            SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((bytes[1] & 0x80) != 0));
         }
         }
     }
     }
 }
 }
@@ -1900,6 +1895,10 @@ static void GIP_HandleGamepadReport(
     int num_bytes)
     int num_bytes)
 {
 {
     Sint16 axis;
     Sint16 axis;
+
+    SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK, ((bytes[1] & 0x40) != 0));
+    SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK, ((bytes[1] & 0x80) != 0));
+
     axis = bytes[2];
     axis = bytes[2];
     axis |= bytes[3] << 8;
     axis |= bytes[3] << 8;
     axis = SDL_clamp(axis, 0, 1023);
     axis = SDL_clamp(axis, 0, 1023);
@@ -2241,7 +2240,7 @@ static bool GIP_HandleSystemMessage(
     }
     }
 }
 }
 
 
-static GIP_Attachment * GIP_EnsureAttachment(GIP_Device *device, Uint8 attachment_index)
+static GIP_Attachment *GIP_EnsureAttachment(GIP_Device *device, Uint8 attachment_index)
 {
 {
     GIP_Attachment *attachment = device->attachments[attachment_index];
     GIP_Attachment *attachment = device->attachments[attachment_index];
     if (!attachment) {
     if (!attachment) {
@@ -2280,7 +2279,7 @@ static bool GIP_HandleMessage(
         case GIP_LL_BUTTON_INFO_REPORT:
         case GIP_LL_BUTTON_INFO_REPORT:
             return GIP_HandleLLButtonInfoReport(attachment, header, bytes, num_bytes);
             return GIP_HandleLLButtonInfoReport(attachment, header, bytes, num_bytes);
         case GIP_LL_OVERFLOW_INPUT_REPORT:
         case GIP_LL_OVERFLOW_INPUT_REPORT:
-            return  GIP_HandleLLOverflowInputReport(attachment, header, bytes, num_bytes);
+            return GIP_HandleLLOverflowInputReport(attachment, header, bytes, num_bytes);
         }
         }
     }
     }
     SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,
     SDL_LogWarn(SDL_LOG_CATEGORY_INPUT,