SDL_joystick.h 35 KB

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