SDL_haptic.h 36 KB

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