SDL_joystick.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 Sam Lantinga <[email protected]>
  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 "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted
  24. * then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.
  25. *
  26. * The term "player_index" is the number assigned to a player on a specific
  27. * controller. For XInput controllers this returns the XInput user index.
  28. * Many joysticks will not be able to supply this information.
  29. *
  30. * The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of
  31. * the device (a X360 wired controller for example). This identifier is platform dependent.
  32. */
  33. #ifndef SDL_joystick_h_
  34. #define SDL_joystick_h_
  35. #include <SDL3/SDL_stdinc.h>
  36. #include <SDL3/SDL_error.h>
  37. #include <SDL3/SDL_guid.h>
  38. #include <SDL3/SDL_mutex.h>
  39. #include <SDL3/SDL_begin_code.h>
  40. /* Set up for C function definitions, even when using C++ */
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /**
  45. * \file SDL_joystick.h
  46. *
  47. * In order to use these functions, SDL_Init() must have been called
  48. * with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
  49. * for joysticks, and load appropriate drivers.
  50. *
  51. * If you would like to receive joystick updates while the application
  52. * is in the background, you should set the following hint before calling
  53. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  54. */
  55. /**
  56. * The joystick structure used to identify an SDL joystick
  57. */
  58. #ifdef SDL_THREAD_SAFETY_ANALYSIS
  59. extern SDL_mutex *SDL_joystick_lock;
  60. #endif
  61. struct SDL_Joystick;
  62. typedef struct SDL_Joystick SDL_Joystick;
  63. /* A structure that encodes the stable unique id for a joystick device */
  64. typedef SDL_GUID SDL_JoystickGUID;
  65. /**
  66. * This is a unique ID for a joystick for the time it is connected to the system,
  67. * and is never reused for the lifetime of the application. If the joystick is
  68. * disconnected and reconnected, it will get a new ID.
  69. *
  70. * The ID value starts at 1 and increments from there. The value 0 is an invalid ID.
  71. */
  72. typedef Uint32 SDL_JoystickID;
  73. typedef enum
  74. {
  75. SDL_JOYSTICK_TYPE_UNKNOWN,
  76. SDL_JOYSTICK_TYPE_GAMEPAD,
  77. SDL_JOYSTICK_TYPE_WHEEL,
  78. SDL_JOYSTICK_TYPE_ARCADE_STICK,
  79. SDL_JOYSTICK_TYPE_FLIGHT_STICK,
  80. SDL_JOYSTICK_TYPE_DANCE_PAD,
  81. SDL_JOYSTICK_TYPE_GUITAR,
  82. SDL_JOYSTICK_TYPE_DRUM_KIT,
  83. SDL_JOYSTICK_TYPE_ARCADE_PAD,
  84. SDL_JOYSTICK_TYPE_THROTTLE
  85. } SDL_JoystickType;
  86. typedef enum
  87. {
  88. SDL_JOYSTICK_POWER_UNKNOWN = -1,
  89. SDL_JOYSTICK_POWER_EMPTY, /* <= 5% */
  90. SDL_JOYSTICK_POWER_LOW, /* <= 20% */
  91. SDL_JOYSTICK_POWER_MEDIUM, /* <= 70% */
  92. SDL_JOYSTICK_POWER_FULL, /* <= 100% */
  93. SDL_JOYSTICK_POWER_WIRED,
  94. SDL_JOYSTICK_POWER_MAX
  95. } SDL_JoystickPowerLevel;
  96. #define SDL_JOYSTICK_AXIS_MAX 32767
  97. #define SDL_JOYSTICK_AXIS_MIN -32768
  98. /* Set max recognized G-force from accelerometer
  99. See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
  100. */
  101. #define SDL_IPHONE_MAX_GFORCE 5.0
  102. /* Function prototypes */
  103. /**
  104. * Locking for atomic access to the joystick API
  105. *
  106. * The SDL joystick functions are thread-safe, however you can lock the joysticks
  107. * while processing to guarantee that the joystick list won't change and joystick
  108. * and gamepad events will not be delivered.
  109. *
  110. * \since This function is available since SDL 3.0.0.
  111. */
  112. extern DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
  113. /**
  114. * Unlocking for atomic access to the joystick API
  115. *
  116. * \since This function is available since SDL 3.0.0.
  117. */
  118. extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
  119. /**
  120. * Return whether there are joysticks connected
  121. *
  122. * \returns SDL_TRUE if there are joysticks connected, SDL_FALSE otherwise.
  123. *
  124. * \since This function is available since SDL 3.0.0.
  125. *
  126. * \sa SDL_GetJoysticks
  127. */
  128. extern DECLSPEC SDL_bool SDLCALL SDL_HasJoysticks(void);
  129. /**
  130. * Get a list of currently connected joysticks.
  131. *
  132. * \param count a pointer filled in with the number of joysticks returned
  133. * \returns a 0 terminated array of joystick instance IDs which should be freed with SDL_free(), or NULL on error; call SDL_GetError() for more details.
  134. *
  135. * \since This function is available since SDL 3.0.0.
  136. *
  137. * \sa SDL_OpenJoystick
  138. */
  139. extern DECLSPEC SDL_JoystickID *SDLCALL SDL_GetJoysticks(int *count);
  140. /**
  141. * Get the implementation dependent name of a joystick.
  142. *
  143. * This can be called before any joysticks are opened.
  144. *
  145. * \param instance_id the joystick instance ID
  146. * \returns the name of the selected joystick. If no name can be found, this
  147. * function returns NULL; call SDL_GetError() for more information.
  148. *
  149. * \since This function is available since SDL 3.0.0.
  150. *
  151. * \sa SDL_GetJoystickName
  152. * \sa SDL_OpenJoystick
  153. */
  154. extern DECLSPEC const char *SDLCALL SDL_GetJoystickInstanceName(SDL_JoystickID instance_id);
  155. /**
  156. * Get the implementation dependent path of a joystick.
  157. *
  158. * This can be called before any joysticks are opened.
  159. *
  160. * \param instance_id the joystick instance ID
  161. * \returns the path of the selected joystick. If no path can be found, this
  162. * function returns NULL; call SDL_GetError() for more information.
  163. *
  164. * \since This function is available since SDL 3.0.0.
  165. *
  166. * \sa SDL_GetJoystickPath
  167. * \sa SDL_OpenJoystick
  168. */
  169. extern DECLSPEC const char *SDLCALL SDL_GetJoystickInstancePath(SDL_JoystickID instance_id);
  170. /**
  171. * Get the player index of a joystick.
  172. *
  173. * This can be called before any joysticks are opened.
  174. *
  175. * \param instance_id the joystick instance ID
  176. * \returns the player index of a joystick, or -1 if it's not available
  177. *
  178. * \since This function is available since SDL 3.0.0.
  179. *
  180. * \sa SDL_GetJoystickPlayerIndex
  181. * \sa SDL_OpenJoystick
  182. */
  183. extern DECLSPEC int SDLCALL SDL_GetJoystickInstancePlayerIndex(SDL_JoystickID instance_id);
  184. /**
  185. * Get the implementation-dependent GUID of a joystick.
  186. *
  187. * This can be called before any joysticks are opened.
  188. *
  189. * \param instance_id the joystick instance ID
  190. * \returns the GUID of the selected joystick. If called on an invalid index,
  191. * this function returns a zero GUID
  192. *
  193. * \since This function is available since SDL 3.0.0.
  194. *
  195. * \sa SDL_GetJoystickGUID
  196. * \sa SDL_GetJoystickGUIDString
  197. */
  198. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickInstanceGUID(SDL_JoystickID instance_id);
  199. /**
  200. * Get the USB vendor ID of a joystick, if available.
  201. *
  202. * This can be called before any joysticks are opened. If the vendor ID isn't
  203. * available this function returns 0.
  204. *
  205. * \param instance_id the joystick instance ID
  206. * \returns the USB vendor ID of the selected joystick. If called on an
  207. * invalid index, this function returns zero
  208. *
  209. * \since This function is available since SDL 3.0.0.
  210. */
  211. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickInstanceVendor(SDL_JoystickID instance_id);
  212. /**
  213. * Get the USB product ID of a joystick, if available.
  214. *
  215. * This can be called before any joysticks are opened. If the product ID isn't
  216. * available this function returns 0.
  217. *
  218. * \param instance_id the joystick instance ID
  219. * \returns the USB product ID of the selected joystick. If called on an
  220. * invalid index, this function returns zero
  221. *
  222. * \since This function is available since SDL 3.0.0.
  223. */
  224. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickInstanceProduct(SDL_JoystickID instance_id);
  225. /**
  226. * Get the product version of a joystick, if available.
  227. *
  228. * This can be called before any joysticks are opened. If the product version
  229. * isn't available this function returns 0.
  230. *
  231. * \param instance_id the joystick instance ID
  232. * \returns the product version of the selected joystick. If called on an
  233. * invalid index, this function returns zero
  234. *
  235. * \since This function is available since SDL 3.0.0.
  236. */
  237. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickInstanceProductVersion(SDL_JoystickID instance_id);
  238. /**
  239. * Get the type of a joystick, if available.
  240. *
  241. * This can be called before any joysticks are opened.
  242. *
  243. * \param instance_id the joystick instance ID
  244. * \returns the SDL_JoystickType of the selected joystick. If called on an
  245. * invalid index, this function returns `SDL_JOYSTICK_TYPE_UNKNOWN`
  246. *
  247. * \since This function is available since SDL 3.0.0.
  248. */
  249. extern DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickInstanceType(SDL_JoystickID instance_id);
  250. /**
  251. * Open a joystick for use.
  252. *
  253. * The joystick subsystem must be initialized before a joystick can be opened
  254. * for use.
  255. *
  256. * \param instance_id the joystick instance ID
  257. * \returns a joystick identifier or NULL if an error occurred; call
  258. * SDL_GetError() for more information.
  259. *
  260. * \since This function is available since SDL 3.0.0.
  261. *
  262. * \sa SDL_CloseJoystick
  263. */
  264. extern DECLSPEC SDL_Joystick *SDLCALL SDL_OpenJoystick(SDL_JoystickID instance_id);
  265. /**
  266. * Get the SDL_Joystick associated with an instance ID.
  267. *
  268. * \param instance_id the instance ID to get the SDL_Joystick for
  269. * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
  270. * for more information.
  271. *
  272. * \since This function is available since SDL 3.0.0.
  273. */
  274. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GetJoystickFromInstanceID(SDL_JoystickID instance_id);
  275. /**
  276. * Get the SDL_Joystick associated with a player index.
  277. *
  278. * \param player_index the player index 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 3.0.0.
  283. */
  284. extern DECLSPEC SDL_Joystick *SDLCALL SDL_GetJoystickFromPlayerIndex(int player_index);
  285. /**
  286. * Attach a new virtual joystick.
  287. *
  288. * \returns the joystick instance ID, or 0 if an error occurred; call SDL_GetError() for more information.
  289. *
  290. * \since This function is available since SDL 3.0.0.
  291. */
  292. extern DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(SDL_JoystickType type,
  293. int naxes,
  294. int nbuttons,
  295. int nhats);
  296. /**
  297. * The structure that defines an extended virtual joystick description
  298. *
  299. * The caller must zero the structure and then initialize the version with `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` before passing it to SDL_AttachVirtualJoystickEx()
  300. * All other elements of this structure are optional and can be left 0.
  301. *
  302. * \sa SDL_AttachVirtualJoystickEx
  303. */
  304. typedef struct SDL_VirtualJoystickDesc
  305. {
  306. Uint16 version; /**< `SDL_VIRTUAL_JOYSTICK_DESC_VERSION` */
  307. Uint16 type; /**< `SDL_JoystickType` */
  308. Uint16 naxes; /**< the number of axes on this joystick */
  309. Uint16 nbuttons; /**< the number of buttons on this joystick */
  310. Uint16 nhats; /**< the number of hats on this joystick */
  311. Uint16 vendor_id; /**< the USB vendor ID of this joystick */
  312. Uint16 product_id; /**< the USB product ID of this joystick */
  313. Uint16 padding; /**< unused */
  314. Uint32 button_mask; /**< A mask of which buttons are valid for this controller
  315. e.g. (1 << SDL_GAMEPAD_BUTTON_A) */
  316. Uint32 axis_mask; /**< A mask of which axes are valid for this controller
  317. e.g. (1 << SDL_GAMEPAD_AXIS_LEFTX) */
  318. const char *name; /**< the name of the joystick */
  319. void *userdata; /**< User data pointer passed to callbacks */
  320. void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */
  321. void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */
  322. int (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */
  323. int (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */
  324. int (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */
  325. int (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */
  326. } SDL_VirtualJoystickDesc;
  327. /**
  328. * \brief The current version of the SDL_VirtualJoystickDesc structure
  329. */
  330. #define SDL_VIRTUAL_JOYSTICK_DESC_VERSION 1
  331. /**
  332. * Attach a new virtual joystick with extended properties.
  333. *
  334. * \returns the joystick instance ID, or 0 if an error occurred; call SDL_GetError() for more information.
  335. *
  336. * \since This function is available since SDL 3.0.0.
  337. */
  338. extern DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystickEx(const SDL_VirtualJoystickDesc *desc);
  339. /**
  340. * Detach a virtual joystick.
  341. *
  342. * \param instance_id the joystick instance ID, previously returned from SDL_AttachVirtualJoystick()
  343. * \returns 0 on success, or -1 if an error occurred.
  344. *
  345. * \since This function is available since SDL 3.0.0.
  346. */
  347. extern DECLSPEC int SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id);
  348. /**
  349. * Query whether or not a joystick is virtual.
  350. *
  351. * \param instance_id the joystick instance ID
  352. * \returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise.
  353. *
  354. * \since This function is available since SDL 3.0.0.
  355. */
  356. extern DECLSPEC SDL_bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);
  357. /**
  358. * Set values on an opened, virtual-joystick's axis.
  359. *
  360. * Please note that values set here will not be applied until the next call to
  361. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  362. * indirectly through various other SDL APIs, including, but not limited to
  363. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  364. * SDL_WaitEvent.
  365. *
  366. * Note that when sending trigger axes, you should scale the value to the full
  367. * range of Sint16. For example, a trigger at rest would have the value of
  368. * `SDL_JOYSTICK_AXIS_MIN`.
  369. *
  370. * \param joystick the virtual joystick on which to set state.
  371. * \param axis the specific axis on the virtual joystick to set.
  372. * \param value the new value for the specified axis.
  373. * \returns 0 on success, -1 on error.
  374. *
  375. * \since This function is available since SDL 3.0.0.
  376. */
  377. extern DECLSPEC int SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
  378. /**
  379. * Set values on an opened, virtual-joystick's button.
  380. *
  381. * Please note that values set here will not be applied until the next call to
  382. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  383. * indirectly through various other SDL APIs, including, but not limited to
  384. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  385. * SDL_WaitEvent.
  386. *
  387. * \param joystick the virtual joystick on which to set state.
  388. * \param button the specific button on the virtual joystick to set.
  389. * \param value the new value for the specified button.
  390. * \returns 0 on success, -1 on error.
  391. *
  392. * \since This function is available since SDL 3.0.0.
  393. */
  394. extern DECLSPEC int SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
  395. /**
  396. * Set values on an opened, virtual-joystick's hat.
  397. *
  398. * Please note that values set here will not be applied until the next call to
  399. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  400. * indirectly through various other SDL APIs, including, but not limited to
  401. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  402. * SDL_WaitEvent.
  403. *
  404. * \param joystick the virtual joystick on which to set state.
  405. * \param hat the specific hat on the virtual joystick to set.
  406. * \param value the new value for the specified hat.
  407. * \returns 0 on success, -1 on error.
  408. *
  409. * \since This function is available since SDL 3.0.0.
  410. */
  411. extern DECLSPEC int SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
  412. /**
  413. * Get the implementation dependent name of a joystick.
  414. *
  415. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  416. * \returns the name of the selected joystick. If no name can be found, this
  417. * function returns NULL; call SDL_GetError() for more information.
  418. *
  419. * \since This function is available since SDL 3.0.0.
  420. *
  421. * \sa SDL_GetJoystickInstanceName
  422. * \sa SDL_OpenJoystick
  423. */
  424. extern DECLSPEC const char *SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);
  425. /**
  426. * Get the implementation dependent path of a joystick.
  427. *
  428. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  429. * \returns the path of the selected joystick. If no path can be found, this
  430. * function returns NULL; call SDL_GetError() for more information.
  431. *
  432. * \since This function is available since SDL 3.0.0.
  433. *
  434. * \sa SDL_GetJoystickInstancePath
  435. */
  436. extern DECLSPEC const char *SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);
  437. /**
  438. * Get the player index of an opened joystick.
  439. *
  440. * For XInput controllers this returns the XInput user index. Many joysticks
  441. * will not be able to supply this information.
  442. *
  443. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  444. * \returns the player index, or -1 if it's not available.
  445. *
  446. * \since This function is available since SDL 3.0.0.
  447. */
  448. extern DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick);
  449. /**
  450. * Set the player index of an opened joystick.
  451. *
  452. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  453. * \param player_index Player index to assign to this joystick, or -1 to clear
  454. * the player index and turn off player LEDs.
  455. *
  456. * \since This function is available since SDL 3.0.0.
  457. */
  458. extern DECLSPEC void SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);
  459. /**
  460. * Get the implementation-dependent GUID for the joystick.
  461. *
  462. * This function requires an open joystick.
  463. *
  464. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  465. * \returns the GUID of the given joystick. If called on an invalid index,
  466. * this function returns a zero GUID; call SDL_GetError() for more
  467. * information.
  468. *
  469. * \since This function is available since SDL 3.0.0.
  470. *
  471. * \sa SDL_GetJoystickInstanceGUID
  472. * \sa SDL_GetJoystickGUIDString
  473. */
  474. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);
  475. /**
  476. * Get the USB vendor ID of an opened joystick, if available.
  477. *
  478. * If the vendor ID isn't available this function returns 0.
  479. *
  480. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  481. * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
  482. *
  483. * \since This function is available since SDL 3.0.0.
  484. */
  485. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick);
  486. /**
  487. * Get the USB product ID of an opened joystick, if available.
  488. *
  489. * If the product ID isn't available this function returns 0.
  490. *
  491. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  492. * \returns the USB product ID of the selected joystick, or 0 if unavailable.
  493. *
  494. * \since This function is available since SDL 3.0.0.
  495. */
  496. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick);
  497. /**
  498. * Get the product version of an opened joystick, if available.
  499. *
  500. * If the product version isn't available this function returns 0.
  501. *
  502. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  503. * \returns the product version of the selected joystick, or 0 if unavailable.
  504. *
  505. * \since This function is available since SDL 3.0.0.
  506. */
  507. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *joystick);
  508. /**
  509. * Get the firmware version of an opened joystick, if available.
  510. *
  511. * If the firmware version isn't available this function returns 0.
  512. *
  513. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  514. * \returns the firmware version of the selected joystick, or 0 if
  515. * unavailable.
  516. *
  517. * \since This function is available since SDL 3.0.0.
  518. */
  519. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);
  520. /**
  521. * Get the serial number of an opened joystick, if available.
  522. *
  523. * Returns the serial number of the joystick, or NULL if it is not available.
  524. *
  525. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  526. * \returns the serial number of the selected joystick, or NULL if
  527. * unavailable.
  528. *
  529. * \since This function is available since SDL 3.0.0.
  530. */
  531. extern DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
  532. /**
  533. * Get the type of an opened joystick.
  534. *
  535. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  536. * \returns the SDL_JoystickType of the selected joystick.
  537. *
  538. * \since This function is available since SDL 3.0.0.
  539. */
  540. extern DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick);
  541. /**
  542. * Get an ASCII string representation for a given SDL_JoystickGUID.
  543. *
  544. * You should supply at least 33 bytes for pszGUID.
  545. *
  546. * \param guid the SDL_JoystickGUID you wish to convert to string
  547. * \param pszGUID buffer in which to write the ASCII string
  548. * \param cbGUID the size of pszGUID
  549. *
  550. * \since This function is available since SDL 3.0.0.
  551. *
  552. * \sa SDL_GetJoystickInstanceGUID
  553. * \sa SDL_GetJoystickGUID
  554. * \sa SDL_GetJoystickGUIDFromString
  555. */
  556. extern DECLSPEC void SDLCALL SDL_GetJoystickGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
  557. /**
  558. * Convert a GUID string into a SDL_JoystickGUID structure.
  559. *
  560. * Performs no error checking. If this function is given a string containing
  561. * an invalid GUID, the function will silently succeed, but the GUID generated
  562. * will not be useful.
  563. *
  564. * \param pchGUID string containing an ASCII representation of a GUID
  565. * \returns a SDL_JoystickGUID structure.
  566. *
  567. * \since This function is available since SDL 3.0.0.
  568. *
  569. * \sa SDL_GetJoystickGUIDString
  570. */
  571. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUIDFromString(const char *pchGUID);
  572. /**
  573. * Get the device information encoded in a SDL_JoystickGUID structure
  574. *
  575. * \param guid the SDL_JoystickGUID you wish to get info about
  576. * \param vendor A pointer filled in with the device VID, or 0 if not
  577. * available
  578. * \param product A pointer filled in with the device PID, or 0 if not
  579. * available
  580. * \param version A pointer filled in with the device version, or 0 if not
  581. * available
  582. * \param crc16 A pointer filled in with a CRC used to distinguish different
  583. * products with the same VID/PID, or 0 if not available
  584. *
  585. * \since This function is available since SDL 3.0.0.
  586. *
  587. * \sa SDL_GetJoystickInstanceGUID
  588. */
  589. extern DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
  590. /**
  591. * Get the status of a specified joystick.
  592. *
  593. * \param joystick the joystick to query
  594. * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not;
  595. * call SDL_GetError() for more information.
  596. *
  597. * \since This function is available since SDL 3.0.0.
  598. *
  599. * \sa SDL_CloseJoystick
  600. * \sa SDL_OpenJoystick
  601. */
  602. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
  603. /**
  604. * Get the instance ID of an opened joystick.
  605. *
  606. * \param joystick an SDL_Joystick structure containing joystick information
  607. * \returns the instance ID of the specified joystick on success or a negative
  608. * error code on failure; call SDL_GetError() for more information.
  609. *
  610. * \since This function is available since SDL 3.0.0.
  611. *
  612. * \sa SDL_OpenJoystick
  613. */
  614. extern DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickInstanceID(SDL_Joystick *joystick);
  615. /**
  616. * Get the number of general axis controls on a joystick.
  617. *
  618. * Often, the directional pad on a game controller will either look like 4
  619. * separate buttons or a POV hat, and not axes, but all of this is up to the
  620. * device and platform.
  621. *
  622. * \param joystick an SDL_Joystick structure containing joystick information
  623. * \returns the number of axis controls/number of axes on success or a
  624. * negative error code on failure; call SDL_GetError() for more
  625. * information.
  626. *
  627. * \since This function is available since SDL 3.0.0.
  628. *
  629. * \sa SDL_GetJoystickAxis
  630. * \sa SDL_OpenJoystick
  631. */
  632. extern DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick);
  633. /**
  634. * Get the number of POV hats on a joystick.
  635. *
  636. * \param joystick an SDL_Joystick structure containing joystick information
  637. * \returns the number of POV hats on success or a negative error code on
  638. * failure; call SDL_GetError() for more information.
  639. *
  640. * \since This function is available since SDL 3.0.0.
  641. *
  642. * \sa SDL_GetJoystickHat
  643. * \sa SDL_OpenJoystick
  644. */
  645. extern DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick);
  646. /**
  647. * Get the number of buttons on a joystick.
  648. *
  649. * \param joystick an SDL_Joystick structure containing joystick information
  650. * \returns the number of buttons on success or a negative error code on
  651. * failure; call SDL_GetError() for more information.
  652. *
  653. * \since This function is available since SDL 3.0.0.
  654. *
  655. * \sa SDL_GetJoystickButton
  656. * \sa SDL_OpenJoystick
  657. */
  658. extern DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick);
  659. /**
  660. * Set the state of joystick event processing.
  661. *
  662. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  663. * yourself and check the state of the joystick when you want joystick
  664. * information.
  665. *
  666. * \param state whether to process joystick events or not
  667. *
  668. * \since This function is available since SDL 3.0.0.
  669. *
  670. * \sa SDL_JoystickEventsEnabled
  671. */
  672. extern DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(SDL_bool enabled);
  673. /**
  674. * Query the state of joystick event processing.
  675. *
  676. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  677. * yourself and check the state of the joystick when you want joystick
  678. * information.
  679. *
  680. * \returns SDL_TRUE if joystick events are being processed, SDL_FALSE otherwise.
  681. *
  682. * \since This function is available since SDL 3.0.0.
  683. *
  684. * \sa SDL_SetJoystickEventsEnabled
  685. */
  686. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickEventsEnabled(void);
  687. /**
  688. * Update the current state of the open joysticks.
  689. *
  690. * This is called automatically by the event loop if any joystick events are
  691. * enabled.
  692. *
  693. * \since This function is available since SDL 3.0.0.
  694. */
  695. extern DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
  696. /**
  697. * Get the current state of an axis control on a joystick.
  698. *
  699. * SDL makes no promises about what part of the joystick any given axis refers
  700. * to. Your game should have some sort of configuration UI to let users
  701. * specify what each axis should be bound to. Alternately, SDL's higher-level
  702. * Game Controller API makes a great effort to apply order to this lower-level
  703. * interface, so you know that a specific axis is the "left thumb stick," etc.
  704. *
  705. * The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to
  706. * 32767) representing the current position of the axis. It may be necessary
  707. * to impose certain tolerances on these values to account for jitter.
  708. *
  709. * \param joystick an SDL_Joystick structure containing joystick information
  710. * \param axis the axis to query; the axis indices start at index 0
  711. * \returns a 16-bit signed integer representing the current position of the
  712. * axis or 0 on failure; call SDL_GetError() for more information.
  713. *
  714. * \since This function is available since SDL 3.0.0.
  715. *
  716. * \sa SDL_GetNumJoystickAxes
  717. */
  718. extern DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick,
  719. int axis);
  720. /**
  721. * Get the initial state of an axis control on a joystick.
  722. *
  723. * The state is a value ranging from -32768 to 32767.
  724. *
  725. * The axis indices start at index 0.
  726. *
  727. * \param joystick an SDL_Joystick structure containing joystick information
  728. * \param axis the axis to query; the axis indices start at index 0
  729. * \param state Upon return, the initial value is supplied here.
  730. * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
  731. *
  732. * \since This function is available since SDL 3.0.0.
  733. */
  734. extern DECLSPEC SDL_bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick,
  735. int axis, Sint16 *state);
  736. /**
  737. * \name Hat positions
  738. */
  739. /* @{ */
  740. #define SDL_HAT_CENTERED 0x00
  741. #define SDL_HAT_UP 0x01
  742. #define SDL_HAT_RIGHT 0x02
  743. #define SDL_HAT_DOWN 0x04
  744. #define SDL_HAT_LEFT 0x08
  745. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  746. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  747. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  748. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  749. /* @} */
  750. /**
  751. * Get the current state of a POV hat on a joystick.
  752. *
  753. * The returned value will be one of the following positions:
  754. *
  755. * - `SDL_HAT_CENTERED`
  756. * - `SDL_HAT_UP`
  757. * - `SDL_HAT_RIGHT`
  758. * - `SDL_HAT_DOWN`
  759. * - `SDL_HAT_LEFT`
  760. * - `SDL_HAT_RIGHTUP`
  761. * - `SDL_HAT_RIGHTDOWN`
  762. * - `SDL_HAT_LEFTUP`
  763. * - `SDL_HAT_LEFTDOWN`
  764. *
  765. * \param joystick an SDL_Joystick structure containing joystick information
  766. * \param hat the hat index to get the state from; indices start at index 0
  767. * \returns the current hat position.
  768. *
  769. * \since This function is available since SDL 3.0.0.
  770. *
  771. * \sa SDL_GetNumJoystickHats
  772. */
  773. extern DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick,
  774. int hat);
  775. /**
  776. * Get the current state of a button on a joystick.
  777. *
  778. * \param joystick an SDL_Joystick structure containing joystick information
  779. * \param button the button index to get the state from; indices start at
  780. * index 0
  781. * \returns 1 if the specified button is pressed, 0 otherwise.
  782. *
  783. * \since This function is available since SDL 3.0.0.
  784. *
  785. * \sa SDL_GetNumJoystickButtons
  786. */
  787. extern DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick,
  788. int button);
  789. /**
  790. * Start a rumble effect.
  791. *
  792. * Each call to this function cancels any previous rumble effect, and calling
  793. * it with 0 intensity stops any rumbling.
  794. *
  795. * \param joystick The joystick to vibrate
  796. * \param low_frequency_rumble The intensity of the low frequency (left)
  797. * rumble motor, from 0 to 0xFFFF
  798. * \param high_frequency_rumble The intensity of the high frequency (right)
  799. * rumble motor, from 0 to 0xFFFF
  800. * \param duration_ms The duration of the rumble effect, in milliseconds
  801. * \returns 0, or -1 if rumble isn't supported on this joystick
  802. *
  803. * \since This function is available since SDL 3.0.0.
  804. *
  805. * \sa SDL_JoystickHasRumble
  806. */
  807. extern DECLSPEC int SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  808. /**
  809. * Start a rumble effect in the joystick's triggers
  810. *
  811. * Each call to this function cancels any previous trigger rumble effect, and
  812. * calling it with 0 intensity stops any rumbling.
  813. *
  814. * Note that this is rumbling of the _triggers_ and not the game controller as
  815. * a whole. This is currently only supported on Xbox One controllers. If you
  816. * want the (more common) whole-controller rumble, use SDL_RumbleJoystick()
  817. * instead.
  818. *
  819. * \param joystick The joystick to vibrate
  820. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  821. * to 0xFFFF
  822. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  823. * to 0xFFFF
  824. * \param duration_ms The duration of the rumble effect, in milliseconds
  825. * \returns 0, or -1 if trigger rumble isn't supported on this joystick
  826. *
  827. * \since This function is available since SDL 3.0.0.
  828. *
  829. * \sa SDL_JoystickHasRumbleTriggers
  830. */
  831. extern DECLSPEC int SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  832. /**
  833. * Query whether a joystick has an LED.
  834. *
  835. * An example of a joystick LED is the light on the back of a PlayStation 4's
  836. * DualShock 4 controller.
  837. *
  838. * \param joystick The joystick to query
  839. * \return SDL_TRUE if the joystick has a modifiable LED, SDL_FALSE otherwise.
  840. *
  841. * \since This function is available since SDL 3.0.0.
  842. */
  843. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick);
  844. /**
  845. * Query whether a joystick has rumble support.
  846. *
  847. * \param joystick The joystick to query
  848. * \return SDL_TRUE if the joystick has rumble, SDL_FALSE otherwise.
  849. *
  850. * \since This function is available since SDL 3.0.0.
  851. *
  852. * \sa SDL_RumbleJoystick
  853. */
  854. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumble(SDL_Joystick *joystick);
  855. /**
  856. * Query whether a joystick has rumble support on triggers.
  857. *
  858. * \param joystick The joystick to query
  859. * \return SDL_TRUE if the joystick has trigger rumble, SDL_FALSE otherwise.
  860. *
  861. * \since This function is available since SDL 3.0.0.
  862. *
  863. * \sa SDL_RumbleJoystickTriggers
  864. */
  865. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick);
  866. /**
  867. * Update a joystick's LED color.
  868. *
  869. * An example of a joystick LED is the light on the back of a PlayStation 4's
  870. * DualShock 4 controller.
  871. *
  872. * \param joystick The joystick to update
  873. * \param red The intensity of the red LED
  874. * \param green The intensity of the green LED
  875. * \param blue The intensity of the blue LED
  876. * \returns 0 on success, -1 if this joystick does not have a modifiable LED
  877. *
  878. * \since This function is available since SDL 3.0.0.
  879. */
  880. extern DECLSPEC int SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
  881. /**
  882. * Send a joystick specific effect packet
  883. *
  884. * \param joystick The joystick to affect
  885. * \param data The data to send to the joystick
  886. * \param size The size of the data to send to the joystick
  887. * \returns 0, or -1 if this joystick or driver doesn't support effect packets
  888. *
  889. * \since This function is available since SDL 3.0.0.
  890. */
  891. extern DECLSPEC int SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
  892. /**
  893. * Close a joystick previously opened with SDL_OpenJoystick().
  894. *
  895. * \param joystick The joystick device to close
  896. *
  897. * \since This function is available since SDL 3.0.0.
  898. *
  899. * \sa SDL_OpenJoystick
  900. */
  901. extern DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);
  902. /**
  903. * Get the battery level of a joystick as SDL_JoystickPowerLevel.
  904. *
  905. * \param joystick the SDL_Joystick to query
  906. * \returns the current battery level as SDL_JoystickPowerLevel on success or
  907. * `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown
  908. *
  909. * \since This function is available since SDL 3.0.0.
  910. */
  911. extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_GetJoystickPowerLevel(SDL_Joystick *joystick);
  912. /* Ends C function definitions when using C++ */
  913. #ifdef __cplusplus
  914. }
  915. #endif
  916. #include <SDL3/SDL_close_code.h>
  917. #endif /* SDL_joystick_h_ */