SDL_joystick.h 36 KB

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