diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c index ee4baf0ed..473df1d9e 100644 --- a/src/joystick/hidapi/SDL_hidapi_switch.c +++ b/src/joystick/hidapi/SDL_hidapi_switch.c @@ -229,17 +229,17 @@ typedef struct { static SDL_bool HasHomeLED(int vendor_id, int product_id) { - /* The Power A Nintendo Switch Pro controllers don't have a Home LED */ - if (vendor_id == 0 && product_id == 0) { - return SDL_FALSE; - } + /* The Power A Nintendo Switch Pro controllers don't have a Home LED */ + if (vendor_id == 0 && product_id == 0) { + return SDL_FALSE; + } - /* HORI Wireless Switch Pad */ - if (vendor_id == 0x0f0d && product_id == 0x00f6) { - return SDL_FALSE; - } + /* HORI Wireless Switch Pad */ + if (vendor_id == 0x0f0d && product_id == 0x00f6) { + return SDL_FALSE; + } - return SDL_TRUE; + return SDL_TRUE; } static SDL_bool @@ -541,7 +541,7 @@ static SDL_bool SetSlotLED(SDL_DriverSwitch_Context *ctx, Uint8 slot) return WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SetPlayerLights, &led_data, sizeof(led_data), NULL); } -static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx) +static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx, Uint8 input_mode) { Uint8 *pStickCal; size_t stick, axis; @@ -594,7 +594,7 @@ static SDL_bool LoadStickCalibration(SDL_DriverSwitch_Context *ctx) } } - if (ctx->m_bUsingBluetooth) { + if (input_mode == k_eSwitchInputReportIDs_SimpleControllerState) { for (stick = 0; stick < 2; ++stick) { for(axis = 0; axis < 2; ++axis) { ctx->m_StickExtents[stick].axis[axis].sMin = (Sint16)(SDL_MIN_SINT16 * 0.5f); @@ -736,7 +736,24 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti ctx->m_bUsingBluetooth = SDL_TRUE; } - if (!LoadStickCalibration(ctx)) { + /* Determine the desired input mode (needed before loading stick calibration) */ + if (ctx->m_bUsingBluetooth) { + input_mode = k_eSwitchInputReportIDs_SimpleControllerState; + } else { + input_mode = k_eSwitchInputReportIDs_FullControllerState; + } + + /* The official Nintendo Switch Pro Controller supports FullControllerState over bluetooth + * just fine. We really should use that, or else the epowerlevel code in + * HandleFullControllerState is completely pointless. We need full state if we want battery + * level and we only care about battery level over bluetooth anyway. + */ + if (device->vendor_id == USB_VENDOR_NINTENDO && + device->product_id == USB_PRODUCT_NINTENDO_SWITCH_PRO) { + input_mode = k_eSwitchInputReportIDs_FullControllerState; + } + + if (!LoadStickCalibration(ctx, input_mode)) { SDL_SetError("Couldn't load stick calibration"); goto error; } @@ -746,12 +763,7 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti goto error; } - /* Set the desired input mode */ - if (ctx->m_bUsingBluetooth) { - input_mode = k_eSwitchInputReportIDs_SimpleControllerState; - } else { - input_mode = k_eSwitchInputReportIDs_FullControllerState; - } + /* Set desired input mode */ if (!SetInputMode(ctx, input_mode)) { SDL_SetError("Couldn't set input mode"); goto error; diff --git a/src/joystick/usb_ids.h b/src/joystick/usb_ids.h index 2603962a3..cf806bdd9 100644 --- a/src/joystick/usb_ids.h +++ b/src/joystick/usb_ids.h @@ -35,6 +35,7 @@ #define USB_VENDOR_VALVE 0x28de #define USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER 0x0337 +#define USB_PRODUCT_NINTENDO_SWITCH_PRO 0x2009 #define USB_PRODUCT_RAZER_PANTHERA 0x0401 #define USB_PRODUCT_RAZER_PANTHERA_EVO 0x1008 #define USB_PRODUCT_SONY_DS4 0x05c4