SDL_haptic.h 42 KB

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