1
0

SDL_haptic.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 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_haptic.h
  20. *
  21. * The SDL haptic subsystem manages haptic (force feedback) devices.
  22. *
  23. * The basic usage is as follows:
  24. * - Initialize the subsystem (::SDL_INIT_HAPTIC).
  25. * - Open a haptic device.
  26. * - SDL_OpenHaptic() to open from index.
  27. * - SDL_OpenHapticFromJoystick() to open from an existing joystick.
  28. * - Create an effect (::SDL_HapticEffect).
  29. * - Upload the effect with SDL_CreateHapticEffect().
  30. * - Run the effect with SDL_RunHapticEffect().
  31. * - (optional) Free the effect with SDL_DestroyHapticEffect().
  32. * - Close the haptic device with SDL_CloseHaptic().
  33. *
  34. * \par Simple rumble example:
  35. * \code
  36. * SDL_Haptic *haptic = NULL;
  37. *
  38. * // Open the device
  39. * SDL_HapticID *haptics = SDL_GetHaptics(NULL);
  40. * if (haptics) {
  41. * haptic = SDL_OpenHaptic(haptics[0]);
  42. * SDL_free(haptics);
  43. * }
  44. * if (haptic == NULL)
  45. * return -1;
  46. *
  47. * // Initialize simple rumble
  48. * if (SDL_InitHapticRumble(haptic) != 0)
  49. * return -1;
  50. *
  51. * // Play effect at 50% strength for 2 seconds
  52. * if (SDL_PlayHapticRumble(haptic, 0.5, 2000) != 0)
  53. * return -1;
  54. * SDL_Delay(2000);
  55. *
  56. * // Clean up
  57. * SDL_CloseHaptic(haptic);
  58. * \endcode
  59. *
  60. * \par Complete example:
  61. * \code
  62. * int test_haptic(SDL_Joystick *joystick)
  63. * {
  64. * SDL_Haptic *haptic;
  65. * SDL_HapticEffect effect;
  66. * int effect_id;
  67. *
  68. * // Open the device
  69. * haptic = SDL_OpenHapticFromJoystick(joystick);
  70. * if (haptic == NULL) return -1; // Most likely joystick isn't haptic
  71. *
  72. * // See if it can do sine waves
  73. * if ((SDL_GetHapticFeatures(haptic) & SDL_HAPTIC_SINE)==0) {
  74. * SDL_CloseHaptic(haptic); // No sine effect
  75. * return -1;
  76. * }
  77. *
  78. * // Create the effect
  79. * SDL_memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default
  80. * effect.type = SDL_HAPTIC_SINE;
  81. * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
  82. * effect.periodic.direction.dir[0] = 18000; // Force comes from south
  83. * effect.periodic.period = 1000; // 1000 ms
  84. * effect.periodic.magnitude = 20000; // 20000/32767 strength
  85. * effect.periodic.length = 5000; // 5 seconds long
  86. * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
  87. * effect.periodic.fade_length = 1000; // Takes 1 second to fade away
  88. *
  89. * // Upload the effect
  90. * effect_id = SDL_CreateHapticEffect(haptic, &effect);
  91. *
  92. * // Test the effect
  93. * SDL_RunHapticEffect(haptic, effect_id, 1);
  94. * SDL_Delay(5000); // Wait for the effect to finish
  95. *
  96. * // We destroy the effect, although closing the device also does this
  97. * SDL_DestroyHapticEffect(haptic, effect_id);
  98. *
  99. * // Close the device
  100. * SDL_CloseHaptic(haptic);
  101. *
  102. * return 0; // Success
  103. * }
  104. * \endcode
  105. *
  106. * Note that the SDL haptic subsystem is not thread-safe.
  107. */
  108. #ifndef SDL_haptic_h_
  109. #define SDL_haptic_h_
  110. #include <SDL3/SDL_stdinc.h>
  111. #include <SDL3/SDL_error.h>
  112. #include <SDL3/SDL_joystick.h>
  113. #include <SDL3/SDL_begin_code.h>
  114. /* Set up for C function definitions, even when using C++ */
  115. #ifdef __cplusplus
  116. extern "C" {
  117. #endif /* __cplusplus */
  118. /* FIXME: For SDL 2.1, adjust all the magnitude variables to be Uint16 (0xFFFF).
  119. *
  120. * At the moment the magnitude variables are mixed between signed/unsigned, and
  121. * it is also not made clear that ALL of those variables expect a max of 0x7FFF.
  122. *
  123. * Some platforms may have higher precision than that (Linux FF, Windows XInput)
  124. * so we should fix the inconsistency in favor of higher possible precision,
  125. * adjusting for platforms that use different scales.
  126. * -flibit
  127. */
  128. /**
  129. * \typedef SDL_Haptic
  130. *
  131. * The haptic structure used to identify an SDL haptic.
  132. *
  133. * \sa SDL_OpenHaptic
  134. * \sa SDL_OpenHapticFromJoystick
  135. * \sa SDL_CloseHaptic
  136. */
  137. struct SDL_Haptic;
  138. typedef struct SDL_Haptic SDL_Haptic;
  139. /**
  140. * \name Haptic features
  141. *
  142. * Different haptic features a device can have.
  143. */
  144. /* @{ */
  145. /**
  146. * \name Haptic effects
  147. */
  148. /* @{ */
  149. /**
  150. * Constant effect supported.
  151. *
  152. * Constant haptic effect.
  153. *
  154. * \sa SDL_HapticCondition
  155. */
  156. #define SDL_HAPTIC_CONSTANT (1u<<0)
  157. /**
  158. * Sine wave effect supported.
  159. *
  160. * Periodic haptic effect that simulates sine waves.
  161. *
  162. * \sa SDL_HapticPeriodic
  163. */
  164. #define SDL_HAPTIC_SINE (1u<<1)
  165. /**
  166. * Left/Right effect supported.
  167. *
  168. * Haptic effect for direct control over high/low frequency motors.
  169. *
  170. * \sa SDL_HapticLeftRight
  171. * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry,
  172. * we ran out of bits, and this is important for XInput devices.
  173. */
  174. #define SDL_HAPTIC_LEFTRIGHT (1u<<2)
  175. /* !!! FIXME: put this back when we have more bits in 2.1 */
  176. /* #define SDL_HAPTIC_SQUARE (1<<2) */
  177. /**
  178. * Triangle wave effect supported.
  179. *
  180. * Periodic haptic effect that simulates triangular waves.
  181. *
  182. * \sa SDL_HapticPeriodic
  183. */
  184. #define SDL_HAPTIC_TRIANGLE (1u<<3)
  185. /**
  186. * Sawtoothup wave effect supported.
  187. *
  188. * Periodic haptic effect that simulates saw tooth up waves.
  189. *
  190. * \sa SDL_HapticPeriodic
  191. */
  192. #define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
  193. /**
  194. * Sawtoothdown wave effect supported.
  195. *
  196. * Periodic haptic effect that simulates saw tooth down waves.
  197. *
  198. * \sa SDL_HapticPeriodic
  199. */
  200. #define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
  201. /**
  202. * Ramp effect supported.
  203. *
  204. * Ramp haptic effect.
  205. *
  206. * \sa SDL_HapticRamp
  207. */
  208. #define SDL_HAPTIC_RAMP (1u<<6)
  209. /**
  210. * Spring effect supported - uses axes position.
  211. *
  212. * Condition haptic effect that simulates a spring. Effect is based on the
  213. * axes position.
  214. *
  215. * \sa SDL_HapticCondition
  216. */
  217. #define SDL_HAPTIC_SPRING (1u<<7)
  218. /**
  219. * Damper effect supported - uses axes velocity.
  220. *
  221. * Condition haptic effect that simulates dampening. Effect is based on the
  222. * axes velocity.
  223. *
  224. * \sa SDL_HapticCondition
  225. */
  226. #define SDL_HAPTIC_DAMPER (1u<<8)
  227. /**
  228. * Inertia effect supported - uses axes acceleration.
  229. *
  230. * Condition haptic effect that simulates inertia. Effect is based on the axes
  231. * acceleration.
  232. *
  233. * \sa SDL_HapticCondition
  234. */
  235. #define SDL_HAPTIC_INERTIA (1u<<9)
  236. /**
  237. * Friction effect supported - uses axes movement.
  238. *
  239. * Condition haptic effect that simulates friction. Effect is based on the
  240. * axes movement.
  241. *
  242. * \sa SDL_HapticCondition
  243. */
  244. #define SDL_HAPTIC_FRICTION (1u<<10)
  245. /**
  246. * Custom effect is supported.
  247. *
  248. * User defined custom haptic effect.
  249. */
  250. #define SDL_HAPTIC_CUSTOM (1u<<11)
  251. /* @} *//* Haptic effects */
  252. /* These last few are features the device has, not effects */
  253. /**
  254. * Device can set global gain.
  255. *
  256. * Device supports setting the global gain.
  257. *
  258. * \sa SDL_SetHapticGain
  259. */
  260. #define SDL_HAPTIC_GAIN (1u<<12)
  261. /**
  262. * Device can set autocenter.
  263. *
  264. * Device supports setting autocenter.
  265. *
  266. * \sa SDL_SetHapticAutocenter
  267. */
  268. #define SDL_HAPTIC_AUTOCENTER (1u<<13)
  269. /**
  270. * Device can be queried for effect status.
  271. *
  272. * Device supports querying effect status.
  273. *
  274. * \sa SDL_GetHapticEffectStatus
  275. */
  276. #define SDL_HAPTIC_STATUS (1u<<14)
  277. /**
  278. * Device can be paused.
  279. *
  280. * Devices supports being paused.
  281. *
  282. * \sa SDL_PauseHaptic
  283. * \sa SDL_ResumeHaptic
  284. */
  285. #define SDL_HAPTIC_PAUSE (1u<<15)
  286. /**
  287. * \name Direction encodings
  288. */
  289. /* @{ */
  290. /**
  291. * Uses polar coordinates for the direction.
  292. *
  293. * \sa SDL_HapticDirection
  294. */
  295. #define SDL_HAPTIC_POLAR 0
  296. /**
  297. * Uses cartesian coordinates for the direction.
  298. *
  299. * \sa SDL_HapticDirection
  300. */
  301. #define SDL_HAPTIC_CARTESIAN 1
  302. /**
  303. * Uses spherical coordinates for the direction.
  304. *
  305. * \sa SDL_HapticDirection
  306. */
  307. #define SDL_HAPTIC_SPHERICAL 2
  308. /**
  309. * Use this value to play an effect on the steering wheel axis.
  310. *
  311. * This provides better compatibility across platforms and devices as SDL
  312. * will guess the correct axis.
  313. *
  314. * \sa SDL_HapticDirection
  315. */
  316. #define SDL_HAPTIC_STEERING_AXIS 3
  317. /* @} *//* Direction encodings */
  318. /* @} *//* Haptic features */
  319. /*
  320. * Misc defines.
  321. */
  322. /**
  323. * Used to play a device an infinite number of times.
  324. *
  325. * \sa SDL_RunHapticEffect
  326. */
  327. #define SDL_HAPTIC_INFINITY 4294967295U
  328. /**
  329. * Structure that represents a haptic direction.
  330. *
  331. * This is the direction where the force comes from,
  332. * instead of the direction in which the force is exerted.
  333. *
  334. * Directions can be specified by:
  335. * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates.
  336. * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.
  337. * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.
  338. *
  339. * Cardinal directions of the haptic device are relative to the positioning
  340. * of the device. North is considered to be away from the user.
  341. *
  342. * The following diagram represents the cardinal directions:
  343. * \verbatim
  344. .--.
  345. |__| .-------.
  346. |=.| |.-----.|
  347. |--| || ||
  348. | | |'-----'|
  349. |__|~')_____('
  350. [ COMPUTER ]
  351. North (0,-1)
  352. ^
  353. |
  354. |
  355. (-1,0) West <----[ HAPTIC ]----> East (1,0)
  356. |
  357. |
  358. v
  359. South (0,1)
  360. [ USER ]
  361. \|||/
  362. (o o)
  363. ---ooO-(_)-Ooo---
  364. \endverbatim
  365. *
  366. * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a
  367. * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses
  368. * the first \c dir parameter. The cardinal directions would be:
  369. * - North: 0 (0 degrees)
  370. * - East: 9000 (90 degrees)
  371. * - South: 18000 (180 degrees)
  372. * - West: 27000 (270 degrees)
  373. *
  374. * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions
  375. * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses
  376. * the first three \c dir parameters. The cardinal directions would be:
  377. * - North: 0,-1, 0
  378. * - East: 1, 0, 0
  379. * - South: 0, 1, 0
  380. * - West: -1, 0, 0
  381. *
  382. * The Z axis represents the height of the effect if supported, otherwise
  383. * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you
  384. * can use any multiple you want, only the direction matters.
  385. *
  386. * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations.
  387. * The first two \c dir parameters are used. The \c dir parameters are as
  388. * follows (all values are in hundredths of degrees):
  389. * - Degrees from (1, 0) rotated towards (0, 1).
  390. * - Degrees towards (0, 0, 1) (device needs at least 3 axes).
  391. *
  392. *
  393. * Example of force coming from the south with all encodings (force coming
  394. * from the south means the user will have to pull the stick to counteract):
  395. * \code
  396. * SDL_HapticDirection direction;
  397. *
  398. * // Cartesian directions
  399. * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
  400. * direction.dir[0] = 0; // X position
  401. * direction.dir[1] = 1; // Y position
  402. * // Assuming the device has 2 axes, we don't need to specify third parameter.
  403. *
  404. * // Polar directions
  405. * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
  406. * direction.dir[0] = 18000; // Polar only uses first parameter
  407. *
  408. * // Spherical coordinates
  409. * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
  410. * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
  411. * \endcode
  412. *
  413. * \sa SDL_HAPTIC_POLAR
  414. * \sa SDL_HAPTIC_CARTESIAN
  415. * \sa SDL_HAPTIC_SPHERICAL
  416. * \sa SDL_HAPTIC_STEERING_AXIS
  417. * \sa SDL_HapticEffect
  418. * \sa SDL_GetNumHapticAxes
  419. */
  420. typedef struct SDL_HapticDirection
  421. {
  422. Uint8 type; /**< The type of encoding. */
  423. Sint32 dir[3]; /**< The encoded direction. */
  424. } SDL_HapticDirection;
  425. /**
  426. * A structure containing a template for a Constant effect.
  427. *
  428. * This struct is exclusively for the ::SDL_HAPTIC_CONSTANT effect.
  429. *
  430. * A constant effect applies a constant force in the specified direction
  431. * to the joystick.
  432. *
  433. * \sa SDL_HAPTIC_CONSTANT
  434. * \sa SDL_HapticEffect
  435. */
  436. typedef struct SDL_HapticConstant
  437. {
  438. /* Header */
  439. Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */
  440. SDL_HapticDirection direction; /**< Direction of the effect. */
  441. /* Replay */
  442. Uint32 length; /**< Duration of the effect. */
  443. Uint16 delay; /**< Delay before starting the effect. */
  444. /* Trigger */
  445. Uint16 button; /**< Button that triggers the effect. */
  446. Uint16 interval; /**< How soon it can be triggered again after button. */
  447. /* Constant */
  448. Sint16 level; /**< Strength of the constant effect. */
  449. /* Envelope */
  450. Uint16 attack_length; /**< Duration of the attack. */
  451. Uint16 attack_level; /**< Level at the start of the attack. */
  452. Uint16 fade_length; /**< Duration of the fade. */
  453. Uint16 fade_level; /**< Level at the end of the fade. */
  454. } SDL_HapticConstant;
  455. /**
  456. * A structure containing a template for a Periodic effect.
  457. *
  458. * The struct handles the following effects:
  459. * - ::SDL_HAPTIC_SINE
  460. * - ::SDL_HAPTIC_LEFTRIGHT
  461. * - ::SDL_HAPTIC_TRIANGLE
  462. * - ::SDL_HAPTIC_SAWTOOTHUP
  463. * - ::SDL_HAPTIC_SAWTOOTHDOWN
  464. *
  465. * A periodic effect consists in a wave-shaped effect that repeats itself
  466. * over time. The type determines the shape of the wave and the parameters
  467. * determine the dimensions of the wave.
  468. *
  469. * Phase is given by hundredth of a degree meaning that giving the phase a value
  470. * of 9000 will displace it 25% of its period. Here are sample values:
  471. * - 0: No phase displacement.
  472. * - 9000: Displaced 25% of its period.
  473. * - 18000: Displaced 50% of its period.
  474. * - 27000: Displaced 75% of its period.
  475. * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
  476. *
  477. * Examples:
  478. * \verbatim
  479. SDL_HAPTIC_SINE
  480. __ __ __ __
  481. / \ / \ / \ /
  482. / \__/ \__/ \__/
  483. SDL_HAPTIC_SQUARE
  484. __ __ __ __ __
  485. | | | | | | | | | |
  486. | |__| |__| |__| |__| |
  487. SDL_HAPTIC_TRIANGLE
  488. /\ /\ /\ /\ /\
  489. / \ / \ / \ / \ /
  490. / \/ \/ \/ \/
  491. SDL_HAPTIC_SAWTOOTHUP
  492. /| /| /| /| /| /| /|
  493. / | / | / | / | / | / | / |
  494. / |/ |/ |/ |/ |/ |/ |
  495. SDL_HAPTIC_SAWTOOTHDOWN
  496. \ |\ |\ |\ |\ |\ |\ |
  497. \ | \ | \ | \ | \ | \ | \ |
  498. \| \| \| \| \| \| \|
  499. \endverbatim
  500. *
  501. * \sa SDL_HAPTIC_SINE
  502. * \sa SDL_HAPTIC_LEFTRIGHT
  503. * \sa SDL_HAPTIC_TRIANGLE
  504. * \sa SDL_HAPTIC_SAWTOOTHUP
  505. * \sa SDL_HAPTIC_SAWTOOTHDOWN
  506. * \sa SDL_HapticEffect
  507. */
  508. typedef struct SDL_HapticPeriodic
  509. {
  510. /* Header */
  511. Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT,
  512. ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or
  513. ::SDL_HAPTIC_SAWTOOTHDOWN */
  514. SDL_HapticDirection direction; /**< Direction of the effect. */
  515. /* Replay */
  516. Uint32 length; /**< Duration of the effect. */
  517. Uint16 delay; /**< Delay before starting the effect. */
  518. /* Trigger */
  519. Uint16 button; /**< Button that triggers the effect. */
  520. Uint16 interval; /**< How soon it can be triggered again after button. */
  521. /* Periodic */
  522. Uint16 period; /**< Period of the wave. */
  523. Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
  524. Sint16 offset; /**< Mean value of the wave. */
  525. Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
  526. /* Envelope */
  527. Uint16 attack_length; /**< Duration of the attack. */
  528. Uint16 attack_level; /**< Level at the start of the attack. */
  529. Uint16 fade_length; /**< Duration of the fade. */
  530. Uint16 fade_level; /**< Level at the end of the fade. */
  531. } SDL_HapticPeriodic;
  532. /**
  533. * A structure containing a template for a Condition effect.
  534. *
  535. * The struct handles the following effects:
  536. * - ::SDL_HAPTIC_SPRING: Effect based on axes position.
  537. * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity.
  538. * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
  539. * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement.
  540. *
  541. * Direction is handled by condition internals instead of a direction member.
  542. * The condition effect specific members have three parameters. The first
  543. * refers to the X axis, the second refers to the Y axis and the third
  544. * refers to the Z axis. The right terms refer to the positive side of the
  545. * axis and the left terms refer to the negative side of the axis. Please
  546. * refer to the ::SDL_HapticDirection diagram for which side is positive and
  547. * which is negative.
  548. *
  549. * \sa SDL_HapticDirection
  550. * \sa SDL_HAPTIC_SPRING
  551. * \sa SDL_HAPTIC_DAMPER
  552. * \sa SDL_HAPTIC_INERTIA
  553. * \sa SDL_HAPTIC_FRICTION
  554. * \sa SDL_HapticEffect
  555. */
  556. typedef struct SDL_HapticCondition
  557. {
  558. /* Header */
  559. Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER,
  560. ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */
  561. SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
  562. /* Replay */
  563. Uint32 length; /**< Duration of the effect. */
  564. Uint16 delay; /**< Delay before starting the effect. */
  565. /* Trigger */
  566. Uint16 button; /**< Button that triggers the effect. */
  567. Uint16 interval; /**< How soon it can be triggered again after button. */
  568. /* Condition */
  569. Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */
  570. Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */
  571. Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */
  572. Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */
  573. Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
  574. Sint16 center[3]; /**< Position of the dead zone. */
  575. } SDL_HapticCondition;
  576. /**
  577. * A structure containing a template for a Ramp effect.
  578. *
  579. * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect.
  580. *
  581. * The ramp effect starts at start strength and ends at end strength.
  582. * It augments in linear fashion. If you use attack and fade with a ramp
  583. * the effects get added to the ramp effect making the effect become
  584. * quadratic instead of linear.
  585. *
  586. * \sa SDL_HAPTIC_RAMP
  587. * \sa SDL_HapticEffect
  588. */
  589. typedef struct SDL_HapticRamp
  590. {
  591. /* Header */
  592. Uint16 type; /**< ::SDL_HAPTIC_RAMP */
  593. SDL_HapticDirection direction; /**< Direction of the effect. */
  594. /* Replay */
  595. Uint32 length; /**< Duration of the effect. */
  596. Uint16 delay; /**< Delay before starting the effect. */
  597. /* Trigger */
  598. Uint16 button; /**< Button that triggers the effect. */
  599. Uint16 interval; /**< How soon it can be triggered again after button. */
  600. /* Ramp */
  601. Sint16 start; /**< Beginning strength level. */
  602. Sint16 end; /**< Ending strength level. */
  603. /* Envelope */
  604. Uint16 attack_length; /**< Duration of the attack. */
  605. Uint16 attack_level; /**< Level at the start of the attack. */
  606. Uint16 fade_length; /**< Duration of the fade. */
  607. Uint16 fade_level; /**< Level at the end of the fade. */
  608. } SDL_HapticRamp;
  609. /**
  610. * A structure containing a template for a Left/Right effect.
  611. *
  612. * This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect.
  613. *
  614. * The Left/Right effect is used to explicitly control the large and small
  615. * motors, commonly found in modern game controllers. The small (right) motor
  616. * is high frequency, and the large (left) motor is low frequency.
  617. *
  618. * \sa SDL_HAPTIC_LEFTRIGHT
  619. * \sa SDL_HapticEffect
  620. */
  621. typedef struct SDL_HapticLeftRight
  622. {
  623. /* Header */
  624. Uint16 type; /**< ::SDL_HAPTIC_LEFTRIGHT */
  625. /* Replay */
  626. Uint32 length; /**< Duration of the effect in milliseconds. */
  627. /* Rumble */
  628. Uint16 large_magnitude; /**< Control of the large controller motor. */
  629. Uint16 small_magnitude; /**< Control of the small controller motor. */
  630. } SDL_HapticLeftRight;
  631. /**
  632. * A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect.
  633. *
  634. * This struct is exclusively for the ::SDL_HAPTIC_CUSTOM effect.
  635. *
  636. * A custom force feedback effect is much like a periodic effect, where the
  637. * application can define its exact shape. You will have to allocate the
  638. * data yourself. Data should consist of channels * samples Uint16 samples.
  639. *
  640. * If channels is one, the effect is rotated using the defined direction.
  641. * Otherwise it uses the samples in data for the different axes.
  642. *
  643. * \sa SDL_HAPTIC_CUSTOM
  644. * \sa SDL_HapticEffect
  645. */
  646. typedef struct SDL_HapticCustom
  647. {
  648. /* Header */
  649. Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */
  650. SDL_HapticDirection direction; /**< Direction of the effect. */
  651. /* Replay */
  652. Uint32 length; /**< Duration of the effect. */
  653. Uint16 delay; /**< Delay before starting the effect. */
  654. /* Trigger */
  655. Uint16 button; /**< Button that triggers the effect. */
  656. Uint16 interval; /**< How soon it can be triggered again after button. */
  657. /* Custom */
  658. Uint8 channels; /**< Axes to use, minimum of one. */
  659. Uint16 period; /**< Sample periods. */
  660. Uint16 samples; /**< Amount of samples. */
  661. Uint16 *data; /**< Should contain channels*samples items. */
  662. /* Envelope */
  663. Uint16 attack_length; /**< Duration of the attack. */
  664. Uint16 attack_level; /**< Level at the start of the attack. */
  665. Uint16 fade_length; /**< Duration of the fade. */
  666. Uint16 fade_level; /**< Level at the end of the fade. */
  667. } SDL_HapticCustom;
  668. /**
  669. * The generic template for any haptic effect.
  670. *
  671. * All values max at 32767 (0x7FFF). Signed values also can be negative.
  672. * Time values unless specified otherwise are in milliseconds.
  673. *
  674. * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767
  675. * value. Neither delay, interval, attack_length nor fade_length support
  676. * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.
  677. *
  678. * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of
  679. * ::SDL_HAPTIC_INFINITY.
  680. *
  681. * Button triggers may not be supported on all devices, it is advised to not
  682. * use them if possible. Buttons start at index 1 instead of index 0 like
  683. * the joystick.
  684. *
  685. * If both attack_length and fade_level are 0, the envelope is not used,
  686. * otherwise both values are used.
  687. *
  688. * Common parts:
  689. * \code
  690. * // Replay - All effects have this
  691. * Uint32 length; // Duration of effect (ms).
  692. * Uint16 delay; // Delay before starting effect.
  693. *
  694. * // Trigger - All effects have this
  695. * Uint16 button; // Button that triggers effect.
  696. * Uint16 interval; // How soon before effect can be triggered again.
  697. *
  698. * // Envelope - All effects except condition effects have this
  699. * Uint16 attack_length; // Duration of the attack (ms).
  700. * Uint16 attack_level; // Level at the start of the attack.
  701. * Uint16 fade_length; // Duration of the fade out (ms).
  702. * Uint16 fade_level; // Level at the end of the fade.
  703. * \endcode
  704. *
  705. *
  706. * Here we have an example of a constant effect evolution in time:
  707. * \verbatim
  708. Strength
  709. ^
  710. |
  711. | effect level --> _________________
  712. | / \
  713. | / \
  714. | / \
  715. | / \
  716. | attack_level --> | \
  717. | | | <--- fade_level
  718. |
  719. +--------------------------------------------------> Time
  720. [--] [---]
  721. attack_length fade_length
  722. [------------------][-----------------------]
  723. delay length
  724. \endverbatim
  725. *
  726. * Note either the attack_level or the fade_level may be above the actual
  727. * effect level.
  728. *
  729. * \sa SDL_HapticConstant
  730. * \sa SDL_HapticPeriodic
  731. * \sa SDL_HapticCondition
  732. * \sa SDL_HapticRamp
  733. * \sa SDL_HapticLeftRight
  734. * \sa SDL_HapticCustom
  735. */
  736. typedef union SDL_HapticEffect
  737. {
  738. /* Common for all force feedback effects */
  739. Uint16 type; /**< Effect type. */
  740. SDL_HapticConstant constant; /**< Constant effect. */
  741. SDL_HapticPeriodic periodic; /**< Periodic effect. */
  742. SDL_HapticCondition condition; /**< Condition effect. */
  743. SDL_HapticRamp ramp; /**< Ramp effect. */
  744. SDL_HapticLeftRight leftright; /**< Left/Right effect. */
  745. SDL_HapticCustom custom; /**< Custom effect. */
  746. } SDL_HapticEffect;
  747. /**
  748. * This is a unique ID for a haptic device for the time it is connected to the system, and is never reused for the lifetime of the application. If the haptic device is disconnected and reconnected, it will get a new ID.
  749. *
  750. * The ID value starts at 1 and increments from there. The value 0 is an invalid ID.
  751. */
  752. typedef Uint32 SDL_HapticID;
  753. /* Function prototypes */
  754. /**
  755. * Get a list of currently connected haptic devices.
  756. *
  757. * \param count a pointer filled in with the number of haptic devices returned
  758. * \returns a 0 terminated array of haptic device instance IDs which should be
  759. * freed with SDL_free(), or NULL on error; call SDL_GetError() for
  760. * more details.
  761. *
  762. * \since This function is available since SDL 3.0.0.
  763. *
  764. * \sa SDL_OpenHaptic
  765. */
  766. extern DECLSPEC SDL_HapticID *SDLCALL SDL_GetHaptics(int *count);
  767. /**
  768. * Get the implementation dependent name of a haptic device.
  769. *
  770. * This can be called before any haptic devices are opened.
  771. *
  772. * \param instance_id the haptic device instance ID
  773. * \returns the name of the selected haptic device. If no name can be found,
  774. * this function returns NULL; call SDL_GetError() for more
  775. * information.
  776. *
  777. * \since This function is available since SDL 3.0.0.
  778. *
  779. * \sa SDL_GetHapticName
  780. * \sa SDL_OpenHaptic
  781. */
  782. extern DECLSPEC const char *SDLCALL SDL_GetHapticInstanceName(SDL_HapticID instance_id);
  783. /**
  784. * Open a haptic device for use.
  785. *
  786. * The index passed as an argument refers to the N'th haptic device on this
  787. * system.
  788. *
  789. * When opening a haptic device, its gain will be set to maximum and
  790. * autocenter will be disabled. To modify these values use SDL_SetHapticGain()
  791. * and SDL_SetHapticAutocenter().
  792. *
  793. * \param instance_id the haptic device instance ID
  794. * \returns the device identifier or NULL on failure; call SDL_GetError() for
  795. * more information.
  796. *
  797. * \since This function is available since SDL 3.0.0.
  798. *
  799. * \sa SDL_CloseHaptic
  800. * \sa SDL_OpenHapticFromJoystick
  801. * \sa SDL_OpenHapticFromMouse
  802. * \sa SDL_PauseHaptic
  803. * \sa SDL_SetHapticAutocenter
  804. * \sa SDL_SetHapticGain
  805. * \sa SDL_StopHapticEffects
  806. */
  807. extern DECLSPEC SDL_Haptic *SDLCALL SDL_OpenHaptic(SDL_HapticID instance_id);
  808. /**
  809. * Get the SDL_Haptic associated with an instance ID, if it has been opened.
  810. *
  811. * \param instance_id the instance ID to get the SDL_Haptic for
  812. * \returns an SDL_Haptic on success or NULL on failure or if it hasn't been
  813. * opened yet; call SDL_GetError() for more information.
  814. *
  815. * \since This function is available since SDL 3.0.0.
  816. */
  817. extern DECLSPEC SDL_Haptic *SDLCALL SDL_GetHapticFromInstanceID(SDL_HapticID instance_id);
  818. /**
  819. * Get the instance ID of an opened haptic device.
  820. *
  821. * \param haptic the SDL_Haptic device to query
  822. * \returns the instance ID of the specified haptic device on success or 0 on
  823. * failure; call SDL_GetError() for more information.
  824. *
  825. * \since This function is available since SDL 3.0.0.
  826. *
  827. * \sa SDL_OpenHaptic
  828. */
  829. extern DECLSPEC SDL_HapticID SDLCALL SDL_GetHapticInstanceID(SDL_Haptic *haptic);
  830. /**
  831. * Get the implementation dependent name of a haptic device.
  832. *
  833. * \param haptic the SDL_Haptic obtained from SDL_OpenJoystick()
  834. * \returns the name of the selected haptic device. If no name can be found,
  835. * this function returns NULL; call SDL_GetError() for more
  836. * information.
  837. *
  838. * \since This function is available since SDL 3.0.0.
  839. *
  840. * \sa SDL_GetHapticInstanceName
  841. * \sa SDL_OpenHaptic
  842. */
  843. extern DECLSPEC const char *SDLCALL SDL_GetHapticName(SDL_Haptic *haptic);
  844. /**
  845. * Query whether or not the current mouse has haptic capabilities.
  846. *
  847. * \returns SDL_TRUE if the mouse is haptic or SDL_FALSE if it isn't.
  848. *
  849. * \since This function is available since SDL 3.0.0.
  850. *
  851. * \sa SDL_OpenHapticFromMouse
  852. */
  853. extern DECLSPEC SDL_bool SDLCALL SDL_IsMouseHaptic(void);
  854. /**
  855. * Try to open a haptic device from the current mouse.
  856. *
  857. * \returns the haptic device identifier or NULL on failure; call
  858. * SDL_GetError() for more information.
  859. *
  860. * \since This function is available since SDL 3.0.0.
  861. *
  862. * \sa SDL_OpenHaptic
  863. * \sa SDL_IsMouseHaptic
  864. */
  865. extern DECLSPEC SDL_Haptic *SDLCALL SDL_OpenHapticFromMouse(void);
  866. /**
  867. * Query if a joystick has haptic features.
  868. *
  869. * \param joystick the SDL_Joystick to test for haptic capabilities
  870. * \returns SDL_TRUE if the joystick is haptic or SDL_FALSE if it isn't.
  871. *
  872. * \since This function is available since SDL 3.0.0.
  873. *
  874. * \sa SDL_OpenHapticFromJoystick
  875. */
  876. extern DECLSPEC SDL_bool SDLCALL SDL_IsJoystickHaptic(SDL_Joystick *joystick);
  877. /**
  878. * Open a haptic device for use from a joystick device.
  879. *
  880. * You must still close the haptic device separately. It will not be closed
  881. * with the joystick.
  882. *
  883. * When opened from a joystick you should first close the haptic device before
  884. * closing the joystick device. If not, on some implementations the haptic
  885. * device will also get unallocated and you'll be unable to use force feedback
  886. * on that device.
  887. *
  888. * \param joystick the SDL_Joystick to create a haptic device from
  889. * \returns a valid haptic device identifier on success or NULL on failure;
  890. * call SDL_GetError() for more information.
  891. *
  892. * \since This function is available since SDL 3.0.0.
  893. *
  894. * \sa SDL_CloseHaptic
  895. * \sa SDL_OpenHaptic
  896. * \sa SDL_IsJoystickHaptic
  897. */
  898. extern DECLSPEC SDL_Haptic *SDLCALL SDL_OpenHapticFromJoystick(SDL_Joystick *joystick);
  899. /**
  900. * Close a haptic device previously opened with SDL_OpenHaptic().
  901. *
  902. * \param haptic the SDL_Haptic device to close
  903. *
  904. * \since This function is available since SDL 3.0.0.
  905. *
  906. * \sa SDL_OpenHaptic
  907. */
  908. extern DECLSPEC void SDLCALL SDL_CloseHaptic(SDL_Haptic *haptic);
  909. /**
  910. * Get the number of effects a haptic device can store.
  911. *
  912. * On some platforms this isn't fully supported, and therefore is an
  913. * approximation. Always check to see if your created effect was actually
  914. * created and do not rely solely on SDL_GetMaxHapticEffects().
  915. *
  916. * \param haptic the SDL_Haptic device to query
  917. * \returns the number of effects the haptic device can store or a negative
  918. * error code on failure; call SDL_GetError() for more information.
  919. *
  920. * \since This function is available since SDL 3.0.0.
  921. *
  922. * \sa SDL_GetMaxHapticEffectsPlaying
  923. * \sa SDL_GetHapticFeatures
  924. */
  925. extern DECLSPEC int SDLCALL SDL_GetMaxHapticEffects(SDL_Haptic *haptic);
  926. /**
  927. * Get the number of effects a haptic device can play at the same time.
  928. *
  929. * This is not supported on all platforms, but will always return a value.
  930. *
  931. * \param haptic the SDL_Haptic device to query maximum playing effects
  932. * \returns the number of effects the haptic device can play at the same time
  933. * or a negative error code on failure; call SDL_GetError() for more
  934. * information.
  935. *
  936. * \since This function is available since SDL 3.0.0.
  937. *
  938. * \sa SDL_GetMaxHapticEffects
  939. * \sa SDL_GetHapticFeatures
  940. */
  941. extern DECLSPEC int SDLCALL SDL_GetMaxHapticEffectsPlaying(SDL_Haptic *haptic);
  942. /**
  943. * Get the haptic device's supported features in bitwise manner.
  944. *
  945. * \param haptic the SDL_Haptic device to query
  946. * \returns a list of supported haptic features in bitwise manner (OR'd), or 0
  947. * on failure; call SDL_GetError() for more information.
  948. *
  949. * \since This function is available since SDL 3.0.0.
  950. *
  951. * \sa SDL_HapticEffectSupported
  952. * \sa SDL_GetMaxHapticEffects
  953. */
  954. extern DECLSPEC unsigned int SDLCALL SDL_GetHapticFeatures(SDL_Haptic *haptic);
  955. /**
  956. * Get the number of haptic axes the device has.
  957. *
  958. * The number of haptic axes might be useful if working with the
  959. * SDL_HapticDirection effect.
  960. *
  961. * \param haptic the SDL_Haptic device to query
  962. * \returns the number of axes on success or a negative error code on failure;
  963. * call SDL_GetError() for more information.
  964. *
  965. * \since This function is available since SDL 3.0.0.
  966. */
  967. extern DECLSPEC int SDLCALL SDL_GetNumHapticAxes(SDL_Haptic *haptic);
  968. /**
  969. * Check to see if an effect is supported by a haptic device.
  970. *
  971. * \param haptic the SDL_Haptic device to query
  972. * \param effect the desired effect to query
  973. * \returns SDL_TRUE if the effect is supported or SDL_FALSE if it isn't.
  974. *
  975. * \since This function is available since SDL 3.0.0.
  976. *
  977. * \sa SDL_CreateHapticEffect
  978. * \sa SDL_GetHapticFeatures
  979. */
  980. extern DECLSPEC SDL_bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, SDL_HapticEffect *effect);
  981. /**
  982. * Create a new haptic effect on a specified device.
  983. *
  984. * \param haptic an SDL_Haptic device to create the effect on
  985. * \param effect an SDL_HapticEffect structure containing the properties of
  986. * the effect to create
  987. * \returns the ID of the effect on success or a negative error code on
  988. * failure; call SDL_GetError() for more information.
  989. *
  990. * \since This function is available since SDL 3.0.0.
  991. *
  992. * \sa SDL_DestroyHapticEffect
  993. * \sa SDL_RunHapticEffect
  994. * \sa SDL_UpdateHapticEffect
  995. */
  996. extern DECLSPEC int SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, SDL_HapticEffect *effect);
  997. /**
  998. * Update the properties of an effect.
  999. *
  1000. * Can be used dynamically, although behavior when dynamically changing
  1001. * direction may be strange. Specifically the effect may re-upload itself and
  1002. * start playing from the start. You also cannot change the type either when
  1003. * running SDL_UpdateHapticEffect().
  1004. *
  1005. * \param haptic the SDL_Haptic device that has the effect
  1006. * \param effect the identifier of the effect to update
  1007. * \param data an SDL_HapticEffect structure containing the new effect
  1008. * properties to use
  1009. * \returns 0 on success or a negative error code on failure; call
  1010. * SDL_GetError() for more information.
  1011. *
  1012. * \since This function is available since SDL 3.0.0.
  1013. *
  1014. * \sa SDL_DestroyHapticEffect
  1015. * \sa SDL_CreateHapticEffect
  1016. * \sa SDL_RunHapticEffect
  1017. */
  1018. extern DECLSPEC int SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, SDL_HapticEffect *data);
  1019. /**
  1020. * Run the haptic effect on its associated haptic device.
  1021. *
  1022. * To repeat the effect over and over indefinitely, set `iterations` to
  1023. * `SDL_HAPTIC_INFINITY`. (Repeats the envelope - attack and fade.) To make
  1024. * one instance of the effect last indefinitely (so the effect does not fade),
  1025. * set the effect's `length` in its structure/union to `SDL_HAPTIC_INFINITY`
  1026. * instead.
  1027. *
  1028. * \param haptic the SDL_Haptic device to run the effect on
  1029. * \param effect the ID of the haptic effect to run
  1030. * \param iterations the number of iterations to run the effect; use
  1031. * `SDL_HAPTIC_INFINITY` to repeat forever
  1032. * \returns 0 on success or a negative error code on failure; call
  1033. * SDL_GetError() for more information.
  1034. *
  1035. * \since This function is available since SDL 3.0.0.
  1036. *
  1037. * \sa SDL_DestroyHapticEffect
  1038. * \sa SDL_GetHapticEffectStatus
  1039. * \sa SDL_StopHapticEffect
  1040. */
  1041. extern DECLSPEC int SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations);
  1042. /**
  1043. * Stop the haptic effect on its associated haptic device.
  1044. *
  1045. * *
  1046. *
  1047. * \param haptic the SDL_Haptic device to stop the effect on
  1048. * \param effect the ID of the haptic effect to stop
  1049. * \returns 0 on success or a negative error code on failure; call
  1050. * SDL_GetError() for more information.
  1051. *
  1052. * \since This function is available since SDL 3.0.0.
  1053. *
  1054. * \sa SDL_DestroyHapticEffect
  1055. * \sa SDL_RunHapticEffect
  1056. */
  1057. extern DECLSPEC int SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int effect);
  1058. /**
  1059. * Destroy a haptic effect on the device.
  1060. *
  1061. * This will stop the effect if it's running. Effects are automatically
  1062. * destroyed when the device is closed.
  1063. *
  1064. * \param haptic the SDL_Haptic device to destroy the effect on
  1065. * \param effect the ID of the haptic effect to destroy
  1066. *
  1067. * \since This function is available since SDL 3.0.0.
  1068. *
  1069. * \sa SDL_CreateHapticEffect
  1070. */
  1071. extern DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect);
  1072. /**
  1073. * Get the status of the current effect on the specified haptic device.
  1074. *
  1075. * Device must support the SDL_HAPTIC_STATUS feature.
  1076. *
  1077. * \param haptic the SDL_Haptic device to query for the effect status on
  1078. * \param effect the ID of the haptic effect to query its status
  1079. * \returns 0 if it isn't playing, 1 if it is playing, or a negative error
  1080. * code on failure; call SDL_GetError() for more information.
  1081. *
  1082. * \since This function is available since SDL 3.0.0.
  1083. *
  1084. * \sa SDL_RunHapticEffect
  1085. * \sa SDL_StopHapticEffect
  1086. */
  1087. extern DECLSPEC int SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect);
  1088. /**
  1089. * Set the global gain of the specified haptic device.
  1090. *
  1091. * Device must support the SDL_HAPTIC_GAIN feature.
  1092. *
  1093. * The user may specify the maximum gain by setting the environment variable
  1094. * `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to
  1095. * SDL_SetHapticGain() will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the
  1096. * maximum.
  1097. *
  1098. * \param haptic the SDL_Haptic device to set the gain on
  1099. * \param gain value to set the gain to, should be between 0 and 100 (0 - 100)
  1100. * \returns 0 on success or a negative error code on failure; call
  1101. * SDL_GetError() for more information.
  1102. *
  1103. * \since This function is available since SDL 3.0.0.
  1104. *
  1105. * \sa SDL_GetHapticFeatures
  1106. */
  1107. extern DECLSPEC int SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain);
  1108. /**
  1109. * Set the global autocenter of the device.
  1110. *
  1111. * Autocenter should be between 0 and 100. Setting it to 0 will disable
  1112. * autocentering.
  1113. *
  1114. * Device must support the SDL_HAPTIC_AUTOCENTER feature.
  1115. *
  1116. * \param haptic the SDL_Haptic device to set autocentering on
  1117. * \param autocenter value to set autocenter to (0-100)
  1118. * \returns 0 on success or a negative error code on failure; call
  1119. * SDL_GetError() for more information.
  1120. *
  1121. * \since This function is available since SDL 3.0.0.
  1122. *
  1123. * \sa SDL_GetHapticFeatures
  1124. */
  1125. extern DECLSPEC int SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter);
  1126. /**
  1127. * Pause a haptic device.
  1128. *
  1129. * Device must support the `SDL_HAPTIC_PAUSE` feature. Call SDL_ResumeHaptic()
  1130. * to resume playback.
  1131. *
  1132. * Do not modify the effects nor add new ones while the device is paused. That
  1133. * can cause all sorts of weird errors.
  1134. *
  1135. * \param haptic the SDL_Haptic device to pause
  1136. * \returns 0 on success or a negative error code on failure; call
  1137. * SDL_GetError() for more information.
  1138. *
  1139. * \since This function is available since SDL 3.0.0.
  1140. *
  1141. * \sa SDL_ResumeHaptic
  1142. */
  1143. extern DECLSPEC int SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic);
  1144. /**
  1145. * Resume a haptic device.
  1146. *
  1147. * Call to unpause after SDL_PauseHaptic().
  1148. *
  1149. * \param haptic the SDL_Haptic device to unpause
  1150. * \returns 0 on success or a negative error code on failure; call
  1151. * SDL_GetError() for more information.
  1152. *
  1153. * \since This function is available since SDL 3.0.0.
  1154. *
  1155. * \sa SDL_PauseHaptic
  1156. */
  1157. extern DECLSPEC int SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic);
  1158. /**
  1159. * Stop all the currently playing effects on a haptic device.
  1160. *
  1161. * \param haptic the SDL_Haptic device to stop
  1162. * \returns 0 on success or a negative error code on failure; call
  1163. * SDL_GetError() for more information.
  1164. *
  1165. * \since This function is available since SDL 3.0.0.
  1166. */
  1167. extern DECLSPEC int SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic);
  1168. /**
  1169. * Check whether rumble is supported on a haptic device.
  1170. *
  1171. * \param haptic haptic device to check for rumble support
  1172. * \returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't, or a
  1173. * negative error code on failure; call SDL_GetError() for more
  1174. * information.
  1175. *
  1176. * \since This function is available since SDL 3.0.0.
  1177. *
  1178. * \sa SDL_InitHapticRumble
  1179. * \sa SDL_PlayHapticRumble
  1180. * \sa SDL_StopHapticRumble
  1181. */
  1182. extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *haptic);
  1183. /**
  1184. * Initialize a haptic device for simple rumble playback.
  1185. *
  1186. * \param haptic the haptic device to initialize for simple rumble playback
  1187. * \returns 0 on success or a negative error code on failure; call
  1188. * SDL_GetError() for more information.
  1189. *
  1190. * \since This function is available since SDL 3.0.0.
  1191. *
  1192. * \sa SDL_OpenHaptic
  1193. * \sa SDL_PlayHapticRumble
  1194. * \sa SDL_StopHapticRumble
  1195. * \sa SDL_HapticRumbleSupported
  1196. */
  1197. extern DECLSPEC int SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic);
  1198. /**
  1199. * Run a simple rumble effect on a haptic device.
  1200. *
  1201. * \param haptic the haptic device to play the rumble effect on
  1202. * \param strength strength of the rumble to play as a 0-1 float value
  1203. * \param length length of the rumble to play in milliseconds
  1204. * \returns 0 on success or a negative error code on failure; call
  1205. * SDL_GetError() for more information.
  1206. *
  1207. * \since This function is available since SDL 3.0.0.
  1208. *
  1209. * \sa SDL_InitHapticRumble
  1210. * \sa SDL_StopHapticRumble
  1211. * \sa SDL_HapticRumbleSupported
  1212. */
  1213. extern DECLSPEC int SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length);
  1214. /**
  1215. * Stop the simple rumble on a haptic device.
  1216. *
  1217. * \param haptic the haptic device to stop the rumble effect on
  1218. * \returns 0 on success or a negative error code on failure; call
  1219. * SDL_GetError() for more information.
  1220. *
  1221. * \since This function is available since SDL 3.0.0.
  1222. *
  1223. * \sa SDL_InitHapticRumble
  1224. * \sa SDL_PlayHapticRumble
  1225. * \sa SDL_HapticRumbleSupported
  1226. */
  1227. extern DECLSPEC int SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic);
  1228. /* Ends C function definitions when using C++ */
  1229. #ifdef __cplusplus
  1230. }
  1231. #endif
  1232. #include <SDL3/SDL_close_code.h>
  1233. #endif /* SDL_haptic_h_ */