Просмотр исходного кода

Fix HIDAPI support for Flydigi Vader 5 Pro (#15594)

Rachel Blackman 1 день назад
Родитель
Сommit
eb340388fc
1 измененных файлов с 24 добавлено и 4 удалено
  1. 24 4
      src/joystick/hidapi/SDL_hidapi_flydigi.c

+ 24 - 4
src/joystick/hidapi/SDL_hidapi_flydigi.c

@@ -295,6 +295,24 @@ static void HIDAPI_DriverFlydigi_SetAvailable(SDL_HIDAPI_Device *device, bool av
     ctx->available = available;
 }
 
+static int HIDAPI_DriverFlydigi_WritePacket(SDL_HIDAPI_Device *device, const Uint8 *data, size_t size)
+{
+    // We know that at the very least the Vader 5 now uses unnumbered reports for commands instead of FLYDIGI_V2_CMD_REPORT_ID.
+    // If other Flydigi things prove to do the same, we can tweak this check to be more general.
+    bool bUsesUnnumberedReports = (device->vendor_id == USB_VENDOR_FLYDIGI_V2 && device->product_id == USB_PRODUCT_FLYDIGI_V2_VADER);
+
+    if (bUsesUnnumberedReports && data[0] == FLYDIGI_V2_CMD_REPORT_ID) {
+        // Zero out the report byte.
+        Uint8 output[USB_PACKET_LENGTH];
+        SDL_memcpy(output, data, SDL_min(size, USB_PACKET_LENGTH));
+        output[0] = 0;
+        return SDL_hid_write(device->dev, output, SDL_min(size, USB_PACKET_LENGTH));
+    }
+
+    return SDL_hid_write(device->dev, data, size);
+}
+
+
 static bool HIDAPI_DriverFlydigi_InitControllerV1(SDL_HIDAPI_Device *device)
 {
     SDL_DriverFlydigi_Context *ctx = (SDL_DriverFlydigi_Context *)device->context;
@@ -303,7 +321,7 @@ static bool HIDAPI_DriverFlydigi_InitControllerV1(SDL_HIDAPI_Device *device)
     for (int attempt = 0; ctx->deviceID == 0 && attempt < 30; ++attempt) {
         const Uint8 request[] = { FLYDIGI_V1_CMD_REPORT_ID, FLYDIGI_V1_GET_INFO_COMMAND, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
         // This write will occasionally return -1, so ignore failure here and try again
-        (void)SDL_hid_write(device->dev, request, sizeof(request));
+        (void)HIDAPI_DriverFlydigi_WritePacket(device, request, sizeof(request));
 
         // Read the reply
         for (int i = 0; i < 100; ++i) {
@@ -399,7 +417,8 @@ static bool SDL_HIDAPI_Flydigi_SendInfoRequest(SDL_HIDAPI_Device *device)
         2,
         0
     };
-    if (SDL_hid_write(device->dev, cmd, sizeof(cmd)) < 0) {
+
+    if (HIDAPI_DriverFlydigi_WritePacket(device, cmd, sizeof(cmd)) < 0) {
         return SDL_SetError("Couldn't query controller info");
     }
     return true;
@@ -441,7 +460,8 @@ static bool SDL_HIDAPI_Flydigi_SendStatusRequest(SDL_HIDAPI_Device *device)
         FLYDIGI_V2_MAGIC2,
         FLYDIGI_V2_GET_STATUS_COMMAND
     };
-    if (SDL_hid_write(device->dev, cmd, sizeof(cmd)) < 0) {
+
+    if (HIDAPI_DriverFlydigi_WritePacket(device, cmd, sizeof(cmd)) < 0) {
         return SDL_SetError("Couldn't query controller status");
     }
     return true;
@@ -469,7 +489,7 @@ static bool SDL_HIDAPI_Flydigi_SendAcquireRequest(SDL_HIDAPI_Device *device, boo
         'S', 'D', 'L', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
     };
 
-    if (SDL_hid_write(device->dev, cmd, sizeof(cmd)) < 0) {
+    if (HIDAPI_DriverFlydigi_WritePacket(device, cmd, sizeof(cmd)) < 0) {
         return SDL_SetError("Couldn't send acquire command");
     }
     return true;