SDL_hidapijoystick_c.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2020 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. #include "../../SDL_internal.h"
  19. #ifndef SDL_JOYSTICK_HIDAPI_H
  20. #define SDL_JOYSTICK_HIDAPI_H
  21. #include "../../hidapi/hidapi/hidapi.h"
  22. #include "../usb_ids.h"
  23. /* This is the full set of HIDAPI drivers available */
  24. #define SDL_JOYSTICK_HIDAPI_PS4
  25. #define SDL_JOYSTICK_HIDAPI_SWITCH
  26. #define SDL_JOYSTICK_HIDAPI_XBOX360
  27. #define SDL_JOYSTICK_HIDAPI_XBOXONE
  28. #define SDL_JOYSTICK_HIDAPI_GAMECUBE
  29. #ifdef __WINDOWS__
  30. /* On Windows, Xbox One controllers are handled by the Xbox 360 driver */
  31. #undef SDL_JOYSTICK_HIDAPI_XBOXONE
  32. /* It turns out HIDAPI for Xbox controllers doesn't allow background input */
  33. #undef SDL_JOYSTICK_HIDAPI_XBOX360
  34. #endif
  35. #ifdef __MACOSX__
  36. /* On Mac OS X, Xbox One controllers are handled by the Xbox 360 driver */
  37. #undef SDL_JOYSTICK_HIDAPI_XBOXONE
  38. #endif
  39. #if defined(__IPHONEOS__) || defined(__TVOS__) || defined(__ANDROID__)
  40. /* Very basic Steam Controller support on mobile devices */
  41. #define SDL_JOYSTICK_HIDAPI_STEAM
  42. #endif
  43. /* Forward declaration */
  44. struct _SDL_HIDAPI_DeviceDriver;
  45. typedef struct _SDL_HIDAPI_Device
  46. {
  47. char *name;
  48. char *path;
  49. Uint16 vendor_id;
  50. Uint16 product_id;
  51. Uint16 version;
  52. SDL_JoystickGUID guid;
  53. int interface_number; /* Available on Windows and Linux */
  54. int interface_class;
  55. int interface_subclass;
  56. int interface_protocol;
  57. Uint16 usage_page; /* Available on Windows and Mac OS X */
  58. Uint16 usage; /* Available on Windows and Mac OS X */
  59. struct _SDL_HIDAPI_DeviceDriver *driver;
  60. void *context;
  61. hid_device *dev;
  62. int num_joysticks;
  63. SDL_JoystickID *joysticks;
  64. /* Used during scanning for device changes */
  65. SDL_bool seen;
  66. struct _SDL_HIDAPI_Device *next;
  67. } SDL_HIDAPI_Device;
  68. typedef struct _SDL_HIDAPI_DeviceDriver
  69. {
  70. const char *hint;
  71. SDL_bool enabled;
  72. SDL_bool (*IsSupportedDevice)(const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol);
  73. const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
  74. SDL_bool (*InitDevice)(SDL_HIDAPI_Device *device);
  75. int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id);
  76. void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index);
  77. SDL_bool (*UpdateDevice)(SDL_HIDAPI_Device *device);
  78. SDL_bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
  79. int (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
  80. void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
  81. void (*FreeDevice)(SDL_HIDAPI_Device *device);
  82. } SDL_HIDAPI_DeviceDriver;
  83. /* The maximum size of a USB packet for HID devices */
  84. #define USB_PACKET_LENGTH 64
  85. /* HIDAPI device support */
  86. extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
  87. extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
  88. extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
  89. extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
  90. extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;
  91. extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
  92. extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
  93. /* Return true if a HID device is present and supported as a joystick */
  94. extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
  95. extern void HIDAPI_UpdateDevices(void);
  96. extern SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID);
  97. extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID);
  98. #endif /* SDL_JOYSTICK_HIDAPI_H */
  99. /* vi: set ts=4 sw=4 expandtab: */