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]; |
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 | */ |
83 | typedef Sint32 SDL_JoystickID; |
84 | |
85 | typedef 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 | |
99 | typedef 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 | 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 |
171 | * This can be 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 |
177 | * at a given device 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. |
195 | * If the vendor ID isn't 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. |
208 | * If the product ID isn't 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. |
221 | * If the product version 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. |
246 | * If the index is out of 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 |
326 | * call to SDL_JoystickUpdate, which can either be called directly, |
327 | * or can be called indirectly through various other SDL APIs, |
328 | * including, but not limited to the following: SDL_PollEvent, |
329 | * SDL_PumpEvents, SDL_WaitEventTimeout, 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 |
342 | * call to SDL_JoystickUpdate, which can either be called directly, |
343 | * or can be called indirectly through various other SDL APIs, |
344 | * including, but not limited to the following: SDL_PollEvent, |
345 | * SDL_PumpEvents, SDL_WaitEventTimeout, 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 |
358 | * call to SDL_JoystickUpdate, which can either be called directly, |
359 | * or can be called indirectly through various other SDL APIs, |
360 | * including, but not limited to the following: SDL_PollEvent, |
361 | * SDL_PumpEvents, SDL_WaitEventTimeout, 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 | * If the product version isn't available this function returns 0. |
441 | * |
442 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen() |
443 | * \returns the product version of the selected joystick, or 0 if unavailable. |
444 | */ |
445 | extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick *joystick); |
446 | |
447 | /** |
448 | * Get the serial number of an opened joystick, if available. |
449 | * |
450 | * Returns the serial number of the joystick, or NULL if it is not available. |
451 | * |
452 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen() |
453 | * \returns the serial number of the selected joystick, or NULL if unavailable. |
454 | */ |
455 | extern DECLSPEC const char * SDLCALL SDL_JoystickGetSerial(SDL_Joystick *joystick); |
456 | |
457 | /** |
458 | * Get the type of an opened joystick. |
459 | * |
460 | * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen() |
461 | * \returns the SDL_JoystickType of the selected joystick. |
462 | */ |
463 | extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick *joystick); |
464 | |
465 | /** |
466 | * Get an ASCII string representation for a given SDL_JoystickGUID. |
467 | * |
468 | * You should supply at least 33 bytes for pszGUID. |
469 | * |
470 | * \param guid the SDL_JoystickGUID you wish to convert to string |
471 | * \param pszGUID buffer in which to write the ASCII string |
472 | * \param cbGUID the size of pszGUID |
473 | * |
474 | * \sa SDL_JoystickGetDeviceGUID |
475 | * \sa SDL_JoystickGetGUID |
476 | * \sa SDL_JoystickGetGUIDFromString |
477 | */ |
478 | extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID); |
479 | |
480 | /** |
481 | * Convert a GUID string into a SDL_JoystickGUID structure. |
482 | * |
483 | * Performs no error checking. If this function is given a string containing |
484 | * an invalid GUID, the function will silently succeed, but the GUID generated |
485 | * will not be useful. |
486 | * |
487 | * \param pchGUID string containing an ASCII representation of a GUID |
488 | * \returns a SDL_JoystickGUID structure. |
489 | * |
490 | * \sa SDL_JoystickGetGUIDString |
491 | */ |
492 | extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID); |
493 | |
494 | /** |
495 | * Get the status of a specified joystick. |
496 | * |
497 | * \param joystick the joystick to query |
498 | * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not; |
499 | * call SDL_GetError() for more information. |
500 | * |
501 | * \sa SDL_JoystickClose |
502 | * \sa SDL_JoystickOpen |
503 | */ |
504 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick *joystick); |
505 | |
506 | /** |
507 | * Get the instance ID of an opened joystick. |
508 | * |
509 | * \param joystick an SDL_Joystick structure containing joystick information |
510 | * \returns the instance ID of the specified joystick on success or a negative |
511 | * error code on failure; call SDL_GetError() for more information. |
512 | * |
513 | * \sa SDL_JoystickOpen |
514 | */ |
515 | extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick *joystick); |
516 | |
517 | /** |
518 | * Get the number of general axis controls on a joystick. |
519 | * |
520 | * Often, the directional pad on a game controller will either look like 4 |
521 | * separate buttons or a POV hat, and not axes, but all of this is up to the |
522 | * device and platform. |
523 | * |
524 | * \param joystick an SDL_Joystick structure containing joystick information |
525 | * \returns the number of axis controls/number of axes on success or a |
526 | * negative error code on failure; call SDL_GetError() for more |
527 | * information. |
528 | * |
529 | * \sa SDL_JoystickGetAxis |
530 | * \sa SDL_JoystickOpen |
531 | */ |
532 | extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick); |
533 | |
534 | /** |
535 | * Get the number of trackballs on a joystick. |
536 | * |
537 | * Joystick trackballs have only relative motion events associated with them |
538 | * and their state cannot be polled. |
539 | * |
540 | * Most joysticks do not have trackballs. |
541 | * |
542 | * \param joystick an SDL_Joystick structure containing joystick information |
543 | * \returns the number of trackballs on success or a negative error code on |
544 | * failure; call SDL_GetError() for more information. |
545 | * |
546 | * \sa SDL_JoystickGetBall |
547 | */ |
548 | extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick); |
549 | |
550 | /** |
551 | * Get the number of POV hats on a joystick. |
552 | * |
553 | * \param joystick an SDL_Joystick structure containing joystick information |
554 | * \returns the number of POV hats on success or a negative error code on |
555 | * failure; call SDL_GetError() for more information. |
556 | * |
557 | * \sa SDL_JoystickGetHat |
558 | * \sa SDL_JoystickOpen |
559 | */ |
560 | extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick); |
561 | |
562 | /** |
563 | * Get the number of buttons on a joystick. |
564 | * |
565 | * \param joystick an SDL_Joystick structure containing joystick information |
566 | * \returns the number of buttons on success or a negative error code on |
567 | * failure; call SDL_GetError() for more information. |
568 | * |
569 | * \sa SDL_JoystickGetButton |
570 | * \sa SDL_JoystickOpen |
571 | */ |
572 | extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick); |
573 | |
574 | /** |
575 | * Update the current state of the open joysticks. |
576 | * |
577 | * This is called automatically by the event loop if any joystick events are |
578 | * enabled. |
579 | * |
580 | * \sa SDL_JoystickEventState |
581 | */ |
582 | extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void); |
583 | |
584 | /** |
585 | * Enable/disable joystick event polling. |
586 | * |
587 | * If joystick events are disabled, you must call SDL_JoystickUpdate() |
588 | * yourself and manually check the state of the joystick when you want |
589 | * joystick information. |
590 | * |
591 | * It is recommended that you leave joystick event handling enabled. |
592 | * |
593 | * **WARNING**: Calling this function may delete all events currently in SDL's |
594 | * event queue. |
595 | * |
596 | * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE` |
597 | * \returns 1 if enabled, 0 if disabled, or a negative error code on failure; |
598 | * call SDL_GetError() for more information. |
599 | * |
600 | * If `state` is `SDL_QUERY` then the current state is returned, |
601 | * otherwise the new processing state is returned. |
602 | * |
603 | * \sa SDL_GameControllerEventState |
604 | */ |
605 | extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state); |
606 | |
607 | #define SDL_JOYSTICK_AXIS_MAX 32767 |
608 | #define SDL_JOYSTICK_AXIS_MIN -32768 |
609 | /** |
610 | * Get the current state of an axis control on a joystick. |
611 | * |
612 | * SDL makes no promises about what part of the joystick any given axis |
613 | * refers to. Your game should have some sort of configuration UI to let |
614 | * users specify what each axis should be bound to. Alternately, SDL's |
615 | * higher-level Game Controller API makes a great effort to apply order |
616 | * to this lower-level interface, so you know that a specific axis is the |
617 | * "left thumb stick," etc. |
618 | * |
619 | * The value returned by SDL_JoystickGetAxis() is a signed integer (-32768 to |
620 | * 32767) representing the current position of the axis. It may be necessary |
621 | * to impose certain tolerances on these values to account for jitter. |
622 | * |
623 | * \param joystick an SDL_Joystick structure containing joystick information |
624 | * \param axis the axis to query; the axis indices start at index 0 |
625 | * \returns a 16-bit signed integer representing the current position of the |
626 | * axis or 0 on failure; call SDL_GetError() for more information. |
627 | * |
628 | * \sa SDL_JoystickNumAxes |
629 | */ |
630 | extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick, |
631 | int axis); |
632 | |
633 | /** |
634 | * Get the initial state of an axis control on a joystick. |
635 | * |
636 | * The state is a value ranging from -32768 to 32767. |
637 | * |
638 | * The axis indices start at index 0. |
639 | * |
640 | * \param joystick an SDL_Joystick structure containing joystick information |
641 | * \param axis the axis to query; the axis indices start at index 0 |
642 | * \param state Upon return, the initial value is supplied here. |
643 | * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not. |
644 | */ |
645 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick *joystick, |
646 | int axis, Sint16 *state); |
647 | |
648 | /** |
649 | * \name Hat positions |
650 | */ |
651 | /* @{ */ |
652 | #define SDL_HAT_CENTERED 0x00 |
653 | #define SDL_HAT_UP 0x01 |
654 | #define SDL_HAT_RIGHT 0x02 |
655 | #define SDL_HAT_DOWN 0x04 |
656 | #define SDL_HAT_LEFT 0x08 |
657 | #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP) |
658 | #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN) |
659 | #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP) |
660 | #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN) |
661 | /* @} */ |
662 | |
663 | /** |
664 | * Get the current state of a POV hat on a joystick. |
665 | * |
666 | * The returned value will be one of the following positions: |
667 | * |
668 | * - `SDL_HAT_CENTERED` |
669 | * - `SDL_HAT_UP` |
670 | * - `SDL_HAT_RIGHT` |
671 | * - `SDL_HAT_DOWN` |
672 | * - `SDL_HAT_LEFT` |
673 | * - `SDL_HAT_RIGHTUP` |
674 | * - `SDL_HAT_RIGHTDOWN` |
675 | * - `SDL_HAT_LEFTUP` |
676 | * - `SDL_HAT_LEFTDOWN` |
677 | * |
678 | * \param joystick an SDL_Joystick structure containing joystick information |
679 | * \param hat the hat index to get the state from; indices start at index 0 |
680 | * \returns the current hat position. |
681 | * |
682 | * \sa SDL_JoystickNumHats |
683 | */ |
684 | extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick, |
685 | int hat); |
686 | |
687 | /** |
688 | * Get the ball axis change since the last poll. |
689 | * |
690 | * Trackballs can only return relative motion since the last call to |
691 | * SDL_JoystickGetBall(), these motion deltas are placed into `dx` and |
692 | * `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 | * |
734 | * \returns 0, or -1 if rumble isn't supported on this joystick |
735 | */ |
736 | extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms); |
737 | |
738 | /** |
739 | * Start a rumble effect in the joystick's triggers |
740 | * |
741 | * Each call to this function cancels any previous trigger rumble effect, |
742 | * and calling it with 0 intensity stops any rumbling. |
743 | * |
744 | * Note that this function is for _trigger_ rumble; the first joystick to |
745 | * support this was the PlayStation 5's DualShock 5 controller. If you want |
746 | * the (more common) whole-controller rumble, use SDL_JoystickRumble() 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 | * |
755 | * \returns 0, or -1 if trigger rumble isn't supported on this joystick |
756 | */ |
757 | extern DECLSPEC int SDLCALL SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms); |
758 | |
759 | /** |
760 | * Query whether a joystick has an LED. |
761 | * |
762 | * An example of a joystick LED is the light on the back of a PlayStation 4's |
763 | * DualShock 4 controller. |
764 | * |
765 | * \param joystick The joystick to query |
766 | * \return SDL_TRUE if the joystick has a modifiable LED, SDL_FALSE otherwise. |
767 | */ |
768 | extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick); |
769 | |
770 | /** |
771 | * Update a joystick's LED color. |
772 | * |
773 | * An example of a joystick LED is the light on the back of a PlayStation 4's |
774 | * DualShock 4 controller. |
775 | * |
776 | * \param joystick The joystick to update |
777 | * \param red The intensity of the red LED |
778 | * \param green The intensity of the green LED |
779 | * \param blue The intensity of the blue LED |
780 | * |
781 | * \returns 0 on success, -1 if this joystick does not have a modifiable LED |
782 | */ |
783 | extern DECLSPEC int SDLCALL SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); |
784 | |
785 | /** |
786 | * Close a joystick previously opened with SDL_JoystickOpen(). |
787 | * |
788 | * \param joystick The joystick device to close |
789 | * |
790 | * \sa SDL_JoystickOpen |
791 | */ |
792 | extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick); |
793 | |
794 | /** |
795 | * Get the battery level of a joystick as SDL_JoystickPowerLevel. |
796 | * |
797 | * \param joystick the SDL_Joystick to query |
798 | * \returns the current battery level as SDL_JoystickPowerLevel on success or |
799 | * `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown |
800 | * |
801 | * \since This function is available since SDL 2.0.4. |
802 | */ |
803 | extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick); |
804 | |
805 | /* Ends C function definitions when using C++ */ |
806 | #ifdef __cplusplus |
807 | } |
808 | #endif |
809 | #include "close_code.h" |
810 | |
811 | #endif /* SDL_joystick_h_ */ |
812 | |
813 | /* vi: set ts=4 sw=4 expandtab: */ |
814 | |