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

source code of include/SDL2/SDL_joystick.h