SDL_joystick.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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. * # CategoryJoystick
  20. *
  21. * SDL joystick support.
  22. *
  23. * This is the lower-level joystick handling. If you want the simpler option,
  24. * where what buttons does what is well-defined, you should use the gamepad
  25. * API instead.
  26. *
  27. * The term "instance_id" is the current instantiation of a joystick device in
  28. * the system, if the joystick is removed and then re-inserted then it will
  29. * get a new instance_id, instance_id's are monotonically increasing
  30. * identifiers of a joystick plugged in.
  31. *
  32. * The term "player_index" is the number assigned to a player on a specific
  33. * controller. For XInput controllers this returns the XInput user index. Many
  34. * joysticks will not be able to supply this information.
  35. *
  36. * SDL_GUID is used as a stable 128-bit identifier for a joystick device that
  37. * does not change over time. It identifies class of the device (a X360 wired
  38. * controller for example). This identifier is platform dependent.
  39. *
  40. * In order to use these functions, SDL_Init() must have been called with the
  41. * SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for joysticks,
  42. * and load appropriate drivers.
  43. *
  44. * If you would like to receive joystick updates while the application is in
  45. * the background, you should set the following hint before calling
  46. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  47. */
  48. #ifndef SDL_joystick_h_
  49. #define SDL_joystick_h_
  50. #include <SDL3/SDL_stdinc.h>
  51. #include <SDL3/SDL_error.h>
  52. #include <SDL3/SDL_guid.h>
  53. #include <SDL3/SDL_mutex.h>
  54. #include <SDL3/SDL_power.h>
  55. #include <SDL3/SDL_properties.h>
  56. #include <SDL3/SDL_sensor.h>
  57. #include <SDL3/SDL_begin_code.h>
  58. /* Set up for C function definitions, even when using C++ */
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. #ifdef SDL_THREAD_SAFETY_ANALYSIS
  63. /*
  64. * This is not an exported symbol from SDL, this is only in the headers to
  65. * help Clang's thread safety analysis tools to function. Do not attempt
  66. * to access this symbol from your app, it will not work!
  67. */
  68. extern SDL_Mutex *SDL_joystick_lock;
  69. #endif
  70. /**
  71. * The joystick structure used to identify an SDL joystick.
  72. *
  73. * This is opaque data.
  74. *
  75. * \since This struct is available since SDL 3.0.0.
  76. */
  77. typedef struct SDL_Joystick SDL_Joystick;
  78. /**
  79. * This is a unique ID for a joystick for the time it is connected to the
  80. * system, and is never reused for the lifetime of the application.
  81. *
  82. * If the joystick is disconnected and reconnected, it will get a new ID.
  83. *
  84. * The value 0 is an invalid ID.
  85. *
  86. * \since This datatype is available since SDL 3.0.0.
  87. */
  88. typedef Uint32 SDL_JoystickID;
  89. /**
  90. * An enum of some common joystick types.
  91. *
  92. * In some cases, SDL can identify a low-level joystick as being a certain
  93. * type of device, and will report it through SDL_GetJoystickType (or
  94. * SDL_GetJoystickTypeForID).
  95. *
  96. * This is by no means a complete list of everything that can be plugged into
  97. * a computer.
  98. *
  99. * \since This enum is available since SDL 3.0.0.
  100. */
  101. typedef enum SDL_JoystickType
  102. {
  103. SDL_JOYSTICK_TYPE_UNKNOWN,
  104. SDL_JOYSTICK_TYPE_GAMEPAD,
  105. SDL_JOYSTICK_TYPE_WHEEL,
  106. SDL_JOYSTICK_TYPE_ARCADE_STICK,
  107. SDL_JOYSTICK_TYPE_FLIGHT_STICK,
  108. SDL_JOYSTICK_TYPE_DANCE_PAD,
  109. SDL_JOYSTICK_TYPE_GUITAR,
  110. SDL_JOYSTICK_TYPE_DRUM_KIT,
  111. SDL_JOYSTICK_TYPE_ARCADE_PAD,
  112. SDL_JOYSTICK_TYPE_THROTTLE
  113. } SDL_JoystickType;
  114. /**
  115. * Possible connection states for a joystick device.
  116. *
  117. * This is used by SDL_GetJoystickConnectionState to report how a device is
  118. * connected to the system.
  119. *
  120. * \since This enum is available since SDL 3.0.0.
  121. */
  122. typedef enum SDL_JoystickConnectionState
  123. {
  124. SDL_JOYSTICK_CONNECTION_INVALID = -1,
  125. SDL_JOYSTICK_CONNECTION_UNKNOWN,
  126. SDL_JOYSTICK_CONNECTION_WIRED,
  127. SDL_JOYSTICK_CONNECTION_WIRELESS
  128. } SDL_JoystickConnectionState;
  129. /**
  130. * The largest value an SDL_Joystick's axis can report.
  131. *
  132. * \since This macro is available since SDL 3.0.0.
  133. *
  134. * \sa SDL_JOYSTICK_AXIS_MIN
  135. */
  136. #define SDL_JOYSTICK_AXIS_MAX 32767
  137. /**
  138. * The smallest value an SDL_Joystick's axis can report.
  139. *
  140. * This is a negative number!
  141. *
  142. * \since This macro is available since SDL 3.0.0.
  143. *
  144. * \sa SDL_JOYSTICK_AXIS_MAX
  145. */
  146. #define SDL_JOYSTICK_AXIS_MIN -32768
  147. /* Set max recognized G-force from accelerometer
  148. See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
  149. */
  150. #define SDL_IPHONE_MAX_GFORCE 5.0
  151. /* Function prototypes */
  152. /**
  153. * Locking for atomic access to the joystick API.
  154. *
  155. * The SDL joystick functions are thread-safe, however you can lock the
  156. * joysticks while processing to guarantee that the joystick list won't change
  157. * and joystick and gamepad events will not be delivered.
  158. *
  159. * \since This function is available since SDL 3.0.0.
  160. */
  161. extern SDL_DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
  162. /**
  163. * Unlocking for atomic access to the joystick API.
  164. *
  165. * \since This function is available since SDL 3.0.0.
  166. */
  167. extern SDL_DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
  168. /**
  169. * Return whether a joystick is currently connected.
  170. *
  171. * \returns SDL_TRUE if a joystick is connected, SDL_FALSE otherwise.
  172. *
  173. * \since This function is available since SDL 3.0.0.
  174. *
  175. * \sa SDL_GetJoysticks
  176. */
  177. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasJoystick(void);
  178. /**
  179. * Get a list of currently connected joysticks.
  180. *
  181. * \param count a pointer filled in with the number of joysticks returned, may
  182. * be NULL.
  183. * \returns a 0 terminated array of joystick instance IDs or NULL on failure;
  184. * call SDL_GetError() for more information. This should be freed
  185. * with SDL_free() when it is no longer needed.
  186. *
  187. * \since This function is available since SDL 3.0.0.
  188. *
  189. * \sa SDL_HasJoystick
  190. * \sa SDL_OpenJoystick
  191. */
  192. extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count);
  193. /**
  194. * Get the implementation dependent name of a joystick.
  195. *
  196. * This can be called before any joysticks are opened.
  197. *
  198. * \param instance_id the joystick instance ID.
  199. * \returns the name of the selected joystick. If no name can be found, this
  200. * function returns NULL; call SDL_GetError() for more information.
  201. *
  202. * \since This function is available since SDL 3.0.0.
  203. *
  204. * \sa SDL_GetJoystickName
  205. * \sa SDL_GetJoysticks
  206. */
  207. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id);
  208. /**
  209. * Get the implementation dependent path of a joystick.
  210. *
  211. * This can be called before any joysticks are opened.
  212. *
  213. * \param instance_id the joystick instance ID.
  214. * \returns the path of the selected joystick. If no path can be found, this
  215. * function returns NULL; call SDL_GetError() for more information.
  216. *
  217. * \since This function is available since SDL 3.0.0.
  218. *
  219. * \sa SDL_GetJoystickPath
  220. * \sa SDL_GetJoysticks
  221. */
  222. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id);
  223. /**
  224. * Get the player index of a joystick.
  225. *
  226. * This can be called before any joysticks are opened.
  227. *
  228. * \param instance_id the joystick instance ID.
  229. * \returns the player index of a joystick, or -1 if it's not available.
  230. *
  231. * \since This function is available since SDL 3.0.0.
  232. *
  233. * \sa SDL_GetJoystickPlayerIndex
  234. * \sa SDL_GetJoysticks
  235. */
  236. extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndexForID(SDL_JoystickID instance_id);
  237. /**
  238. * Get the implementation-dependent GUID of a joystick.
  239. *
  240. * This can be called before any joysticks are opened.
  241. *
  242. * \param instance_id the joystick instance ID.
  243. * \returns the GUID of the selected joystick. If called with an invalid
  244. * instance_id, this function returns a zero GUID.
  245. *
  246. * \since This function is available since SDL 3.0.0.
  247. *
  248. * \sa SDL_GetJoystickGUID
  249. * \sa SDL_GUIDToString
  250. */
  251. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id);
  252. /**
  253. * Get the USB vendor ID of a joystick, if available.
  254. *
  255. * This can be called before any joysticks are opened. If the vendor ID isn't
  256. * available this function returns 0.
  257. *
  258. * \param instance_id the joystick instance ID.
  259. * \returns the USB vendor ID of the selected joystick. If called with an
  260. * invalid instance_id, this function returns 0.
  261. *
  262. * \since This function is available since SDL 3.0.0.
  263. *
  264. * \sa SDL_GetJoystickVendor
  265. * \sa SDL_GetJoysticks
  266. */
  267. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendorForID(SDL_JoystickID instance_id);
  268. /**
  269. * Get the USB product ID of a joystick, if available.
  270. *
  271. * This can be called before any joysticks are opened. If the product ID isn't
  272. * available this function returns 0.
  273. *
  274. * \param instance_id the joystick instance ID.
  275. * \returns the USB product ID of the selected joystick. If called with an
  276. * invalid instance_id, this function returns 0.
  277. *
  278. * \since This function is available since SDL 3.0.0.
  279. *
  280. * \sa SDL_GetJoystickProduct
  281. * \sa SDL_GetJoysticks
  282. */
  283. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductForID(SDL_JoystickID instance_id);
  284. /**
  285. * Get the product version of a joystick, if available.
  286. *
  287. * This can be called before any joysticks are opened. If the product version
  288. * isn't available this function returns 0.
  289. *
  290. * \param instance_id the joystick instance ID.
  291. * \returns the product version of the selected joystick. If called with an
  292. * invalid instance_id, this function returns 0.
  293. *
  294. * \since This function is available since SDL 3.0.0.
  295. *
  296. * \sa SDL_GetJoystickProductVersion
  297. * \sa SDL_GetJoysticks
  298. */
  299. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersionForID(SDL_JoystickID instance_id);
  300. /**
  301. * Get the type of a joystick, if available.
  302. *
  303. * This can be called before any joysticks are opened.
  304. *
  305. * \param instance_id the joystick instance ID.
  306. * \returns the SDL_JoystickType of the selected joystick. If called with an
  307. * invalid instance_id, this function returns
  308. * `SDL_JOYSTICK_TYPE_UNKNOWN`.
  309. *
  310. * \since This function is available since SDL 3.0.0.
  311. *
  312. * \sa SDL_GetJoystickType
  313. * \sa SDL_GetJoysticks
  314. */
  315. extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickTypeForID(SDL_JoystickID instance_id);
  316. /**
  317. * Open a joystick for use.
  318. *
  319. * The joystick subsystem must be initialized before a joystick can be opened
  320. * for use.
  321. *
  322. * \param instance_id the joystick instance ID.
  323. * \returns a joystick identifier or NULL on failure; call SDL_GetError() for
  324. * more information.
  325. *
  326. * \since This function is available since SDL 3.0.0.
  327. *
  328. * \sa SDL_CloseJoystick
  329. */
  330. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_OpenJoystick(SDL_JoystickID instance_id);
  331. /**
  332. * Get the SDL_Joystick associated with an instance ID, if it has been opened.
  333. *
  334. * \param instance_id the instance ID to get the SDL_Joystick for.
  335. * \returns an SDL_Joystick on success or NULL on failure or if it hasn't been
  336. * opened yet; call SDL_GetError() for more information.
  337. *
  338. * \since This function is available since SDL 3.0.0.
  339. */
  340. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromID(SDL_JoystickID instance_id);
  341. /**
  342. * Get the SDL_Joystick associated with a player index.
  343. *
  344. * \param player_index the player index to get the SDL_Joystick for.
  345. * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
  346. * for more information.
  347. *
  348. * \since This function is available since SDL 3.0.0.
  349. *
  350. * \sa SDL_GetJoystickPlayerIndex
  351. * \sa SDL_SetJoystickPlayerIndex
  352. */
  353. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromPlayerIndex(int player_index);
  354. /**
  355. * The structure that describes a virtual joystick touchpad.
  356. *
  357. * \since This struct is available since SDL 3.0.0.
  358. *
  359. * \sa SDL_VirtualJoystickDesc
  360. */
  361. typedef struct SDL_VirtualJoystickTouchpadDesc
  362. {
  363. Uint16 nfingers; /**< the number of simultaneous fingers on this touchpad */
  364. Uint16 padding[3];
  365. } SDL_VirtualJoystickTouchpadDesc;
  366. /**
  367. * The structure that describes a virtual joystick sensor.
  368. *
  369. * \since This struct is available since SDL 3.0.0.
  370. *
  371. * \sa SDL_VirtualJoystickDesc
  372. */
  373. typedef struct SDL_VirtualJoystickSensorDesc
  374. {
  375. SDL_SensorType type; /**< the type of this sensor */
  376. float rate; /**< the update frequency of this sensor, may be 0.0f */
  377. } SDL_VirtualJoystickSensorDesc;
  378. /**
  379. * The structure that describes a virtual joystick.
  380. *
  381. * All elements of this structure are optional and can be left 0.
  382. *
  383. * \since This struct is available since SDL 3.0.0.
  384. *
  385. * \sa SDL_AttachVirtualJoystick
  386. * \sa SDL_VirtualJoystickSensorDesc
  387. * \sa SDL_VirtualJoystickTouchpadDesc
  388. */
  389. typedef struct SDL_VirtualJoystickDesc
  390. {
  391. Uint16 type; /**< `SDL_JoystickType` */
  392. Uint16 padding; /**< unused */
  393. Uint16 vendor_id; /**< the USB vendor ID of this joystick */
  394. Uint16 product_id; /**< the USB product ID of this joystick */
  395. Uint16 naxes; /**< the number of axes on this joystick */
  396. Uint16 nbuttons; /**< the number of buttons on this joystick */
  397. Uint16 nballs; /**< the number of balls on this joystick */
  398. Uint16 nhats; /**< the number of hats on this joystick */
  399. Uint16 ntouchpads; /**< the number of touchpads on this joystick, requires `touchpads` to point at valid descriptions */
  400. Uint16 nsensors; /**< the number of sensors on this joystick, requires `sensors` to point at valid descriptions */
  401. Uint16 padding2[2]; /**< unused */
  402. Uint32 button_mask; /**< A mask of which buttons are valid for this controller
  403. e.g. (1 << SDL_GAMEPAD_BUTTON_SOUTH) */
  404. Uint32 axis_mask; /**< A mask of which axes are valid for this controller
  405. e.g. (1 << SDL_GAMEPAD_AXIS_LEFTX) */
  406. const char *name; /**< the name of the joystick */
  407. const SDL_VirtualJoystickTouchpadDesc *touchpads; /**< A pointer to an array of touchpad descriptions, required if `ntouchpads` is > 0 */
  408. const SDL_VirtualJoystickSensorDesc *sensors; /**< A pointer to an array of sensor descriptions, required if `nsensors` is > 0 */
  409. void *userdata; /**< User data pointer passed to callbacks */
  410. void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */
  411. void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */
  412. int (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */
  413. int (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */
  414. int (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */
  415. int (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */
  416. int (SDLCALL *SetSensorsEnabled)(void *userdata, SDL_bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */
  417. } SDL_VirtualJoystickDesc;
  418. /**
  419. * Attach a new virtual joystick.
  420. *
  421. * \param desc joystick description.
  422. * \returns the joystick instance ID, or 0 on failure; call SDL_GetError() for
  423. * more information.
  424. *
  425. * \since This function is available since SDL 3.0.0.
  426. *
  427. * \sa SDL_DetachVirtualJoystick
  428. */
  429. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc);
  430. /**
  431. * Detach a virtual joystick.
  432. *
  433. * \param instance_id the joystick instance ID, previously returned from
  434. * SDL_AttachVirtualJoystick().
  435. * \returns 0 on success or a negative error code on failure; call
  436. * SDL_GetError() for more information.
  437. *
  438. * \since This function is available since SDL 3.0.0.
  439. *
  440. * \sa SDL_AttachVirtualJoystick
  441. */
  442. extern SDL_DECLSPEC int SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id);
  443. /**
  444. * Query whether or not a joystick is virtual.
  445. *
  446. * \param instance_id the joystick instance ID.
  447. * \returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise.
  448. *
  449. * \since This function is available since SDL 3.0.0.
  450. */
  451. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);
  452. /**
  453. * Set the state of an axis on an opened virtual joystick.
  454. *
  455. * Please note that values set here will not be applied until the next call to
  456. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  457. * indirectly through various other SDL APIs, including, but not limited to
  458. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  459. * SDL_WaitEvent.
  460. *
  461. * Note that when sending trigger axes, you should scale the value to the full
  462. * range of Sint16. For example, a trigger at rest would have the value of
  463. * `SDL_JOYSTICK_AXIS_MIN`.
  464. *
  465. * \param joystick the virtual joystick on which to set state.
  466. * \param axis the index of the axis on the virtual joystick to update.
  467. * \param value the new value for the specified axis.
  468. * \returns 0 on success or a negative error code on failure; call
  469. * SDL_GetError() for more information.
  470. *
  471. * \since This function is available since SDL 3.0.0.
  472. */
  473. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
  474. /**
  475. * Generate ball motion on an opened virtual joystick.
  476. *
  477. * Please note that values set here will not be applied until the next call to
  478. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  479. * indirectly through various other SDL APIs, including, but not limited to
  480. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  481. * SDL_WaitEvent.
  482. *
  483. * \param joystick the virtual joystick on which to set state.
  484. * \param ball the index of the ball on the virtual joystick to update.
  485. * \param xrel the relative motion on the X axis.
  486. * \param yrel the relative motion on the Y axis.
  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 SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel);
  493. /**
  494. * Set the state of a button on an opened virtual joystick.
  495. *
  496. * Please note that values set here will not be applied until the next call to
  497. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  498. * indirectly through various other SDL APIs, including, but not limited to
  499. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  500. * SDL_WaitEvent.
  501. *
  502. * \param joystick the virtual joystick on which to set state.
  503. * \param button the index of the button on the virtual joystick to update.
  504. * \param value the new value for the specified button.
  505. * \returns 0 on success or a negative error code on failure; call
  506. * SDL_GetError() for more information.
  507. *
  508. * \since This function is available since SDL 3.0.0.
  509. */
  510. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
  511. /**
  512. * Set the state of a hat on an opened virtual joystick.
  513. *
  514. * Please note that values set here will not be applied until the next call to
  515. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  516. * indirectly through various other SDL APIs, including, but not limited to
  517. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  518. * SDL_WaitEvent.
  519. *
  520. * \param joystick the virtual joystick on which to set state.
  521. * \param hat the index of the hat on the virtual joystick to update.
  522. * \param value the new value for the specified hat.
  523. * \returns 0 on success or a negative error code on failure; call
  524. * SDL_GetError() for more information.
  525. *
  526. * \since This function is available since SDL 3.0.0.
  527. */
  528. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
  529. /**
  530. * Set touchpad finger state on an opened virtual joystick.
  531. *
  532. * Please note that values set here will not be applied until the next call to
  533. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  534. * indirectly through various other SDL APIs, including, but not limited to
  535. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  536. * SDL_WaitEvent.
  537. *
  538. * \param joystick the virtual joystick on which to set state.
  539. * \param touchpad the index of the touchpad on the virtual joystick to
  540. * update.
  541. * \param finger the index of the finger on the touchpad to set.
  542. * \param state `SDL_PRESSED` if the finger is pressed, `SDL_RELEASED` if the
  543. * finger is released.
  544. * \param x the x coordinate of the finger on the touchpad, normalized 0 to 1,
  545. * with the origin in the upper left.
  546. * \param y the y coordinate of the finger on the touchpad, normalized 0 to 1,
  547. * with the origin in the upper left.
  548. * \param pressure the pressure of the finger.
  549. * \returns 0 on success or a negative error code on failure; call
  550. * SDL_GetError() for more information.
  551. *
  552. * \since This function is available since SDL 3.0.0.
  553. */
  554. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure);
  555. /**
  556. * Send a sensor update for an opened virtual joystick.
  557. *
  558. * Please note that values set here will not be applied until the next call to
  559. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  560. * indirectly through various other SDL APIs, including, but not limited to
  561. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  562. * SDL_WaitEvent.
  563. *
  564. * \param joystick the virtual joystick on which to set state.
  565. * \param type the type of the sensor on the virtual joystick to update.
  566. * \param sensor_timestamp a 64-bit timestamp in nanoseconds associated with
  567. * the sensor reading.
  568. * \param data the data associated with the sensor reading.
  569. * \param num_values the number of values pointed to by `data`.
  570. * \returns 0 on success or a negative error code on failure; call
  571. * SDL_GetError() for more information.
  572. *
  573. * \since This function is available since SDL 3.0.0.
  574. */
  575. extern SDL_DECLSPEC int SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
  576. /**
  577. * Get the properties associated with a joystick.
  578. *
  579. * The following read-only properties are provided by SDL:
  580. *
  581. * - `SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN`: true if this joystick has an
  582. * LED that has adjustable brightness
  583. * - `SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN`: true if this joystick has an LED
  584. * that has adjustable color
  585. * - `SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN`: true if this joystick has a
  586. * player LED
  587. * - `SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN`: true if this joystick has
  588. * left/right rumble
  589. * - `SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this joystick has
  590. * simple trigger rumble
  591. *
  592. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  593. * \returns a valid property ID on success or 0 on failure; call
  594. * SDL_GetError() for more information.
  595. *
  596. * \since This function is available since SDL 3.0.0.
  597. */
  598. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick);
  599. #define SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN "SDL.joystick.cap.mono_led"
  600. #define SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN "SDL.joystick.cap.rgb_led"
  601. #define SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN "SDL.joystick.cap.player_led"
  602. #define SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN "SDL.joystick.cap.rumble"
  603. #define SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN "SDL.joystick.cap.trigger_rumble"
  604. /**
  605. * Get the implementation dependent name of a joystick.
  606. *
  607. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  608. * \returns the name of the selected joystick. If no name can be found, this
  609. * function returns NULL; call SDL_GetError() for more information.
  610. *
  611. * \since This function is available since SDL 3.0.0.
  612. *
  613. * \sa SDL_GetJoystickNameForID
  614. */
  615. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);
  616. /**
  617. * Get the implementation dependent path of a joystick.
  618. *
  619. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  620. * \returns the path of the selected joystick. If no path can be found, this
  621. * function returns NULL; call SDL_GetError() for more information.
  622. *
  623. * \since This function is available since SDL 3.0.0.
  624. *
  625. * \sa SDL_GetJoystickPathForID
  626. */
  627. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);
  628. /**
  629. * Get the player index of an opened joystick.
  630. *
  631. * For XInput controllers this returns the XInput user index. Many joysticks
  632. * will not be able to supply this information.
  633. *
  634. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  635. * \returns the player index, or -1 if it's not available.
  636. *
  637. * \since This function is available since SDL 3.0.0.
  638. *
  639. * \sa SDL_SetJoystickPlayerIndex
  640. */
  641. extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick);
  642. /**
  643. * Set the player index of an opened joystick.
  644. *
  645. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  646. * \param player_index player index to assign to this joystick, or -1 to clear
  647. * the player index and turn off player LEDs.
  648. * \returns 0 on success or a negative error code on failure; call
  649. * SDL_GetError() for more information.
  650. *
  651. * \since This function is available since SDL 3.0.0.
  652. *
  653. * \sa SDL_GetJoystickPlayerIndex
  654. */
  655. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);
  656. /**
  657. * Get the implementation-dependent GUID for the joystick.
  658. *
  659. * This function requires an open joystick.
  660. *
  661. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  662. * \returns the GUID of the given joystick. If called on an invalid index,
  663. * this function returns a zero GUID; call SDL_GetError() for more
  664. * information.
  665. *
  666. * \since This function is available since SDL 3.0.0.
  667. *
  668. * \sa SDL_GetJoystickGUIDForID
  669. * \sa SDL_GUIDToString
  670. */
  671. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);
  672. /**
  673. * Get the USB vendor ID of an opened joystick, if available.
  674. *
  675. * If the vendor ID isn't available this function returns 0.
  676. *
  677. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  678. * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
  679. *
  680. * \since This function is available since SDL 3.0.0.
  681. *
  682. * \sa SDL_GetJoystickVendorForID
  683. */
  684. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick);
  685. /**
  686. * Get the USB product ID of an opened joystick, if available.
  687. *
  688. * If the product ID isn't available this function returns 0.
  689. *
  690. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  691. * \returns the USB product ID of the selected joystick, or 0 if unavailable.
  692. *
  693. * \since This function is available since SDL 3.0.0.
  694. *
  695. * \sa SDL_GetJoystickProductForID
  696. */
  697. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick);
  698. /**
  699. * Get the product version of an opened joystick, if available.
  700. *
  701. * If the product version isn't available this function returns 0.
  702. *
  703. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  704. * \returns the product version of the selected joystick, or 0 if unavailable.
  705. *
  706. * \since This function is available since SDL 3.0.0.
  707. *
  708. * \sa SDL_GetJoystickProductVersionForID
  709. */
  710. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *joystick);
  711. /**
  712. * Get the firmware version of an opened joystick, if available.
  713. *
  714. * If the firmware version isn't available this function returns 0.
  715. *
  716. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  717. * \returns the firmware version of the selected joystick, or 0 if
  718. * unavailable.
  719. *
  720. * \since This function is available since SDL 3.0.0.
  721. */
  722. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);
  723. /**
  724. * Get the serial number of an opened joystick, if available.
  725. *
  726. * Returns the serial number of the joystick, or NULL if it is not available.
  727. *
  728. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  729. * \returns the serial number of the selected joystick, or NULL if
  730. * unavailable.
  731. *
  732. * \since This function is available since SDL 3.0.0.
  733. */
  734. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
  735. /**
  736. * Get the type of an opened joystick.
  737. *
  738. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  739. * \returns the SDL_JoystickType of the selected joystick.
  740. *
  741. * \since This function is available since SDL 3.0.0.
  742. *
  743. * \sa SDL_GetJoystickTypeForID
  744. */
  745. extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick);
  746. /**
  747. * Get the device information encoded in a SDL_GUID structure.
  748. *
  749. * \param guid the SDL_GUID you wish to get info about.
  750. * \param vendor a pointer filled in with the device VID, or 0 if not
  751. * available.
  752. * \param product a pointer filled in with the device PID, or 0 if not
  753. * available.
  754. * \param version a pointer filled in with the device version, or 0 if not
  755. * available.
  756. * \param crc16 a pointer filled in with a CRC used to distinguish different
  757. * products with the same VID/PID, or 0 if not available.
  758. *
  759. * \since This function is available since SDL 3.0.0.
  760. *
  761. * \sa SDL_GetJoystickGUIDForID
  762. */
  763. extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
  764. /**
  765. * Get the status of a specified joystick.
  766. *
  767. * \param joystick the joystick to query.
  768. * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not;
  769. * call SDL_GetError() for more information.
  770. *
  771. * \since This function is available since SDL 3.0.0.
  772. */
  773. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
  774. /**
  775. * Get the instance ID of an opened joystick.
  776. *
  777. * \param joystick an SDL_Joystick structure containing joystick information.
  778. * \returns the instance ID of the specified joystick on success or 0 on
  779. * failure; call SDL_GetError() for more information.
  780. *
  781. * \since This function is available since SDL 3.0.0.
  782. */
  783. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joystick);
  784. /**
  785. * Get the number of general axis controls on a joystick.
  786. *
  787. * Often, the directional pad on a game controller will either look like 4
  788. * separate buttons or a POV hat, and not axes, but all of this is up to the
  789. * device and platform.
  790. *
  791. * \param joystick an SDL_Joystick structure containing joystick information.
  792. * \returns the number of axis controls/number of axes on success or a
  793. * negative error code on failure; call SDL_GetError() for more
  794. * information.
  795. *
  796. * \since This function is available since SDL 3.0.0.
  797. *
  798. * \sa SDL_GetJoystickAxis
  799. * \sa SDL_GetNumJoystickBalls
  800. * \sa SDL_GetNumJoystickButtons
  801. * \sa SDL_GetNumJoystickHats
  802. */
  803. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick);
  804. /**
  805. * Get the number of trackballs on a joystick.
  806. *
  807. * Joystick trackballs have only relative motion events associated with them
  808. * and their state cannot be polled.
  809. *
  810. * Most joysticks do not have trackballs.
  811. *
  812. * \param joystick an SDL_Joystick structure containing joystick information.
  813. * \returns the number of trackballs on success or a negative error code on
  814. * failure; call SDL_GetError() for more information.
  815. *
  816. * \since This function is available since SDL 3.0.0.
  817. *
  818. * \sa SDL_GetJoystickBall
  819. * \sa SDL_GetNumJoystickAxes
  820. * \sa SDL_GetNumJoystickButtons
  821. * \sa SDL_GetNumJoystickHats
  822. */
  823. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickBalls(SDL_Joystick *joystick);
  824. /**
  825. * Get the number of POV hats on a joystick.
  826. *
  827. * \param joystick an SDL_Joystick structure containing joystick information.
  828. * \returns the number of POV hats on success or a negative error code on
  829. * failure; call SDL_GetError() for more information.
  830. *
  831. * \since This function is available since SDL 3.0.0.
  832. *
  833. * \sa SDL_GetJoystickHat
  834. * \sa SDL_GetNumJoystickAxes
  835. * \sa SDL_GetNumJoystickBalls
  836. * \sa SDL_GetNumJoystickButtons
  837. */
  838. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick);
  839. /**
  840. * Get the number of buttons on a joystick.
  841. *
  842. * \param joystick an SDL_Joystick structure containing joystick information.
  843. * \returns the number of buttons on success or a negative error code on
  844. * failure; call SDL_GetError() for more information.
  845. *
  846. * \since This function is available since SDL 3.0.0.
  847. *
  848. * \sa SDL_GetJoystickButton
  849. * \sa SDL_GetNumJoystickAxes
  850. * \sa SDL_GetNumJoystickBalls
  851. * \sa SDL_GetNumJoystickHats
  852. */
  853. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick);
  854. /**
  855. * Set the state of joystick event processing.
  856. *
  857. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  858. * yourself and check the state of the joystick when you want joystick
  859. * information.
  860. *
  861. * \param enabled whether to process joystick events or not.
  862. *
  863. * \since This function is available since SDL 3.0.0.
  864. *
  865. * \sa SDL_JoystickEventsEnabled
  866. * \sa SDL_UpdateJoysticks
  867. */
  868. extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(SDL_bool enabled);
  869. /**
  870. * Query the state of joystick event processing.
  871. *
  872. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  873. * yourself and check the state of the joystick when you want joystick
  874. * information.
  875. *
  876. * \returns SDL_TRUE if joystick events are being processed, SDL_FALSE
  877. * otherwise.
  878. *
  879. * \since This function is available since SDL 3.0.0.
  880. *
  881. * \sa SDL_SetJoystickEventsEnabled
  882. */
  883. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_JoystickEventsEnabled(void);
  884. /**
  885. * Update the current state of the open joysticks.
  886. *
  887. * This is called automatically by the event loop if any joystick events are
  888. * enabled.
  889. *
  890. * \since This function is available since SDL 3.0.0.
  891. */
  892. extern SDL_DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
  893. /**
  894. * Get the current state of an axis control on a joystick.
  895. *
  896. * SDL makes no promises about what part of the joystick any given axis refers
  897. * to. Your game should have some sort of configuration UI to let users
  898. * specify what each axis should be bound to. Alternately, SDL's higher-level
  899. * Game Controller API makes a great effort to apply order to this lower-level
  900. * interface, so you know that a specific axis is the "left thumb stick," etc.
  901. *
  902. * The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to
  903. * 32767) representing the current position of the axis. It may be necessary
  904. * to impose certain tolerances on these values to account for jitter.
  905. *
  906. * \param joystick an SDL_Joystick structure containing joystick information.
  907. * \param axis the axis to query; the axis indices start at index 0.
  908. * \returns a 16-bit signed integer representing the current position of the
  909. * axis or 0 on failure; call SDL_GetError() for more information.
  910. *
  911. * \since This function is available since SDL 3.0.0.
  912. *
  913. * \sa SDL_GetNumJoystickAxes
  914. */
  915. extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick, int axis);
  916. /**
  917. * Get the initial state of an axis control on a joystick.
  918. *
  919. * The state is a value ranging from -32768 to 32767.
  920. *
  921. * The axis indices start at index 0.
  922. *
  923. * \param joystick an SDL_Joystick structure containing joystick information.
  924. * \param axis the axis to query; the axis indices start at index 0.
  925. * \param state upon return, the initial value is supplied here.
  926. * \returns SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
  927. *
  928. * \since This function is available since SDL 3.0.0.
  929. */
  930. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state);
  931. /**
  932. * Get the ball axis change since the last poll.
  933. *
  934. * Trackballs can only return relative motion since the last call to
  935. * SDL_GetJoystickBall(), these motion deltas are placed into `dx` and `dy`.
  936. *
  937. * Most joysticks do not have trackballs.
  938. *
  939. * \param joystick the SDL_Joystick to query.
  940. * \param ball the ball index to query; ball indices start at index 0.
  941. * \param dx stores the difference in the x axis position since the last poll.
  942. * \param dy stores the difference in the y axis position since the last poll.
  943. * \returns 0 on success or a negative error code on failure; call
  944. * SDL_GetError() for more information.
  945. *
  946. * \since This function is available since SDL 3.0.0.
  947. *
  948. * \sa SDL_GetNumJoystickBalls
  949. */
  950. extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
  951. /**
  952. * Get the current state of a POV hat on a joystick.
  953. *
  954. * The returned value will be one of the `SDL_HAT_*` values.
  955. *
  956. * \param joystick an SDL_Joystick structure containing joystick information.
  957. * \param hat the hat index to get the state from; indices start at index 0.
  958. * \returns the current hat position.
  959. *
  960. * \since This function is available since SDL 3.0.0.
  961. *
  962. * \sa SDL_GetNumJoystickHats
  963. */
  964. extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int hat);
  965. #define SDL_HAT_CENTERED 0x00u
  966. #define SDL_HAT_UP 0x01u
  967. #define SDL_HAT_RIGHT 0x02u
  968. #define SDL_HAT_DOWN 0x04u
  969. #define SDL_HAT_LEFT 0x08u
  970. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  971. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  972. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  973. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  974. /**
  975. * Get the current state of a button on a joystick.
  976. *
  977. * \param joystick an SDL_Joystick structure containing joystick information.
  978. * \param button the button index to get the state from; indices start at
  979. * index 0.
  980. * \returns 1 if the specified button is pressed, 0 otherwise.
  981. *
  982. * \since This function is available since SDL 3.0.0.
  983. *
  984. * \sa SDL_GetNumJoystickButtons
  985. */
  986. extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
  987. /**
  988. * Start a rumble effect.
  989. *
  990. * Each call to this function cancels any previous rumble effect, and calling
  991. * it with 0 intensity stops any rumbling.
  992. *
  993. * This function requires you to process SDL events or call
  994. * SDL_UpdateJoysticks() to update rumble state.
  995. *
  996. * \param joystick the joystick to vibrate.
  997. * \param low_frequency_rumble the intensity of the low frequency (left)
  998. * rumble motor, from 0 to 0xFFFF.
  999. * \param high_frequency_rumble the intensity of the high frequency (right)
  1000. * rumble motor, from 0 to 0xFFFF.
  1001. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1002. * \returns 0, or -1 if rumble isn't supported on this joystick.
  1003. *
  1004. * \since This function is available since SDL 3.0.0.
  1005. */
  1006. extern SDL_DECLSPEC int SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  1007. /**
  1008. * Start a rumble effect in the joystick's triggers.
  1009. *
  1010. * Each call to this function cancels any previous trigger rumble effect, and
  1011. * calling it with 0 intensity stops any rumbling.
  1012. *
  1013. * Note that this is rumbling of the _triggers_ and not the game controller as
  1014. * a whole. This is currently only supported on Xbox One controllers. If you
  1015. * want the (more common) whole-controller rumble, use SDL_RumbleJoystick()
  1016. * instead.
  1017. *
  1018. * This function requires you to process SDL events or call
  1019. * SDL_UpdateJoysticks() to update rumble state.
  1020. *
  1021. * \param joystick the joystick to vibrate.
  1022. * \param left_rumble the intensity of the left trigger rumble motor, from 0
  1023. * to 0xFFFF.
  1024. * \param right_rumble the intensity of the right trigger rumble motor, from 0
  1025. * to 0xFFFF.
  1026. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1027. * \returns 0 on success or a negative error code on failure; call
  1028. * SDL_GetError() for more information.
  1029. *
  1030. * \since This function is available since SDL 3.0.0.
  1031. *
  1032. * \sa SDL_RumbleJoystick
  1033. */
  1034. extern SDL_DECLSPEC int SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  1035. /**
  1036. * Update a joystick's LED color.
  1037. *
  1038. * An example of a joystick LED is the light on the back of a PlayStation 4's
  1039. * DualShock 4 controller.
  1040. *
  1041. * For joysticks with a single color LED, the maximum of the RGB values will
  1042. * be used as the LED brightness.
  1043. *
  1044. * \param joystick the joystick to update.
  1045. * \param red the intensity of the red LED.
  1046. * \param green the intensity of the green LED.
  1047. * \param blue the intensity of the blue LED.
  1048. * \returns 0 on success or a negative error code on failure; call
  1049. * SDL_GetError() for more information.
  1050. *
  1051. * \since This function is available since SDL 3.0.0.
  1052. */
  1053. extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
  1054. /**
  1055. * Send a joystick specific effect packet.
  1056. *
  1057. * \param joystick the joystick to affect.
  1058. * \param data the data to send to the joystick.
  1059. * \param size the size of the data to send to the joystick.
  1060. * \returns 0 on success or a negative error code on failure; call
  1061. * SDL_GetError() for more information.
  1062. *
  1063. * \since This function is available since SDL 3.0.0.
  1064. */
  1065. extern SDL_DECLSPEC int SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
  1066. /**
  1067. * Close a joystick previously opened with SDL_OpenJoystick().
  1068. *
  1069. * \param joystick the joystick device to close.
  1070. *
  1071. * \since This function is available since SDL 3.0.0.
  1072. *
  1073. * \sa SDL_OpenJoystick
  1074. */
  1075. extern SDL_DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);
  1076. /**
  1077. * Get the connection state of a joystick.
  1078. *
  1079. * \param joystick the joystick to query.
  1080. * \returns the connection state on success or
  1081. * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
  1082. * for more information.
  1083. *
  1084. * \since This function is available since SDL 3.0.0.
  1085. */
  1086. extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetJoystickConnectionState(SDL_Joystick *joystick);
  1087. /**
  1088. * Get the battery state of a joystick.
  1089. *
  1090. * You should never take a battery status as absolute truth. Batteries
  1091. * (especially failing batteries) are delicate hardware, and the values
  1092. * reported here are best estimates based on what that hardware reports. It's
  1093. * not uncommon for older batteries to lose stored power much faster than it
  1094. * reports, or completely drain when reporting it has 20 percent left, etc.
  1095. *
  1096. * \param joystick the joystick to query.
  1097. * \param percent a pointer filled in with the percentage of battery life
  1098. * left, between 0 and 100, or NULL to ignore. This will be
  1099. * filled in with -1 we can't determine a value or there is no
  1100. * battery.
  1101. * \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;
  1102. * call SDL_GetError() for more information.
  1103. *
  1104. * \since This function is available since SDL 3.0.0.
  1105. */
  1106. extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent);
  1107. /* Ends C function definitions when using C++ */
  1108. #ifdef __cplusplus
  1109. }
  1110. #endif
  1111. #include <SDL3/SDL_close_code.h>
  1112. #endif /* SDL_joystick_h_ */