SDL  2.0
SDL_joystick.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2021 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 extern DECLSPEC void SDLCALL SDL_LockJoysticks(void);
129 
130 
131 /**
132  * Unlocking 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 extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void);
142 
143 /**
144  * Count the number of joysticks attached to the system.
145  *
146  * \returns the number of attached joysticks on success or a negative error
147  * code on failure; call SDL_GetError() for more information.
148  *
149  * \sa SDL_JoystickName
150  * \sa SDL_JoystickOpen
151  */
152 extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
153 
154 /**
155  * Get the implementation dependent name of a joystick.
156  *
157  * This can be called before any joysticks are opened.
158  *
159  * \param device_index the index of the joystick to query (the N'th joystick
160  * on the system)
161  * \returns the name of the selected joystick. If no name can be found, this
162  * function returns NULL; call SDL_GetError() for more information.
163  *
164  * \sa SDL_JoystickName
165  * \sa SDL_JoystickOpen
166  */
167 extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
168 
169 /**
170  * Get the player index of a joystick, or -1 if it's not available This can be
171  * called before any joysticks are opened.
172  */
173 extern DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index);
174 
175 /**
176  * Get the implementation-dependent GUID for the joystick at a given device
177  * index.
178  *
179  * This function can be called before any joysticks are opened.
180  *
181  * \param device_index the index of the joystick to query (the N'th joystick
182  * on the system
183  * \returns the GUID of the selected joystick. If called on an invalid index,
184  * this function returns a zero GUID
185  *
186  * \sa SDL_JoystickGetGUID
187  * \sa SDL_JoystickGetGUIDString
188  */
189 extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
190 
191 /**
192  * Get the USB vendor ID of a joystick, if available.
193  *
194  * This can be called before any joysticks are opened. If the vendor ID isn't
195  * available this function returns 0.
196  *
197  * \param device_index the index of the joystick to query (the N'th joystick
198  * on the system
199  * \returns the USB vendor ID of the selected joystick. If called on an
200  * invalid index, this function returns zero
201  */
202 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index);
203 
204 /**
205  * Get the USB product ID of a joystick, if available.
206  *
207  * This can be called before any joysticks are opened. If the product ID isn't
208  * available this function returns 0.
209  *
210  * \param device_index the index of the joystick to query (the N'th joystick
211  * on the system
212  * \returns the USB product ID of the selected joystick. If called on an
213  * invalid index, this function returns zero
214  */
215 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index);
216 
217 /**
218  * Get the product version of a joystick, if available.
219  *
220  * This can be called before any joysticks are opened. If the product version
221  * isn't available this function returns 0.
222  *
223  * \param device_index the index of the joystick to query (the N'th joystick
224  * on the system
225  * \returns the product version of the selected joystick. If called on an
226  * invalid index, this function returns zero
227  */
228 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index);
229 
230 /**
231  * Get the type of a joystick, if available.
232  *
233  * This can be called before any joysticks are opened.
234  *
235  * \param device_index the index of the joystick to query (the N'th joystick
236  * on the system
237  * \returns the SDL_JoystickType of the selected joystick. If called on an
238  * invalid index, this function returns `SDL_JOYSTICK_TYPE_UNKNOWN`
239  */
240 extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index);
241 
242 /**
243  * Get the instance ID of a joystick.
244  *
245  * This can be called before any joysticks are opened. If the index is out of
246  * range, this function will return -1.
247  *
248  * \param device_index the index of the joystick to query (the N'th joystick
249  * on the system
250  * \returns the instance id of the selected joystick. If called on an invalid
251  * index, this function returns zero
252  */
253 extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickGetDeviceInstanceID(int device_index);
254 
255 /**
256  * Open a joystick for use.
257  *
258  * The `device_index` argument refers to the N'th joystick presently
259  * recognized by SDL on the system. It is **NOT** the same as the instance ID
260  * used to identify the joystick in future events. See
261  * SDL_JoystickInstanceID() for more details about instance IDs.
262  *
263  * The joystick subsystem must be initialized before a joystick can be opened
264  * for use.
265  *
266  * \param device_index the index of the joystick to query
267  * \returns a joystick identifier or NULL if an error occurred; call
268  * SDL_GetError() for more information.
269  *
270  * \sa SDL_JoystickClose
271  * \sa SDL_JoystickInstanceID
272  */
273 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
274 
275 /**
276  * Get the SDL_Joystick associated with an instance id.
277  *
278  * \param instance_id the instance id to get the SDL_Joystick for
279  * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
280  * for more information.
281  *
282  * \since This function is available since SDL 2.0.4.
283  */
284 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID instance_id);
285 
286 /**
287  * Get the SDL_Joystick associated with a player index.
288  *
289  * \param player_index the player index to get the SDL_Joystick for
290  * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
291  * for more information.
292  */
293 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromPlayerIndex(int player_index);
294 
295 /**
296  * Attach a new virtual joystick.
297  *
298  * \returns the joystick's device index, or -1 if an error occurred.
299  */
300 extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type,
301  int naxes,
302  int nbuttons,
303  int nhats);
304 
305 /**
306  * Detach a virtual joystick.
307  *
308  * \param device_index a value previously returned from
309  * SDL_JoystickAttachVirtual()
310  * \returns 0 on success, or -1 if an error occurred.
311  */
312 extern DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index);
313 
314 /**
315  * Query whether or not the joystick at a given device index is virtual.
316  *
317  * \param device_index a joystick device index.
318  * \returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise.
319  */
320 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index);
321 
322 /**
323  * Set values on an opened, virtual-joystick's axis.
324  *
325  * Please note that values set here will not be applied until the next call to
326  * SDL_JoystickUpdate, which can either be called directly, or can be called
327  * indirectly through various other SDL APIs, including, but not limited to
328  * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
329  * SDL_WaitEvent.
330  *
331  * \param joystick the virtual joystick on which to set state.
332  * \param axis the specific axis on the virtual joystick to set.
333  * \param value the new value for the specified axis.
334  * \returns 0 on success, -1 on error.
335  */
336 extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
337 
338 /**
339  * Set values on an opened, virtual-joystick's button.
340  *
341  * Please note that values set here will not be applied until the next call to
342  * SDL_JoystickUpdate, which can either be called directly, or can be called
343  * indirectly through various other SDL APIs, including, but not limited to
344  * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
345  * SDL_WaitEvent.
346  *
347  * \param joystick the virtual joystick on which to set state.
348  * \param button the specific button on the virtual joystick to set.
349  * \param value the new value for the specified button.
350  * \returns 0 on success, -1 on error.
351  */
352 extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
353 
354 /**
355  * Set values on an opened, virtual-joystick's hat.
356  *
357  * Please note that values set here will not be applied until the next call to
358  * SDL_JoystickUpdate, which can either be called directly, or can be called
359  * indirectly through various other SDL APIs, including, but not limited to
360  * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
361  * SDL_WaitEvent.
362  *
363  * \param joystick the virtual joystick on which to set state.
364  * \param hat the specific hat on the virtual joystick to set.
365  * \param value the new value for the specified hat.
366  * \returns 0 on success, -1 on error.
367  */
368 extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
369 
370 /**
371  * Get the implementation dependent name of a joystick.
372  *
373  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
374  * \returns the name of the selected joystick. If no name can be found, this
375  * function returns NULL; call SDL_GetError() for more information.
376  *
377  * \since This function is available since SDL 2.0.0.
378  *
379  * \sa SDL_JoystickNameForIndex
380  * \sa SDL_JoystickOpen
381  */
382 extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick *joystick);
383 
384 /**
385  * Get the player index of an opened joystick.
386  *
387  * For XInput controllers this returns the XInput user index. Many joysticks
388  * will not be able to supply this information.
389  *
390  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
391  * \returns the player index, or -1 if it's not available.
392  */
393 extern DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick *joystick);
394 
395 /**
396  * Set the player index of an opened joystick.
397  *
398  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
399  * \param player_index the player index to set.
400  */
401 extern DECLSPEC void SDLCALL SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index);
402 
403 /**
404  * Get the implementation-dependent GUID for the joystick.
405  *
406  * This function requires an open joystick.
407  *
408  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
409  * \returns the GUID of the given joystick. If called on an invalid index,
410  * this function returns a zero GUID; call SDL_GetError() for more
411  * information.
412  *
413  * \sa SDL_JoystickGetDeviceGUID
414  * \sa SDL_JoystickGetGUIDString
415  */
416 extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick *joystick);
417 
418 /**
419  * Get the USB vendor ID of an opened joystick, if available.
420  *
421  * If the vendor ID isn't available this function returns 0.
422  *
423  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
424  * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
425  */
426 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick *joystick);
427 
428 /**
429  * Get the USB product ID of an opened joystick, if available.
430  *
431  * If the product ID isn't available this function returns 0.
432  *
433  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
434  * \returns the USB product ID of the selected joystick, or 0 if unavailable.
435  */
436 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick *joystick);
437 
438 /**
439  * Get the product version of an opened joystick, if available.
440  *
441  * If the product version isn't available this function returns 0.
442  *
443  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
444  * \returns the product version of the selected joystick, or 0 if unavailable.
445  */
446 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick *joystick);
447 
448 /**
449  * Get the serial number of an opened joystick, if available.
450  *
451  * Returns the serial number of the joystick, or NULL if it is not available.
452  *
453  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
454  * \returns the serial number of the selected joystick, or NULL if
455  * unavailable.
456  */
457 extern DECLSPEC const char * SDLCALL SDL_JoystickGetSerial(SDL_Joystick *joystick);
458 
459 /**
460  * Get the type of an opened joystick.
461  *
462  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
463  * \returns the SDL_JoystickType of the selected joystick.
464  */
465 extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick *joystick);
466 
467 /**
468  * Get an ASCII string representation for a given SDL_JoystickGUID.
469  *
470  * You should supply at least 33 bytes for pszGUID.
471  *
472  * \param guid the SDL_JoystickGUID you wish to convert to string
473  * \param pszGUID buffer in which to write the ASCII string
474  * \param cbGUID the size of pszGUID
475  *
476  * \sa SDL_JoystickGetDeviceGUID
477  * \sa SDL_JoystickGetGUID
478  * \sa SDL_JoystickGetGUIDFromString
479  */
480 extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
481 
482 /**
483  * Convert a GUID string into a SDL_JoystickGUID structure.
484  *
485  * Performs no error checking. If this function is given a string containing
486  * an invalid GUID, the function will silently succeed, but the GUID generated
487  * will not be useful.
488  *
489  * \param pchGUID string containing an ASCII representation of a GUID
490  * \returns a SDL_JoystickGUID structure.
491  *
492  * \sa SDL_JoystickGetGUIDString
493  */
494 extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
495 
496 /**
497  * Get the status of a specified joystick.
498  *
499  * \param joystick the joystick to query
500  * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not;
501  * call SDL_GetError() for more information.
502  *
503  * \sa SDL_JoystickClose
504  * \sa SDL_JoystickOpen
505  */
506 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick *joystick);
507 
508 /**
509  * Get the instance ID of an opened joystick.
510  *
511  * \param joystick an SDL_Joystick structure containing joystick information
512  * \returns the instance ID of the specified joystick on success or a negative
513  * error code on failure; call SDL_GetError() for more information.
514  *
515  * \sa SDL_JoystickOpen
516  */
517 extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick *joystick);
518 
519 /**
520  * Get the number of general axis controls on a joystick.
521  *
522  * Often, the directional pad on a game controller will either look like 4
523  * separate buttons or a POV hat, and not axes, but all of this is up to the
524  * device and platform.
525  *
526  * \param joystick an SDL_Joystick structure containing joystick information
527  * \returns the number of axis controls/number of axes on success or a
528  * negative error code on failure; call SDL_GetError() for more
529  * information.
530  *
531  * \sa SDL_JoystickGetAxis
532  * \sa SDL_JoystickOpen
533  */
534 extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick);
535 
536 /**
537  * Get the number of trackballs on a joystick.
538  *
539  * Joystick trackballs have only relative motion events associated with them
540  * and their state cannot be polled.
541  *
542  * Most joysticks do not have trackballs.
543  *
544  * \param joystick an SDL_Joystick structure containing joystick information
545  * \returns the number of trackballs on success or a negative error code on
546  * failure; call SDL_GetError() for more information.
547  *
548  * \sa SDL_JoystickGetBall
549  */
550 extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick);
551 
552 /**
553  * Get the number of POV hats on a joystick.
554  *
555  * \param joystick an SDL_Joystick structure containing joystick information
556  * \returns the number of POV hats on success or a negative error code on
557  * failure; call SDL_GetError() for more information.
558  *
559  * \sa SDL_JoystickGetHat
560  * \sa SDL_JoystickOpen
561  */
562 extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick);
563 
564 /**
565  * Get the number of buttons on a joystick.
566  *
567  * \param joystick an SDL_Joystick structure containing joystick information
568  * \returns the number of buttons on success or a negative error code on
569  * failure; call SDL_GetError() for more information.
570  *
571  * \sa SDL_JoystickGetButton
572  * \sa SDL_JoystickOpen
573  */
574 extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick);
575 
576 /**
577  * Update the current state of the open joysticks.
578  *
579  * This is called automatically by the event loop if any joystick events are
580  * enabled.
581  *
582  * \sa SDL_JoystickEventState
583  */
584 extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
585 
586 /**
587  * Enable/disable joystick event polling.
588  *
589  * If joystick events are disabled, you must call SDL_JoystickUpdate()
590  * yourself and manually check the state of the joystick when you want
591  * joystick information.
592  *
593  * It is recommended that you leave joystick event handling enabled.
594  *
595  * **WARNING**: Calling this function may delete all events currently in SDL's
596  * event queue.
597  *
598  * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`
599  * \returns 1 if enabled, 0 if disabled, or a negative error code on failure;
600  * call SDL_GetError() for more information.
601  *
602  * If `state` is `SDL_QUERY` then the current state is returned,
603  * otherwise the new processing state is returned.
604  *
605  * \sa SDL_GameControllerEventState
606  */
607 extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
608 
609 #define SDL_JOYSTICK_AXIS_MAX 32767
610 #define SDL_JOYSTICK_AXIS_MIN -32768
611 /**
612  * Get the current state of an axis control on a joystick.
613  *
614  * SDL makes no promises about what part of the joystick any given axis refers
615  * to. Your game should have some sort of configuration UI to let users
616  * specify what each axis should be bound to. Alternately, SDL's higher-level
617  * Game Controller API makes a great effort to apply order to this lower-level
618  * interface, so you know that a specific axis is the "left thumb stick," etc.
619  *
620  * The value returned by SDL_JoystickGetAxis() is a signed integer (-32768 to
621  * 32767) representing the current position of the axis. It may be necessary
622  * to impose certain tolerances on these values to account for jitter.
623  *
624  * \param joystick an SDL_Joystick structure containing joystick information
625  * \param axis the axis to query; the axis indices start at index 0
626  * \returns a 16-bit signed integer representing the current position of the
627  * axis or 0 on failure; call SDL_GetError() for more information.
628  *
629  * \sa SDL_JoystickNumAxes
630  */
631 extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick,
632  int axis);
633 
634 /**
635  * Get the initial state of an axis control on a joystick.
636  *
637  * The state is a value ranging from -32768 to 32767.
638  *
639  * The axis indices start at index 0.
640  *
641  * \param joystick an SDL_Joystick structure containing joystick information
642  * \param axis the axis to query; the axis indices start at index 0
643  * \param state Upon return, the initial value is supplied here.
644  * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
645  */
646 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick *joystick,
647  int axis, Sint16 *state);
648 
649 /**
650  * \name Hat positions
651  */
652 /* @{ */
653 #define SDL_HAT_CENTERED 0x00
654 #define SDL_HAT_UP 0x01
655 #define SDL_HAT_RIGHT 0x02
656 #define SDL_HAT_DOWN 0x04
657 #define SDL_HAT_LEFT 0x08
658 #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
659 #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
660 #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
661 #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
662 /* @} */
663 
664 /**
665  * Get the current state of a POV hat on a joystick.
666  *
667  * The returned value will be one of the following positions:
668  *
669  * - `SDL_HAT_CENTERED`
670  * - `SDL_HAT_UP`
671  * - `SDL_HAT_RIGHT`
672  * - `SDL_HAT_DOWN`
673  * - `SDL_HAT_LEFT`
674  * - `SDL_HAT_RIGHTUP`
675  * - `SDL_HAT_RIGHTDOWN`
676  * - `SDL_HAT_LEFTUP`
677  * - `SDL_HAT_LEFTDOWN`
678  *
679  * \param joystick an SDL_Joystick structure containing joystick information
680  * \param hat the hat index to get the state from; indices start at index 0
681  * \returns the current hat position.
682  *
683  * \sa SDL_JoystickNumHats
684  */
685 extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick,
686  int hat);
687 
688 /**
689  * Get the ball axis change since the last poll.
690  *
691  * Trackballs can only return relative motion since the last call to
692  * SDL_JoystickGetBall(), these motion deltas are placed into `dx` and `dy`.
693  *
694  * Most joysticks do not have trackballs.
695  *
696  * \param joystick the SDL_Joystick to query
697  * \param ball the ball index to query; ball indices start at index 0
698  * \param dx stores the difference in the x axis position since the last poll
699  * \param dy stores the difference in the y axis position since the last poll
700  * \returns 0 on success or a negative error code on failure; call
701  * SDL_GetError() for more information.
702  *
703  * \sa SDL_JoystickNumBalls
704  */
705 extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick,
706  int ball, int *dx, int *dy);
707 
708 /**
709  * Get the current state of a button on a joystick.
710  *
711  * \param joystick an SDL_Joystick structure containing joystick information
712  * \param button the button index to get the state from; indices start at
713  * index 0
714  * \returns 1 if the specified button is pressed, 0 otherwise.
715  *
716  * \sa SDL_JoystickNumButtons
717  */
718 extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick,
719  int button);
720 
721 /**
722  * Start a rumble effect.
723  *
724  * Each call to this function cancels any previous rumble effect, and calling
725  * it with 0 intensity stops any rumbling.
726  *
727  * \param joystick The joystick to vibrate
728  * \param low_frequency_rumble The intensity of the low frequency (left)
729  * rumble motor, from 0 to 0xFFFF
730  * \param high_frequency_rumble The intensity of the high frequency (right)
731  * rumble motor, from 0 to 0xFFFF
732  * \param duration_ms The duration of the rumble effect, in milliseconds
733  * \returns 0, or -1 if rumble isn't supported on this joystick
734  */
735 extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
736 
737 /**
738  * Start a rumble effect in the joystick's triggers
739  *
740  * Each call to this function cancels any previous trigger rumble effect, and
741  * calling it with 0 intensity stops any rumbling.
742  *
743  * Note that this function is for _trigger_ rumble; the first joystick to
744  * support this was the PlayStation 5's DualShock 5 controller. If you want
745  * the (more common) whole-controller rumble, use SDL_JoystickRumble()
746  * instead.
747  *
748  * \param joystick The joystick to vibrate
749  * \param left_rumble The intensity of the left trigger rumble motor, from 0
750  * to 0xFFFF
751  * \param right_rumble The intensity of the right trigger rumble motor, from 0
752  * to 0xFFFF
753  * \param duration_ms The duration of the rumble effect, in milliseconds
754  * \returns 0, or -1 if trigger rumble isn't supported on this joystick
755  */
756 extern DECLSPEC int SDLCALL SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
757 
758 /**
759  * Query whether a joystick has an LED.
760  *
761  * An example of a joystick LED is the light on the back of a PlayStation 4's
762  * DualShock 4 controller.
763  *
764  * \param joystick The joystick to query
765  * \return SDL_TRUE if the joystick has a modifiable LED, SDL_FALSE otherwise.
766  */
767 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick);
768 
769 /**
770  * Update a joystick's LED color.
771  *
772  * An example of a joystick LED is the light on the back of a PlayStation 4's
773  * DualShock 4 controller.
774  *
775  * \param joystick The joystick to update
776  * \param red The intensity of the red LED
777  * \param green The intensity of the green LED
778  * \param blue The intensity of the blue LED
779  * \returns 0 on success, -1 if this joystick does not have a modifiable LED
780  */
781 extern DECLSPEC int SDLCALL SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
782 
783 /**
784  * Send a joystick specific effect packet
785  *
786  * \param joystick The joystick to affect
787  * \param data The data to send to the joystick
788  * \param size The size of the data to send to the joystick
789  * \returns 0, or -1 if this joystick or driver doesn't support effect packets
790  */
791 extern DECLSPEC int SDLCALL SDL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size);
792 
793 /**
794  * Close a joystick previously opened with SDL_JoystickOpen().
795  *
796  * \param joystick The joystick device to close
797  *
798  * \sa SDL_JoystickOpen
799  */
800 extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick);
801 
802 /**
803  * Get the battery level of a joystick as SDL_JoystickPowerLevel.
804  *
805  * \param joystick the SDL_Joystick to query
806  * \returns the current battery level as SDL_JoystickPowerLevel on success or
807  * `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown
808  *
809  * \since This function is available since SDL 2.0.4.
810  */
811 extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick);
812 
813 #ifdef __LINUX__
814 /**
815  * Return the device path this currently opened joystick.
816  * If no path can be found, this function returns NULL.
817  */
818 extern DECLSPEC const char *SDLCALL VCS_SDL_JoystickLinuxDevicePath(SDL_Joystick * joystick);
819 
820 #endif
821 
822 /* Ends C function definitions when using C++ */
823 #ifdef __cplusplus
824 }
825 #endif
826 #include "close_code.h"
827 
828 #endif /* SDL_joystick_h_ */
829 
830 /* vi: set ts=4 sw=4 expandtab: */
void SDL_UnlockJoysticks(void)
SDL_Joystick * SDL_JoystickFromPlayerIndex(int player_index)
SDL_bool SDL_JoystickHasLED(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
int SDL_JoystickGetDevicePlayerIndex(int device_index)
SDL_bool
Definition: SDL_stdinc.h:167
SDL_JoystickType SDL_JoystickGetType(SDL_Joystick *joystick)
int SDL_JoystickAttachVirtual(SDL_JoystickType type, int naxes, int nbuttons, int nhats)
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:83
Uint16 SDL_JoystickGetDeviceProduct(int device_index)
SDL_bool SDL_JoystickGetAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state)
void SDL_JoystickClose(SDL_Joystick *joystick)
Uint16 SDL_JoystickGetProduct(SDL_Joystick *joystick)
int SDL_JoystickSetVirtualButton(SDL_Joystick *joystick, int button, Uint8 value)
int SDL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
Uint16 SDL_JoystickGetVendor(SDL_Joystick *joystick)
uint32_t Uint32
Definition: SDL_stdinc.h:209
SDL_bool SDL_JoystickIsVirtual(int device_index)
int SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
int SDL_JoystickDetachVirtual(int device_index)
int SDL_JoystickSetVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value)
const char * SDL_JoystickNameForIndex(int device_index)
Uint16 SDL_JoystickGetDeviceProductVersion(int device_index)
SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick *joystick)
SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick)
struct _SDL_Joystick SDL_Joystick
Definition: SDL_joystick.h:69
uint16_t Uint16
Definition: SDL_stdinc.h:197
void SDL_LockJoysticks(void)
SDL_Joystick * SDL_JoystickOpen(int device_index)
Uint16 SDL_JoystickGetProductVersion(SDL_Joystick *joystick)
int SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
SDL_JoystickType SDL_JoystickGetDeviceType(int device_index)
int SDL_JoystickSetVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value)
const char * SDL_JoystickGetSerial(SDL_Joystick *joystick)
int SDL_JoystickEventState(int state)
int32_t Sint32
Definition: SDL_stdinc.h:203
int SDL_JoystickNumHats(SDL_Joystick *joystick)
SDL_JoystickPowerLevel
Definition: SDL_joystick.h:99
SDL_JoystickType
Definition: SDL_joystick.h:85
SDL_Joystick * SDL_JoystickFromInstanceID(SDL_JoystickID instance_id)
SDL_bool SDL_JoystickGetAttached(SDL_Joystick *joystick)
void SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index)
const char * SDL_JoystickName(SDL_Joystick *joystick)
SDL_JoystickID SDL_JoystickGetDeviceInstanceID(int device_index)
Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat)
void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
Uint8 SDL_JoystickGetButton(SDL_Joystick *joystick, int button)
SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
int SDL_JoystickNumAxes(SDL_Joystick *joystick)
int SDL_NumJoysticks(void)
int SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
void SDL_JoystickUpdate(void)
uint8_t Uint8
Definition: SDL_stdinc.h:185
int SDL_JoystickNumBalls(SDL_Joystick *joystick)
int SDL_JoystickNumButtons(SDL_Joystick *joystick)
Sint16 SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis)
SDL_JoystickID SDL_JoystickInstanceID(SDL_Joystick *joystick)
Uint16 SDL_JoystickGetDeviceVendor(int device_index)
int16_t Sint16
Definition: SDL_stdinc.h:191
int SDL_JoystickGetPlayerIndex(SDL_Joystick *joystick)