Forráskód Böngészése

Try to guess the type of a Nintendo Switch controller if we can't read the device info

Sam Lantinga 10 hónapja
szülő
commit
6619de8f24
1 módosított fájl, 21 hozzáadás és 0 törlés
  1. 21 0
      src/joystick/hidapi/SDL_hidapi_switch.c

+ 21 - 0
src/joystick/hidapi/SDL_hidapi_switch.c

@@ -1279,6 +1279,27 @@ static void UpdateDeviceIdentity(SDL_HIDAPI_Device *device)
             break;
         case k_eSwitchDeviceInfoControllerType_Unknown:
             /* We couldn't read the device info for this controller, might not be fully compliant */
+            if (device->vendor_id == USB_VENDOR_NINTENDO) {
+                switch (device->product_id) {
+                case USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT:
+                    ctx->m_eControllerType = k_eSwitchDeviceInfoControllerType_JoyConLeft;
+                    HIDAPI_SetDeviceName(device, "Nintendo Switch Joy-Con (L)");
+                    device->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT;
+                    break;
+                case USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT:
+                    ctx->m_eControllerType = k_eSwitchDeviceInfoControllerType_JoyConRight;
+                    HIDAPI_SetDeviceName(device, "Nintendo Switch Joy-Con (R)");
+                    device->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT;
+                    break;
+                case USB_PRODUCT_NINTENDO_SWITCH_PRO:
+                    ctx->m_eControllerType = k_eSwitchDeviceInfoControllerType_ProController;
+                    HIDAPI_SetDeviceName(device, "Nintendo Switch Pro Controller");
+                    device->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO;
+                    break;
+                default:
+                    break;
+                }
+            }
             return;
         default:
             device->type = SDL_GAMEPAD_TYPE_STANDARD;