From 2ed82eb0fe078566a8909b4a856c6baa4c024771 Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Sun, 24 Aug 2008 17:32:50 +0000 Subject: [PATCH] Added SDL_HapticStopAll. Cleaned up the dummy haptic driver a bit. --- include/SDL_haptic.h | 18 +++++++++++--- src/haptic/SDL_haptic.c | 13 ++++++++++ src/haptic/SDL_syshaptic.h | 7 ++++++ src/haptic/darwin/SDL_syshaptic.c | 23 +++++++++++++++-- src/haptic/dummy/SDL_syshaptic.c | 41 +++++++++++++++++++++---------- src/haptic/linux/SDL_syshaptic.c | 20 +++++++++++++++ src/haptic/win32/SDL_syshaptic.c | 20 +++++++++++++++ 7 files changed, 124 insertions(+), 18 deletions(-) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index 7c7c81712..3b48abea6 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -764,6 +764,8 @@ extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index); * \sa SDL_HapticClose * \sa SDL_HapticSetGain * \sa SDL_HapticSetAutocenter + * \sa SDL_HapticPause + * \sa SDL_HapticStopAll */ extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index); @@ -1080,7 +1082,7 @@ extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic, int aut /** * \fn extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic) * - * \brief Pauses the haptic device. + * \brief Pauses a haptic device. * * Device must support the SDL_HAPTIC_PAUSE feature. Call SDL_HapticUnpause * to resume playback. @@ -1098,17 +1100,27 @@ extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic); /** * \fn extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic) * - * \brief Unpauses the haptic device. + * \brief Unpauses a haptic device. * * Call to unpause after SDL_HapticPause. * * \param haptic Haptic device to pause. - * \return 0 on success or -1 on error. + * \return 0 on success or -1 on error. * * \sa SDL_HapticPause */ extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic); +/** + * \fn extern DECSLPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic) + * + * \brief Stops all the currently playing effects on a haptic device. + * + * \param haptic Haptic device to stop. + * \return 0 on success or -1 on error. + */ +extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic); + /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index 476b49b0c..69a1490fc 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -673,3 +673,16 @@ SDL_HapticUnpause(SDL_Haptic * haptic) return SDL_SYS_HapticUnpause(haptic); } +/* + * Stops all the currently playing effects. + */ +int +SDL_HapticStopAll(SDL_Haptic * haptic) +{ + if (!ValidHaptic(haptic)) { + return -1; + } + + return SDL_SYS_HapticStopAll(haptic); +} + diff --git a/src/haptic/SDL_syshaptic.h b/src/haptic/SDL_syshaptic.h index d5a6a4daa..51e3670d5 100644 --- a/src/haptic/SDL_syshaptic.h +++ b/src/haptic/SDL_syshaptic.h @@ -194,3 +194,10 @@ extern int SDL_SYS_HapticPause(SDL_Haptic * haptic); */ extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic); +/* + * Stops all the currently playing haptic effects on the device. + * + * Returns 0 on success, -1 on error. + */ +extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic); + diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c index 0f18c02ae..0ec731296 100644 --- a/src/haptic/darwin/SDL_syshaptic.c +++ b/src/haptic/darwin/SDL_syshaptic.c @@ -1233,7 +1233,7 @@ SDL_SYS_HapticPause(SDL_Haptic * haptic) HRESULT ret; ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, - FFSFFC_PAUSE); + FFSFFC_PAUSE); if (ret != FF_OK) { SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); return -1; @@ -1252,7 +1252,7 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic) HRESULT ret; ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, - FFSFFC_CONTINUE); + FFSFFC_CONTINUE); if (ret != FF_OK) { SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); return -1; @@ -1262,4 +1262,23 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic) } +/* + * Stops all currently playing effects. + */ +int +SDL_SYS_HapticStopAll(SDL_Haptic * haptic) +{ + HRESULT ret; + + ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, + FFSFFC_STOPALL); + if (ret != FF_OK) { + SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret)); + return -1; + } + + return 0; +} + + #endif /* SDL_HAPTIC_IOKIT */ diff --git a/src/haptic/dummy/SDL_syshaptic.c b/src/haptic/dummy/SDL_syshaptic.c index 4c5aff9e3..a3003dc74 100644 --- a/src/haptic/dummy/SDL_syshaptic.c +++ b/src/haptic/dummy/SDL_syshaptic.c @@ -27,6 +27,13 @@ #include "../SDL_syshaptic.h" +static int +SDL_SYS_LogicError(void) +{ + SDL_SetError("Logic error: No haptic devices available.");; +} + + int SDL_SYS_HapticInit(void) { @@ -37,7 +44,7 @@ SDL_SYS_HapticInit(void) const char * SDL_SYS_HapticName(int index) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return NULL; } @@ -45,7 +52,7 @@ SDL_SYS_HapticName(int index) int SDL_SYS_HapticOpen(SDL_Haptic * haptic) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return -1; } @@ -67,7 +74,7 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return -1; } @@ -98,7 +105,7 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect, SDL_HapticEffect * base) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return -1; } @@ -108,7 +115,7 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect * effect, SDL_HapticEffect * data) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return -1; } @@ -116,7 +123,7 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, Uint32 iterations) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return -1; } @@ -124,7 +131,7 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, Uint int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return -1; } @@ -132,14 +139,14 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect) void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return; } int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect) { - SDL_SetError("Logic error: No Haptic devices available."); + SDL_SYS_LogicError(); return -1; } @@ -147,7 +154,7 @@ int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * ef int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return -1; } @@ -155,23 +162,31 @@ SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return -1; } int SDL_SYS_HapticPause(SDL_Haptic * haptic) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); return -1; } int SDL_SYS_HapticUnpause(SDL_Haptic * haptic) { - SDL_SetError("Logic error: No haptic devices available."); + SDL_SYS_LogicError(); + return -1; +} + +int +SDL_SYS_HapticStopAll(SDL_Haptic * haptic) +{ + SDL_SYS_LogicError(); return -1; } + #endif /* SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED */ diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index d2c29a9fd..42d5e2146 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -910,4 +910,24 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic) } +/* + * Stops all the currently playing effects. + */ +int +SDL_SYS_HapticStopAll(SDL_Haptic * haptic) +{ + int i, ret;; + + for (i=0; ineffects; i++) { + ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]); + if (ret < 0) { + SDL_SetError("Haptic: Error while trying to stop all playing effects."); + return -1; + } + } + + return 0; +} + + #endif /* SDL_HAPTIC_LINUX */ diff --git a/src/haptic/win32/SDL_syshaptic.c b/src/haptic/win32/SDL_syshaptic.c index 6d409dbc6..9bc613d75 100644 --- a/src/haptic/win32/SDL_syshaptic.c +++ b/src/haptic/win32/SDL_syshaptic.c @@ -1344,4 +1344,24 @@ SDL_SYS_HapticUnpause(SDL_Haptic * haptic) } +/* + * Stops all the playing effects on the device. + */ +int +SDL_SYS_HapticUnpause(SDL_Haptic * haptic) +{ + HRESULT ret; + + /* Try to stop the effects. */ + ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device, + DISFFC_STOPALL ); + if (FAILED(ret)) { + DI_SetError("Stopping the device",ret); + return -1; + } + + return 0; +} + + #endif /* SDL_HAPTIC_DINPUT */