SDL_haptic.h 42 KB

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