SDL_joystick.h 38 KB

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