Path: blob/master/thirdparty/sdl/include/SDL3/SDL_haptic.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 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* # CategoryHaptic23*24* The SDL haptic subsystem manages haptic (force feedback) devices.25*26* The basic usage is as follows:27*28* - Initialize the subsystem (SDL_INIT_HAPTIC).29* - Open a haptic device.30* - SDL_OpenHaptic() to open from index.31* - SDL_OpenHapticFromJoystick() to open from an existing joystick.32* - Create an effect (SDL_HapticEffect).33* - Upload the effect with SDL_CreateHapticEffect().34* - Run the effect with SDL_RunHapticEffect().35* - (optional) Free the effect with SDL_DestroyHapticEffect().36* - Close the haptic device with SDL_CloseHaptic().37*38* Simple rumble example:39*40* ```c41* SDL_Haptic *haptic = NULL;42*43* // Open the device44* SDL_HapticID *haptics = SDL_GetHaptics(NULL);45* if (haptics) {46* haptic = SDL_OpenHaptic(haptics[0]);47* SDL_free(haptics);48* }49* if (haptic == NULL)50* return;51*52* // Initialize simple rumble53* if (!SDL_InitHapticRumble(haptic))54* return;55*56* // Play effect at 50% strength for 2 seconds57* if (!SDL_PlayHapticRumble(haptic, 0.5, 2000))58* return;59* SDL_Delay(2000);60*61* // Clean up62* SDL_CloseHaptic(haptic);63* ```64*65* Complete example:66*67* ```c68* bool test_haptic(SDL_Joystick *joystick)69* {70* SDL_Haptic *haptic;71* SDL_HapticEffect effect;72* int effect_id;73*74* // Open the device75* haptic = SDL_OpenHapticFromJoystick(joystick);76* if (haptic == NULL) return false; // Most likely joystick isn't haptic77*78* // See if it can do sine waves79* if ((SDL_GetHapticFeatures(haptic) & SDL_HAPTIC_SINE)==0) {80* SDL_CloseHaptic(haptic); // No sine effect81* return false;82* }83*84* // Create the effect85* SDL_memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default86* effect.type = SDL_HAPTIC_SINE;87* effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates88* effect.periodic.direction.dir[0] = 18000; // Force comes from south89* effect.periodic.period = 1000; // 1000 ms90* effect.periodic.magnitude = 20000; // 20000/32767 strength91* effect.periodic.length = 5000; // 5 seconds long92* effect.periodic.attack_length = 1000; // Takes 1 second to get max strength93* effect.periodic.fade_length = 1000; // Takes 1 second to fade away94*95* // Upload the effect96* effect_id = SDL_CreateHapticEffect(haptic, &effect);97*98* // Test the effect99* SDL_RunHapticEffect(haptic, effect_id, 1);100* SDL_Delay(5000); // Wait for the effect to finish101*102* // We destroy the effect, although closing the device also does this103* SDL_DestroyHapticEffect(haptic, effect_id);104*105* // Close the device106* SDL_CloseHaptic(haptic);107*108* return true; // Success109* }110* ```111*112* Note that the SDL haptic subsystem is not thread-safe.113*/114115116#ifndef SDL_haptic_h_117#define SDL_haptic_h_118119#include <SDL3/SDL_stdinc.h>120#include <SDL3/SDL_error.h>121#include <SDL3/SDL_joystick.h>122123#include <SDL3/SDL_begin_code.h>124/* Set up for C function definitions, even when using C++ */125#ifdef __cplusplus126extern "C" {127#endif /* __cplusplus */128129/* FIXME:130*131* At the moment the magnitude variables are mixed between signed/unsigned, and132* it is also not made clear that ALL of those variables expect a max of 0x7FFF.133*134* Some platforms may have higher precision than that (Linux FF, Windows XInput)135* so we should fix the inconsistency in favor of higher possible precision,136* adjusting for platforms that use different scales.137* -flibit138*/139140/**141* The haptic structure used to identify an SDL haptic.142*143* \since This struct is available since SDL 3.2.0.144*145* \sa SDL_OpenHaptic146* \sa SDL_OpenHapticFromJoystick147* \sa SDL_CloseHaptic148*/149typedef struct SDL_Haptic SDL_Haptic;150151152/**153* \name Haptic features154*155* Different haptic features a device can have.156*/157/* @{ */158159/**160* \name Haptic effects161*/162/* @{ */163164/**165* Constant effect supported.166*167* Constant haptic effect.168*169* \since This macro is available since SDL 3.2.0.170*171* \sa SDL_HapticCondition172*/173#define SDL_HAPTIC_CONSTANT (1u<<0)174175/**176* Sine wave effect supported.177*178* Periodic haptic effect that simulates sine waves.179*180* \since This macro is available since SDL 3.2.0.181*182* \sa SDL_HapticPeriodic183*/184#define SDL_HAPTIC_SINE (1u<<1)185186/**187* Square wave effect supported.188*189* Periodic haptic effect that simulates square waves.190*191* \since This macro is available since SDL 3.2.0.192*193* \sa SDL_HapticPeriodic194*/195#define SDL_HAPTIC_SQUARE (1u<<2)196197/**198* Triangle wave effect supported.199*200* Periodic haptic effect that simulates triangular waves.201*202* \since This macro is available since SDL 3.2.0.203*204* \sa SDL_HapticPeriodic205*/206#define SDL_HAPTIC_TRIANGLE (1u<<3)207208/**209* Sawtoothup wave effect supported.210*211* Periodic haptic effect that simulates saw tooth up waves.212*213* \since This macro is available since SDL 3.2.0.214*215* \sa SDL_HapticPeriodic216*/217#define SDL_HAPTIC_SAWTOOTHUP (1u<<4)218219/**220* Sawtoothdown wave effect supported.221*222* Periodic haptic effect that simulates saw tooth down waves.223*224* \since This macro is available since SDL 3.2.0.225*226* \sa SDL_HapticPeriodic227*/228#define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)229230/**231* Ramp effect supported.232*233* Ramp haptic effect.234*235* \since This macro is available since SDL 3.2.0.236*237* \sa SDL_HapticRamp238*/239#define SDL_HAPTIC_RAMP (1u<<6)240241/**242* Spring effect supported - uses axes position.243*244* Condition haptic effect that simulates a spring. Effect is based on the245* axes position.246*247* \since This macro is available since SDL 3.2.0.248*249* \sa SDL_HapticCondition250*/251#define SDL_HAPTIC_SPRING (1u<<7)252253/**254* Damper effect supported - uses axes velocity.255*256* Condition haptic effect that simulates dampening. Effect is based on the257* axes velocity.258*259* \since This macro is available since SDL 3.2.0.260*261* \sa SDL_HapticCondition262*/263#define SDL_HAPTIC_DAMPER (1u<<8)264265/**266* Inertia effect supported - uses axes acceleration.267*268* Condition haptic effect that simulates inertia. Effect is based on the axes269* acceleration.270*271* \since This macro is available since SDL 3.2.0.272*273* \sa SDL_HapticCondition274*/275#define SDL_HAPTIC_INERTIA (1u<<9)276277/**278* Friction effect supported - uses axes movement.279*280* Condition haptic effect that simulates friction. Effect is based on the281* axes movement.282*283* \since This macro is available since SDL 3.2.0.284*285* \sa SDL_HapticCondition286*/287#define SDL_HAPTIC_FRICTION (1u<<10)288289/**290* Left/Right effect supported.291*292* Haptic effect for direct control over high/low frequency motors.293*294* \since This macro is available since SDL 3.2.0.295*296* \sa SDL_HapticLeftRight297*/298#define SDL_HAPTIC_LEFTRIGHT (1u<<11)299300/**301* Reserved for future use.302*303* \since This macro is available since SDL 3.2.0.304*/305#define SDL_HAPTIC_RESERVED1 (1u<<12)306307/**308* Reserved for future use.309*310* \since This macro is available since SDL 3.2.0.311*/312#define SDL_HAPTIC_RESERVED2 (1u<<13)313314/**315* Reserved for future use.316*317* \since This macro is available since SDL 3.2.0.318*/319#define SDL_HAPTIC_RESERVED3 (1u<<14)320321/**322* Custom effect is supported.323*324* User defined custom haptic effect.325*326* \since This macro is available since SDL 3.2.0.327*/328#define SDL_HAPTIC_CUSTOM (1u<<15)329330/* @} *//* Haptic effects */331332/* These last few are features the device has, not effects */333334/**335* Device can set global gain.336*337* Device supports setting the global gain.338*339* \since This macro is available since SDL 3.2.0.340*341* \sa SDL_SetHapticGain342*/343#define SDL_HAPTIC_GAIN (1u<<16)344345/**346* Device can set autocenter.347*348* Device supports setting autocenter.349*350* \since This macro is available since SDL 3.2.0.351*352* \sa SDL_SetHapticAutocenter353*/354#define SDL_HAPTIC_AUTOCENTER (1u<<17)355356/**357* Device can be queried for effect status.358*359* Device supports querying effect status.360*361* \since This macro is available since SDL 3.2.0.362*363* \sa SDL_GetHapticEffectStatus364*/365#define SDL_HAPTIC_STATUS (1u<<18)366367/**368* Device can be paused.369*370* Devices supports being paused.371*372* \since This macro is available since SDL 3.2.0.373*374* \sa SDL_PauseHaptic375* \sa SDL_ResumeHaptic376*/377#define SDL_HAPTIC_PAUSE (1u<<19)378379380/**381* \name Direction encodings382*/383/* @{ */384385/**386* Uses polar coordinates for the direction.387*388* \since This macro is available since SDL 3.2.0.389*390* \sa SDL_HapticDirection391*/392#define SDL_HAPTIC_POLAR 0393394/**395* Uses cartesian coordinates for the direction.396*397* \since This macro is available since SDL 3.2.0.398*399* \sa SDL_HapticDirection400*/401#define SDL_HAPTIC_CARTESIAN 1402403/**404* Uses spherical coordinates for the direction.405*406* \since This macro is available since SDL 3.2.0.407*408* \sa SDL_HapticDirection409*/410#define SDL_HAPTIC_SPHERICAL 2411412/**413* Use this value to play an effect on the steering wheel axis.414*415* This provides better compatibility across platforms and devices as SDL will416* guess the correct axis.417*418* \since This macro is available since SDL 3.2.0.419*420* \sa SDL_HapticDirection421*/422#define SDL_HAPTIC_STEERING_AXIS 3423424/* @} *//* Direction encodings */425426/* @} *//* Haptic features */427428/*429* Misc defines.430*/431432/**433* Used to play a device an infinite number of times.434*435* \since This macro is available since SDL 3.2.0.436*437* \sa SDL_RunHapticEffect438*/439#define SDL_HAPTIC_INFINITY 4294967295U440441442/**443* Structure that represents a haptic direction.444*445* This is the direction where the force comes from, instead of the direction446* in which the force is exerted.447*448* Directions can be specified by:449*450* - SDL_HAPTIC_POLAR : Specified by polar coordinates.451* - SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.452* - SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.453*454* Cardinal directions of the haptic device are relative to the positioning of455* the device. North is considered to be away from the user.456*457* The following diagram represents the cardinal directions:458*459* ```460* .--.461* |__| .-------.462* |=.| |.-----.|463* |--| || ||464* | | |'-----'|465* |__|~')_____('466* [ COMPUTER ]467*468*469* North (0,-1)470* ^471* |472* |473* (-1,0) West <----[ HAPTIC ]----> East (1,0)474* |475* |476* v477* South (0,1)478*479*480* [ USER ]481* \|||/482* (o o)483* ---ooO-(_)-Ooo---484* ```485*486* If type is SDL_HAPTIC_POLAR, direction is encoded by hundredths of a degree487* starting north and turning clockwise. SDL_HAPTIC_POLAR only uses the first488* `dir` parameter. The cardinal directions would be:489*490* - North: 0 (0 degrees)491* - East: 9000 (90 degrees)492* - South: 18000 (180 degrees)493* - West: 27000 (270 degrees)494*495* If type is SDL_HAPTIC_CARTESIAN, direction is encoded by three positions (X496* axis, Y axis and Z axis (with 3 axes)). SDL_HAPTIC_CARTESIAN uses the first497* three `dir` parameters. The cardinal directions would be:498*499* - North: 0,-1, 0500* - East: 1, 0, 0501* - South: 0, 1, 0502* - West: -1, 0, 0503*504* The Z axis represents the height of the effect if supported, otherwise it's505* unused. In cartesian encoding (1, 2) would be the same as (2, 4), you can506* use any multiple you want, only the direction matters.507*508* If type is SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations. The509* first two `dir` parameters are used. The `dir` parameters are as follows510* (all values are in hundredths of degrees):511*512* - Degrees from (1, 0) rotated towards (0, 1).513* - Degrees towards (0, 0, 1) (device needs at least 3 axes).514*515* Example of force coming from the south with all encodings (force coming516* from the south means the user will have to pull the stick to counteract):517*518* ```c519* SDL_HapticDirection direction;520*521* // Cartesian directions522* direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.523* direction.dir[0] = 0; // X position524* direction.dir[1] = 1; // Y position525* // Assuming the device has 2 axes, we don't need to specify third parameter.526*527* // Polar directions528* direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.529* direction.dir[0] = 18000; // Polar only uses first parameter530*531* // Spherical coordinates532* direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding533* direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.534* ```535*536* \since This struct is available since SDL 3.2.0.537*538* \sa SDL_HAPTIC_POLAR539* \sa SDL_HAPTIC_CARTESIAN540* \sa SDL_HAPTIC_SPHERICAL541* \sa SDL_HAPTIC_STEERING_AXIS542* \sa SDL_HapticEffect543* \sa SDL_GetNumHapticAxes544*/545typedef struct SDL_HapticDirection546{547Uint8 type; /**< The type of encoding. */548Sint32 dir[3]; /**< The encoded direction. */549} SDL_HapticDirection;550551552/**553* A structure containing a template for a Constant effect.554*555* This struct is exclusively for the SDL_HAPTIC_CONSTANT effect.556*557* A constant effect applies a constant force in the specified direction to558* the joystick.559*560* \since This struct is available since SDL 3.2.0.561*562* \sa SDL_HAPTIC_CONSTANT563* \sa SDL_HapticEffect564*/565typedef struct SDL_HapticConstant566{567/* Header */568Uint16 type; /**< SDL_HAPTIC_CONSTANT */569SDL_HapticDirection direction; /**< Direction of the effect. */570571/* Replay */572Uint32 length; /**< Duration of the effect. */573Uint16 delay; /**< Delay before starting the effect. */574575/* Trigger */576Uint16 button; /**< Button that triggers the effect. */577Uint16 interval; /**< How soon it can be triggered again after button. */578579/* Constant */580Sint16 level; /**< Strength of the constant effect. */581582/* Envelope */583Uint16 attack_length; /**< Duration of the attack. */584Uint16 attack_level; /**< Level at the start of the attack. */585Uint16 fade_length; /**< Duration of the fade. */586Uint16 fade_level; /**< Level at the end of the fade. */587} SDL_HapticConstant;588589/**590* A structure containing a template for a Periodic effect.591*592* The struct handles the following effects:593*594* - SDL_HAPTIC_SINE595* - SDL_HAPTIC_SQUARE596* - SDL_HAPTIC_TRIANGLE597* - SDL_HAPTIC_SAWTOOTHUP598* - SDL_HAPTIC_SAWTOOTHDOWN599*600* A periodic effect consists in a wave-shaped effect that repeats itself over601* time. The type determines the shape of the wave and the parameters602* determine the dimensions of the wave.603*604* Phase is given by hundredth of a degree meaning that giving the phase a605* value of 9000 will displace it 25% of its period. Here are sample values:606*607* - 0: No phase displacement.608* - 9000: Displaced 25% of its period.609* - 18000: Displaced 50% of its period.610* - 27000: Displaced 75% of its period.611* - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.612*613* Examples:614*615* ```616* SDL_HAPTIC_SINE617* __ __ __ __618* / \ / \ / \ /619* / \__/ \__/ \__/620*621* SDL_HAPTIC_SQUARE622* __ __ __ __ __623* | | | | | | | | | |624* | |__| |__| |__| |__| |625*626* SDL_HAPTIC_TRIANGLE627* /\ /\ /\ /\ /\628* / \ / \ / \ / \ /629* / \/ \/ \/ \/630*631* SDL_HAPTIC_SAWTOOTHUP632* /| /| /| /| /| /| /|633* / | / | / | / | / | / | / |634* / |/ |/ |/ |/ |/ |/ |635*636* SDL_HAPTIC_SAWTOOTHDOWN637* \ |\ |\ |\ |\ |\ |\ |638* \ | \ | \ | \ | \ | \ | \ |639* \| \| \| \| \| \| \|640* ```641*642* \since This struct is available since SDL 3.2.0.643*644* \sa SDL_HAPTIC_SINE645* \sa SDL_HAPTIC_SQUARE646* \sa SDL_HAPTIC_TRIANGLE647* \sa SDL_HAPTIC_SAWTOOTHUP648* \sa SDL_HAPTIC_SAWTOOTHDOWN649* \sa SDL_HapticEffect650*/651typedef struct SDL_HapticPeriodic652{653/* Header */654Uint16 type; /**< SDL_HAPTIC_SINE, SDL_HAPTIC_SQUARE655SDL_HAPTIC_TRIANGLE, SDL_HAPTIC_SAWTOOTHUP or656SDL_HAPTIC_SAWTOOTHDOWN */657SDL_HapticDirection direction; /**< Direction of the effect. */658659/* Replay */660Uint32 length; /**< Duration of the effect. */661Uint16 delay; /**< Delay before starting the effect. */662663/* Trigger */664Uint16 button; /**< Button that triggers the effect. */665Uint16 interval; /**< How soon it can be triggered again after button. */666667/* Periodic */668Uint16 period; /**< Period of the wave. */669Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */670Sint16 offset; /**< Mean value of the wave. */671Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */672673/* Envelope */674Uint16 attack_length; /**< Duration of the attack. */675Uint16 attack_level; /**< Level at the start of the attack. */676Uint16 fade_length; /**< Duration of the fade. */677Uint16 fade_level; /**< Level at the end of the fade. */678} SDL_HapticPeriodic;679680/**681* A structure containing a template for a Condition effect.682*683* The struct handles the following effects:684*685* - SDL_HAPTIC_SPRING: Effect based on axes position.686* - SDL_HAPTIC_DAMPER: Effect based on axes velocity.687* - SDL_HAPTIC_INERTIA: Effect based on axes acceleration.688* - SDL_HAPTIC_FRICTION: Effect based on axes movement.689*690* Direction is handled by condition internals instead of a direction member.691* The condition effect specific members have three parameters. The first692* refers to the X axis, the second refers to the Y axis and the third refers693* to the Z axis. The right terms refer to the positive side of the axis and694* the left terms refer to the negative side of the axis. Please refer to the695* SDL_HapticDirection diagram for which side is positive and which is696* negative.697*698* \since This struct is available since SDL 3.2.0.699*700* \sa SDL_HapticDirection701* \sa SDL_HAPTIC_SPRING702* \sa SDL_HAPTIC_DAMPER703* \sa SDL_HAPTIC_INERTIA704* \sa SDL_HAPTIC_FRICTION705* \sa SDL_HapticEffect706*/707typedef struct SDL_HapticCondition708{709/* Header */710Uint16 type; /**< SDL_HAPTIC_SPRING, SDL_HAPTIC_DAMPER,711SDL_HAPTIC_INERTIA or SDL_HAPTIC_FRICTION */712SDL_HapticDirection direction; /**< Direction of the effect. */713714/* Replay */715Uint32 length; /**< Duration of the effect. */716Uint16 delay; /**< Delay before starting the effect. */717718/* Trigger */719Uint16 button; /**< Button that triggers the effect. */720Uint16 interval; /**< How soon it can be triggered again after button. */721722/* Condition */723Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */724Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */725Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */726Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */727Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */728Sint16 center[3]; /**< Position of the dead zone. */729} SDL_HapticCondition;730731/**732* A structure containing a template for a Ramp effect.733*734* This struct is exclusively for the SDL_HAPTIC_RAMP effect.735*736* The ramp effect starts at start strength and ends at end strength. It737* augments in linear fashion. If you use attack and fade with a ramp the738* effects get added to the ramp effect making the effect become quadratic739* instead of linear.740*741* \since This struct is available since SDL 3.2.0.742*743* \sa SDL_HAPTIC_RAMP744* \sa SDL_HapticEffect745*/746typedef struct SDL_HapticRamp747{748/* Header */749Uint16 type; /**< SDL_HAPTIC_RAMP */750SDL_HapticDirection direction; /**< Direction of the effect. */751752/* Replay */753Uint32 length; /**< Duration of the effect. */754Uint16 delay; /**< Delay before starting the effect. */755756/* Trigger */757Uint16 button; /**< Button that triggers the effect. */758Uint16 interval; /**< How soon it can be triggered again after button. */759760/* Ramp */761Sint16 start; /**< Beginning strength level. */762Sint16 end; /**< Ending strength level. */763764/* Envelope */765Uint16 attack_length; /**< Duration of the attack. */766Uint16 attack_level; /**< Level at the start of the attack. */767Uint16 fade_length; /**< Duration of the fade. */768Uint16 fade_level; /**< Level at the end of the fade. */769} SDL_HapticRamp;770771/**772* A structure containing a template for a Left/Right effect.773*774* This struct is exclusively for the SDL_HAPTIC_LEFTRIGHT effect.775*776* The Left/Right effect is used to explicitly control the large and small777* motors, commonly found in modern game controllers. The small (right) motor778* is high frequency, and the large (left) motor is low frequency.779*780* \since This struct is available since SDL 3.2.0.781*782* \sa SDL_HAPTIC_LEFTRIGHT783* \sa SDL_HapticEffect784*/785typedef struct SDL_HapticLeftRight786{787/* Header */788Uint16 type; /**< SDL_HAPTIC_LEFTRIGHT */789790/* Replay */791Uint32 length; /**< Duration of the effect in milliseconds. */792793/* Rumble */794Uint16 large_magnitude; /**< Control of the large controller motor. */795Uint16 small_magnitude; /**< Control of the small controller motor. */796} SDL_HapticLeftRight;797798/**799* A structure containing a template for the SDL_HAPTIC_CUSTOM effect.800*801* This struct is exclusively for the SDL_HAPTIC_CUSTOM effect.802*803* A custom force feedback effect is much like a periodic effect, where the804* application can define its exact shape. You will have to allocate the data805* yourself. Data should consist of channels * samples Uint16 samples.806*807* If channels is one, the effect is rotated using the defined direction.808* Otherwise it uses the samples in data for the different axes.809*810* \since This struct is available since SDL 3.2.0.811*812* \sa SDL_HAPTIC_CUSTOM813* \sa SDL_HapticEffect814*/815typedef struct SDL_HapticCustom816{817/* Header */818Uint16 type; /**< SDL_HAPTIC_CUSTOM */819SDL_HapticDirection direction; /**< Direction of the effect. */820821/* Replay */822Uint32 length; /**< Duration of the effect. */823Uint16 delay; /**< Delay before starting the effect. */824825/* Trigger */826Uint16 button; /**< Button that triggers the effect. */827Uint16 interval; /**< How soon it can be triggered again after button. */828829/* Custom */830Uint8 channels; /**< Axes to use, minimum of one. */831Uint16 period; /**< Sample periods. */832Uint16 samples; /**< Amount of samples. */833Uint16 *data; /**< Should contain channels*samples items. */834835/* Envelope */836Uint16 attack_length; /**< Duration of the attack. */837Uint16 attack_level; /**< Level at the start of the attack. */838Uint16 fade_length; /**< Duration of the fade. */839Uint16 fade_level; /**< Level at the end of the fade. */840} SDL_HapticCustom;841842/**843* The generic template for any haptic effect.844*845* All values max at 32767 (0x7FFF). Signed values also can be negative. Time846* values unless specified otherwise are in milliseconds.847*848* You can also pass SDL_HAPTIC_INFINITY to length instead of a 0-32767 value.849* Neither delay, interval, attack_length nor fade_length support850* SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.851*852* Additionally, the SDL_HAPTIC_RAMP effect does not support a duration of853* SDL_HAPTIC_INFINITY.854*855* Button triggers may not be supported on all devices, it is advised to not856* use them if possible. Buttons start at index 1 instead of index 0 like the857* joystick.858*859* If both attack_length and fade_level are 0, the envelope is not used,860* otherwise both values are used.861*862* Common parts:863*864* ```c865* // Replay - All effects have this866* Uint32 length; // Duration of effect (ms).867* Uint16 delay; // Delay before starting effect.868*869* // Trigger - All effects have this870* Uint16 button; // Button that triggers effect.871* Uint16 interval; // How soon before effect can be triggered again.872*873* // Envelope - All effects except condition effects have this874* Uint16 attack_length; // Duration of the attack (ms).875* Uint16 attack_level; // Level at the start of the attack.876* Uint16 fade_length; // Duration of the fade out (ms).877* Uint16 fade_level; // Level at the end of the fade.878* ```879*880* Here we have an example of a constant effect evolution in time:881*882* ```883* Strength884* ^885* |886* | effect level --> _________________887* | / \888* | / \889* | / \890* | / \891* | attack_level --> | \892* | | | <--- fade_level893* |894* +--------------------------------------------------> Time895* [--] [---]896* attack_length fade_length897*898* [------------------][-----------------------]899* delay length900* ```901*902* Note either the attack_level or the fade_level may be above the actual903* effect level.904*905* \since This struct is available since SDL 3.2.0.906*907* \sa SDL_HapticConstant908* \sa SDL_HapticPeriodic909* \sa SDL_HapticCondition910* \sa SDL_HapticRamp911* \sa SDL_HapticLeftRight912* \sa SDL_HapticCustom913*/914typedef union SDL_HapticEffect915{916/* Common for all force feedback effects */917Uint16 type; /**< Effect type. */918SDL_HapticConstant constant; /**< Constant effect. */919SDL_HapticPeriodic periodic; /**< Periodic effect. */920SDL_HapticCondition condition; /**< Condition effect. */921SDL_HapticRamp ramp; /**< Ramp effect. */922SDL_HapticLeftRight leftright; /**< Left/Right effect. */923SDL_HapticCustom custom; /**< Custom effect. */924} SDL_HapticEffect;925926/**927* This is a unique ID for a haptic device for the time it is connected to the928* system, and is never reused for the lifetime of the application.929*930* If the haptic device is disconnected and reconnected, it will get a new ID.931*932* The value 0 is an invalid ID.933*934* \since This datatype is available since SDL 3.2.0.935*/936typedef Uint32 SDL_HapticID;937938939/* Function prototypes */940941/**942* Get a list of currently connected haptic devices.943*944* \param count a pointer filled in with the number of haptic devices945* returned, may be NULL.946* \returns a 0 terminated array of haptic device instance IDs or NULL on947* failure; call SDL_GetError() for more information. This should be948* freed with SDL_free() when it is no longer needed.949*950* \since This function is available since SDL 3.2.0.951*952* \sa SDL_OpenHaptic953*/954extern SDL_DECLSPEC SDL_HapticID * SDLCALL SDL_GetHaptics(int *count);955956/**957* Get the implementation dependent name of a haptic device.958*959* This can be called before any haptic devices are opened.960*961* \param instance_id the haptic device instance ID.962* \returns the name of the selected haptic device. If no name can be found,963* this function returns NULL; call SDL_GetError() for more964* information.965*966* \since This function is available since SDL 3.2.0.967*968* \sa SDL_GetHapticName969* \sa SDL_OpenHaptic970*/971extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticNameForID(SDL_HapticID instance_id);972973/**974* Open a haptic device for use.975*976* The index passed as an argument refers to the N'th haptic device on this977* system.978*979* When opening a haptic device, its gain will be set to maximum and980* autocenter will be disabled. To modify these values use SDL_SetHapticGain()981* and SDL_SetHapticAutocenter().982*983* \param instance_id the haptic device instance ID.984* \returns the device identifier or NULL on failure; call SDL_GetError() for985* more information.986*987* \since This function is available since SDL 3.2.0.988*989* \sa SDL_CloseHaptic990* \sa SDL_GetHaptics991* \sa SDL_OpenHapticFromJoystick992* \sa SDL_OpenHapticFromMouse993* \sa SDL_SetHapticAutocenter994* \sa SDL_SetHapticGain995*/996extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHaptic(SDL_HapticID instance_id);997998999/**1000* Get the SDL_Haptic associated with an instance ID, if it has been opened.1001*1002* \param instance_id the instance ID to get the SDL_Haptic for.1003* \returns an SDL_Haptic on success or NULL on failure or if it hasn't been1004* opened yet; call SDL_GetError() for more information.1005*1006* \since This function is available since SDL 3.2.0.1007*/1008extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_GetHapticFromID(SDL_HapticID instance_id);10091010/**1011* Get the instance ID of an opened haptic device.1012*1013* \param haptic the SDL_Haptic device to query.1014* \returns the instance ID of the specified haptic device on success or 0 on1015* failure; call SDL_GetError() for more information.1016*1017* \since This function is available since SDL 3.2.0.1018*/1019extern SDL_DECLSPEC SDL_HapticID SDLCALL SDL_GetHapticID(SDL_Haptic *haptic);10201021/**1022* Get the implementation dependent name of a haptic device.1023*1024* \param haptic the SDL_Haptic obtained from SDL_OpenJoystick().1025* \returns the name of the selected haptic device. If no name can be found,1026* this function returns NULL; call SDL_GetError() for more1027* information.1028*1029* \since This function is available since SDL 3.2.0.1030*1031* \sa SDL_GetHapticNameForID1032*/1033extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticName(SDL_Haptic *haptic);10341035/**1036* Query whether or not the current mouse has haptic capabilities.1037*1038* \returns true if the mouse is haptic or false if it isn't.1039*1040* \since This function is available since SDL 3.2.0.1041*1042* \sa SDL_OpenHapticFromMouse1043*/1044extern SDL_DECLSPEC bool SDLCALL SDL_IsMouseHaptic(void);10451046/**1047* Try to open a haptic device from the current mouse.1048*1049* \returns the haptic device identifier or NULL on failure; call1050* SDL_GetError() for more information.1051*1052* \since This function is available since SDL 3.2.0.1053*1054* \sa SDL_CloseHaptic1055* \sa SDL_IsMouseHaptic1056*/1057extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromMouse(void);10581059/**1060* Query if a joystick has haptic features.1061*1062* \param joystick the SDL_Joystick to test for haptic capabilities.1063* \returns true if the joystick is haptic or false if it isn't.1064*1065* \since This function is available since SDL 3.2.0.1066*1067* \sa SDL_OpenHapticFromJoystick1068*/1069extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickHaptic(SDL_Joystick *joystick);10701071/**1072* Open a haptic device for use from a joystick device.1073*1074* You must still close the haptic device separately. It will not be closed1075* with the joystick.1076*1077* When opened from a joystick you should first close the haptic device before1078* closing the joystick device. If not, on some implementations the haptic1079* device will also get unallocated and you'll be unable to use force feedback1080* on that device.1081*1082* \param joystick the SDL_Joystick to create a haptic device from.1083* \returns a valid haptic device identifier on success or NULL on failure;1084* call SDL_GetError() for more information.1085*1086* \since This function is available since SDL 3.2.0.1087*1088* \sa SDL_CloseHaptic1089* \sa SDL_IsJoystickHaptic1090*/1091extern SDL_DECLSPEC SDL_Haptic * SDLCALL SDL_OpenHapticFromJoystick(SDL_Joystick *joystick);10921093/**1094* Close a haptic device previously opened with SDL_OpenHaptic().1095*1096* \param haptic the SDL_Haptic device to close.1097*1098* \since This function is available since SDL 3.2.0.1099*1100* \sa SDL_OpenHaptic1101*/1102extern SDL_DECLSPEC void SDLCALL SDL_CloseHaptic(SDL_Haptic *haptic);11031104/**1105* Get the number of effects a haptic device can store.1106*1107* On some platforms this isn't fully supported, and therefore is an1108* approximation. Always check to see if your created effect was actually1109* created and do not rely solely on SDL_GetMaxHapticEffects().1110*1111* \param haptic the SDL_Haptic device to query.1112* \returns the number of effects the haptic device can store or a negative1113* error code on failure; call SDL_GetError() for more information.1114*1115* \since This function is available since SDL 3.2.0.1116*1117* \sa SDL_GetMaxHapticEffectsPlaying1118* \sa SDL_GetHapticFeatures1119*/1120extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffects(SDL_Haptic *haptic);11211122/**1123* Get the number of effects a haptic device can play at the same time.1124*1125* This is not supported on all platforms, but will always return a value.1126*1127* \param haptic the SDL_Haptic device to query maximum playing effects.1128* \returns the number of effects the haptic device can play at the same time1129* or -1 on failure; call SDL_GetError() for more information.1130*1131* \since This function is available since SDL 3.2.0.1132*1133* \sa SDL_GetMaxHapticEffects1134* \sa SDL_GetHapticFeatures1135*/1136extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffectsPlaying(SDL_Haptic *haptic);11371138/**1139* Get the haptic device's supported features in bitwise manner.1140*1141* \param haptic the SDL_Haptic device to query.1142* \returns a list of supported haptic features in bitwise manner (OR'd), or 01143* on failure; call SDL_GetError() for more information.1144*1145* \since This function is available since SDL 3.2.0.1146*1147* \sa SDL_HapticEffectSupported1148* \sa SDL_GetMaxHapticEffects1149*/1150extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetHapticFeatures(SDL_Haptic *haptic);11511152/**1153* Get the number of haptic axes the device has.1154*1155* The number of haptic axes might be useful if working with the1156* SDL_HapticDirection effect.1157*1158* \param haptic the SDL_Haptic device to query.1159* \returns the number of axes on success or -1 on failure; call1160* SDL_GetError() for more information.1161*1162* \since This function is available since SDL 3.2.0.1163*/1164extern SDL_DECLSPEC int SDLCALL SDL_GetNumHapticAxes(SDL_Haptic *haptic);11651166/**1167* Check to see if an effect is supported by a haptic device.1168*1169* \param haptic the SDL_Haptic device to query.1170* \param effect the desired effect to query.1171* \returns true if the effect is supported or false if it isn't.1172*1173* \since This function is available since SDL 3.2.0.1174*1175* \sa SDL_CreateHapticEffect1176* \sa SDL_GetHapticFeatures1177*/1178extern SDL_DECLSPEC bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effect);11791180/**1181* Create a new haptic effect on a specified device.1182*1183* \param haptic an SDL_Haptic device to create the effect on.1184* \param effect an SDL_HapticEffect structure containing the properties of1185* the effect to create.1186* \returns the ID of the effect on success or -1 on failure; call1187* SDL_GetError() for more information.1188*1189* \since This function is available since SDL 3.2.0.1190*1191* \sa SDL_DestroyHapticEffect1192* \sa SDL_RunHapticEffect1193* \sa SDL_UpdateHapticEffect1194*/1195extern SDL_DECLSPEC int SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect);11961197/**1198* Update the properties of an effect.1199*1200* Can be used dynamically, although behavior when dynamically changing1201* direction may be strange. Specifically the effect may re-upload itself and1202* start playing from the start. You also cannot change the type either when1203* running SDL_UpdateHapticEffect().1204*1205* \param haptic the SDL_Haptic device that has the effect.1206* \param effect the identifier of the effect to update.1207* \param data an SDL_HapticEffect structure containing the new effect1208* properties to use.1209* \returns true on success or false on failure; call SDL_GetError() for more1210* information.1211*1212* \since This function is available since SDL 3.2.0.1213*1214* \sa SDL_CreateHapticEffect1215* \sa SDL_RunHapticEffect1216*/1217extern SDL_DECLSPEC bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data);12181219/**1220* Run the haptic effect on its associated haptic device.1221*1222* To repeat the effect over and over indefinitely, set `iterations` to1223* `SDL_HAPTIC_INFINITY`. (Repeats the envelope - attack and fade.) To make1224* one instance of the effect last indefinitely (so the effect does not fade),1225* set the effect's `length` in its structure/union to `SDL_HAPTIC_INFINITY`1226* instead.1227*1228* \param haptic the SDL_Haptic device to run the effect on.1229* \param effect the ID of the haptic effect to run.1230* \param iterations the number of iterations to run the effect; use1231* `SDL_HAPTIC_INFINITY` to repeat forever.1232* \returns true on success or false on failure; call SDL_GetError() for more1233* information.1234*1235* \since This function is available since SDL 3.2.0.1236*1237* \sa SDL_GetHapticEffectStatus1238* \sa SDL_StopHapticEffect1239* \sa SDL_StopHapticEffects1240*/1241extern SDL_DECLSPEC bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations);12421243/**1244* Stop the haptic effect on its associated haptic device.1245*1246* \param haptic the SDL_Haptic device to stop the effect on.1247* \param effect the ID of the haptic effect to stop.1248* \returns true on success or false on failure; call SDL_GetError() for more1249* information.1250*1251* \since This function is available since SDL 3.2.0.1252*1253* \sa SDL_RunHapticEffect1254* \sa SDL_StopHapticEffects1255*/1256extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int effect);12571258/**1259* Destroy a haptic effect on the device.1260*1261* This will stop the effect if it's running. Effects are automatically1262* destroyed when the device is closed.1263*1264* \param haptic the SDL_Haptic device to destroy the effect on.1265* \param effect the ID of the haptic effect to destroy.1266*1267* \since This function is available since SDL 3.2.0.1268*1269* \sa SDL_CreateHapticEffect1270*/1271extern SDL_DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect);12721273/**1274* Get the status of the current effect on the specified haptic device.1275*1276* Device must support the SDL_HAPTIC_STATUS feature.1277*1278* \param haptic the SDL_Haptic device to query for the effect status on.1279* \param effect the ID of the haptic effect to query its status.1280* \returns true if it is playing, false if it isn't playing or haptic status1281* isn't supported.1282*1283* \since This function is available since SDL 3.2.0.1284*1285* \sa SDL_GetHapticFeatures1286*/1287extern SDL_DECLSPEC bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect);12881289/**1290* Set the global gain of the specified haptic device.1291*1292* Device must support the SDL_HAPTIC_GAIN feature.1293*1294* The user may specify the maximum gain by setting the environment variable1295* `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to1296* SDL_SetHapticGain() will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the1297* maximum.1298*1299* \param haptic the SDL_Haptic device to set the gain on.1300* \param gain value to set the gain to, should be between 0 and 100 (0 -1301* 100).1302* \returns true on success or false on failure; call SDL_GetError() for more1303* information.1304*1305* \since This function is available since SDL 3.2.0.1306*1307* \sa SDL_GetHapticFeatures1308*/1309extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain);13101311/**1312* Set the global autocenter of the device.1313*1314* Autocenter should be between 0 and 100. Setting it to 0 will disable1315* autocentering.1316*1317* Device must support the SDL_HAPTIC_AUTOCENTER feature.1318*1319* \param haptic the SDL_Haptic device to set autocentering on.1320* \param autocenter value to set autocenter to (0-100).1321* \returns true on success or false on failure; call SDL_GetError() for more1322* information.1323*1324* \since This function is available since SDL 3.2.0.1325*1326* \sa SDL_GetHapticFeatures1327*/1328extern SDL_DECLSPEC bool SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter);13291330/**1331* Pause a haptic device.1332*1333* Device must support the `SDL_HAPTIC_PAUSE` feature. Call SDL_ResumeHaptic()1334* to resume playback.1335*1336* Do not modify the effects nor add new ones while the device is paused. That1337* can cause all sorts of weird errors.1338*1339* \param haptic the SDL_Haptic device to pause.1340* \returns true on success or false on failure; call SDL_GetError() for more1341* information.1342*1343* \since This function is available since SDL 3.2.0.1344*1345* \sa SDL_ResumeHaptic1346*/1347extern SDL_DECLSPEC bool SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic);13481349/**1350* Resume a haptic device.1351*1352* Call to unpause after SDL_PauseHaptic().1353*1354* \param haptic the SDL_Haptic device to unpause.1355* \returns true on success or false on failure; call SDL_GetError() for more1356* information.1357*1358* \since This function is available since SDL 3.2.0.1359*1360* \sa SDL_PauseHaptic1361*/1362extern SDL_DECLSPEC bool SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic);13631364/**1365* Stop all the currently playing effects on a haptic device.1366*1367* \param haptic the SDL_Haptic device to stop.1368* \returns true on success or false on failure; call SDL_GetError() for more1369* information.1370*1371* \since This function is available since SDL 3.2.0.1372*1373* \sa SDL_RunHapticEffect1374* \sa SDL_StopHapticEffects1375*/1376extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic);13771378/**1379* Check whether rumble is supported on a haptic device.1380*1381* \param haptic haptic device to check for rumble support.1382* \returns true if the effect is supported or false if it isn't.1383*1384* \since This function is available since SDL 3.2.0.1385*1386* \sa SDL_InitHapticRumble1387*/1388extern SDL_DECLSPEC bool SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *haptic);13891390/**1391* Initialize a haptic device for simple rumble playback.1392*1393* \param haptic the haptic device to initialize for simple rumble playback.1394* \returns true on success or false on failure; call SDL_GetError() for more1395* information.1396*1397* \since This function is available since SDL 3.2.0.1398*1399* \sa SDL_PlayHapticRumble1400* \sa SDL_StopHapticRumble1401* \sa SDL_HapticRumbleSupported1402*/1403extern SDL_DECLSPEC bool SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic);14041405/**1406* Run a simple rumble effect on a haptic device.1407*1408* \param haptic the haptic device to play the rumble effect on.1409* \param strength strength of the rumble to play as a 0-1 float value.1410* \param length length of the rumble to play in milliseconds.1411* \returns true on success or false on failure; call SDL_GetError() for more1412* information.1413*1414* \since This function is available since SDL 3.2.0.1415*1416* \sa SDL_InitHapticRumble1417* \sa SDL_StopHapticRumble1418*/1419extern SDL_DECLSPEC bool SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length);14201421/**1422* Stop the simple rumble on a haptic device.1423*1424* \param haptic the haptic device to stop the rumble effect on.1425* \returns true on success or false on failure; call SDL_GetError() for more1426* information.1427*1428* \since This function is available since SDL 3.2.0.1429*1430* \sa SDL_PlayHapticRumble1431*/1432extern SDL_DECLSPEC bool SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic);14331434/* Ends C function definitions when using C++ */1435#ifdef __cplusplus1436}1437#endif1438#include <SDL3/SDL_close_code.h>14391440#endif /* SDL_haptic_h_ */144114421443