SDL_haptic.h 42 KB

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