🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1069 lines
38 KiB

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