|
| 1 | +/* |
| 2 | + Simple DirectMedia Layer |
| 3 | + Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> |
| 4 | +
|
| 5 | + This software is provided 'as-is', without any express or implied |
| 6 | + warranty. In no event will the authors be held liable for any damages |
| 7 | + arising from the use of this software. |
| 8 | +
|
| 9 | + Permission is granted to anyone to use this software for any purpose, |
| 10 | + including commercial applications, and to alter it and redistribute it |
| 11 | + freely, subject to the following restrictions: |
| 12 | +
|
| 13 | + 1. The origin of this software must not be misrepresented; you must not |
| 14 | + claim that you wrote the original software. If you use this software |
| 15 | + in a product, an acknowledgment in the product documentation would be |
| 16 | + appreciated but is not required. |
| 17 | + 2. Altered source versions must be plainly marked as such, and must not be |
| 18 | + misrepresented as being the original software. |
| 19 | + 3. This notice may not be removed or altered from any source distribution. |
| 20 | +*/ |
| 21 | +/* This driver supports the Nintendo Switch Pro controller. |
| 22 | + Code and logic contributed by Valve Corporation under the SDL zlib license. |
| 23 | +*/ |
| 24 | +#include "SDL_internal.h" |
| 25 | + |
| 26 | +#ifdef SDL_JOYSTICK_HIDAPI |
| 27 | + |
| 28 | +#include "../../SDL_hints_c.h" |
| 29 | +#include "../SDL_sysjoystick.h" |
| 30 | +#include "SDL_hidapijoystick_c.h" |
| 31 | +#include "SDL_hidapi_rumble.h" |
| 32 | +#include "SDL_hidapi_nintendo.h" |
| 33 | + |
| 34 | +#ifdef SDL_JOYSTICK_HIDAPI_SWITCH2 |
| 35 | + |
| 36 | +static void HIDAPI_DriverSwitch2_RegisterHints(SDL_HintCallback callback, void *userdata) |
| 37 | +{ |
| 38 | + SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH2, callback, userdata); |
| 39 | +} |
| 40 | + |
| 41 | +static void HIDAPI_DriverSwitch2_UnregisterHints(SDL_HintCallback callback, void *userdata) |
| 42 | +{ |
| 43 | + SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_SWITCH2, callback, userdata); |
| 44 | +} |
| 45 | + |
| 46 | +static bool HIDAPI_DriverSwitch2_IsEnabled(void) |
| 47 | +{ |
| 48 | + return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_SWITCH2, SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT)); |
| 49 | +} |
| 50 | + |
| 51 | +static bool HIDAPI_DriverSwitch2_IsSupportedDevice(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol) |
| 52 | +{ |
| 53 | + if (vendor_id == USB_VENDOR_NINTENDO) { |
| 54 | + if (product_id == USB_PRODUCT_NINTENDO_SWITCH2_GAMECUBE_CONTROLLER) { |
| 55 | + return true; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + return false; |
| 60 | +} |
| 61 | + |
| 62 | +static bool HIDAPI_DriverSwitch2_InitDevice(SDL_HIDAPI_Device *device) |
| 63 | +{ |
| 64 | + return false; |
| 65 | +} |
| 66 | + |
| 67 | +static int HIDAPI_DriverSwitch2_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id) |
| 68 | +{ |
| 69 | + return 0; |
| 70 | +} |
| 71 | + |
| 72 | +static void HIDAPI_DriverSwitch2_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index) |
| 73 | +{ |
| 74 | +} |
| 75 | + |
| 76 | +static bool HIDAPI_DriverSwitch2_UpdateDevice(SDL_HIDAPI_Device *device) |
| 77 | +{ |
| 78 | + return false; |
| 79 | +} |
| 80 | + |
| 81 | +static bool HIDAPI_DriverSwitch2_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) |
| 82 | +{ |
| 83 | + return false; |
| 84 | +} |
| 85 | + |
| 86 | +static bool HIDAPI_DriverSwitch2_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) |
| 87 | +{ |
| 88 | + return false; |
| 89 | +} |
| 90 | + |
| 91 | +static bool HIDAPI_DriverSwitch2_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) |
| 92 | +{ |
| 93 | + return false; |
| 94 | +} |
| 95 | + |
| 96 | +static Uint32 HIDAPI_DriverSwitch2_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) |
| 97 | +{ |
| 98 | + return 0; |
| 99 | +} |
| 100 | + |
| 101 | +static bool HIDAPI_DriverSwitch2_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) |
| 102 | +{ |
| 103 | + return false; |
| 104 | +} |
| 105 | + |
| 106 | +static bool HIDAPI_DriverSwitch2_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) |
| 107 | +{ |
| 108 | + return false; |
| 109 | +} |
| 110 | + |
| 111 | +static bool HIDAPI_DriverSwitch2_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) |
| 112 | +{ |
| 113 | + return false; |
| 114 | +} |
| 115 | + |
| 116 | +static void HIDAPI_DriverSwitch2_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) |
| 117 | +{ |
| 118 | +} |
| 119 | + |
| 120 | +static void HIDAPI_DriverSwitch2_FreeDevice(SDL_HIDAPI_Device *device) |
| 121 | +{ |
| 122 | +} |
| 123 | + |
| 124 | +SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch2 = { |
| 125 | + SDL_HINT_JOYSTICK_HIDAPI_SWITCH2, |
| 126 | + true, |
| 127 | + HIDAPI_DriverSwitch2_RegisterHints, |
| 128 | + HIDAPI_DriverSwitch2_UnregisterHints, |
| 129 | + HIDAPI_DriverSwitch2_IsEnabled, |
| 130 | + HIDAPI_DriverSwitch2_IsSupportedDevice, |
| 131 | + HIDAPI_DriverSwitch2_InitDevice, |
| 132 | + HIDAPI_DriverSwitch2_GetDevicePlayerIndex, |
| 133 | + HIDAPI_DriverSwitch2_SetDevicePlayerIndex, |
| 134 | + HIDAPI_DriverSwitch2_UpdateDevice, |
| 135 | + HIDAPI_DriverSwitch2_OpenJoystick, |
| 136 | + HIDAPI_DriverSwitch2_RumbleJoystick, |
| 137 | + HIDAPI_DriverSwitch2_RumbleJoystickTriggers, |
| 138 | + HIDAPI_DriverSwitch2_GetJoystickCapabilities, |
| 139 | + HIDAPI_DriverSwitch2_SetJoystickLED, |
| 140 | + HIDAPI_DriverSwitch2_SendJoystickEffect, |
| 141 | + HIDAPI_DriverSwitch2_SetJoystickSensorsEnabled, |
| 142 | + HIDAPI_DriverSwitch2_CloseJoystick, |
| 143 | + HIDAPI_DriverSwitch2_FreeDevice, |
| 144 | +}; |
| 145 | + |
| 146 | +#endif // SDL_JOYSTICK_HIDAPI_SWITCH2 |
| 147 | + |
| 148 | +#endif // SDL_JOYSTICK_HIDAPI |
0 commit comments