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