Simple rumble API for haptic
Edgar Simo 2011-02-20 10:27:52 PST Adding patch that adds a simplified API for the haptic subsystem built ontop of the "real one" for those who want simple rumble without jumping through hoops. Adds 4 functions: - extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic); - extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic); - extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length ); - extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic); Also provided is test/testrumble.c which does test this. This has all been tested on linux and has worked, but due to being built ontop of the other haptic API it should work on all OS the same.
This commit is contained in:
parent
e7aaeec596
commit
f2209fb448
5 changed files with 326 additions and 3 deletions
|
@ -25,7 +25,7 @@
|
|||
*
|
||||
* \brief The SDL Haptic subsystem allows you to control haptic (force feedback)
|
||||
* devices.
|
||||
*
|
||||
*
|
||||
* The basic usage is as follows:
|
||||
* - Initialize the Subsystem (::SDL_INIT_HAPTIC).
|
||||
* - Open a Haptic Device.
|
||||
|
@ -37,7 +37,29 @@
|
|||
* - (optional) Free the effect with SDL_HapticDestroyEffect().
|
||||
* - Close the haptic device with SDL_HapticClose().
|
||||
*
|
||||
* \par Example:
|
||||
* \par Simple rumble example:
|
||||
* \code
|
||||
* SDL_Haptic *haptic;
|
||||
*
|
||||
* // Open the device
|
||||
* haptic = SDL_HapticOpen( 0 );
|
||||
* if (haptic == NULL)
|
||||
* return -1;
|
||||
*
|
||||
* // Initialize simple rumble
|
||||
* if (SDL_HapticRumbleInit( haptic ) != 0)
|
||||
* return -1;
|
||||
*
|
||||
* // Play effect at 50% strength for 2 seconds
|
||||
* if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0)
|
||||
* return -1;
|
||||
* SDL_Delay( 2000 );
|
||||
*
|
||||
* // Clean up
|
||||
* SDL_HapticClose( haptic );
|
||||
* \endcode
|
||||
*
|
||||
* \par Complete example:
|
||||
* \code
|
||||
* int test_haptic( SDL_Joystick * joystick ) {
|
||||
* SDL_Haptic *haptic;
|
||||
|
@ -933,7 +955,7 @@ extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
|
|||
*
|
||||
* \param haptic Haptic device to check on.
|
||||
* \param effect Effect to check to see if it is supported.
|
||||
* \return 1 if effect is supported, 0 if it isn't or -1 on error.
|
||||
* \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
|
||||
*
|
||||
* \sa SDL_HapticQuery
|
||||
* \sa SDL_HapticNewEffect
|
||||
|
@ -1113,6 +1135,58 @@ extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
|
|||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);
|
||||
|
||||
/**
|
||||
* \brief Checks to see if rumble is supported on a haptic device..
|
||||
*
|
||||
* \param haptic Haptic device to check to see if it supports rumble.
|
||||
* \return SDL_TRUE if effect is supported, SDL_FALSE if it isn't or -1 on error.
|
||||
*
|
||||
* \sa SDL_HapticRumbleInit
|
||||
* \sa SDL_HapticRumblePlay
|
||||
* \sa SDL_HapticRumbleStop
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);
|
||||
|
||||
/**
|
||||
* \brief Initializes the haptic device for simple rumble playback.
|
||||
*
|
||||
* \param haptic Haptic device to initialize for simple rumble playback.
|
||||
* \return 0 on success or -1 on error.
|
||||
*
|
||||
* \sa SDL_HapticOpen
|
||||
* \sa SDL_HapticRumbleSupported
|
||||
* \sa SDL_HapticRumblePlay
|
||||
* \sa SDL_HapticRumbleStop
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);
|
||||
|
||||
/**
|
||||
* \brief Runs simple rumble on a haptic device
|
||||
*
|
||||
* \param haptic Haptic device to play rumble effect on.
|
||||
* \param strength Strength of the rumble to play as a 0-1 float value.
|
||||
* \param length Length of the rumble to play in miliseconds.
|
||||
* \return 0 on success or -1 on error.
|
||||
*
|
||||
* \sa SDL_HapticRumbleSupported
|
||||
* \sa SDL_HapticRumbleInit
|
||||
* \sa SDL_HapticRumbleStop
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length );
|
||||
|
||||
/**
|
||||
* \brief Stops the simple rumble on a haptic device.
|
||||
*
|
||||
* \param haptic Haptic to stop the rumble on.
|
||||
* \return 0 on success or -1 on error.
|
||||
*
|
||||
* \sa SDL_HapticRumbleSupported
|
||||
* \sa SDL_HapticRumbleInit
|
||||
* \sa SDL_HapticRumblePlay
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);
|
||||
|
||||
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue