1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2025 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 
22 /**
23  * # CategoryJoystick
24  *
25  * Include file for SDL joystick event handling
26  *
27  * The term "device_index" identifies currently plugged in joystick devices
28  * between 0 and SDL_NumJoysticks(), with the exact joystick behind a
29  * device_index changing as joysticks are plugged and unplugged.
30  *
31  * The term "instance_id" is the current instantiation of a joystick device in
32  * the system, if the joystick is removed and then re-inserted then it will
33  * get a new instance_id, instance_id's are monotonically increasing
34  * identifiers of a joystick plugged in.
35  *
36  * The term "player_index" is the number assigned to a player on a specific
37  * controller. For XInput controllers this returns the XInput user index. Many
38  * joysticks will not be able to supply this information.
39  *
40  * The term JoystickGUID is a stable 128-bit identifier for a joystick device
41  * that does not change over time, it identifies class of the device (a X360
42  * wired controller for example). This identifier is platform dependent.
43  */
44 
45 #ifndef SDL_joystick_h_
46 #define SDL_joystick_h_
47 
48 #include "SDL_stdinc.h"
49 #include "SDL_error.h"
50 #include "SDL_guid.h"
51 #include "SDL_mutex.h"
52 
53 #include "begin_code.h"
54 /* Set up for C function definitions, even when using C++ */
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /**
60  *  \file SDL_joystick.h
61  *
62  *  In order to use these functions, SDL_Init() must have been called
63  *  with the SDL_INIT_JOYSTICK flag.  This causes SDL to scan the system
64  *  for joysticks, and load appropriate drivers.
65  *
66  *  If you would like to receive joystick updates while the application
67  *  is in the background, you should set the following hint before calling
68  *  SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
69  */
70 
71 /**
72  * The joystick structure used to identify an SDL joystick
73  */
74 #ifdef SDL_THREAD_SAFETY_ANALYSIS
75 extern SDL_mutex *SDL_joystick_lock;
76 #endif
77 struct _SDL_Joystick;
78 typedef struct _SDL_Joystick SDL_Joystick;
79 
80 /**
81  * A structure that encodes the stable unique id for a joystick device.
82  *
83  * This is just a standard SDL_GUID by a different name.
84  */
85 typedef SDL_GUID SDL_JoystickGUID;
86 
87 /**
88  * This is a unique ID for a joystick for the time it is connected to the
89  * system, and is never reused for the lifetime of the application.
90  *
91  * If the joystick is disconnected and reconnected, it will get a new ID.
92  *
93  * The ID value starts at 0 and increments from there. The value -1 is an
94  * invalid ID.
95  */
96 typedef Sint32 SDL_JoystickID;
97 
98 typedef enum
99 {
100     SDL_JOYSTICK_TYPE_UNKNOWN,
101     SDL_JOYSTICK_TYPE_GAMECONTROLLER,
102     SDL_JOYSTICK_TYPE_WHEEL,
103     SDL_JOYSTICK_TYPE_ARCADE_STICK,
104     SDL_JOYSTICK_TYPE_FLIGHT_STICK,
105     SDL_JOYSTICK_TYPE_DANCE_PAD,
106     SDL_JOYSTICK_TYPE_GUITAR,
107     SDL_JOYSTICK_TYPE_DRUM_KIT,
108     SDL_JOYSTICK_TYPE_ARCADE_PAD,
109     SDL_JOYSTICK_TYPE_THROTTLE
110 } SDL_JoystickType;
111 
112 typedef enum
113 {
114     SDL_JOYSTICK_POWER_UNKNOWN = -1,
115     SDL_JOYSTICK_POWER_EMPTY,   /* <= 5% */
116     SDL_JOYSTICK_POWER_LOW,     /* <= 20% */
117     SDL_JOYSTICK_POWER_MEDIUM,  /* <= 70% */
118     SDL_JOYSTICK_POWER_FULL,    /* <= 100% */
119     SDL_JOYSTICK_POWER_WIRED,
120     SDL_JOYSTICK_POWER_MAX
121 } SDL_JoystickPowerLevel;
122 
123 /* Set max recognized G-force from accelerometer
124    See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
125  */
126 #define SDL_IPHONE_MAX_GFORCE 5.0
127 
128 
129 /* Function prototypes */
130 
131 /**
132  * Locking for multi-threaded access to the joystick API
133  *
134  * If you are using the joystick API or handling events from multiple threads
135  * you should use these locking functions to protect access to the joysticks.
136  *
137  * In particular, you are guaranteed that the joystick list won't change, so
138  * the API functions that take a joystick index will be valid, and joystick
139  * and game controller events will not be delivered.
140  *
141  * As of SDL 2.26.0, you can take the joystick lock around reinitializing the
142  * joystick subsystem, to prevent other threads from seeing joysticks in an
143  * uninitialized state. However, all open joysticks will be closed and SDL
144  * functions called with them will fail.
145  *
146  * \since This function is available since SDL 2.0.7.
147  */
148 extern DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
149 
150 
151 /**
152  * Unlocking for multi-threaded access to the joystick API
153  *
154  * If you are using the joystick API or handling events from multiple threads
155  * you should use these locking functions to protect access to the joysticks.
156  *
157  * In particular, you are guaranteed that the joystick list won't change, so
158  * the API functions that take a joystick index will be valid, and joystick
159  * and game controller events will not be delivered.
160  *
161  * \since This function is available since SDL 2.0.7.
162  */
163 extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
164 
165 /**
166  * Count the number of joysticks attached to the system.
167  *
168  * \returns the number of attached joysticks on success or a negative error
169  *          code on failure; call SDL_GetError() for more information.
170  *
171  * \since This function is available since SDL 2.0.0.
172  *
173  * \sa SDL_JoystickName
174  * \sa SDL_JoystickPath
175  * \sa SDL_JoystickOpen
176  */
177 extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
178 
179 /**
180  * Get the implementation dependent name of a joystick.
181  *
182  * This can be called before any joysticks are opened.
183  *
184  * \param device_index the index of the joystick to query (the N'th joystick
185  *                     on the system).
186  * \returns the name of the selected joystick. If no name can be found, this
187  *          function returns NULL; call SDL_GetError() for more information.
188  *
189  * \since This function is available since SDL 2.0.0.
190  *
191  * \sa SDL_JoystickName
192  * \sa SDL_JoystickOpen
193  */
194 extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
195 
196 /**
197  * Get the implementation dependent path of a joystick.
198  *
199  * This can be called before any joysticks are opened.
200  *
201  * \param device_index the index of the joystick to query (the N'th joystick
202  *                     on the system).
203  * \returns the path of the selected joystick. If no path can be found, this
204  *          function returns NULL; call SDL_GetError() for more information.
205  *
206  * \since This function is available since SDL 2.24.0.
207  *
208  * \sa SDL_JoystickPath
209  * \sa SDL_JoystickOpen
210  */
211 extern DECLSPEC const char *SDLCALL SDL_JoystickPathForIndex(int device_index);
212 
213 /**
214  * Get the player index of a joystick, or -1 if it's not available This can be
215  * called before any joysticks are opened.
216  *
217  * \since This function is available since SDL 2.0.9.
218  */
219 extern DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index);
220 
221 /**
222  * Get the implementation-dependent GUID for the joystick at a given device
223  * index.
224  *
225  * This function can be called before any joysticks are opened.
226  *
227  * \param device_index the index of the joystick to query (the N'th joystick
228  *                     on the system.
229  * \returns the GUID of the selected joystick. If called on an invalid index,
230  *          this function returns a zero GUID.
231  *
232  * \since This function is available since SDL 2.0.0.
233  *
234  * \sa SDL_JoystickGetGUID
235  * \sa SDL_JoystickGetGUIDString
236  */
237 extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
238 
239 /**
240  * Get the USB vendor ID of a joystick, if available.
241  *
242  * This can be called before any joysticks are opened. If the vendor ID isn't
243  * available this function returns 0.
244  *
245  * \param device_index the index of the joystick to query (the N'th joystick
246  *                     on the system.
247  * \returns the USB vendor ID of the selected joystick. If called on an
248  *          invalid index, this function returns zero.
249  *
250  * \since This function is available since SDL 2.0.6.
251  */
252 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index);
253 
254 /**
255  * Get the USB product ID of a joystick, if available.
256  *
257  * This can be called before any joysticks are opened. If the product ID isn't
258  * available this function returns 0.
259  *
260  * \param device_index the index of the joystick to query (the N'th joystick
261  *                     on the system.
262  * \returns the USB product ID of the selected joystick. If called on an
263  *          invalid index, this function returns zero.
264  *
265  * \since This function is available since SDL 2.0.6.
266  */
267 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index);
268 
269 /**
270  * Get the product version of a joystick, if available.
271  *
272  * This can be called before any joysticks are opened. If the product version
273  * isn't available this function returns 0.
274  *
275  * \param device_index the index of the joystick to query (the N'th joystick
276  *                     on the system.
277  * \returns the product version of the selected joystick. If called on an
278  *          invalid index, this function returns zero.
279  *
280  * \since This function is available since SDL 2.0.6.
281  */
282 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index);
283 
284 /**
285  * Get the type of a joystick, if available.
286  *
287  * This can be called before any joysticks are opened.
288  *
289  * \param device_index the index of the joystick to query (the N'th joystick
290  *                     on the system.
291  * \returns the SDL_JoystickType of the selected joystick. If called on an
292  *          invalid index, this function returns `SDL_JOYSTICK_TYPE_UNKNOWN`.
293  *
294  * \since This function is available since SDL 2.0.6.
295  */
296 extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index);
297 
298 /**
299  * Get the instance ID of a joystick.
300  *
301  * This can be called before any joysticks are opened.
302  *
303  * \param device_index the index of the joystick to query (the N'th joystick
304  *                     on the system.
305  * \returns the instance id of the selected joystick. If called on an invalid
306  *          index, this function returns -1.
307  *
308  * \since This function is available since SDL 2.0.6.
309  */
310 extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickGetDeviceInstanceID(int device_index);
311 
312 /**
313  * Open a joystick for use.
314  *
315  * The `device_index` argument refers to the N'th joystick presently
316  * recognized by SDL on the system. It is **NOT** the same as the instance ID
317  * used to identify the joystick in future events. See
318  * SDL_JoystickInstanceID() for more details about instance IDs.
319  *
320  * The joystick subsystem must be initialized before a joystick can be opened
321  * for use.
322  *
323  * \param device_index the index of the joystick to query.
324  * \returns a joystick identifier or NULL if an error occurred; call
325  *          SDL_GetError() for more information.
326  *
327  * \since This function is available since SDL 2.0.0.
328  *
329  * \sa SDL_JoystickClose
330  * \sa SDL_JoystickInstanceID
331  */
332 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
333 
334 /**
335  * Get the SDL_Joystick associated with an instance id.
336  *
337  * \param instance_id the instance id to get the SDL_Joystick for.
338  * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
339  *          for more information.
340  *
341  * \since This function is available since SDL 2.0.4.
342  */
343 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID instance_id);
344 
345 /**
346  * Get the SDL_Joystick associated with a player index.
347  *
348  * \param player_index the player index to get the SDL_Joystick for.
349  * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
350  *          for more information.
351  *
352  * \since This function is available since SDL 2.0.12.
353  */
354 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromPlayerIndex(int player_index);
355 
356 /**
357  * Attach a new virtual joystick.
358  *
359  * \returns the joystick's device index, or -1 if an error occurred.
360  *
361  * \since This function is available since SDL 2.0.14.
362  */
363 extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type,
364                                                       int naxes,
365                                                       int nbuttons,
366                                                       int nhats);
367 
368 /**
369  * The structure that defines an extended virtual joystick description
370  *
371  * The caller must zero the structure and then initialize the version with
372  * `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` before passing it to
373  * SDL_JoystickAttachVirtualEx() All other elements of this structure are
374  * optional and can be left 0.
375  *
376  * \sa SDL_JoystickAttachVirtualEx
377  */
378 typedef struct SDL_VirtualJoystickDesc
379 {
380     Uint16 version;     /**< `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` */
381     Uint16 type;        /**< `SDL_JoystickType` */
382     Uint16 naxes;       /**< the number of axes on this joystick */
383     Uint16 nbuttons;    /**< the number of buttons on this joystick */
384     Uint16 nhats;       /**< the number of hats on this joystick */
385     Uint16 vendor_id;   /**< the USB vendor ID of this joystick */
386     Uint16 product_id;  /**< the USB product ID of this joystick */
387     Uint16 padding;     /**< unused */
388     Uint32 button_mask; /**< A mask of which buttons are valid for this controller
389                              e.g. (1 << SDL_CONTROLLER_BUTTON_A) */
390     Uint32 axis_mask;   /**< A mask of which axes are valid for this controller
391                              e.g. (1 << SDL_CONTROLLER_AXIS_LEFTX) */
392     const char *name;   /**< the name of the joystick */
393 
394     void *userdata;     /**< User data pointer passed to callbacks */
395     void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */
396     void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */
397     int (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_JoystickRumble() */
398     int (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_JoystickRumbleTriggers() */
399     int (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_JoystickSetLED() */
400     int (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_JoystickSendEffect() */
401 
402 } SDL_VirtualJoystickDesc;
403 
404 /**
405  * The current version of the SDL_VirtualJoystickDesc structure
406  */
407 #define SDL_VIRTUAL_JOYSTICK_DESC_VERSION   1
408 
409 /**
410  * Attach a new virtual joystick with extended properties.
411  *
412  * \returns the joystick's device index, or -1 if an error occurred.
413  *
414  * \since This function is available since SDL 2.24.0.
415  */
416 extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtualEx(const SDL_VirtualJoystickDesc *desc);
417 
418 /**
419  * Detach a virtual joystick.
420  *
421  * \param device_index a value previously returned from
422  *                     SDL_JoystickAttachVirtual().
423  * \returns 0 on success, or -1 if an error occurred.
424  *
425  * \since This function is available since SDL 2.0.14.
426  */
427 extern DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index);
428 
429 /**
430  * Query whether or not the joystick at a given device index is virtual.
431  *
432  * \param device_index a joystick device index.
433  * \returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise.
434  *
435  * \since This function is available since SDL 2.0.14.
436  */
437 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index);
438 
439 /**
440  * Set values on an opened, virtual-joystick's axis.
441  *
442  * Please note that values set here will not be applied until the next call to
443  * SDL_JoystickUpdate, which can either be called directly, or can be called
444  * indirectly through various other SDL APIs, including, but not limited to
445  * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
446  * SDL_WaitEvent.
447  *
448  * Note that when sending trigger axes, you should scale the value to the full
449  * range of Sint16. For example, a trigger at rest would have the value of
450  * `SDL_JOYSTICK_AXIS_MIN`.
451  *
452  * \param joystick the virtual joystick on which to set state.
453  * \param axis the specific axis on the virtual joystick to set.
454  * \param value the new value for the specified axis.
455  * \returns 0 on success, -1 on error.
456  *
457  * \since This function is available since SDL 2.0.14.
458  */
459 extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
460 
461 /**
462  * Set values on an opened, virtual-joystick's button.
463  *
464  * Please note that values set here will not be applied until the next call to
465  * SDL_JoystickUpdate, which can either be called directly, or can be called
466  * indirectly through various other SDL APIs, including, but not limited to
467  * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
468  * SDL_WaitEvent.
469  *
470  * \param joystick the virtual joystick on which to set state.
471  * \param button the specific button on the virtual joystick to set.
472  * \param value the new value for the specified button.
473  * \returns 0 on success, -1 on error.
474  *
475  * \since This function is available since SDL 2.0.14.
476  */
477 extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
478 
479 /**
480  * Set values on an opened, virtual-joystick's hat.
481  *
482  * Please note that values set here will not be applied until the next call to
483  * SDL_JoystickUpdate, which can either be called directly, or can be called
484  * indirectly through various other SDL APIs, including, but not limited to
485  * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
486  * SDL_WaitEvent.
487  *
488  * \param joystick the virtual joystick on which to set state.
489  * \param hat the specific hat on the virtual joystick to set.
490  * \param value the new value for the specified hat.
491  * \returns 0 on success, -1 on error.
492  *
493  * \since This function is available since SDL 2.0.14.
494  */
495 extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
496 
497 /**
498  * Get the implementation dependent name of a joystick.
499  *
500  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
501  * \returns the name of the selected joystick. If no name can be found, this
502  *          function returns NULL; call SDL_GetError() for more information.
503  *
504  * \since This function is available since SDL 2.0.0.
505  *
506  * \sa SDL_JoystickNameForIndex
507  * \sa SDL_JoystickOpen
508  */
509 extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick *joystick);
510 
511 /**
512  * Get the implementation dependent path of a joystick.
513  *
514  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
515  * \returns the path of the selected joystick. If no path can be found, this
516  *          function returns NULL; call SDL_GetError() for more information.
517  *
518  * \since This function is available since SDL 2.24.0.
519  *
520  * \sa SDL_JoystickPathForIndex
521  */
522 extern DECLSPEC const char *SDLCALL SDL_JoystickPath(SDL_Joystick *joystick);
523 
524 /**
525  * Get the player index of an opened joystick.
526  *
527  * For XInput controllers this returns the XInput user index. Many joysticks
528  * will not be able to supply this information.
529  *
530  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
531  * \returns the player index, or -1 if it's not available.
532  *
533  * \since This function is available since SDL 2.0.9.
534  */
535 extern DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick *joystick);
536 
537 /**
538  * Set the player index of an opened joystick.
539  *
540  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
541  * \param player_index Player index to assign to this joystick, or -1 to clear
542  *                     the player index and turn off player LEDs.
543  *
544  * \since This function is available since SDL 2.0.12.
545  */
546 extern DECLSPEC void SDLCALL SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index);
547 
548 /**
549  * Get the implementation-dependent GUID for the joystick.
550  *
551  * This function requires an open joystick.
552  *
553  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
554  * \returns the GUID of the given joystick. If called on an invalid index,
555  *          this function returns a zero GUID; call SDL_GetError() for more
556  *          information.
557  *
558  * \since This function is available since SDL 2.0.0.
559  *
560  * \sa SDL_JoystickGetDeviceGUID
561  * \sa SDL_JoystickGetGUIDString
562  */
563 extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick *joystick);
564 
565 /**
566  * Get the USB vendor ID of an opened joystick, if available.
567  *
568  * If the vendor ID isn't available this function returns 0.
569  *
570  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
571  * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
572  *
573  * \since This function is available since SDL 2.0.6.
574  */
575 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick *joystick);
576 
577 /**
578  * Get the USB product ID of an opened joystick, if available.
579  *
580  * If the product ID isn't available this function returns 0.
581  *
582  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
583  * \returns the USB product ID of the selected joystick, or 0 if unavailable.
584  *
585  * \since This function is available since SDL 2.0.6.
586  */
587 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick *joystick);
588 
589 /**
590  * Get the product version of an opened joystick, if available.
591  *
592  * If the product version isn't available this function returns 0.
593  *
594  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
595  * \returns the product version of the selected joystick, or 0 if unavailable.
596  *
597  * \since This function is available since SDL 2.0.6.
598  */
599 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick *joystick);
600 
601 /**
602  * Get the firmware version of an opened joystick, if available.
603  *
604  * If the firmware version isn't available this function returns 0.
605  *
606  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
607  * \returns the firmware version of the selected joystick, or 0 if
608  *          unavailable.
609  *
610  * \since This function is available since SDL 2.24.0.
611  */
612 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetFirmwareVersion(SDL_Joystick *joystick);
613 
614 /**
615  * Get the serial number of an opened joystick, if available.
616  *
617  * Returns the serial number of the joystick, or NULL if it is not available.
618  *
619  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
620  * \returns the serial number of the selected joystick, or NULL if
621  *          unavailable.
622  *
623  * \since This function is available since SDL 2.0.14.
624  */
625 extern DECLSPEC const char * SDLCALL SDL_JoystickGetSerial(SDL_Joystick *joystick);
626 
627 /**
628  * Get the type of an opened joystick.
629  *
630  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen().
631  * \returns the SDL_JoystickType of the selected joystick.
632  *
633  * \since This function is available since SDL 2.0.6.
634  */
635 extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick *joystick);
636 
637 /**
638  * Get an ASCII string representation for a given SDL_JoystickGUID.
639  *
640  * You should supply at least 33 bytes for pszGUID.
641  *
642  * \param guid the SDL_JoystickGUID you wish to convert to string.
643  * \param pszGUID buffer in which to write the ASCII string.
644  * \param cbGUID the size of pszGUID.
645  *
646  * \since This function is available since SDL 2.0.0.
647  *
648  * \sa SDL_JoystickGetDeviceGUID
649  * \sa SDL_JoystickGetGUID
650  * \sa SDL_JoystickGetGUIDFromString
651  */
652 extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
653 
654 /**
655  * Convert a GUID string into a SDL_JoystickGUID structure.
656  *
657  * Performs no error checking. If this function is given a string containing
658  * an invalid GUID, the function will silently succeed, but the GUID generated
659  * will not be useful.
660  *
661  * \param pchGUID string containing an ASCII representation of a GUID.
662  * \returns a SDL_JoystickGUID structure.
663  *
664  * \since This function is available since SDL 2.0.0.
665  *
666  * \sa SDL_JoystickGetGUIDString
667  */
668 extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
669 
670 /**
671  * Get the device information encoded in a SDL_JoystickGUID structure
672  *
673  * \param guid the SDL_JoystickGUID you wish to get info about.
674  * \param vendor A pointer filled in with the device VID, or 0 if not
675  *               available.
676  * \param product A pointer filled in with the device PID, or 0 if not
677  *                available.
678  * \param version A pointer filled in with the device version, or 0 if not
679  *                available.
680  * \param crc16 A pointer filled in with a CRC used to distinguish different
681  *              products with the same VID/PID, or 0 if not available.
682  *
683  * \since This function is available since SDL 2.26.0.
684  *
685  * \sa SDL_JoystickGetDeviceGUID
686  */
687 extern DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
688 
689 /**
690  * Get the status of a specified joystick.
691  *
692  * \param joystick the joystick to query.
693  * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not;
694  *          call SDL_GetError() for more information.
695  *
696  * \since This function is available since SDL 2.0.0.
697  *
698  * \sa SDL_JoystickClose
699  * \sa SDL_JoystickOpen
700  */
701 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick *joystick);
702 
703 /**
704  * Get the instance ID of an opened joystick.
705  *
706  * \param joystick an SDL_Joystick structure containing joystick information.
707  * \returns the instance ID of the specified joystick on success or a negative
708  *          error code on failure; call SDL_GetError() for more information.
709  *
710  * \since This function is available since SDL 2.0.0.
711  *
712  * \sa SDL_JoystickOpen
713  */
714 extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick *joystick);
715 
716 /**
717  * Get the number of general axis controls on a joystick.
718  *
719  * Often, the directional pad on a game controller will either look like 4
720  * separate buttons or a POV hat, and not axes, but all of this is up to the
721  * device and platform.
722  *
723  * \param joystick an SDL_Joystick structure containing joystick information.
724  * \returns the number of axis controls/number of axes on success or a
725  *          negative error code on failure; call SDL_GetError() for more
726  *          information.
727  *
728  * \since This function is available since SDL 2.0.0.
729  *
730  * \sa SDL_JoystickGetAxis
731  * \sa SDL_JoystickOpen
732  */
733 extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick);
734 
735 /**
736  * Get the number of trackballs on a joystick.
737  *
738  * Joystick trackballs have only relative motion events associated with them
739  * and their state cannot be polled.
740  *
741  * Most joysticks do not have trackballs.
742  *
743  * \param joystick an SDL_Joystick structure containing joystick information.
744  * \returns the number of trackballs on success or a negative error code on
745  *          failure; call SDL_GetError() for more information.
746  *
747  * \since This function is available since SDL 2.0.0.
748  *
749  * \sa SDL_JoystickGetBall
750  */
751 extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick);
752 
753 /**
754  * Get the number of POV hats on a joystick.
755  *
756  * \param joystick an SDL_Joystick structure containing joystick information.
757  * \returns the number of POV hats on success or a negative error code on
758  *          failure; call SDL_GetError() for more information.
759  *
760  * \since This function is available since SDL 2.0.0.
761  *
762  * \sa SDL_JoystickGetHat
763  * \sa SDL_JoystickOpen
764  */
765 extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick);
766 
767 /**
768  * Get the number of buttons on a joystick.
769  *
770  * \param joystick an SDL_Joystick structure containing joystick information.
771  * \returns the number of buttons on success or a negative error code on
772  *          failure; call SDL_GetError() for more information.
773  *
774  * \since This function is available since SDL 2.0.0.
775  *
776  * \sa SDL_JoystickGetButton
777  * \sa SDL_JoystickOpen
778  */
779 extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick);
780 
781 /**
782  * Update the current state of the open joysticks.
783  *
784  * This is called automatically by the event loop if any joystick events are
785  * enabled.
786  *
787  * \since This function is available since SDL 2.0.0.
788  *
789  * \sa SDL_JoystickEventState
790  */
791 extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
792 
793 /**
794  * Enable/disable joystick event polling.
795  *
796  * If joystick events are disabled, you must call SDL_JoystickUpdate()
797  * yourself and manually check the state of the joystick when you want
798  * joystick information.
799  *
800  * It is recommended that you leave joystick event handling enabled.
801  *
802  * **WARNING**: Calling this function may delete all events currently in SDL's
803  * event queue.
804  *
805  * While `param` is meant to be one of `SDL_QUERY`, `SDL_IGNORE`, or
806  * `SDL_ENABLE`, this function accepts any value, with any non-zero value that
807  * isn't `SDL_QUERY` being treated as `SDL_ENABLE`.
808  *
809  * If SDL was built with events disabled (extremely uncommon!), this will do
810  * nothing and always return `SDL_IGNORE`.
811  *
812  * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`.
813  * \returns If `state` is `SDL_QUERY` then the current state is returned,
814  *          otherwise `state` is returned (even if it was not one of the
815  *          allowed values).
816  *
817  * \since This function is available since SDL 2.0.0.
818  *
819  * \sa SDL_GameControllerEventState
820  */
821 extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
822 
823 /* Limits for joystick axes... */
824 #define SDL_JOYSTICK_AXIS_MAX   32767
825 #define SDL_JOYSTICK_AXIS_MIN   -32768
826 
827 /**
828  * Get the current state of an axis control on a joystick.
829  *
830  * SDL makes no promises about what part of the joystick any given axis refers
831  * to. Your game should have some sort of configuration UI to let users
832  * specify what each axis should be bound to. Alternately, SDL's higher-level
833  * Game Controller API makes a great effort to apply order to this lower-level
834  * interface, so you know that a specific axis is the "left thumb stick," etc.
835  *
836  * The value returned by SDL_JoystickGetAxis() is a signed integer (-32768 to
837  * 32767) representing the current position of the axis. It may be necessary
838  * to impose certain tolerances on these values to account for jitter.
839  *
840  * \param joystick an SDL_Joystick structure containing joystick information.
841  * \param axis the axis to query; the axis indices start at index 0.
842  * \returns a 16-bit signed integer representing the current position of the
843  *          axis or 0 on failure; call SDL_GetError() for more information.
844  *
845  * \since This function is available since SDL 2.0.0.
846  *
847  * \sa SDL_JoystickNumAxes
848  */
849 extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick,
850                                                    int axis);
851 
852 /**
853  * Get the initial state of an axis control on a joystick.
854  *
855  * The state is a value ranging from -32768 to 32767.
856  *
857  * The axis indices start at index 0.
858  *
859  * \param joystick an SDL_Joystick structure containing joystick information.
860  * \param axis the axis to query; the axis indices start at index 0.
861  * \param state Upon return, the initial value is supplied here.
862  * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
863  *
864  * \since This function is available since SDL 2.0.6.
865  */
866 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick *joystick,
867                                                    int axis, Sint16 *state);
868 
869 /**
870  *  \name Hat positions
871  */
872 /* @{ */
873 #define SDL_HAT_CENTERED    0x00
874 #define SDL_HAT_UP          0x01
875 #define SDL_HAT_RIGHT       0x02
876 #define SDL_HAT_DOWN        0x04
877 #define SDL_HAT_LEFT        0x08
878 #define SDL_HAT_RIGHTUP     (SDL_HAT_RIGHT|SDL_HAT_UP)
879 #define SDL_HAT_RIGHTDOWN   (SDL_HAT_RIGHT|SDL_HAT_DOWN)
880 #define SDL_HAT_LEFTUP      (SDL_HAT_LEFT|SDL_HAT_UP)
881 #define SDL_HAT_LEFTDOWN    (SDL_HAT_LEFT|SDL_HAT_DOWN)
882 /* @} */
883 
884 /**
885  * Get the current state of a POV hat on a joystick.
886  *
887  * The returned value will be one of the following positions:
888  *
889  * - `SDL_HAT_CENTERED`
890  * - `SDL_HAT_UP`
891  * - `SDL_HAT_RIGHT`
892  * - `SDL_HAT_DOWN`
893  * - `SDL_HAT_LEFT`
894  * - `SDL_HAT_RIGHTUP`
895  * - `SDL_HAT_RIGHTDOWN`
896  * - `SDL_HAT_LEFTUP`
897  * - `SDL_HAT_LEFTDOWN`
898  *
899  * \param joystick an SDL_Joystick structure containing joystick information.
900  * \param hat the hat index to get the state from; indices start at index 0.
901  * \returns the current hat position.
902  *
903  * \since This function is available since SDL 2.0.0.
904  *
905  * \sa SDL_JoystickNumHats
906  */
907 extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick,
908                                                  int hat);
909 
910 /**
911  * Get the ball axis change since the last poll.
912  *
913  * Trackballs can only return relative motion since the last call to
914  * SDL_JoystickGetBall(), these motion deltas are placed into `dx` and `dy`.
915  *
916  * Most joysticks do not have trackballs.
917  *
918  * \param joystick the SDL_Joystick to query.
919  * \param ball the ball index to query; ball indices start at index 0.
920  * \param dx stores the difference in the x axis position since the last poll.
921  * \param dy stores the difference in the y axis position since the last poll.
922  * \returns 0 on success or a negative error code on failure; call
923  *          SDL_GetError() for more information.
924  *
925  * \since This function is available since SDL 2.0.0.
926  *
927  * \sa SDL_JoystickNumBalls
928  */
929 extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick,
930                                                 int ball, int *dx, int *dy);
931 
932 /**
933  * Get the current state of a button on a joystick.
934  *
935  * \param joystick an SDL_Joystick structure containing joystick information.
936  * \param button the button index to get the state from; indices start at
937  *               index 0.
938  * \returns 1 if the specified button is pressed, 0 otherwise.
939  *
940  * \since This function is available since SDL 2.0.0.
941  *
942  * \sa SDL_JoystickNumButtons
943  */
944 extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick,
945                                                     int button);
946 
947 /**
948  * Start a rumble effect.
949  *
950  * Each call to this function cancels any previous rumble effect, and calling
951  * it with 0 intensity stops any rumbling.
952  *
953  * \param joystick The joystick to vibrate.
954  * \param low_frequency_rumble The intensity of the low frequency (left)
955  *                             rumble motor, from 0 to 0xFFFF.
956  * \param high_frequency_rumble The intensity of the high frequency (right)
957  *                              rumble motor, from 0 to 0xFFFF.
958  * \param duration_ms The duration of the rumble effect, in milliseconds.
959  * \returns 0, or -1 if rumble isn't supported on this joystick.
960  *
961  * \since This function is available since SDL 2.0.9.
962  *
963  * \sa SDL_JoystickHasRumble
964  */
965 extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
966 
967 /**
968  * Start a rumble effect in the joystick's triggers
969  *
970  * Each call to this function cancels any previous trigger rumble effect, and
971  * calling it with 0 intensity stops any rumbling.
972  *
973  * Note that this is rumbling of the _triggers_ and not the game controller as
974  * a whole. This is currently only supported on Xbox One controllers. If you
975  * want the (more common) whole-controller rumble, use SDL_JoystickRumble()
976  * instead.
977  *
978  * \param joystick The joystick to vibrate.
979  * \param left_rumble The intensity of the left trigger rumble motor, from 0
980  *                    to 0xFFFF.
981  * \param right_rumble The intensity of the right trigger rumble motor, from 0
982  *                     to 0xFFFF.
983  * \param duration_ms The duration of the rumble effect, in milliseconds.
984  * \returns 0, or -1 if trigger rumble isn't supported on this joystick.
985  *
986  * \since This function is available since SDL 2.0.14.
987  *
988  * \sa SDL_JoystickHasRumbleTriggers
989  */
990 extern DECLSPEC int SDLCALL SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
991 
992 /**
993  * Query whether a joystick has an LED.
994  *
995  * An example of a joystick LED is the light on the back of a PlayStation 4's
996  * DualShock 4 controller.
997  *
998  * \param joystick The joystick to query.
999  * \return SDL_TRUE if the joystick has a modifiable LED, SDL_FALSE otherwise.
1000  *
1001  * \since This function is available since SDL 2.0.14.
1002  */
1003 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick);
1004 
1005 /**
1006  * Query whether a joystick has rumble support.
1007  *
1008  * \param joystick The joystick to query.
1009  * \return SDL_TRUE if the joystick has rumble, SDL_FALSE otherwise.
1010  *
1011  * \since This function is available since SDL 2.0.18.
1012  *
1013  * \sa SDL_JoystickRumble
1014  */
1015 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumble(SDL_Joystick *joystick);
1016 
1017 /**
1018  * Query whether a joystick has rumble support on triggers.
1019  *
1020  * \param joystick The joystick to query.
1021  * \return SDL_TRUE if the joystick has trigger rumble, SDL_FALSE otherwise.
1022  *
1023  * \since This function is available since SDL 2.0.18.
1024  *
1025  * \sa SDL_JoystickRumbleTriggers
1026  */
1027 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick);
1028 
1029 /**
1030  * Update a joystick's LED color.
1031  *
1032  * An example of a joystick LED is the light on the back of a PlayStation 4's
1033  * DualShock 4 controller.
1034  *
1035  * \param joystick The joystick to update.
1036  * \param red The intensity of the red LED.
1037  * \param green The intensity of the green LED.
1038  * \param blue The intensity of the blue LED.
1039  * \returns 0 on success, -1 if this joystick does not have a modifiable LED.
1040  *
1041  * \since This function is available since SDL 2.0.14.
1042  */
1043 extern DECLSPEC int SDLCALL SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
1044 
1045 /**
1046  * Send a joystick specific effect packet
1047  *
1048  * \param joystick The joystick to affect.
1049  * \param data The data to send to the joystick.
1050  * \param size The size of the data to send to the joystick.
1051  * \returns 0, or -1 if this joystick or driver doesn't support effect
1052  *          packets.
1053  *
1054  * \since This function is available since SDL 2.0.16.
1055  */
1056 extern DECLSPEC int SDLCALL SDL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size);
1057 
1058 /**
1059  * Close a joystick previously opened with SDL_JoystickOpen().
1060  *
1061  * \param joystick The joystick device to close.
1062  *
1063  * \since This function is available since SDL 2.0.0.
1064  *
1065  * \sa SDL_JoystickOpen
1066  */
1067 extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick);
1068 
1069 /**
1070  * Get the battery level of a joystick as SDL_JoystickPowerLevel.
1071  *
1072  * \param joystick the SDL_Joystick to query.
1073  * \returns the current battery level as SDL_JoystickPowerLevel on success or
1074  *          `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown.
1075  *
1076  * \since This function is available since SDL 2.0.4.
1077  */
1078 extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick);
1079 
1080 /* Ends C function definitions when using C++ */
1081 #ifdef __cplusplus
1082 }
1083 #endif
1084 #include "close_code.h"
1085 
1086 #endif /* SDL_joystick_h_ */
1087 
1088 /* vi: set ts=4 sw=4 expandtab: */