SDL_hidapi_switch2.c 4.9 KB

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