changeset 2646:9408be170bff gsoc2008_force_feedback

Added SDL_HapticStopAll. Cleaned up the dummy haptic driver a bit.
author Edgar Simo <bobbens@gmail.com>
date Sun, 24 Aug 2008 17:32:50 +0000
parents 269ba4f28d0e
children e871cff1e3d2
files include/SDL_haptic.h src/haptic/SDL_haptic.c src/haptic/SDL_syshaptic.h src/haptic/darwin/SDL_syshaptic.c src/haptic/dummy/SDL_syshaptic.c src/haptic/linux/SDL_syshaptic.c src/haptic/win32/SDL_syshaptic.c
diffstat 7 files changed, 124 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_haptic.h	Sun Aug 24 17:17:45 2008 +0000
+++ b/include/SDL_haptic.h	Sun Aug 24 17:32:50 2008 +0000
@@ -764,6 +764,8 @@
  * \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 @@
 /**
  * \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 @@
 /**
  * \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
--- a/src/haptic/SDL_haptic.c	Sun Aug 24 17:17:45 2008 +0000
+++ b/src/haptic/SDL_haptic.c	Sun Aug 24 17:32:50 2008 +0000
@@ -673,3 +673,16 @@
    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);
+}
+
--- a/src/haptic/SDL_syshaptic.h	Sun Aug 24 17:17:45 2008 +0000
+++ b/src/haptic/SDL_syshaptic.h	Sun Aug 24 17:32:50 2008 +0000
@@ -194,3 +194,10 @@
  */
 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);
+
--- a/src/haptic/darwin/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
+++ b/src/haptic/darwin/SDL_syshaptic.c	Sun Aug 24 17:32:50 2008 +0000
@@ -1233,7 +1233,7 @@
    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 @@
    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 @@
 }
 
 
+/*
+ * 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 */
--- a/src/haptic/dummy/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
+++ b/src/haptic/dummy/SDL_syshaptic.c	Sun Aug 24 17:32:50 2008 +0000
@@ -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 @@
 const char *
 SDL_SYS_HapticName(int index)
 {
-   SDL_SetError("Logic error: No haptic devices available.");
+   SDL_SYS_LogicError();
    return NULL;
 }
 
@@ -45,7 +52,7 @@
 int
 SDL_SYS_HapticOpen(SDL_Haptic * haptic)
 {
-   SDL_SetError("Logic error: No haptic devices available.");
+   SDL_SYS_LogicError();
    return -1;
 }
 
@@ -67,7 +74,7 @@
 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 @@
                         struct haptic_effect * effect,
                         SDL_HapticEffect * base)
 {
-   SDL_SetError("Logic error: No haptic devices available.");
+   SDL_SYS_LogicError();
    return -1;
 }
 
@@ -108,7 +115,7 @@
                            struct haptic_effect * effect,
                            SDL_HapticEffect * data)
 {
-   SDL_SetError("Logic error: No haptic devices available.");
+   SDL_SYS_LogicError();
    return -1;
 }
 
@@ -116,7 +123,7 @@
 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 @@
 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 @@
 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_HapticSetGain(SDL_Haptic * haptic, int gain)
 {
-   SDL_SetError("Logic error: No haptic devices available.");
+   SDL_SYS_LogicError();
    return -1;
 }
 
@@ -155,23 +162,31 @@
 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 */
--- a/src/haptic/linux/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Sun Aug 24 17:32:50 2008 +0000
@@ -910,4 +910,24 @@
 }
 
 
+/*
+ * Stops all the currently playing effects.
+ */
+int
+SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
+{
+   int i, ret;;
+
+   for (i=0; i<haptic->neffects; 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 */
--- a/src/haptic/win32/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
+++ b/src/haptic/win32/SDL_syshaptic.c	Sun Aug 24 17:32:50 2008 +0000
@@ -1344,4 +1344,24 @@
 }
 
 
+/*
+ * 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 */