SDL_joystick.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  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_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. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  421. * \returns a valid property ID on success or 0 on failure; call
  422. * SDL_GetError() for more information.
  423. *
  424. * \since This function is available since SDL 3.0.0.
  425. *
  426. * \sa SDL_GetProperty
  427. * \sa SDL_SetProperty
  428. */
  429. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick);
  430. /**
  431. * Get the implementation dependent name of a joystick.
  432. *
  433. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  434. * \returns the name of the selected joystick. If no name can be found, this
  435. * function returns NULL; call SDL_GetError() for more information.
  436. *
  437. * \since This function is available since SDL 3.0.0.
  438. *
  439. * \sa SDL_GetJoystickInstanceName
  440. * \sa SDL_OpenJoystick
  441. */
  442. extern DECLSPEC const char *SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);
  443. /**
  444. * Get the implementation dependent path of a joystick.
  445. *
  446. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  447. * \returns the path of the selected joystick. If no path can be found, this
  448. * function returns NULL; call SDL_GetError() for more information.
  449. *
  450. * \since This function is available since SDL 3.0.0.
  451. *
  452. * \sa SDL_GetJoystickInstancePath
  453. */
  454. extern DECLSPEC const char *SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);
  455. /**
  456. * Get the player index of an opened joystick.
  457. *
  458. * For XInput controllers this returns the XInput user index. Many joysticks
  459. * will not be able to supply this information.
  460. *
  461. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  462. * \returns the player index, or -1 if it's not available.
  463. *
  464. * \since This function is available since SDL 3.0.0.
  465. */
  466. extern DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick);
  467. /**
  468. * Set the player index of an opened joystick.
  469. *
  470. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  471. * \param player_index Player index to assign to this joystick, or -1 to clear
  472. * the player index and turn off player LEDs.
  473. * \returns 0 on success or a negative error code on failure; call
  474. * SDL_GetError() for more information.
  475. *
  476. * \since This function is available since SDL 3.0.0.
  477. */
  478. extern DECLSPEC int SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);
  479. /**
  480. * Get the implementation-dependent GUID for the joystick.
  481. *
  482. * This function requires an open joystick.
  483. *
  484. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  485. * \returns the GUID of the given joystick. If called on an invalid index,
  486. * this function returns a zero GUID; call SDL_GetError() for more
  487. * information.
  488. *
  489. * \since This function is available since SDL 3.0.0.
  490. *
  491. * \sa SDL_GetJoystickInstanceGUID
  492. * \sa SDL_GetJoystickGUIDString
  493. */
  494. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);
  495. /**
  496. * Get the USB vendor ID of an opened joystick, if available.
  497. *
  498. * If the vendor ID isn't available this function returns 0.
  499. *
  500. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  501. * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
  502. *
  503. * \since This function is available since SDL 3.0.0.
  504. */
  505. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick);
  506. /**
  507. * Get the USB product ID of an opened joystick, if available.
  508. *
  509. * If the product ID isn't available this function returns 0.
  510. *
  511. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  512. * \returns the USB product ID of the selected joystick, or 0 if unavailable.
  513. *
  514. * \since This function is available since SDL 3.0.0.
  515. */
  516. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick);
  517. /**
  518. * Get the product version of an opened joystick, if available.
  519. *
  520. * If the product version isn't available this function returns 0.
  521. *
  522. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  523. * \returns the product version of the selected joystick, or 0 if unavailable.
  524. *
  525. * \since This function is available since SDL 3.0.0.
  526. */
  527. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *joystick);
  528. /**
  529. * Get the firmware version of an opened joystick, if available.
  530. *
  531. * If the firmware version isn't available this function returns 0.
  532. *
  533. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  534. * \returns the firmware version of the selected joystick, or 0 if
  535. * unavailable.
  536. *
  537. * \since This function is available since SDL 3.0.0.
  538. */
  539. extern DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);
  540. /**
  541. * Get the serial number of an opened joystick, if available.
  542. *
  543. * Returns the serial number of the joystick, or NULL if it is not available.
  544. *
  545. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  546. * \returns the serial number of the selected joystick, or NULL if
  547. * unavailable.
  548. *
  549. * \since This function is available since SDL 3.0.0.
  550. */
  551. extern DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
  552. /**
  553. * Get the type of an opened joystick.
  554. *
  555. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick()
  556. * \returns the SDL_JoystickType of the selected joystick.
  557. *
  558. * \since This function is available since SDL 3.0.0.
  559. */
  560. extern DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick);
  561. /**
  562. * Get an ASCII string representation for a given SDL_JoystickGUID.
  563. *
  564. * You should supply at least 33 bytes for pszGUID.
  565. *
  566. * \param guid the SDL_JoystickGUID you wish to convert to string
  567. * \param pszGUID buffer in which to write the ASCII string
  568. * \param cbGUID the size of pszGUID
  569. * \returns 0 on success or a negative error code on failure; call
  570. * SDL_GetError() for more information.
  571. *
  572. * \since This function is available since SDL 3.0.0.
  573. *
  574. * \sa SDL_GetJoystickInstanceGUID
  575. * \sa SDL_GetJoystickGUID
  576. * \sa SDL_GetJoystickGUIDFromString
  577. */
  578. extern DECLSPEC int SDLCALL SDL_GetJoystickGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
  579. /**
  580. * Convert a GUID string into a SDL_JoystickGUID structure.
  581. *
  582. * Performs no error checking. If this function is given a string containing
  583. * an invalid GUID, the function will silently succeed, but the GUID generated
  584. * will not be useful.
  585. *
  586. * \param pchGUID string containing an ASCII representation of a GUID
  587. * \returns a SDL_JoystickGUID structure.
  588. *
  589. * \since This function is available since SDL 3.0.0.
  590. *
  591. * \sa SDL_GetJoystickGUIDString
  592. */
  593. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_GetJoystickGUIDFromString(const char *pchGUID);
  594. /**
  595. * Get the device information encoded in a SDL_JoystickGUID structure
  596. *
  597. * \param guid the SDL_JoystickGUID you wish to get info about
  598. * \param vendor A pointer filled in with the device VID, or 0 if not
  599. * available
  600. * \param product A pointer filled in with the device PID, or 0 if not
  601. * available
  602. * \param version A pointer filled in with the device version, or 0 if not
  603. * available
  604. * \param crc16 A pointer filled in with a CRC used to distinguish different
  605. * products with the same VID/PID, or 0 if not available
  606. *
  607. * \since This function is available since SDL 3.0.0.
  608. *
  609. * \sa SDL_GetJoystickInstanceGUID
  610. */
  611. extern DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
  612. /**
  613. * Get the status of a specified joystick.
  614. *
  615. * \param joystick the joystick to query
  616. * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not;
  617. * call SDL_GetError() for more information.
  618. *
  619. * \since This function is available since SDL 3.0.0.
  620. *
  621. * \sa SDL_CloseJoystick
  622. * \sa SDL_OpenJoystick
  623. */
  624. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
  625. /**
  626. * Get the instance ID of an opened joystick.
  627. *
  628. * \param joystick an SDL_Joystick structure containing joystick information
  629. * \returns the instance ID of the specified joystick on success or 0 on
  630. * failure; call SDL_GetError() for more information.
  631. *
  632. * \since This function is available since SDL 3.0.0.
  633. *
  634. * \sa SDL_OpenJoystick
  635. */
  636. extern DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickInstanceID(SDL_Joystick *joystick);
  637. /**
  638. * Get the number of general axis controls on a joystick.
  639. *
  640. * Often, the directional pad on a game controller will either look like 4
  641. * separate buttons or a POV hat, and not axes, but all of this is up to the
  642. * device and platform.
  643. *
  644. * \param joystick an SDL_Joystick structure containing joystick information
  645. * \returns the number of axis controls/number of axes on success or a
  646. * negative error code on failure; call SDL_GetError() for more
  647. * information.
  648. *
  649. * \since This function is available since SDL 3.0.0.
  650. *
  651. * \sa SDL_GetJoystickAxis
  652. * \sa SDL_OpenJoystick
  653. */
  654. extern DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick);
  655. /**
  656. * Get the number of POV hats on a joystick.
  657. *
  658. * \param joystick an SDL_Joystick structure containing joystick information
  659. * \returns the number of POV hats on success or a negative error code on
  660. * failure; call SDL_GetError() for more information.
  661. *
  662. * \since This function is available since SDL 3.0.0.
  663. *
  664. * \sa SDL_GetJoystickHat
  665. * \sa SDL_OpenJoystick
  666. */
  667. extern DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick);
  668. /**
  669. * Get the number of buttons on a joystick.
  670. *
  671. * \param joystick an SDL_Joystick structure containing joystick information
  672. * \returns the number of buttons on success or a negative error code on
  673. * failure; call SDL_GetError() for more information.
  674. *
  675. * \since This function is available since SDL 3.0.0.
  676. *
  677. * \sa SDL_GetJoystickButton
  678. * \sa SDL_OpenJoystick
  679. */
  680. extern DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick);
  681. /**
  682. * Set the state of joystick event processing.
  683. *
  684. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  685. * yourself and check the state of the joystick when you want joystick
  686. * information.
  687. *
  688. * \param enabled whether to process joystick events or not
  689. *
  690. * \since This function is available since SDL 3.0.0.
  691. *
  692. * \sa SDL_JoystickEventsEnabled
  693. */
  694. extern DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(SDL_bool enabled);
  695. /**
  696. * Query 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. * \returns SDL_TRUE if joystick events are being processed, SDL_FALSE
  703. * otherwise.
  704. *
  705. * \since This function is available since SDL 3.0.0.
  706. *
  707. * \sa SDL_SetJoystickEventsEnabled
  708. */
  709. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickEventsEnabled(void);
  710. /**
  711. * Update the current state of the open joysticks.
  712. *
  713. * This is called automatically by the event loop if any joystick events are
  714. * enabled.
  715. *
  716. * \since This function is available since SDL 3.0.0.
  717. */
  718. extern DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
  719. /**
  720. * Get the current state of an axis control on a joystick.
  721. *
  722. * SDL makes no promises about what part of the joystick any given axis refers
  723. * to. Your game should have some sort of configuration UI to let users
  724. * specify what each axis should be bound to. Alternately, SDL's higher-level
  725. * Game Controller API makes a great effort to apply order to this lower-level
  726. * interface, so you know that a specific axis is the "left thumb stick," etc.
  727. *
  728. * The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to
  729. * 32767) representing the current position of the axis. It may be necessary
  730. * to impose certain tolerances on these values to account for jitter.
  731. *
  732. * \param joystick an SDL_Joystick structure containing joystick information
  733. * \param axis the axis to query; the axis indices start at index 0
  734. * \returns a 16-bit signed integer representing the current position of the
  735. * axis or 0 on failure; call SDL_GetError() for more information.
  736. *
  737. * \since This function is available since SDL 3.0.0.
  738. *
  739. * \sa SDL_GetNumJoystickAxes
  740. */
  741. extern DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick,
  742. int axis);
  743. /**
  744. * Get the initial state of an axis control on a joystick.
  745. *
  746. * The state is a value ranging from -32768 to 32767.
  747. *
  748. * The axis indices start at index 0.
  749. *
  750. * \param joystick an SDL_Joystick structure containing joystick information
  751. * \param axis the axis to query; the axis indices start at index 0
  752. * \param state Upon return, the initial value is supplied here.
  753. * \returns SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
  754. *
  755. * \since This function is available since SDL 3.0.0.
  756. */
  757. extern DECLSPEC SDL_bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick,
  758. int axis, Sint16 *state);
  759. /**
  760. * \name Hat positions
  761. */
  762. /* @{ */
  763. #define SDL_HAT_CENTERED 0x00
  764. #define SDL_HAT_UP 0x01
  765. #define SDL_HAT_RIGHT 0x02
  766. #define SDL_HAT_DOWN 0x04
  767. #define SDL_HAT_LEFT 0x08
  768. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  769. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  770. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  771. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  772. /* @} */
  773. /**
  774. * Get the current state of a POV hat on a joystick.
  775. *
  776. * The returned value will be one of the following positions:
  777. *
  778. * - `SDL_HAT_CENTERED`
  779. * - `SDL_HAT_UP`
  780. * - `SDL_HAT_RIGHT`
  781. * - `SDL_HAT_DOWN`
  782. * - `SDL_HAT_LEFT`
  783. * - `SDL_HAT_RIGHTUP`
  784. * - `SDL_HAT_RIGHTDOWN`
  785. * - `SDL_HAT_LEFTUP`
  786. * - `SDL_HAT_LEFTDOWN`
  787. *
  788. * \param joystick an SDL_Joystick structure containing joystick information
  789. * \param hat the hat index to get the state from; indices start at index 0
  790. * \returns the current hat position.
  791. *
  792. * \since This function is available since SDL 3.0.0.
  793. *
  794. * \sa SDL_GetNumJoystickHats
  795. */
  796. extern DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick,
  797. int hat);
  798. /**
  799. * Get the current state of a button on a joystick.
  800. *
  801. * \param joystick an SDL_Joystick structure containing joystick information
  802. * \param button the button index to get the state from; indices start at
  803. * index 0
  804. * \returns 1 if the specified button is pressed, 0 otherwise.
  805. *
  806. * \since This function is available since SDL 3.0.0.
  807. *
  808. * \sa SDL_GetNumJoystickButtons
  809. */
  810. extern DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick,
  811. int button);
  812. /**
  813. * Start a rumble effect.
  814. *
  815. * Each call to this function cancels any previous rumble effect, and calling
  816. * it with 0 intensity stops any rumbling.
  817. *
  818. * \param joystick The joystick to vibrate
  819. * \param low_frequency_rumble The intensity of the low frequency (left)
  820. * rumble motor, from 0 to 0xFFFF
  821. * \param high_frequency_rumble The intensity of the high frequency (right)
  822. * rumble motor, from 0 to 0xFFFF
  823. * \param duration_ms The duration of the rumble effect, in milliseconds
  824. * \returns 0, or -1 if rumble isn't supported on this joystick
  825. *
  826. * \since This function is available since SDL 3.0.0.
  827. *
  828. * \sa SDL_JoystickHasRumble
  829. */
  830. extern DECLSPEC int SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  831. /**
  832. * Start a rumble effect in the joystick's triggers
  833. *
  834. * Each call to this function cancels any previous trigger rumble effect, and
  835. * calling it with 0 intensity stops any rumbling.
  836. *
  837. * Note that this is rumbling of the _triggers_ and not the game controller as
  838. * a whole. This is currently only supported on Xbox One controllers. If you
  839. * want the (more common) whole-controller rumble, use SDL_RumbleJoystick()
  840. * instead.
  841. *
  842. * \param joystick The joystick to vibrate
  843. * \param left_rumble The intensity of the left trigger rumble motor, from 0
  844. * to 0xFFFF
  845. * \param right_rumble The intensity of the right trigger rumble motor, from 0
  846. * to 0xFFFF
  847. * \param duration_ms The duration of the rumble effect, in milliseconds
  848. * \returns 0 on success or a negative error code on failure; call
  849. * SDL_GetError() for more information.
  850. *
  851. * \since This function is available since SDL 3.0.0.
  852. *
  853. * \sa SDL_JoystickHasRumbleTriggers
  854. */
  855. extern DECLSPEC int SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  856. /**
  857. * Query whether a joystick has an LED.
  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 query
  863. * \returns SDL_TRUE if the joystick has a modifiable LED, SDL_FALSE
  864. * otherwise.
  865. *
  866. * \since This function is available since SDL 3.0.0.
  867. */
  868. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick);
  869. /**
  870. * Query whether a joystick has rumble support.
  871. *
  872. * \param joystick The joystick to query
  873. * \returns SDL_TRUE if the joystick has rumble, SDL_FALSE otherwise.
  874. *
  875. * \since This function is available since SDL 3.0.0.
  876. *
  877. * \sa SDL_RumbleJoystick
  878. */
  879. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumble(SDL_Joystick *joystick);
  880. /**
  881. * Query whether a joystick has rumble support on triggers.
  882. *
  883. * \param joystick The joystick to query
  884. * \returns SDL_TRUE if the joystick has trigger rumble, SDL_FALSE otherwise.
  885. *
  886. * \since This function is available since SDL 3.0.0.
  887. *
  888. * \sa SDL_RumbleJoystickTriggers
  889. */
  890. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick);
  891. /**
  892. * Update a joystick's LED color.
  893. *
  894. * An example of a joystick LED is the light on the back of a PlayStation 4's
  895. * DualShock 4 controller.
  896. *
  897. * \param joystick The joystick to update
  898. * \param red The intensity of the red LED
  899. * \param green The intensity of the green LED
  900. * \param blue The intensity of the blue LED
  901. * \returns 0 on success or a negative error code on failure; call
  902. * SDL_GetError() for more information.
  903. *
  904. * \since This function is available since SDL 3.0.0.
  905. */
  906. extern DECLSPEC int SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
  907. /**
  908. * Send a joystick specific effect packet
  909. *
  910. * \param joystick The joystick to affect
  911. * \param data The data to send to the joystick
  912. * \param size The size of the data to send to the joystick
  913. * \returns 0 on success or a negative error code on failure; call
  914. * SDL_GetError() for more information.
  915. *
  916. * \since This function is available since SDL 3.0.0.
  917. */
  918. extern DECLSPEC int SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
  919. /**
  920. * Close a joystick previously opened with SDL_OpenJoystick().
  921. *
  922. * \param joystick The joystick device to close
  923. *
  924. * \since This function is available since SDL 3.0.0.
  925. *
  926. * \sa SDL_OpenJoystick
  927. */
  928. extern DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);
  929. /**
  930. * Get the battery level of a joystick as SDL_JoystickPowerLevel.
  931. *
  932. * \param joystick the SDL_Joystick to query
  933. * \returns the current battery level as SDL_JoystickPowerLevel on success or
  934. * `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown
  935. *
  936. * \since This function is available since SDL 3.0.0.
  937. */
  938. extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_GetJoystickPowerLevel(SDL_Joystick *joystick);
  939. /* Ends C function definitions when using C++ */
  940. #ifdef __cplusplus
  941. }
  942. #endif
  943. #include <SDL3/SDL_close_code.h>
  944. #endif /* SDL_joystick_h_ */