SDL  2.0
SDL_sysjoystick.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_sysjoystick_h_
24 #define SDL_sysjoystick_h_
25 
26 /* This is the system specific header for the SDL joystick API */
27 
28 #include "SDL_joystick.h"
29 #include "SDL_joystick_c.h"
30 
31 /* The SDL joystick structure */
32 typedef struct _SDL_JoystickAxisInfo
33 {
34  Sint16 initial_value; /* Initial axis state */
35  Sint16 value; /* Current axis state */
36  Sint16 zero; /* Zero point on the axis (-32768 for triggers) */
37  SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */
38  SDL_bool has_second_value; /* Whether we've seen a second value on the axis yet */
39  SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */
41 
42 typedef struct _SDL_JoystickTouchpadFingerInfo
43 {
45  float x;
46  float y;
47  float pressure;
49 
50 typedef struct _SDL_JoystickTouchpadInfo
51 {
52  int nfingers;
55 
56 typedef struct _SDL_JoystickSensorInfo
57 {
60  float data[3]; /* If this needs to expand, update SDL_ControllerSensorEvent */
62 
64 {
65  SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
66  char *name; /* Joystick name - system dependent */
67  char *serial; /* Joystick serial */
68  SDL_JoystickGUID guid; /* Joystick guid */
69 
70  int naxes; /* Number of axis controls on the joystick */
72 
73  int nhats; /* Number of hats on the joystick */
74  Uint8 *hats; /* Current hat states */
75 
76  int nballs; /* Number of trackballs on the joystick */
77  struct balldelta {
78  int dx;
79  int dy;
80  } *balls; /* Current ball motion deltas */
81 
82  int nbuttons; /* Number of buttons on the joystick */
83  Uint8 *buttons; /* Current button states */
84 
85  int ntouchpads; /* Number of touchpads on the joystick */
86  SDL_JoystickTouchpadInfo *touchpads; /* Current touchpad states */
87 
88  int nsensors; /* Number of sensors on the joystick */
91 
95 
99 
103 
106  SDL_bool delayed_guide_button; /* SDL_TRUE if this device has the guide button event delayed */
107  SDL_JoystickPowerLevel epowerlevel; /* power level of this joystick, SDL_JOYSTICK_POWER_UNKNOWN if not supported */
108 
109  struct _SDL_JoystickDriver *driver;
110 
111  struct joystick_hwdata *hwdata; /* Driver dependent information */
112 
113  int ref_count; /* Reference count for multiple opens */
114 
115  struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
116 };
117 
118 /* Device bus definitions */
119 #define SDL_HARDWARE_BUS_USB 0x03
120 #define SDL_HARDWARE_BUS_BLUETOOTH 0x05
121 
122 /* Macro to combine a USB vendor ID and product ID into a single Uint32 value */
123 #define MAKE_VIDPID(VID, PID) (((Uint32)(VID))<<16|(PID))
124 
125 typedef struct _SDL_JoystickDriver
126 {
127  /* Function to scan the system for joysticks.
128  * Joystick 0 should be the system default joystick.
129  * This function should return 0, or -1 on an unrecoverable error.
130  */
131  int (*Init)(void);
132 
133  /* Function to return the number of joystick devices plugged in right now */
134  int (*GetCount)(void);
135 
136  /* Function to cause any queued joystick insertions to be processed */
137  void (*Detect)(void);
138 
139  /* Function to get the device-dependent name of a joystick */
140  const char *(*GetDeviceName)(int device_index);
141 
142  /* Function to get the player index of a joystick */
143  int (*GetDevicePlayerIndex)(int device_index);
144 
145  /* Function to get the player index of a joystick */
146  void (*SetDevicePlayerIndex)(int device_index, int player_index);
147 
148  /* Function to return the stable GUID for a plugged in device */
149  SDL_JoystickGUID (*GetDeviceGUID)(int device_index);
150 
151  /* Function to get the current instance id of the joystick located at device_index */
152  SDL_JoystickID (*GetDeviceInstanceID)(int device_index);
153 
154  /* Function to open a joystick for use.
155  The joystick to open is specified by the device index.
156  This should fill the nbuttons and naxes fields of the joystick structure.
157  It returns 0, or -1 if there is an error.
158  */
159  int (*Open)(SDL_Joystick *joystick, int device_index);
160 
161  /* Rumble functionality */
162  int (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
163  int (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
164 
165  /* LED functionality */
166  SDL_bool (*HasLED)(SDL_Joystick *joystick);
167  int (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
168 
169  /* Sensor functionality */
170  int (*SetSensorsEnabled)(SDL_Joystick *joystick, SDL_bool enabled);
171 
172  /* Function to update the state of a joystick - called as a device poll.
173  * This function shouldn't update the joystick structure directly,
174  * but instead should call SDL_PrivateJoystick*() to deliver events
175  * and update joystick device state.
176  */
177  void (*Update)(SDL_Joystick *joystick);
178 
179  /* Function to close a joystick after use */
180  void (*Close)(SDL_Joystick *joystick);
181 
182  /* Function to perform any system-specific joystick related cleanup */
183  void (*Quit)(void);
184 
185  /* Function to get the autodetected controller mapping; returns false if there isn't any. */
186  SDL_bool (*GetGamepadMapping)(int device_index, SDL_GamepadMapping * out);
187 
189 
190 /* Windows and Mac OSX has a limit of MAX_DWORD / 1000, Linux kernel has a limit of 0xFFFF */
191 #define SDL_MAX_RUMBLE_DURATION_MS 0xFFFF
192 
193 /* The available joystick drivers */
207 
208 #endif /* SDL_sysjoystick_h_ */
209 
210 /* 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
const GLubyte GLuint red
Definition: SDL_glfuncs.h:80
SDL_JoystickPowerLevel
Definition: SDL_joystick.h:98
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:81
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLbyte GLbyte blue
GLbyte green
SDL_SensorType
Definition: SDL_sensor.h:70
uint16_t Uint16
Definition: SDL_stdinc.h:197
int16_t Sint16
Definition: SDL_stdinc.h:191
SDL_bool
Definition: SDL_stdinc.h:168
uint8_t Uint8
Definition: SDL_stdinc.h:185
uint32_t Uint32
Definition: SDL_stdinc.h:209
SDL_JoystickDriver SDL_BSD_JoystickDriver
SDL_JoystickDriver SDL_WGI_JoystickDriver
SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver
SDL_JoystickDriver SDL_IOS_JoystickDriver
SDL_JoystickDriver SDL_ANDROID_JoystickDriver
SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver
SDL_JoystickDriver SDL_DUMMY_JoystickDriver
SDL_JoystickDriver SDL_LINUX_JoystickDriver
SDL_JoystickDriver SDL_HIDAPI_JoystickDriver
SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver
SDL_JoystickDriver SDL_DARWIN_JoystickDriver
SDL_JoystickDriver SDL_WINDOWS_JoystickDriver
SDL_JoystickDriver SDL_HAIKU_JoystickDriver
SDL_bool is_game_controller
struct _SDL_Joystick::balldelta * balls
SDL_JoystickTouchpadInfo * touchpads
SDL_JoystickID instance_id
struct _SDL_JoystickDriver * driver
Uint16 left_trigger_rumble
Uint16 high_frequency_rumble
SDL_JoystickAxisInfo * axes
SDL_JoystickSensorInfo * sensors
Uint16 low_frequency_rumble
struct joystick_hwdata * hwdata
Uint16 right_trigger_rumble
SDL_JoystickGUID guid
Uint32 trigger_rumble_expiration
SDL_JoystickPowerLevel epowerlevel
SDL_bool delayed_guide_button
struct _SDL_Joystick * next
Uint32 rumble_expiration
SDL_JoystickTouchpadFingerInfo * fingers
static SDL_Joystick * joystick
Definition: testjoystick.c:37
typedef int(__stdcall *FARPROC)()