SDL  2.0
SDL_hidapijoystick_c.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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 #include "../../SDL_internal.h"
22 
23 #ifndef SDL_JOYSTICK_HIDAPI_H
24 #define SDL_JOYSTICK_HIDAPI_H
25 
26 #include "SDL_atomic.h"
27 #include "SDL_mutex.h"
28 #include "SDL_joystick.h"
29 #include "SDL_gamecontroller.h"
30 #include "../../hidapi/hidapi/hidapi.h"
31 #include "../usb_ids.h"
32 
33 /* This is the full set of HIDAPI drivers available */
34 #define SDL_JOYSTICK_HIDAPI_PS4
35 #define SDL_JOYSTICK_HIDAPI_SWITCH
36 #define SDL_JOYSTICK_HIDAPI_XBOX360
37 #define SDL_JOYSTICK_HIDAPI_XBOXONE
38 #define SDL_JOYSTICK_HIDAPI_GAMECUBE
39 
40 #ifdef __WINDOWS__
41 /* On Windows, Xbox One controllers are handled by the Xbox 360 driver */
42 #undef SDL_JOYSTICK_HIDAPI_XBOXONE
43 /* It turns out HIDAPI for Xbox controllers doesn't allow background input */
44 #undef SDL_JOYSTICK_HIDAPI_XBOX360
45 #endif
46 
47 #ifdef __MACOSX__
48 /* On Mac OS X, Xbox One controllers are handled by the Xbox 360 driver */
49 #undef SDL_JOYSTICK_HIDAPI_XBOXONE
50 #endif
51 
52 #if defined(__IPHONEOS__) || defined(__TVOS__) || defined(__ANDROID__)
53 /* Very basic Steam Controller support on mobile devices */
54 #define SDL_JOYSTICK_HIDAPI_STEAM
55 #endif
56 
57 /* The maximum size of a USB packet for HID devices */
58 #define USB_PACKET_LENGTH 64
59 
60 /* Forward declaration */
62 
63 typedef struct _SDL_HIDAPI_Device
64 {
65  char *name;
66  char *path;
71  int interface_number; /* Available on Windows and Linux */
75  Uint16 usage_page; /* Available on Windows and Mac OS X */
76  Uint16 usage; /* Available on Windows and Mac OS X */
77 
79  void *context;
85 
86  /* Used during scanning for device changes */
88 
90 } SDL_HIDAPI_Device;
91 
93 {
94  const char *hint;
96  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);
97  const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
98  SDL_bool (*InitDevice)(SDL_HIDAPI_Device *device);
99  int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id);
100  void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index);
101  SDL_bool (*UpdateDevice)(SDL_HIDAPI_Device *device);
102  SDL_bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
103  int (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
104  void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
105  void (*FreeDevice)(SDL_HIDAPI_Device *device);
106 
107 } SDL_HIDAPI_DeviceDriver;
108 
109 
110 /* HIDAPI device support */
111 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
112 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
113 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
114 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
115 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;
116 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
117 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
118 
119 /* Return true if a HID device is present and supported as a joystick */
120 extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
121 
122 extern void HIDAPI_UpdateDevices(void);
123 extern SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID);
124 extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID);
125 
126 #endif /* SDL_JOYSTICK_HIDAPI_H */
127 
128 /* vi: set ts=4 sw=4 expandtab: */
SDL_HIDAPI_DriverPS4
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4
_SDL_HIDAPI_DeviceDriver::UpdateDevice
SDL_bool(* UpdateDevice)(SDL_HIDAPI_Device *device)
Definition: SDL_hidapijoystick_c.h:101
_SDL_HIDAPI_Device::driver
struct _SDL_HIDAPI_DeviceDriver * driver
Definition: SDL_hidapijoystick_c.h:78
_SDL_HIDAPI_DeviceDriver::FreeDevice
void(* FreeDevice)(SDL_HIDAPI_Device *device)
Definition: SDL_hidapijoystick_c.h:105
_SDL_HIDAPI_Device::interface_number
int interface_number
Definition: SDL_hidapijoystick_c.h:71
SDL_atomic.h
_SDL_HIDAPI_Device
Definition: SDL_hidapijoystick_c.h:63
HIDAPI_JoystickConnected
SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID)
SDL_joystick.h
SDL_mutex
Definition: SDL_sysmutex.c:29
_SDL_HIDAPI_Device::version
Uint16 version
Definition: SDL_hidapijoystick_c.h:69
_SDL_HIDAPI_DeviceDriver
Definition: SDL_hidapijoystick_c.h:92
HIDAPI_IsDevicePresent
SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
_SDL_HIDAPI_DeviceDriver::RumbleJoystick
int(* RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
Definition: SDL_hidapijoystick_c.h:103
_SDL_HIDAPI_Device::interface_subclass
int interface_subclass
Definition: SDL_hidapijoystick_c.h:73
_SDL_HIDAPI_Device::next
struct _SDL_HIDAPI_Device * next
Definition: SDL_hidapijoystick_c.h:89
_SDL_HIDAPI_Device::interface_class
int interface_class
Definition: SDL_hidapijoystick_c.h:72
_SDL_HIDAPI_Device::path
char * path
Definition: SDL_hidapijoystick_c.h:66
SDL_JoystickID
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:81
SDL_HIDAPI_DriverSwitch
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch
_SDL_HIDAPI_DeviceDriver::hint
const char * hint
Definition: SDL_hidapijoystick_c.h:94
_SDL_HIDAPI_Device::interface_protocol
int interface_protocol
Definition: SDL_hidapijoystick_c.h:74
SDL_HIDAPI_DriverXbox360
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360
_SDL_HIDAPI_Device::usage
Uint16 usage
Definition: SDL_hidapijoystick_c.h:76
_SDL_HIDAPI_Device::context
void * context
Definition: SDL_hidapijoystick_c.h:79
_SDL_HIDAPI_Device::rumble_pending
SDL_atomic_t rumble_pending
Definition: SDL_hidapijoystick_c.h:82
SDL_mutex.h
_SDL_HIDAPI_Device::joysticks
SDL_JoystickID * joysticks
Definition: SDL_hidapijoystick_c.h:84
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:663
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
_SDL_HIDAPI_Device::seen
SDL_bool seen
Definition: SDL_hidapijoystick_c.h:87
_SDL_HIDAPI_Device::dev_lock
SDL_mutex * dev_lock
Definition: SDL_hidapijoystick_c.h:80
SDL_gamecontroller.h
_SDL_HIDAPI_Device::num_joysticks
int num_joysticks
Definition: SDL_hidapijoystick_c.h:83
_SDL_HIDAPI_DeviceDriver::GetDevicePlayerIndex
int(* GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
Definition: SDL_hidapijoystick_c.h:99
SDL_HIDAPI_DriverXboxOne
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne
HIDAPI_JoystickDisconnected
void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID)
SDL_HIDAPI_DriverSteam
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam
_SDL_HIDAPI_Device::name
char * name
Definition: SDL_hidapijoystick_c.h:65
SDL_GameControllerType
SDL_GameControllerType
Definition: SDL_gamecontroller.h:60
_SDL_HIDAPI_Device::guid
SDL_JoystickGUID guid
Definition: SDL_hidapijoystick_c.h:70
SDL_atomic_t
A type representing an atomic integer value. It is a struct so people don't accidentally use numeric ...
Definition: SDL_atomic.h:216
SDL_HIDAPI_DriverGameCube
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube
_SDL_HIDAPI_Device::product_id
Uint16 product_id
Definition: SDL_hidapijoystick_c.h:68
_SDL_HIDAPI_Device::vendor_id
Uint16 vendor_id
Definition: SDL_hidapijoystick_c.h:67
HIDAPI_UpdateDevices
void HIDAPI_UpdateDevices(void)
_SDL_HIDAPI_DeviceDriver::IsSupportedDevice
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)
Definition: SDL_hidapijoystick_c.h:96
hid_device
struct hid_device_ hid_device
Definition: hidapi.h:54
void
const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char int const SDL_PRINTF_FORMAT_STRING char const char const SDL_SCANF_FORMAT_STRING char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Definition: SDL_dynapi_procs.h:89
_SDL_HIDAPI_DeviceDriver::enabled
SDL_bool enabled
Definition: SDL_hidapijoystick_c.h:95
_SDL_HIDAPI_DeviceDriver::SetDevicePlayerIndex
void(* SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
Definition: SDL_hidapijoystick_c.h:100
device
static SDL_AudioDeviceID device
Definition: loopwave.c:37
SDL_JoystickGUID
Definition: SDL_joystick.h:70
_SDL_HIDAPI_Device::usage_page
Uint16 usage_page
Definition: SDL_hidapijoystick_c.h:75
type
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
_SDL_HIDAPI_DeviceDriver::InitDevice
SDL_bool(* InitDevice)(SDL_HIDAPI_Device *device)
Definition: SDL_hidapijoystick_c.h:98
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:161
_SDL_HIDAPI_DeviceDriver::CloseJoystick
void(* CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
Definition: SDL_hidapijoystick_c.h:104
_SDL_HIDAPI_Device::dev
hid_device * dev
Definition: SDL_hidapijoystick_c.h:81
_SDL_HIDAPI_DeviceDriver::OpenJoystick
SDL_bool(* OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
Definition: SDL_hidapijoystick_c.h:102
SDL_HIDAPI_DriverXbox360W
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W