Path: blob/main/system/include/SDL/SDL_haptic.h
6169 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2011 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* \file SDL_haptic.h23*24* \brief The SDL Haptic subsystem allows you to control haptic (force feedback)25* devices.26*27* The basic usage is as follows:28* - Initialize the Subsystem (::SDL_INIT_HAPTIC).29* - Open a Haptic Device.30* - SDL_HapticOpen() to open from index.31* - SDL_HapticOpenFromJoystick() to open from an existing joystick.32* - Create an effect (::SDL_HapticEffect).33* - Upload the effect with SDL_HapticNewEffect().34* - Run the effect with SDL_HapticRunEffect().35* - (optional) Free the effect with SDL_HapticDestroyEffect().36* - Close the haptic device with SDL_HapticClose().37*38* \par Simple rumble example:39* \code40* SDL_Haptic *haptic;41*42* // Open the device43* haptic = SDL_HapticOpen( 0 );44* if (haptic == NULL)45* return -1;46*47* // Initialize simple rumble48* if (SDL_HapticRumbleInit( haptic ) != 0)49* return -1;50*51* // Play effect at 50% strength for 2 seconds52* if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0)53* return -1;54* SDL_Delay( 2000 );55*56* // Clean up57* SDL_HapticClose( haptic );58* \endcode59*60* \par Complete example:61* \code62* int test_haptic( SDL_Joystick * joystick ) {63* SDL_Haptic *haptic;64* SDL_HapticEffect effect;65* int effect_id;66*67* // Open the device68* haptic = SDL_HapticOpenFromJoystick( joystick );69* if (haptic == NULL) return -1; // Most likely joystick isn't haptic70*71* // See if it can do sine waves72* if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) {73* SDL_HapticClose(haptic); // No sine effect74* return -1;75* }76*77* // Create the effect78* memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default79* effect.type = SDL_HAPTIC_SINE;80* effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates81* effect.periodic.direction.dir[0] = 18000; // Force comes from south82* effect.periodic.period = 1000; // 1000 ms83* effect.periodic.magnitude = 20000; // 20000/32767 strength84* effect.periodic.length = 5000; // 5 seconds long85* effect.periodic.attack_length = 1000; // Takes 1 second to get max strength86* effect.periodic.fade_length = 1000; // Takes 1 second to fade away87*88* // Upload the effect89* effect_id = SDL_HapticNewEffect( haptic, &effect );90*91* // Test the effect92* SDL_HapticRunEffect( haptic, effect_id, 1 );93* SDL_Delay( 5000); // Wait for the effect to finish94*95* // We destroy the effect, although closing the device also does this96* SDL_HapticDestroyEffect( haptic, effect_id );97*98* // Close the device99* SDL_HapticClose(haptic);100*101* return 0; // Success102* }103* \endcode104*105* You can also find out more information on my blog:106* http://bobbens.dyndns.org/journal/2010/sdl_haptic/107*108* \author Edgar Simo Serra109*/110111#ifndef _SDL_haptic_h112#define _SDL_haptic_h113114#include "SDL_stdinc.h"115#include "SDL_error.h"116#include "SDL_joystick.h"117118#include "begin_code.h"119/* Set up for C function definitions, even when using C++ */120#ifdef __cplusplus121/* *INDENT-OFF* */122extern "C" {123/* *INDENT-ON* */124#endif /* __cplusplus */125126/**127* \typedef SDL_Haptic128*129* \brief The haptic structure used to identify an SDL haptic.130*131* \sa SDL_HapticOpen132* \sa SDL_HapticOpenFromJoystick133* \sa SDL_HapticClose134*/135struct _SDL_Haptic;136typedef struct _SDL_Haptic SDL_Haptic;137138139/**140* \name Haptic features141*142* Different haptic features a device can have.143*/144/*@{*/145146/**147* \name Haptic effects148*/149/*@{*/150151/**152* \brief Constant effect supported.153*154* Constant haptic effect.155*156* \sa SDL_HapticCondition157*/158#define SDL_HAPTIC_CONSTANT (1<<0)159160/**161* \brief Sine wave effect supported.162*163* Periodic haptic effect that simulates sine waves.164*165* \sa SDL_HapticPeriodic166*/167#define SDL_HAPTIC_SINE (1<<1)168169/**170* \brief Square wave effect supported.171*172* Periodic haptic effect that simulates square waves.173*174* \sa SDL_HapticPeriodic175*/176#define SDL_HAPTIC_SQUARE (1<<2)177178/**179* \brief Triangle wave effect supported.180*181* Periodic haptic effect that simulates triangular waves.182*183* \sa SDL_HapticPeriodic184*/185#define SDL_HAPTIC_TRIANGLE (1<<3)186187/**188* \brief Sawtoothup wave effect supported.189*190* Periodic haptic effect that simulates saw tooth up waves.191*192* \sa SDL_HapticPeriodic193*/194#define SDL_HAPTIC_SAWTOOTHUP (1<<4)195196/**197* \brief Sawtoothdown wave effect supported.198*199* Periodic haptic effect that simulates saw tooth down waves.200*201* \sa SDL_HapticPeriodic202*/203#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5)204205/**206* \brief Ramp effect supported.207*208* Ramp haptic effect.209*210* \sa SDL_HapticRamp211*/212#define SDL_HAPTIC_RAMP (1<<6)213214/**215* \brief Spring effect supported - uses axes position.216*217* Condition haptic effect that simulates a spring. Effect is based on the218* axes position.219*220* \sa SDL_HapticCondition221*/222#define SDL_HAPTIC_SPRING (1<<7)223224/**225* \brief Damper effect supported - uses axes velocity.226*227* Condition haptic effect that simulates dampening. Effect is based on the228* axes velocity.229*230* \sa SDL_HapticCondition231*/232#define SDL_HAPTIC_DAMPER (1<<8)233234/**235* \brief Inertia effect supported - uses axes acceleration.236*237* Condition haptic effect that simulates inertia. Effect is based on the axes238* acceleration.239*240* \sa SDL_HapticCondition241*/242#define SDL_HAPTIC_INERTIA (1<<9)243244/**245* \brief Friction effect supported - uses axes movement.246*247* Condition haptic effect that simulates friction. Effect is based on the248* axes movement.249*250* \sa SDL_HapticCondition251*/252#define SDL_HAPTIC_FRICTION (1<<10)253254/**255* \brief Custom effect is supported.256*257* User defined custom haptic effect.258*/259#define SDL_HAPTIC_CUSTOM (1<<11)260261/*@}*//*Haptic effects*/262263/* These last few are features the device has, not effects */264265/**266* \brief Device can set global gain.267*268* Device supports setting the global gain.269*270* \sa SDL_HapticSetGain271*/272#define SDL_HAPTIC_GAIN (1<<12)273274/**275* \brief Device can set autocenter.276*277* Device supports setting autocenter.278*279* \sa SDL_HapticSetAutocenter280*/281#define SDL_HAPTIC_AUTOCENTER (1<<13)282283/**284* \brief Device can be queried for effect status.285*286* Device can be queried for effect status.287*288* \sa SDL_HapticGetEffectStatus289*/290#define SDL_HAPTIC_STATUS (1<<14)291292/**293* \brief Device can be paused.294*295* \sa SDL_HapticPause296* \sa SDL_HapticUnpause297*/298#define SDL_HAPTIC_PAUSE (1<<15)299300301/**302* \name Direction encodings303*/304/*@{*/305306/**307* \brief Uses polar coordinates for the direction.308*309* \sa SDL_HapticDirection310*/311#define SDL_HAPTIC_POLAR 0312313/**314* \brief Uses cartesian coordinates for the direction.315*316* \sa SDL_HapticDirection317*/318#define SDL_HAPTIC_CARTESIAN 1319320/**321* \brief Uses spherical coordinates for the direction.322*323* \sa SDL_HapticDirection324*/325#define SDL_HAPTIC_SPHERICAL 2326327/*@}*//*Direction encodings*/328329/*@}*//*Haptic features*/330331/*332* Misc defines.333*/334335/**336* \brief Used to play a device an infinite number of times.337*338* \sa SDL_HapticRunEffect339*/340#define SDL_HAPTIC_INFINITY 4294967295U341342343/**344* \brief Structure that represents a haptic direction.345*346* Directions can be specified by:347* - ::SDL_HAPTIC_POLAR : Specified by polar coordinates.348* - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.349* - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.350*351* Cardinal directions of the haptic device are relative to the positioning352* of the device. North is considered to be away from the user.353*354* The following diagram represents the cardinal directions:355* \verbatim356.--.357|__| .-------.358|=.| |.-----.|359|--| || ||360| | |'-----'|361|__|~')_____('362[ COMPUTER ]363364365North (0,-1)366^367|368|369(1,0) West <----[ HAPTIC ]----> East (-1,0)370|371|372v373South (0,1)374375376[ USER ]377\|||/378(o o)379---ooO-(_)-Ooo---380\endverbatim381*382* If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a383* degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses384* the first \c dir parameter. The cardinal directions would be:385* - North: 0 (0 degrees)386* - East: 9000 (90 degrees)387* - South: 18000 (180 degrees)388* - West: 27000 (270 degrees)389*390* If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions391* (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses392* the first three \c dir parameters. The cardinal directions would be:393* - North: 0,-1, 0394* - East: -1, 0, 0395* - South: 0, 1, 0396* - West: 1, 0, 0397*398* The Z axis represents the height of the effect if supported, otherwise399* it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you400* can use any multiple you want, only the direction matters.401*402* If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations.403* The first two \c dir parameters are used. The \c dir parameters are as404* follows (all values are in hundredths of degrees):405* - Degrees from (1, 0) rotated towards (0, 1).406* - Degrees towards (0, 0, 1) (device needs at least 3 axes).407*408*409* Example of force coming from the south with all encodings (force coming410* from the south means the user will have to pull the stick to counteract):411* \code412* SDL_HapticDirection direction;413*414* // Cartesian directions415* direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.416* direction.dir[0] = 0; // X position417* direction.dir[1] = 1; // Y position418* // Assuming the device has 2 axes, we don't need to specify third parameter.419*420* // Polar directions421* direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.422* direction.dir[0] = 18000; // Polar only uses first parameter423*424* // Spherical coordinates425* direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding426* direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.427* \endcode428*429* \sa SDL_HAPTIC_POLAR430* \sa SDL_HAPTIC_CARTESIAN431* \sa SDL_HAPTIC_SPHERICAL432* \sa SDL_HapticEffect433* \sa SDL_HapticNumAxes434*/435typedef struct SDL_HapticDirection436{437Uint8 type; /**< The type of encoding. */438Sint32 dir[3]; /**< The encoded direction. */439} SDL_HapticDirection;440441442/**443* \brief A structure containing a template for a Constant effect.444*445* The struct is exclusive to the ::SDL_HAPTIC_CONSTANT effect.446*447* A constant effect applies a constant force in the specified direction448* to the joystick.449*450* \sa SDL_HAPTIC_CONSTANT451* \sa SDL_HapticEffect452*/453typedef struct SDL_HapticConstant454{455/* Header */456Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */457SDL_HapticDirection direction; /**< Direction of the effect. */458459/* Replay */460Uint32 length; /**< Duration of the effect. */461Uint16 delay; /**< Delay before starting the effect. */462463/* Trigger */464Uint16 button; /**< Button that triggers the effect. */465Uint16 interval; /**< How soon it can be triggered again after button. */466467/* Constant */468Sint16 level; /**< Strength of the constant effect. */469470/* Envelope */471Uint16 attack_length; /**< Duration of the attack. */472Uint16 attack_level; /**< Level at the start of the attack. */473Uint16 fade_length; /**< Duration of the fade. */474Uint16 fade_level; /**< Level at the end of the fade. */475} SDL_HapticConstant;476477/**478* \brief A structure containing a template for a Periodic effect.479*480* The struct handles the following effects:481* - ::SDL_HAPTIC_SINE482* - ::SDL_HAPTIC_SQUARE483* - ::SDL_HAPTIC_TRIANGLE484* - ::SDL_HAPTIC_SAWTOOTHUP485* - ::SDL_HAPTIC_SAWTOOTHDOWN486*487* A periodic effect consists in a wave-shaped effect that repeats itself488* over time. The type determines the shape of the wave and the parameters489* determine the dimensions of the wave.490*491* Phase is given by hundredth of a cyle meaning that giving the phase a value492* of 9000 will displace it 25% of it's period. Here are sample values:493* - 0: No phase displacement.494* - 9000: Displaced 25% of it's period.495* - 18000: Displaced 50% of it's period.496* - 27000: Displaced 75% of it's period.497* - 36000: Displaced 100% of it's period, same as 0, but 0 is preffered.498*499* Examples:500* \verbatim501SDL_HAPTIC_SINE502__ __ __ __503/ \ / \ / \ /504/ \__/ \__/ \__/505506SDL_HAPTIC_SQUARE507__ __ __ __ __508| | | | | | | | | |509| |__| |__| |__| |__| |510511SDL_HAPTIC_TRIANGLE512/\ /\ /\ /\ /\513/ \ / \ / \ / \ /514/ \/ \/ \/ \/515516SDL_HAPTIC_SAWTOOTHUP517/| /| /| /| /| /| /|518/ | / | / | / | / | / | / |519/ |/ |/ |/ |/ |/ |/ |520521SDL_HAPTIC_SAWTOOTHDOWN522\ |\ |\ |\ |\ |\ |\ |523\ | \ | \ | \ | \ | \ | \ |524\| \| \| \| \| \| \|525\endverbatim526*527* \sa SDL_HAPTIC_SINE528* \sa SDL_HAPTIC_SQUARE529* \sa SDL_HAPTIC_TRIANGLE530* \sa SDL_HAPTIC_SAWTOOTHUP531* \sa SDL_HAPTIC_SAWTOOTHDOWN532* \sa SDL_HapticEffect533*/534typedef struct SDL_HapticPeriodic535{536/* Header */537Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_SQUARE,538::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or539::SDL_HAPTIC_SAWTOOTHDOWN */540SDL_HapticDirection direction; /**< Direction of the effect. */541542/* Replay */543Uint32 length; /**< Duration of the effect. */544Uint16 delay; /**< Delay before starting the effect. */545546/* Trigger */547Uint16 button; /**< Button that triggers the effect. */548Uint16 interval; /**< How soon it can be triggered again after button. */549550/* Periodic */551Uint16 period; /**< Period of the wave. */552Sint16 magnitude; /**< Peak value. */553Sint16 offset; /**< Mean value of the wave. */554Uint16 phase; /**< Horizontal shift given by hundredth of a cycle. */555556/* Envelope */557Uint16 attack_length; /**< Duration of the attack. */558Uint16 attack_level; /**< Level at the start of the attack. */559Uint16 fade_length; /**< Duration of the fade. */560Uint16 fade_level; /**< Level at the end of the fade. */561} SDL_HapticPeriodic;562563/**564* \brief A structure containing a template for a Condition effect.565*566* The struct handles the following effects:567* - ::SDL_HAPTIC_SPRING: Effect based on axes position.568* - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity.569* - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration.570* - ::SDL_HAPTIC_FRICTION: Effect based on axes movement.571*572* Direction is handled by condition internals instead of a direction member.573* The condition effect specific members have three parameters. The first574* refers to the X axis, the second refers to the Y axis and the third575* refers to the Z axis. The right terms refer to the positive side of the576* axis and the left terms refer to the negative side of the axis. Please577* refer to the ::SDL_HapticDirection diagram for which side is positive and578* which is negative.579*580* \sa SDL_HapticDirection581* \sa SDL_HAPTIC_SPRING582* \sa SDL_HAPTIC_DAMPER583* \sa SDL_HAPTIC_INERTIA584* \sa SDL_HAPTIC_FRICTION585* \sa SDL_HapticEffect586*/587typedef struct SDL_HapticCondition588{589/* Header */590Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER,591::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */592SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */593594/* Replay */595Uint32 length; /**< Duration of the effect. */596Uint16 delay; /**< Delay before starting the effect. */597598/* Trigger */599Uint16 button; /**< Button that triggers the effect. */600Uint16 interval; /**< How soon it can be triggered again after button. */601602/* Condition */603Uint16 right_sat[3]; /**< Level when joystick is to the positive side. */604Uint16 left_sat[3]; /**< Level when joystick is to the negative side. */605Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */606Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */607Uint16 deadband[3]; /**< Size of the dead zone. */608Sint16 center[3]; /**< Position of the dead zone. */609} SDL_HapticCondition;610611/**612* \brief A structure containing a template for a Ramp effect.613*614* This struct is exclusively for the ::SDL_HAPTIC_RAMP effect.615*616* The ramp effect starts at start strength and ends at end strength.617* It augments in linear fashion. If you use attack and fade with a ramp618* they effects get added to the ramp effect making the effect become619* quadratic instead of linear.620*621* \sa SDL_HAPTIC_RAMP622* \sa SDL_HapticEffect623*/624typedef struct SDL_HapticRamp625{626/* Header */627Uint16 type; /**< ::SDL_HAPTIC_RAMP */628SDL_HapticDirection direction; /**< Direction of the effect. */629630/* Replay */631Uint32 length; /**< Duration of the effect. */632Uint16 delay; /**< Delay before starting the effect. */633634/* Trigger */635Uint16 button; /**< Button that triggers the effect. */636Uint16 interval; /**< How soon it can be triggered again after button. */637638/* Ramp */639Sint16 start; /**< Beginning strength level. */640Sint16 end; /**< Ending strength level. */641642/* Envelope */643Uint16 attack_length; /**< Duration of the attack. */644Uint16 attack_level; /**< Level at the start of the attack. */645Uint16 fade_length; /**< Duration of the fade. */646Uint16 fade_level; /**< Level at the end of the fade. */647} SDL_HapticRamp;648649/**650* \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect.651*652* A custom force feedback effect is much like a periodic effect, where the653* application can define it's exact shape. You will have to allocate the654* data yourself. Data should consist of channels * samples Uint16 samples.655*656* If channels is one, the effect is rotated using the defined direction.657* Otherwise it uses the samples in data for the different axes.658*659* \sa SDL_HAPTIC_CUSTOM660* \sa SDL_HapticEffect661*/662typedef struct SDL_HapticCustom663{664/* Header */665Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */666SDL_HapticDirection direction; /**< Direction of the effect. */667668/* Replay */669Uint32 length; /**< Duration of the effect. */670Uint16 delay; /**< Delay before starting the effect. */671672/* Trigger */673Uint16 button; /**< Button that triggers the effect. */674Uint16 interval; /**< How soon it can be triggered again after button. */675676/* Custom */677Uint8 channels; /**< Axes to use, minimum of one. */678Uint16 period; /**< Sample periods. */679Uint16 samples; /**< Amount of samples. */680Uint16 *data; /**< Should contain channels*samples items. */681682/* Envelope */683Uint16 attack_length; /**< Duration of the attack. */684Uint16 attack_level; /**< Level at the start of the attack. */685Uint16 fade_length; /**< Duration of the fade. */686Uint16 fade_level; /**< Level at the end of the fade. */687} SDL_HapticCustom;688689/**690* \brief The generic template for any haptic effect.691*692* All values max at 32767 (0x7FFF). Signed values also can be negative.693* Time values unless specified otherwise are in milliseconds.694*695* You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767696* value. Neither delay, interval, attack_length nor fade_length support697* ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.698*699* Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of700* ::SDL_HAPTIC_INFINITY.701*702* Button triggers may not be supported on all devices, it is advised to not703* use them if possible. Buttons start at index 1 instead of index 0 like704* they joystick.705*706* If both attack_length and fade_level are 0, the envelope is not used,707* otherwise both values are used.708*709* Common parts:710* \code711* // Replay - All effects have this712* Uint32 length; // Duration of effect (ms).713* Uint16 delay; // Delay before starting effect.714*715* // Trigger - All effects have this716* Uint16 button; // Button that triggers effect.717* Uint16 interval; // How soon before effect can be triggered again.718*719* // Envelope - All effects except condition effects have this720* Uint16 attack_length; // Duration of the attack (ms).721* Uint16 attack_level; // Level at the start of the attack.722* Uint16 fade_length; // Duration of the fade out (ms).723* Uint16 fade_level; // Level at the end of the fade.724* \endcode725*726*727* Here we have an example of a constant effect evolution in time:728* \verbatim729Strength730^731|732| effect level --> _________________733| / \734| / \735| / \736| / \737| attack_level --> | \738| | | <--- fade_level739|740+--------------------------------------------------> Time741[--] [---]742attack_length fade_length743744[------------------][-----------------------]745delay length746\endverbatim747*748* Note either the attack_level or the fade_level may be above the actual749* effect level.750*751* \sa SDL_HapticConstant752* \sa SDL_HapticPeriodic753* \sa SDL_HapticCondition754* \sa SDL_HapticRamp755* \sa SDL_HapticCustom756*/757typedef union SDL_HapticEffect758{759/* Common for all force feedback effects */760Uint16 type; /**< Effect type. */761SDL_HapticConstant constant; /**< Constant effect. */762SDL_HapticPeriodic periodic; /**< Periodic effect. */763SDL_HapticCondition condition; /**< Condition effect. */764SDL_HapticRamp ramp; /**< Ramp effect. */765SDL_HapticCustom custom; /**< Custom effect. */766} SDL_HapticEffect;767768769/* Function prototypes */770/**771* \brief Count the number of joysticks attached to the system.772*773* \return Number of haptic devices detected on the system.774*/775extern DECLSPEC int SDLCALL SDL_NumHaptics(void);776777/**778* \brief Get the implementation dependent name of a Haptic device.779*780* This can be called before any joysticks are opened.781* If no name can be found, this function returns NULL.782*783* \param device_index Index of the device to get it's name.784* \return Name of the device or NULL on error.785*786* \sa SDL_NumHaptics787*/788extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);789790/**791* \brief Opens a Haptic device for usage.792*793* The index passed as an argument refers to the N'th Haptic device on this794* system.795*796* When opening a haptic device, it's gain will be set to maximum and797* autocenter will be disabled. To modify these values use798* SDL_HapticSetGain() and SDL_HapticSetAutocenter().799*800* \param device_index Index of the device to open.801* \return Device identifier or NULL on error.802*803* \sa SDL_HapticIndex804* \sa SDL_HapticOpenFromMouse805* \sa SDL_HapticOpenFromJoystick806* \sa SDL_HapticClose807* \sa SDL_HapticSetGain808* \sa SDL_HapticSetAutocenter809* \sa SDL_HapticPause810* \sa SDL_HapticStopAll811*/812extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);813814/**815* \brief Checks if the haptic device at index has been opened.816*817* \param device_index Index to check to see if it has been opened.818* \return 1 if it has been opened or 0 if it hasn't.819*820* \sa SDL_HapticOpen821* \sa SDL_HapticIndex822*/823extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index);824825/**826* \brief Gets the index of a haptic device.827*828* \param haptic Haptic device to get the index of.829* \return The index of the haptic device or -1 on error.830*831* \sa SDL_HapticOpen832* \sa SDL_HapticOpened833*/834extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic);835836/**837* \brief Gets whether or not the current mouse has haptic capabilities.838*839* \return SDL_TRUE if the mouse is haptic, SDL_FALSE if it isn't.840*841* \sa SDL_HapticOpenFromMouse842*/843extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void);844845/**846* \brief Tries to open a haptic device from the current mouse.847*848* \return The haptic device identifier or NULL on error.849*850* \sa SDL_MouseIsHaptic851* \sa SDL_HapticOpen852*/853extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void);854855/**856* \brief Checks to see if a joystick has haptic features.857*858* \param joystick Joystick to test for haptic capabilities.859* \return 1 if the joystick is haptic, 0 if it isn't860* or -1 if an error ocurred.861*862* \sa SDL_HapticOpenFromJoystick863*/864extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick);865866/**867* \brief Opens a Haptic device for usage from a Joystick device.868*869* You must still close the haptic device seperately. It will not be closed870* with the joystick.871*872* When opening from a joystick you should first close the haptic device before873* closing the joystick device. If not, on some implementations the haptic874* device will also get unallocated and you'll be unable to use force feedback875* on that device.876*877* \param joystick Joystick to create a haptic device from.878* \return A valid haptic device identifier on success or NULL on error.879*880* \sa SDL_HapticOpen881* \sa SDL_HapticClose882*/883extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick *884joystick);885886/**887* \brief Closes a Haptic device previously opened with SDL_HapticOpen().888*889* \param haptic Haptic device to close.890*/891extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic);892893/**894* \brief Returns the number of effects a haptic device can store.895*896* On some platforms this isn't fully supported, and therefore is an897* aproximation. Always check to see if your created effect was actually898* created and do not rely solely on SDL_HapticNumEffects().899*900* \param haptic The haptic device to query effect max.901* \return The number of effects the haptic device can store or902* -1 on error.903*904* \sa SDL_HapticNumEffectsPlaying905* \sa SDL_HapticQuery906*/907extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic);908909/**910* \brief Returns the number of effects a haptic device can play at the same911* time.912*913* This is not supported on all platforms, but will always return a value.914* Added here for the sake of completness.915*916* \param haptic The haptic device to query maximum playing effects.917* \return The number of effects the haptic device can play at the same time918* or -1 on error.919*920* \sa SDL_HapticNumEffects921* \sa SDL_HapticQuery922*/923extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic);924925/**926* \brief Gets the haptic devices supported features in bitwise matter.927*928* Example:929* \code930* if (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT) {931* printf("We have constant haptic effect!");932* }933* \endcode934*935* \param haptic The haptic device to query.936* \return Haptic features in bitwise manner (OR'd).937*938* \sa SDL_HapticNumEffects939* \sa SDL_HapticEffectSupported940*/941extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic);942943944/**945* \brief Gets the number of haptic axes the device has.946*947* \sa SDL_HapticDirection948*/949extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);950951/**952* \brief Checks to see if effect is supported by haptic.953*954* \param haptic Haptic device to check on.955* \param effect Effect to check to see if it is supported.956* \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.957*958* \sa SDL_HapticQuery959* \sa SDL_HapticNewEffect960*/961extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic,962SDL_HapticEffect *963effect);964965/**966* \brief Creates a new haptic effect on the device.967*968* \param haptic Haptic device to create the effect on.969* \param effect Properties of the effect to create.970* \return The id of the effect on success or -1 on error.971*972* \sa SDL_HapticUpdateEffect973* \sa SDL_HapticRunEffect974* \sa SDL_HapticDestroyEffect975*/976extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic,977SDL_HapticEffect * effect);978979/**980* \brief Updates the properties of an effect.981*982* Can be used dynamically, although behaviour when dynamically changing983* direction may be strange. Specifically the effect may reupload itself984* and start playing from the start. You cannot change the type either when985* running SDL_HapticUpdateEffect().986*987* \param haptic Haptic device that has the effect.988* \param effect Effect to update.989* \param data New effect properties to use.990* \return The id of the effect on success or -1 on error.991*992* \sa SDL_HapticNewEffect993* \sa SDL_HapticRunEffect994* \sa SDL_HapticDestroyEffect995*/996extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic,997int effect,998SDL_HapticEffect * data);9991000/**1001* \brief Runs the haptic effect on it's assosciated haptic device.1002*1003* If iterations are ::SDL_HAPTIC_INFINITY, it'll run the effect over and over1004* repeating the envelope (attack and fade) every time. If you only want the1005* effect to last forever, set ::SDL_HAPTIC_INFINITY in the effect's length1006* parameter.1007*1008* \param haptic Haptic device to run the effect on.1009* \param effect Identifier of the haptic effect to run.1010* \param iterations Number of iterations to run the effect. Use1011* ::SDL_HAPTIC_INFINITY for infinity.1012* \return 0 on success or -1 on error.1013*1014* \sa SDL_HapticStopEffect1015* \sa SDL_HapticDestroyEffect1016* \sa SDL_HapticGetEffectStatus1017*/1018extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic,1019int effect,1020Uint32 iterations);10211022/**1023* \brief Stops the haptic effect on it's assosciated haptic device.1024*1025* \param haptic Haptic device to stop the effect on.1026* \param effect Identifier of the effect to stop.1027* \return 0 on success or -1 on error.1028*1029* \sa SDL_HapticRunEffect1030* \sa SDL_HapticDestroyEffect1031*/1032extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic,1033int effect);10341035/**1036* \brief Destroys a haptic effect on the device.1037*1038* This will stop the effect if it's running. Effects are automatically1039* destroyed when the device is closed.1040*1041* \param haptic Device to destroy the effect on.1042* \param effect Identifier of the effect to destroy.1043*1044* \sa SDL_HapticNewEffect1045*/1046extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic,1047int effect);10481049/**1050* \brief Gets the status of the current effect on the haptic device.1051*1052* Device must support the ::SDL_HAPTIC_STATUS feature.1053*1054* \param haptic Haptic device to query the effect status on.1055* \param effect Identifier of the effect to query it's status.1056* \return 0 if it isn't playing, ::SDL_HAPTIC_PLAYING if it is playing1057* or -1 on error.1058*1059* \sa SDL_HapticRunEffect1060* \sa SDL_HapticStopEffect1061*/1062extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic,1063int effect);10641065/**1066* \brief Sets the global gain of the device.1067*1068* Device must support the ::SDL_HAPTIC_GAIN feature.1069*1070* The user may specify the maxmimum gain by setting the environment variable1071* ::SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to1072* SDL_HapticSetGain() will scale linearly using ::SDL_HAPTIC_GAIN_MAX as the1073* maximum.1074*1075* \param haptic Haptic device to set the gain on.1076* \param gain Value to set the gain to, should be between 0 and 100.1077* \return 0 on success or -1 on error.1078*1079* \sa SDL_HapticQuery1080*/1081extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain);10821083/**1084* \brief Sets the global autocenter of the device.1085*1086* Autocenter should be between 0 and 100. Setting it to 0 will disable1087* autocentering.1088*1089* Device must support the ::SDL_HAPTIC_AUTOCENTER feature.1090*1091* \param haptic Haptic device to set autocentering on.1092* \param autocenter Value to set autocenter to, 0 disables autocentering.1093* \return 0 on success or -1 on error.1094*1095* \sa SDL_HapticQuery1096*/1097extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic,1098int autocenter);10991100/**1101* \brief Pauses a haptic device.1102*1103* Device must support the ::SDL_HAPTIC_PAUSE feature. Call1104* SDL_HapticUnpause() to resume playback.1105*1106* Do not modify the effects nor add new ones while the device is paused.1107* That can cause all sorts of weird errors.1108*1109* \param haptic Haptic device to pause.1110* \return 0 on success or -1 on error.1111*1112* \sa SDL_HapticUnpause1113*/1114extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);11151116/**1117* \brief Unpauses a haptic device.1118*1119* Call to unpause after SDL_HapticPause().1120*1121* \param haptic Haptic device to pause.1122* \return 0 on success or -1 on error.1123*1124* \sa SDL_HapticPause1125*/1126extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);11271128/**1129* \brief Stops all the currently playing effects on a haptic device.1130*1131* \param haptic Haptic device to stop.1132* \return 0 on success or -1 on error.1133*/1134extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);11351136/**1137* \brief Checks to see if rumble is supported on a haptic device..1138*1139* \param haptic Haptic device to check to see if it supports rumble.1140* \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.1141*1142* \sa SDL_HapticRumbleInit1143* \sa SDL_HapticRumblePlay1144* \sa SDL_HapticRumbleStop1145*/1146extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);11471148/**1149* \brief Initializes the haptic device for simple rumble playback.1150*1151* \param haptic Haptic device to initialize for simple rumble playback.1152* \return 0 on success or -1 on error.1153*1154* \sa SDL_HapticOpen1155* \sa SDL_HapticRumbleSupported1156* \sa SDL_HapticRumblePlay1157* \sa SDL_HapticRumbleStop1158*/1159extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);11601161/**1162* \brief Runs simple rumble on a haptic device1163*1164* \param haptic Haptic device to play rumble effect on.1165* \param strength Strength of the rumble to play as a 0-1 float value.1166* \param length Length of the rumble to play in miliseconds.1167* \return 0 on success or -1 on error.1168*1169* \sa SDL_HapticRumbleSupported1170* \sa SDL_HapticRumbleInit1171* \sa SDL_HapticRumbleStop1172*/1173extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length );11741175/**1176* \brief Stops the simple rumble on a haptic device.1177*1178* \param haptic Haptic to stop the rumble on.1179* \return 0 on success or -1 on error.1180*1181* \sa SDL_HapticRumbleSupported1182* \sa SDL_HapticRumbleInit1183* \sa SDL_HapticRumblePlay1184*/1185extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);1186118711881189/* Ends C function definitions when using C++ */1190#ifdef __cplusplus1191/* *INDENT-OFF* */1192}1193/* *INDENT-ON* */1194#endif1195#include "close_code.h"11961197#endif /* _SDL_haptic_h */11981199/* vi: set ts=4 sw=4 expandtab: */120012011202