🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1238 lines
38 KiB

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