Browse Source

switch2: Simplify init data array

Vicki Pfau 2 months ago
parent
commit
061ce935df
1 changed files with 22 additions and 25 deletions
  1. 22 25
      src/joystick/hidapi/SDL_hidapi_switch2.c

+ 22 - 25
src/joystick/hidapi/SDL_hidapi_switch2.c

@@ -344,42 +344,39 @@ static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
     }
     ctx->interface_claimed = true;
 
-    const struct {
-        Uint8 size;
-        const Uint8 *data;
-    } init_sequence[] = {
-        { 8, (Uint8[]) { // Unknown purpose
+    const Uint8 *init_sequence[] = {
+        (Uint8[]) { // Unknown purpose
             0x7, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
-        }},
-        { 8, (Uint8[]) { // Unknown purpose
+        },
+        (Uint8[]) { // Unknown purpose
             0x16, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
-        }},
-        { 12, (Uint8[]) { // Set feature output bit mask
+        },
+        (Uint8[]) { // Set feature output bit mask
             0x0c, 0x91, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00
-        }},
-        { 8, (Uint8[]) { // Unknown purpose
+        },
+        (Uint8[]) { // Unknown purpose
             0x11, 0x91, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0,
-        }},
-        { 28, (Uint8[]) { // Set rumble data?
+        },
+        (Uint8[]) { // Set rumble data?
             0x0a, 0x91, 0x00, 0x08, 0x00, 0x14, 0x00, 0x00,
             0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
             0xff, 0x35, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00,
             0x00, 0x00, 0x00, 0x00
-        }},
-        { 12, (Uint8[]) { // Enable feature output bits
+        },
+        (Uint8[]) { // Enable feature output bits
             0x0c, 0x91, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00
-        }},
-        { 8, (Uint8[]) { // Unknown purpose
+        },
+        (Uint8[]) { // Unknown purpose
             0x10, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
-        }},
-        { 8, (Uint8[]) { // Enable rumble
+        },
+        (Uint8[]) { // Enable rumble
             0x01, 0x91, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
-        }},
-        { 16, (Uint8[]) { // Start output
+        },
+        (Uint8[]) { // Start output
             0x03, 0x91, 0x00, 0x0d, 0x00, 0x08, 0x00, 0x00,
             0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-        }},
-        { 0, NULL }, // Sentinel
+        },
+        NULL, // Sentinel
     };
     unsigned char flash_read_command[] = {
         0x02, 0x91, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00,
@@ -458,8 +455,8 @@ static bool HIDAPI_DriverSwitch2_InitUSB(SDL_HIDAPI_Device *device)
         }
     }
 
-    for (int i = 0; init_sequence[i].size; i++) {
-        res = SendBulkData(ctx, init_sequence[i].data, init_sequence[i].size);
+    for (int i = 0; init_sequence[i]; i++) {
+        res = SendBulkData(ctx, init_sequence[i], init_sequence[i][5] + 8);
         if (res < 0) {
             return SDL_SetError("Couldn't send initialization data: %d\n", res);
         }