SDL Library
Embed:
(wiki syntax)
Show/hide line numbers
SDL_haptic.h
Go to the documentation of this file.
00001 /* 00002 Simple DirectMedia Layer 00003 Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any damages 00007 arising from the use of this software. 00008 00009 Permission is granted to anyone to use this software for any purpose, 00010 including commercial applications, and to alter it and redistribute it 00011 freely, subject to the following restrictions: 00012 00013 1. The origin of this software must not be misrepresented; you must not 00014 claim that you wrote the original software. If you use this software 00015 in a product, an acknowledgment in the product documentation would be 00016 appreciated but is not required. 00017 2. Altered source versions must be plainly marked as such, and must not be 00018 misrepresented as being the original software. 00019 3. This notice may not be removed or altered from any source distribution. 00020 */ 00021 00022 /** 00023 * \file SDL_haptic.h 00024 * 00025 * \brief The SDL Haptic subsystem allows you to control haptic (force feedback) 00026 * devices. 00027 * 00028 * The basic usage is as follows: 00029 * - Initialize the Subsystem (::SDL_INIT_HAPTIC). 00030 * - Open a Haptic Device. 00031 * - SDL_HapticOpen() to open from index. 00032 * - SDL_HapticOpenFromJoystick() to open from an existing joystick. 00033 * - Create an effect (::SDL_HapticEffect). 00034 * - Upload the effect with SDL_HapticNewEffect(). 00035 * - Run the effect with SDL_HapticRunEffect(). 00036 * - (optional) Free the effect with SDL_HapticDestroyEffect(). 00037 * - Close the haptic device with SDL_HapticClose(). 00038 * 00039 * \par Simple rumble example: 00040 * \code 00041 * SDL_Haptic *haptic; 00042 * 00043 * // Open the device 00044 * haptic = SDL_HapticOpen( 0 ); 00045 * if (haptic == NULL) 00046 * return -1; 00047 * 00048 * // Initialize simple rumble 00049 * if (SDL_HapticRumbleInit( haptic ) != 0) 00050 * return -1; 00051 * 00052 * // Play effect at 50% strength for 2 seconds 00053 * if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0) 00054 * return -1; 00055 * SDL_Delay( 2000 ); 00056 * 00057 * // Clean up 00058 * SDL_HapticClose( haptic ); 00059 * \endcode 00060 * 00061 * \par Complete example: 00062 * \code 00063 * int test_haptic( SDL_Joystick * joystick ) { 00064 * SDL_Haptic *haptic; 00065 * SDL_HapticEffect effect; 00066 * int effect_id; 00067 * 00068 * // Open the device 00069 * haptic = SDL_HapticOpenFromJoystick( joystick ); 00070 * if (haptic == NULL) return -1; // Most likely joystick isn't haptic 00071 * 00072 * // See if it can do sine waves 00073 * if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) { 00074 * SDL_HapticClose(haptic); // No sine effect 00075 * return -1; 00076 * } 00077 * 00078 * // Create the effect 00079 * memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default 00080 * effect.type = SDL_HAPTIC_SINE; 00081 * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates 00082 * effect.periodic.direction.dir[0] = 18000; // Force comes from south 00083 * effect.periodic.period = 1000; // 1000 ms 00084 * effect.periodic.magnitude = 20000; // 20000/32767 strength 00085 * effect.periodic.length = 5000; // 5 seconds long 00086 * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength 00087 * effect.periodic.fade_length = 1000; // Takes 1 second to fade away 00088 * 00089 * // Upload the effect 00090 * effect_id = SDL_HapticNewEffect( haptic, &effect ); 00091 * 00092 * // Test the effect 00093 * SDL_HapticRunEffect( haptic, effect_id, 1 ); 00094 * SDL_Delay( 5000); // Wait for the effect to finish 00095 * 00096 * // We destroy the effect, although closing the device also does this 00097 * SDL_HapticDestroyEffect( haptic, effect_id ); 00098 * 00099 * // Close the device 00100 * SDL_HapticClose(haptic); 00101 * 00102 * return 0; // Success 00103 * } 00104 * \endcode 00105 * 00106 * You can also find out more information on my blog: 00107 * http://bobbens.dyndns.org/journal/2010/sdl_haptic/ 00108 * 00109 * \author Edgar Simo Serra 00110 */ 00111 00112 #ifndef _SDL_haptic_h 00113 #define _SDL_haptic_h 00114 00115 #include "SDL_stdinc.h" 00116 #include "SDL_error.h" 00117 #include "SDL_joystick.h" 00118 00119 #include "begin_code.h" 00120 /* Set up for C function definitions, even when using C++ */ 00121 #ifdef __cplusplus 00122 extern "C" { 00123 #endif /* __cplusplus */ 00124 00125 /** 00126 * \typedef SDL_Haptic 00127 * 00128 * \brief The haptic structure used to identify an SDL haptic. 00129 * 00130 * \sa SDL_HapticOpen 00131 * \sa SDL_HapticOpenFromJoystick 00132 * \sa SDL_HapticClose 00133 */ 00134 struct _SDL_Haptic; 00135 typedef struct _SDL_Haptic SDL_Haptic; 00136 00137 00138 /** 00139 * \name Haptic features 00140 * 00141 * Different haptic features a device can have. 00142 */ 00143 /* @{ */ 00144 00145 /** 00146 * \name Haptic effects 00147 */ 00148 /* @{ */ 00149 00150 /** 00151 * \brief Constant effect supported. 00152 * 00153 * Constant haptic effect. 00154 * 00155 * \sa SDL_HapticCondition 00156 */ 00157 #define SDL_HAPTIC_CONSTANT (1<<0) 00158 00159 /** 00160 * \brief Sine wave effect supported. 00161 * 00162 * Periodic haptic effect that simulates sine waves. 00163 * 00164 * \sa SDL_HapticPeriodic 00165 */ 00166 #define SDL_HAPTIC_SINE (1<<1) 00167 00168 /** 00169 * \brief Left/Right effect supported. 00170 * 00171 * Haptic effect for direct control over high/low frequency motors. 00172 * 00173 * \sa SDL_HapticLeftRight 00174 * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry, 00175 * we ran out of bits, and this is important for XInput devices. 00176 */ 00177 #define SDL_HAPTIC_LEFTRIGHT (1<<2) 00178 00179 /* !!! FIXME: put this back when we have more bits in 2.1 */ 00180 /* #define SDL_HAPTIC_SQUARE (1<<2) */ 00181 00182 /** 00183 * \brief Triangle wave effect supported. 00184 * 00185 * Periodic haptic effect that simulates triangular waves. 00186 * 00187 * \sa SDL_HapticPeriodic 00188 */ 00189 #define SDL_HAPTIC_TRIANGLE (1<<3) 00190 00191 /** 00192 * \brief Sawtoothup wave effect supported. 00193 * 00194 * Periodic haptic effect that simulates saw tooth up waves. 00195 * 00196 * \sa SDL_HapticPeriodic 00197 */ 00198 #define SDL_HAPTIC_SAWTOOTHUP (1<<4) 00199 00200 /** 00201 * \brief Sawtoothdown wave effect supported. 00202 * 00203 * Periodic haptic effect that simulates saw tooth down waves. 00204 * 00205 * \sa SDL_HapticPeriodic 00206 */ 00207 #define SDL_HAPTIC_SAWTOOTHDOWN (1<<5) 00208 00209 /** 00210 * \brief Ramp effect supported. 00211 * 00212 * Ramp haptic effect. 00213 * 00214 * \sa SDL_HapticRamp 00215 */ 00216 #define SDL_HAPTIC_RAMP (1<<6) 00217 00218 /** 00219 * \brief Spring effect supported - uses axes position. 00220 * 00221 * Condition haptic effect that simulates a spring. Effect is based on the 00222 * axes position. 00223 * 00224 * \sa SDL_HapticCondition 00225 */ 00226 #define SDL_HAPTIC_SPRING (1<<7) 00227 00228 /** 00229 * \brief Damper effect supported - uses axes velocity. 00230 * 00231 * Condition haptic effect that simulates dampening. Effect is based on the 00232 * axes velocity. 00233 * 00234 * \sa SDL_HapticCondition 00235 */ 00236 #define SDL_HAPTIC_DAMPER (1<<8) 00237 00238 /** 00239 * \brief Inertia effect supported - uses axes acceleration. 00240 * 00241 * Condition haptic effect that simulates inertia. Effect is based on the axes 00242 * acceleration. 00243 * 00244 * \sa SDL_HapticCondition 00245 */ 00246 #define SDL_HAPTIC_INERTIA (1<<9) 00247 00248 /** 00249 * \brief Friction effect supported - uses axes movement. 00250 * 00251 * Condition haptic effect that simulates friction. Effect is based on the 00252 * axes movement. 00253 * 00254 * \sa SDL_HapticCondition 00255 */ 00256 #define SDL_HAPTIC_FRICTION (1<<10) 00257 00258 /** 00259 * \brief Custom effect is supported. 00260 * 00261 * User defined custom haptic effect. 00262 */ 00263 #define SDL_HAPTIC_CUSTOM (1<<11) 00264 00265 /* @} *//* Haptic effects */ 00266 00267 /* These last few are features the device has, not effects */ 00268 00269 /** 00270 * \brief Device can set global gain. 00271 * 00272 * Device supports setting the global gain. 00273 * 00274 * \sa SDL_HapticSetGain 00275 */ 00276 #define SDL_HAPTIC_GAIN (1<<12) 00277 00278 /** 00279 * \brief Device can set autocenter. 00280 * 00281 * Device supports setting autocenter. 00282 * 00283 * \sa SDL_HapticSetAutocenter 00284 */ 00285 #define SDL_HAPTIC_AUTOCENTER (1<<13) 00286 00287 /** 00288 * \brief Device can be queried for effect status. 00289 * 00290 * Device can be queried for effect status. 00291 * 00292 * \sa SDL_HapticGetEffectStatus 00293 */ 00294 #define SDL_HAPTIC_STATUS (1<<14) 00295 00296 /** 00297 * \brief Device can be paused. 00298 * 00299 * \sa SDL_HapticPause 00300 * \sa SDL_HapticUnpause 00301 */ 00302 #define SDL_HAPTIC_PAUSE (1<<15) 00303 00304 00305 /** 00306 * \name Direction encodings 00307 */ 00308 /* @{ */ 00309 00310 /** 00311 * \brief Uses polar coordinates for the direction. 00312 * 00313 * \sa SDL_HapticDirection 00314 */ 00315 #define SDL_HAPTIC_POLAR 0 00316 00317 /** 00318 * \brief Uses cartesian coordinates for the direction. 00319 * 00320 * \sa SDL_HapticDirection 00321 */ 00322 #define SDL_HAPTIC_CARTESIAN 1 00323 00324 /** 00325 * \brief Uses spherical coordinates for the direction. 00326 * 00327 * \sa SDL_HapticDirection 00328 */ 00329 #define SDL_HAPTIC_SPHERICAL 2 00330 00331 /* @} *//* Direction encodings */ 00332 00333 /* @} *//* Haptic features */ 00334 00335 /* 00336 * Misc defines. 00337 */ 00338 00339 /** 00340 * \brief Used to play a device an infinite number of times. 00341 * 00342 * \sa SDL_HapticRunEffect 00343 */ 00344 #define SDL_HAPTIC_INFINITY 4294967295U 00345 00346 00347 /** 00348 * \brief Structure that represents a haptic direction. 00349 * 00350 * Directions can be specified by: 00351 * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates. 00352 * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates. 00353 * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates. 00354 * 00355 * Cardinal directions of the haptic device are relative to the positioning 00356 * of the device. North is considered to be away from the user. 00357 * 00358 * The following diagram represents the cardinal directions: 00359 * \verbatim 00360 .--. 00361 |__| .-------. 00362 |=.| |.-----.| 00363 |--| || || 00364 | | |'-----'| 00365 |__|~')_____(' 00366 [ COMPUTER ] 00367 00368 00369 North (0,-1) 00370 ^ 00371 | 00372 | 00373 (1,0) West <----[ HAPTIC ]----> East (-1,0) 00374 | 00375 | 00376 v 00377 South (0,1) 00378 00379 00380 [ USER ] 00381 \|||/ 00382 (o o) 00383 ---ooO-(_)-Ooo--- 00384 \endverbatim 00385 * 00386 * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a 00387 * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses 00388 * the first \c dir parameter. The cardinal directions would be: 00389 * - North: 0 (0 degrees) 00390 * - East: 9000 (90 degrees) 00391 * - South: 18000 (180 degrees) 00392 * - West: 27000 (270 degrees) 00393 * 00394 * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions 00395 * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses 00396 * the first three \c dir parameters. The cardinal directions would be: 00397 * - North: 0,-1, 0 00398 * - East: -1, 0, 0 00399 * - South: 0, 1, 0 00400 * - West: 1, 0, 0 00401 * 00402 * The Z axis represents the height of the effect if supported, otherwise 00403 * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you 00404 * can use any multiple you want, only the direction matters. 00405 * 00406 * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations. 00407 * The first two \c dir parameters are used. The \c dir parameters are as 00408 * follows (all values are in hundredths of degrees): 00409 * - Degrees from (1, 0) rotated towards (0, 1). 00410 * - Degrees towards (0, 0, 1) (device needs at least 3 axes). 00411 * 00412 * 00413 * Example of force coming from the south with all encodings (force coming 00414 * from the south means the user will have to pull the stick to counteract): 00415 * \code 00416 * SDL_HapticDirection direction; 00417 * 00418 * // Cartesian directions 00419 * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding. 00420 * direction.dir[0] = 0; // X position 00421 * direction.dir[1] = 1; // Y position 00422 * // Assuming the device has 2 axes, we don't need to specify third parameter. 00423 * 00424 * // Polar directions 00425 * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding. 00426 * direction.dir[0] = 18000; // Polar only uses first parameter 00427 * 00428 * // Spherical coordinates 00429 * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding 00430 * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters. 00431 * \endcode 00432 * 00433 * \sa SDL_HAPTIC_POLAR 00434 * \sa SDL_HAPTIC_CARTESIAN 00435 * \sa SDL_HAPTIC_SPHERICAL 00436 * \sa SDL_HapticEffect 00437 * \sa SDL_HapticNumAxes 00438 */ 00439 typedef struct SDL_HapticDirection 00440 { 00441 Uint8 type; /**< The type of encoding. */ 00442 Sint32 dir[3]; /**< The encoded direction. */ 00443 } SDL_HapticDirection; 00444 00445 00446 /** 00447 * \brief A structure containing a template for a Constant effect. 00448 * 00449 * The struct is exclusive to the ::SDL_HAPTIC_CONSTANT effect. 00450 * 00451 * A constant effect applies a constant force in the specified direction 00452 * to the joystick. 00453 * 00454 * \sa SDL_HAPTIC_CONSTANT 00455 * \sa SDL_HapticEffect 00456 */ 00457 typedef struct SDL_HapticConstant 00458 { 00459 /* Header */ 00460 Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */ 00461 SDL_HapticDirection direction; /**< Direction of the effect. */ 00462 00463 /* Replay */ 00464 Uint32 length; /**< Duration of the effect. */ 00465 Uint16 delay; /**< Delay before starting the effect. */ 00466 00467 /* Trigger */ 00468 Uint16 button; /**< Button that triggers the effect. */ 00469 Uint16 interval; /**< How soon it can be triggered again after button. */ 00470 00471 /* Constant */ 00472 Sint16 level; /**< Strength of the constant effect. */ 00473 00474 /* Envelope */ 00475 Uint16 attack_length; /**< Duration of the attack. */ 00476 Uint16 attack_level; /**< Level at the start of the attack. */ 00477 Uint16 fade_length; /**< Duration of the fade. */ 00478 Uint16 fade_level; /**< Level at the end of the fade. */ 00479 } SDL_HapticConstant; 00480 00481 /** 00482 * \brief A structure containing a template for a Periodic effect. 00483 * 00484 * The struct handles the following effects: 00485 * - ::SDL_HAPTIC_SINE 00486 * - ::SDL_HAPTIC_LEFTRIGHT 00487 * - ::SDL_HAPTIC_TRIANGLE 00488 * - ::SDL_HAPTIC_SAWTOOTHUP 00489 * - ::SDL_HAPTIC_SAWTOOTHDOWN 00490 * 00491 * A periodic effect consists in a wave-shaped effect that repeats itself 00492 * over time. The type determines the shape of the wave and the parameters 00493 * determine the dimensions of the wave. 00494 * 00495 * Phase is given by hundredth of a cycle meaning that giving the phase a value 00496 * of 9000 will displace it 25% of its period. Here are sample values: 00497 * - 0: No phase displacement. 00498 * - 9000: Displaced 25% of its period. 00499 * - 18000: Displaced 50% of its period. 00500 * - 27000: Displaced 75% of its period. 00501 * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred. 00502 * 00503 * Examples: 00504 * \verbatim 00505 SDL_HAPTIC_SINE 00506 __ __ __ __ 00507 / \ / \ / \ / 00508 / \__/ \__/ \__/ 00509 00510 SDL_HAPTIC_SQUARE 00511 __ __ __ __ __ 00512 | | | | | | | | | | 00513 | |__| |__| |__| |__| | 00514 00515 SDL_HAPTIC_TRIANGLE 00516 /\ /\ /\ /\ /\ 00517 / \ / \ / \ / \ / 00518 / \/ \/ \/ \/ 00519 00520 SDL_HAPTIC_SAWTOOTHUP 00521 /| /| /| /| /| /| /| 00522 / | / | / | / | / | / | / | 00523 / |/ |/ |/ |/ |/ |/ | 00524 00525 SDL_HAPTIC_SAWTOOTHDOWN 00526 \ |\ |\ |\ |\ |\ |\ | 00527 \ | \ | \ | \ | \ | \ | \ | 00528 \| \| \| \| \| \| \| 00529 \endverbatim 00530 * 00531 * \sa SDL_HAPTIC_SINE 00532 * \sa SDL_HAPTIC_LEFTRIGHT 00533 * \sa SDL_HAPTIC_TRIANGLE 00534 * \sa SDL_HAPTIC_SAWTOOTHUP 00535 * \sa SDL_HAPTIC_SAWTOOTHDOWN 00536 * \sa SDL_HapticEffect 00537 */ 00538 typedef struct SDL_HapticPeriodic 00539 { 00540 /* Header */ 00541 Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT, 00542 ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or 00543 ::SDL_HAPTIC_SAWTOOTHDOWN */ 00544 SDL_HapticDirection direction; /**< Direction of the effect. */ 00545 00546 /* Replay */ 00547 Uint32 length; /**< Duration of the effect. */ 00548 Uint16 delay; /**< Delay before starting the effect. */ 00549 00550 /* Trigger */ 00551 Uint16 button; /**< Button that triggers the effect. */ 00552 Uint16 interval; /**< How soon it can be triggered again after button. */ 00553 00554 /* Periodic */ 00555 Uint16 period; /**< Period of the wave. */ 00556 Sint16 magnitude; /**< Peak value. */ 00557 Sint16 offset; /**< Mean value of the wave. */ 00558 Uint16 phase; /**< Horizontal shift given by hundredth of a cycle. */ 00559 00560 /* Envelope */ 00561 Uint16 attack_length; /**< Duration of the attack. */ 00562 Uint16 attack_level; /**< Level at the start of the attack. */ 00563 Uint16 fade_length; /**< Duration of the fade. */ 00564 Uint16 fade_level; /**< Level at the end of the fade. */ 00565 } SDL_HapticPeriodic; 00566 00567 /** 00568 * \brief A structure containing a template for a Condition effect. 00569 * 00570 * The struct handles the following effects: 00571 * - ::SDL_HAPTIC_SPRING: Effect based on axes position. 00572 * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity. 00573 * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration. 00574 * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement. 00575 * 00576 * Direction is handled by condition internals instead of a direction member. 00577 * The condition effect specific members have three parameters. The first 00578 * refers to the X axis, the second refers to the Y axis and the third 00579 * refers to the Z axis. The right terms refer to the positive side of the 00580 * axis and the left terms refer to the negative side of the axis. Please 00581 * refer to the ::SDL_HapticDirection diagram for which side is positive and 00582 * which is negative. 00583 * 00584 * \sa SDL_HapticDirection 00585 * \sa SDL_HAPTIC_SPRING 00586 * \sa SDL_HAPTIC_DAMPER 00587 * \sa SDL_HAPTIC_INERTIA 00588 * \sa SDL_HAPTIC_FRICTION 00589 * \sa SDL_HapticEffect 00590 */ 00591 typedef struct SDL_HapticCondition 00592 { 00593 /* Header */ 00594 Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER, 00595 ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */ 00596 SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */ 00597 00598 /* Replay */ 00599 Uint32 length; /**< Duration of the effect. */ 00600 Uint16 delay; /**< Delay before starting the effect. */ 00601 00602 /* Trigger */ 00603 Uint16 button; /**< Button that triggers the effect. */ 00604 Uint16 interval; /**< How soon it can be triggered again after button. */ 00605 00606 /* Condition */ 00607 Uint16 right_sat[3]; /**< Level when joystick is to the positive side. */ 00608 Uint16 left_sat[3]; /**< Level when joystick is to the negative side. */ 00609 Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */ 00610 Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */ 00611 Uint16 deadband[3]; /**< Size of the dead zone. */ 00612 Sint16 center[3]; /**< Position of the dead zone. */ 00613 } SDL_HapticCondition; 00614 00615 /** 00616 * \brief A structure containing a template for a Ramp effect. 00617 * 00618 * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect. 00619 * 00620 * The ramp effect starts at start strength and ends at end strength. 00621 * It augments in linear fashion. If you use attack and fade with a ramp 00622 * the effects get added to the ramp effect making the effect become 00623 * quadratic instead of linear. 00624 * 00625 * \sa SDL_HAPTIC_RAMP 00626 * \sa SDL_HapticEffect 00627 */ 00628 typedef struct SDL_HapticRamp 00629 { 00630 /* Header */ 00631 Uint16 type; /**< ::SDL_HAPTIC_RAMP */ 00632 SDL_HapticDirection direction; /**< Direction of the effect. */ 00633 00634 /* Replay */ 00635 Uint32 length; /**< Duration of the effect. */ 00636 Uint16 delay; /**< Delay before starting the effect. */ 00637 00638 /* Trigger */ 00639 Uint16 button; /**< Button that triggers the effect. */ 00640 Uint16 interval; /**< How soon it can be triggered again after button. */ 00641 00642 /* Ramp */ 00643 Sint16 start; /**< Beginning strength level. */ 00644 Sint16 end; /**< Ending strength level. */ 00645 00646 /* Envelope */ 00647 Uint16 attack_length; /**< Duration of the attack. */ 00648 Uint16 attack_level; /**< Level at the start of the attack. */ 00649 Uint16 fade_length; /**< Duration of the fade. */ 00650 Uint16 fade_level; /**< Level at the end of the fade. */ 00651 } SDL_HapticRamp; 00652 00653 /** 00654 * \brief A structure containing a template for a Left/Right effect. 00655 * 00656 * This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect. 00657 * 00658 * The Left/Right effect is used to explicitly control the large and small 00659 * motors, commonly found in modern game controllers. One motor is high 00660 * frequency, the other is low frequency. 00661 * 00662 * \sa SDL_HAPTIC_LEFTRIGHT 00663 * \sa SDL_HapticEffect 00664 */ 00665 typedef struct SDL_HapticLeftRight 00666 { 00667 /* Header */ 00668 Uint16 type; /**< ::SDL_HAPTIC_LEFTRIGHT */ 00669 00670 /* Replay */ 00671 Uint32 length; /**< Duration of the effect. */ 00672 00673 /* Rumble */ 00674 Uint16 large_magnitude; /**< Control of the large controller motor. */ 00675 Uint16 small_magnitude; /**< Control of the small controller motor. */ 00676 } SDL_HapticLeftRight; 00677 00678 /** 00679 * \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect. 00680 * 00681 * A custom force feedback effect is much like a periodic effect, where the 00682 * application can define its exact shape. You will have to allocate the 00683 * data yourself. Data should consist of channels * samples Uint16 samples. 00684 * 00685 * If channels is one, the effect is rotated using the defined direction. 00686 * Otherwise it uses the samples in data for the different axes. 00687 * 00688 * \sa SDL_HAPTIC_CUSTOM 00689 * \sa SDL_HapticEffect 00690 */ 00691 typedef struct SDL_HapticCustom 00692 { 00693 /* Header */ 00694 Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */ 00695 SDL_HapticDirection direction; /**< Direction of the effect. */ 00696 00697 /* Replay */ 00698 Uint32 length; /**< Duration of the effect. */ 00699 Uint16 delay; /**< Delay before starting the effect. */ 00700 00701 /* Trigger */ 00702 Uint16 button; /**< Button that triggers the effect. */ 00703 Uint16 interval; /**< How soon it can be triggered again after button. */ 00704 00705 /* Custom */ 00706 Uint8 channels; /**< Axes to use, minimum of one. */ 00707 Uint16 period; /**< Sample periods. */ 00708 Uint16 samples; /**< Amount of samples. */ 00709 Uint16 *data; /**< Should contain channels*samples items. */ 00710 00711 /* Envelope */ 00712 Uint16 attack_length; /**< Duration of the attack. */ 00713 Uint16 attack_level; /**< Level at the start of the attack. */ 00714 Uint16 fade_length; /**< Duration of the fade. */ 00715 Uint16 fade_level; /**< Level at the end of the fade. */ 00716 } SDL_HapticCustom; 00717 00718 /** 00719 * \brief The generic template for any haptic effect. 00720 * 00721 * All values max at 32767 (0x7FFF). Signed values also can be negative. 00722 * Time values unless specified otherwise are in milliseconds. 00723 * 00724 * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767 00725 * value. Neither delay, interval, attack_length nor fade_length support 00726 * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends. 00727 * 00728 * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of 00729 * ::SDL_HAPTIC_INFINITY. 00730 * 00731 * Button triggers may not be supported on all devices, it is advised to not 00732 * use them if possible. Buttons start at index 1 instead of index 0 like 00733 * the joystick. 00734 * 00735 * If both attack_length and fade_level are 0, the envelope is not used, 00736 * otherwise both values are used. 00737 * 00738 * Common parts: 00739 * \code 00740 * // Replay - All effects have this 00741 * Uint32 length; // Duration of effect (ms). 00742 * Uint16 delay; // Delay before starting effect. 00743 * 00744 * // Trigger - All effects have this 00745 * Uint16 button; // Button that triggers effect. 00746 * Uint16 interval; // How soon before effect can be triggered again. 00747 * 00748 * // Envelope - All effects except condition effects have this 00749 * Uint16 attack_length; // Duration of the attack (ms). 00750 * Uint16 attack_level; // Level at the start of the attack. 00751 * Uint16 fade_length; // Duration of the fade out (ms). 00752 * Uint16 fade_level; // Level at the end of the fade. 00753 * \endcode 00754 * 00755 * 00756 * Here we have an example of a constant effect evolution in time: 00757 * \verbatim 00758 Strength 00759 ^ 00760 | 00761 | effect level --> _________________ 00762 | / \ 00763 | / \ 00764 | / \ 00765 | / \ 00766 | attack_level --> | \ 00767 | | | <--- fade_level 00768 | 00769 +--------------------------------------------------> Time 00770 [--] [---] 00771 attack_length fade_length 00772 00773 [------------------][-----------------------] 00774 delay length 00775 \endverbatim 00776 * 00777 * Note either the attack_level or the fade_level may be above the actual 00778 * effect level. 00779 * 00780 * \sa SDL_HapticConstant 00781 * \sa SDL_HapticPeriodic 00782 * \sa SDL_HapticCondition 00783 * \sa SDL_HapticRamp 00784 * \sa SDL_HapticLeftRight 00785 * \sa SDL_HapticCustom 00786 */ 00787 typedef union SDL_HapticEffect 00788 { 00789 /* Common for all force feedback effects */ 00790 Uint16 type; /**< Effect type. */ 00791 SDL_HapticConstant constant; /**< Constant effect. */ 00792 SDL_HapticPeriodic periodic; /**< Periodic effect. */ 00793 SDL_HapticCondition condition; /**< Condition effect. */ 00794 SDL_HapticRamp ramp; /**< Ramp effect. */ 00795 SDL_HapticLeftRight leftright; /**< Left/Right effect. */ 00796 SDL_HapticCustom custom; /**< Custom effect. */ 00797 } SDL_HapticEffect; 00798 00799 00800 /* Function prototypes */ 00801 /** 00802 * \brief Count the number of haptic devices attached to the system. 00803 * 00804 * \return Number of haptic devices detected on the system. 00805 */ 00806 extern DECLSPEC int SDLCALL SDL_NumHaptics(void); 00807 00808 /** 00809 * \brief Get the implementation dependent name of a Haptic device. 00810 * 00811 * This can be called before any joysticks are opened. 00812 * If no name can be found, this function returns NULL. 00813 * 00814 * \param device_index Index of the device to get its name. 00815 * \return Name of the device or NULL on error. 00816 * 00817 * \sa SDL_NumHaptics 00818 */ 00819 extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index); 00820 00821 /** 00822 * \brief Opens a Haptic device for usage. 00823 * 00824 * The index passed as an argument refers to the N'th Haptic device on this 00825 * system. 00826 * 00827 * When opening a haptic device, its gain will be set to maximum and 00828 * autocenter will be disabled. To modify these values use 00829 * SDL_HapticSetGain() and SDL_HapticSetAutocenter(). 00830 * 00831 * \param device_index Index of the device to open. 00832 * \return Device identifier or NULL on error. 00833 * 00834 * \sa SDL_HapticIndex 00835 * \sa SDL_HapticOpenFromMouse 00836 * \sa SDL_HapticOpenFromJoystick 00837 * \sa SDL_HapticClose 00838 * \sa SDL_HapticSetGain 00839 * \sa SDL_HapticSetAutocenter 00840 * \sa SDL_HapticPause 00841 * \sa SDL_HapticStopAll 00842 */ 00843 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index); 00844 00845 /** 00846 * \brief Checks if the haptic device at index has been opened. 00847 * 00848 * \param device_index Index to check to see if it has been opened. 00849 * \return 1 if it has been opened or 0 if it hasn't. 00850 * 00851 * \sa SDL_HapticOpen 00852 * \sa SDL_HapticIndex 00853 */ 00854 extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index); 00855 00856 /** 00857 * \brief Gets the index of a haptic device. 00858 * 00859 * \param haptic Haptic device to get the index of. 00860 * \return The index of the haptic device or -1 on error. 00861 * 00862 * \sa SDL_HapticOpen 00863 * \sa SDL_HapticOpened 00864 */ 00865 extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic); 00866 00867 /** 00868 * \brief Gets whether or not the current mouse has haptic capabilities. 00869 * 00870 * \return SDL_TRUE if the mouse is haptic, SDL_FALSE if it isn't. 00871 * 00872 * \sa SDL_HapticOpenFromMouse 00873 */ 00874 extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void); 00875 00876 /** 00877 * \brief Tries to open a haptic device from the current mouse. 00878 * 00879 * \return The haptic device identifier or NULL on error. 00880 * 00881 * \sa SDL_MouseIsHaptic 00882 * \sa SDL_HapticOpen 00883 */ 00884 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void); 00885 00886 /** 00887 * \brief Checks to see if a joystick has haptic features. 00888 * 00889 * \param joystick Joystick to test for haptic capabilities. 00890 * \return 1 if the joystick is haptic, 0 if it isn't 00891 * or -1 if an error ocurred. 00892 * 00893 * \sa SDL_HapticOpenFromJoystick 00894 */ 00895 extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick); 00896 00897 /** 00898 * \brief Opens a Haptic device for usage from a Joystick device. 00899 * 00900 * You must still close the haptic device seperately. It will not be closed 00901 * with the joystick. 00902 * 00903 * When opening from a joystick you should first close the haptic device before 00904 * closing the joystick device. If not, on some implementations the haptic 00905 * device will also get unallocated and you'll be unable to use force feedback 00906 * on that device. 00907 * 00908 * \param joystick Joystick to create a haptic device from. 00909 * \return A valid haptic device identifier on success or NULL on error. 00910 * 00911 * \sa SDL_HapticOpen 00912 * \sa SDL_HapticClose 00913 */ 00914 extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick * 00915 joystick); 00916 00917 /** 00918 * \brief Closes a Haptic device previously opened with SDL_HapticOpen(). 00919 * 00920 * \param haptic Haptic device to close. 00921 */ 00922 extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic); 00923 00924 /** 00925 * \brief Returns the number of effects a haptic device can store. 00926 * 00927 * On some platforms this isn't fully supported, and therefore is an 00928 * approximation. Always check to see if your created effect was actually 00929 * created and do not rely solely on SDL_HapticNumEffects(). 00930 * 00931 * \param haptic The haptic device to query effect max. 00932 * \return The number of effects the haptic device can store or 00933 * -1 on error. 00934 * 00935 * \sa SDL_HapticNumEffectsPlaying 00936 * \sa SDL_HapticQuery 00937 */ 00938 extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic); 00939 00940 /** 00941 * \brief Returns the number of effects a haptic device can play at the same 00942 * time. 00943 * 00944 * This is not supported on all platforms, but will always return a value. 00945 * Added here for the sake of completeness. 00946 * 00947 * \param haptic The haptic device to query maximum playing effects. 00948 * \return The number of effects the haptic device can play at the same time 00949 * or -1 on error. 00950 * 00951 * \sa SDL_HapticNumEffects 00952 * \sa SDL_HapticQuery 00953 */ 00954 extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic); 00955 00956 /** 00957 * \brief Gets the haptic devices supported features in bitwise matter. 00958 * 00959 * Example: 00960 * \code 00961 * if (SDL_HapticQuery(haptic) & SDL_HAPTIC_CONSTANT) { 00962 * printf("We have constant haptic effect!"); 00963 * } 00964 * \endcode 00965 * 00966 * \param haptic The haptic device to query. 00967 * \return Haptic features in bitwise manner (OR'd). 00968 * 00969 * \sa SDL_HapticNumEffects 00970 * \sa SDL_HapticEffectSupported 00971 */ 00972 extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic); 00973 00974 00975 /** 00976 * \brief Gets the number of haptic axes the device has. 00977 * 00978 * \sa SDL_HapticDirection 00979 */ 00980 extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic); 00981 00982 /** 00983 * \brief Checks to see if effect is supported by haptic. 00984 * 00985 * \param haptic Haptic device to check on. 00986 * \param effect Effect to check to see if it is supported. 00987 * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error. 00988 * 00989 * \sa SDL_HapticQuery 00990 * \sa SDL_HapticNewEffect 00991 */ 00992 extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic, 00993 SDL_HapticEffect * 00994 effect); 00995 00996 /** 00997 * \brief Creates a new haptic effect on the device. 00998 * 00999 * \param haptic Haptic device to create the effect on. 01000 * \param effect Properties of the effect to create. 01001 * \return The id of the effect on success or -1 on error. 01002 * 01003 * \sa SDL_HapticUpdateEffect 01004 * \sa SDL_HapticRunEffect 01005 * \sa SDL_HapticDestroyEffect 01006 */ 01007 extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic, 01008 SDL_HapticEffect * effect); 01009 01010 /** 01011 * \brief Updates the properties of an effect. 01012 * 01013 * Can be used dynamically, although behaviour when dynamically changing 01014 * direction may be strange. Specifically the effect may reupload itself 01015 * and start playing from the start. You cannot change the type either when 01016 * running SDL_HapticUpdateEffect(). 01017 * 01018 * \param haptic Haptic device that has the effect. 01019 * \param effect Effect to update. 01020 * \param data New effect properties to use. 01021 * \return 0 on success or -1 on error. 01022 * 01023 * \sa SDL_HapticNewEffect 01024 * \sa SDL_HapticRunEffect 01025 * \sa SDL_HapticDestroyEffect 01026 */ 01027 extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic, 01028 int effect, 01029 SDL_HapticEffect * data); 01030 01031 /** 01032 * \brief Runs the haptic effect on its associated haptic device. 01033 * 01034 * If iterations are ::SDL_HAPTIC_INFINITY, it'll run the effect over and over 01035 * repeating the envelope (attack and fade) every time. If you only want the 01036 * effect to last forever, set ::SDL_HAPTIC_INFINITY in the effect's length 01037 * parameter. 01038 * 01039 * \param haptic Haptic device to run the effect on. 01040 * \param effect Identifier of the haptic effect to run. 01041 * \param iterations Number of iterations to run the effect. Use 01042 * ::SDL_HAPTIC_INFINITY for infinity. 01043 * \return 0 on success or -1 on error. 01044 * 01045 * \sa SDL_HapticStopEffect 01046 * \sa SDL_HapticDestroyEffect 01047 * \sa SDL_HapticGetEffectStatus 01048 */ 01049 extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic, 01050 int effect, 01051 Uint32 iterations); 01052 01053 /** 01054 * \brief Stops the haptic effect on its associated haptic device. 01055 * 01056 * \param haptic Haptic device to stop the effect on. 01057 * \param effect Identifier of the effect to stop. 01058 * \return 0 on success or -1 on error. 01059 * 01060 * \sa SDL_HapticRunEffect 01061 * \sa SDL_HapticDestroyEffect 01062 */ 01063 extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic, 01064 int effect); 01065 01066 /** 01067 * \brief Destroys a haptic effect on the device. 01068 * 01069 * This will stop the effect if it's running. Effects are automatically 01070 * destroyed when the device is closed. 01071 * 01072 * \param haptic Device to destroy the effect on. 01073 * \param effect Identifier of the effect to destroy. 01074 * 01075 * \sa SDL_HapticNewEffect 01076 */ 01077 extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic, 01078 int effect); 01079 01080 /** 01081 * \brief Gets the status of the current effect on the haptic device. 01082 * 01083 * Device must support the ::SDL_HAPTIC_STATUS feature. 01084 * 01085 * \param haptic Haptic device to query the effect status on. 01086 * \param effect Identifier of the effect to query its status. 01087 * \return 0 if it isn't playing, 1 if it is playing or -1 on error. 01088 * 01089 * \sa SDL_HapticRunEffect 01090 * \sa SDL_HapticStopEffect 01091 */ 01092 extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic, 01093 int effect); 01094 01095 /** 01096 * \brief Sets the global gain of the device. 01097 * 01098 * Device must support the ::SDL_HAPTIC_GAIN feature. 01099 * 01100 * The user may specify the maximum gain by setting the environment variable 01101 * SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to 01102 * SDL_HapticSetGain() will scale linearly using SDL_HAPTIC_GAIN_MAX as the 01103 * maximum. 01104 * 01105 * \param haptic Haptic device to set the gain on. 01106 * \param gain Value to set the gain to, should be between 0 and 100. 01107 * \return 0 on success or -1 on error. 01108 * 01109 * \sa SDL_HapticQuery 01110 */ 01111 extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain); 01112 01113 /** 01114 * \brief Sets the global autocenter of the device. 01115 * 01116 * Autocenter should be between 0 and 100. Setting it to 0 will disable 01117 * autocentering. 01118 * 01119 * Device must support the ::SDL_HAPTIC_AUTOCENTER feature. 01120 * 01121 * \param haptic Haptic device to set autocentering on. 01122 * \param autocenter Value to set autocenter to, 0 disables autocentering. 01123 * \return 0 on success or -1 on error. 01124 * 01125 * \sa SDL_HapticQuery 01126 */ 01127 extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic, 01128 int autocenter); 01129 01130 /** 01131 * \brief Pauses a haptic device. 01132 * 01133 * Device must support the ::SDL_HAPTIC_PAUSE feature. Call 01134 * SDL_HapticUnpause() to resume playback. 01135 * 01136 * Do not modify the effects nor add new ones while the device is paused. 01137 * That can cause all sorts of weird errors. 01138 * 01139 * \param haptic Haptic device to pause. 01140 * \return 0 on success or -1 on error. 01141 * 01142 * \sa SDL_HapticUnpause 01143 */ 01144 extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic); 01145 01146 /** 01147 * \brief Unpauses a haptic device. 01148 * 01149 * Call to unpause after SDL_HapticPause(). 01150 * 01151 * \param haptic Haptic device to pause. 01152 * \return 0 on success or -1 on error. 01153 * 01154 * \sa SDL_HapticPause 01155 */ 01156 extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic); 01157 01158 /** 01159 * \brief Stops all the currently playing effects on a haptic device. 01160 * 01161 * \param haptic Haptic device to stop. 01162 * \return 0 on success or -1 on error. 01163 */ 01164 extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic); 01165 01166 /** 01167 * \brief Checks to see if rumble is supported on a haptic device. 01168 * 01169 * \param haptic Haptic device to check to see if it supports rumble. 01170 * \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error. 01171 * 01172 * \sa SDL_HapticRumbleInit 01173 * \sa SDL_HapticRumblePlay 01174 * \sa SDL_HapticRumbleStop 01175 */ 01176 extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic); 01177 01178 /** 01179 * \brief Initializes the haptic device for simple rumble playback. 01180 * 01181 * \param haptic Haptic device to initialize for simple rumble playback. 01182 * \return 0 on success or -1 on error. 01183 * 01184 * \sa SDL_HapticOpen 01185 * \sa SDL_HapticRumbleSupported 01186 * \sa SDL_HapticRumblePlay 01187 * \sa SDL_HapticRumbleStop 01188 */ 01189 extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic); 01190 01191 /** 01192 * \brief Runs simple rumble on a haptic device 01193 * 01194 * \param haptic Haptic device to play rumble effect on. 01195 * \param strength Strength of the rumble to play as a 0-1 float value. 01196 * \param length Length of the rumble to play in milliseconds. 01197 * \return 0 on success or -1 on error. 01198 * 01199 * \sa SDL_HapticRumbleSupported 01200 * \sa SDL_HapticRumbleInit 01201 * \sa SDL_HapticRumbleStop 01202 */ 01203 extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length ); 01204 01205 /** 01206 * \brief Stops the simple rumble on a haptic device. 01207 * 01208 * \param haptic Haptic to stop the rumble on. 01209 * \return 0 on success or -1 on error. 01210 * 01211 * \sa SDL_HapticRumbleSupported 01212 * \sa SDL_HapticRumbleInit 01213 * \sa SDL_HapticRumblePlay 01214 */ 01215 extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic); 01216 01217 /* Ends C function definitions when using C++ */ 01218 #ifdef __cplusplus 01219 } 01220 #endif 01221 #include "close_code.h" 01222 01223 #endif /* _SDL_haptic_h */ 01224 01225 /* vi: set ts=4 sw=4 expandtab: */
Generated on Tue Jul 12 2022 15:10:18 by 1.7.2