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_PS5
36 #define SDL_JOYSTICK_HIDAPI_SWITCH
37 #define SDL_JOYSTICK_HIDAPI_XBOX360
38 #define SDL_JOYSTICK_HIDAPI_XBOXONE
39 #define SDL_JOYSTICK_HIDAPI_GAMECUBE
40 
41 #if defined(__IPHONEOS__) || defined(__TVOS__) || defined(__ANDROID__)
42 /* Very basic Steam Controller support on mobile devices */
43 #define SDL_JOYSTICK_HIDAPI_STEAM
44 #endif
45 
46 /* The maximum size of a USB packet for HID devices */
47 #define USB_PACKET_LENGTH 64
48 
49 /* Forward declaration */
50 struct _SDL_HIDAPI_DeviceDriver;
51 
52 typedef struct _SDL_HIDAPI_Device
53 {
54  char *name;
55  char *path;
59  char *serial;
61  int interface_number; /* Available on Windows and Linux */
65  Uint16 usage_page; /* Available on Windows and Mac OS X */
66  Uint16 usage; /* Available on Windows and Mac OS X */
67 
68  struct _SDL_HIDAPI_DeviceDriver *driver;
69  void *context;
75 
76  /* Used during scanning for device changes */
78 
79  /* Used to flag that the device is being updated */
81 
82  struct _SDL_HIDAPI_Device *next;
84 
85 typedef struct _SDL_HIDAPI_DeviceDriver
86 {
87  const char *hint;
89  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);
90  const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
92  int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id);
93  void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index);
94  SDL_bool (*UpdateDevice)(SDL_HIDAPI_Device *device);
95  SDL_bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
96  int (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
97  int (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
98  SDL_bool (*HasJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
99  int (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
100  int (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled);
101  void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
102  void (*FreeDevice)(SDL_HIDAPI_Device *device);
103 
105 
106 
107 /* HIDAPI device support */
116 
117 /* Return true if a HID device is present and supported as a joystick */
118 extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
119 
120 extern void HIDAPI_UpdateDevices(void);
123 
124 extern void HIDAPI_DumpPacket(const char *prefix, Uint8 *data, int size);
125 
126 #endif /* SDL_JOYSTICK_HIDAPI_H */
127 
128 /* vi: set ts=4 sw=4 expandtab: */
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
SDL_GameControllerType
const GLubyte GLuint red
Definition: SDL_glfuncs.h:80
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam
void HIDAPI_UpdateDevices(void)
void HIDAPI_DumpPacket(const char *prefix, Uint8 *data, int size)
SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID)
void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID)
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360
SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:81
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLbyte GLbyte blue
GLuint const GLchar * name
GLsizeiptr size
GLbyte green
uint16_t Uint16
Definition: SDL_stdinc.h:197
SDL_bool
Definition: SDL_stdinc.h:168
uint8_t Uint8
Definition: SDL_stdinc.h:185
struct hid_device_ hid_device
Definition: hidapi.h:54
static SDL_AudioDeviceID device
Definition: loopwave.c:37
struct _SDL_HIDAPI_Device * next
struct _SDL_HIDAPI_DeviceDriver * driver
SDL_atomic_t rumble_pending
SDL_JoystickGUID guid
SDL_JoystickID * joysticks
A type representing an atomic integer value. It is a struct so people don't accidentally use numeric ...
Definition: SDL_atomic.h:216
static SDL_Joystick * joystick
Definition: testjoystick.c:37
typedef int(__stdcall *FARPROC)()