changeset 2645:269ba4f28d0e gsoc2008_force_feedback

Added support for pausing/unpausing haptic devices.
author Edgar Simo <bobbens@gmail.com>
date Sun, 24 Aug 2008 17:17:45 +0000
parents ef0ba67154c1
children 9408be170bff
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, 200 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_haptic.h	Tue Aug 12 20:49:31 2008 +0000
+++ b/include/SDL_haptic.h	Sun Aug 24 17:17:45 2008 +0000
@@ -240,6 +240,15 @@
  * \sa SDL_HapticGetEffectStatus
  */
 #define SDL_HAPTIC_STATUS     (1<<14) /* Device can be queried for effect status */
+/**
+ * \def SDL_HAPTIC_PAUSE
+ *
+ * \brief Device can be paused.
+ *
+ * \sa SDL_HapticPause
+ * \sa SDL_HapticUnpause
+ */
+#define SDL_HAPTIC_PAUSE      (1<<15) /* Device can be paused. */
 
 
 /*
@@ -1068,6 +1077,38 @@
  */
 extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
 
+/**
+ * \fn extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic)
+ *
+ * \brief Pauses the haptic device.
+ *
+ * Device must support the SDL_HAPTIC_PAUSE feature.  Call SDL_HapticUnpause
+ *  to resume playback.
+ *
+ * Do not modify the effects nor add new ones while the device is paused.
+ *  That can cause all sorts of weird errors.
+ *
+ *    \param haptic Haptic device to pause.
+ *    \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticUnpause
+ */
+extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
+
+/**
+ * \fn extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic)
+ *
+ * \brief Unpauses the haptic device.
+ *
+ * Call to unpause after SDL_HapticPause.
+ *
+ *    \param haptic Haptic device to pause.
+ *     \return 0 on success or -1 on error.
+ *
+ * \sa SDL_HapticPause
+ */
+extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
+
 
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
--- a/src/haptic/SDL_haptic.c	Tue Aug 12 20:49:31 2008 +0000
+++ b/src/haptic/SDL_haptic.c	Sun Aug 24 17:17:45 2008 +0000
@@ -638,4 +638,38 @@
    return 0;
 }
 
+/*
+ * Pauses the haptic device.
+ */
+int
+SDL_HapticPause(SDL_Haptic * haptic)
+{
+   if (!ValidHaptic(haptic)) {
+      return -1;
+   }
 
+   if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
+      SDL_SetError("Haptic: Device does not support setting pausing.");
+      return -1;
+   }
+
+   return SDL_SYS_HapticPause(haptic);
+}
+
+/*
+ * Unpauses the haptic device.
+ */
+int
+SDL_HapticUnpause(SDL_Haptic * haptic)
+{
+   if (!ValidHaptic(haptic)) {
+      return -1;
+   }
+
+   if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
+      return 0; /* Not going to be paused, so we pretend it's unpaused. */
+   }
+
+   return SDL_SYS_HapticUnpause(haptic);
+}
+
--- a/src/haptic/SDL_syshaptic.h	Tue Aug 12 20:49:31 2008 +0000
+++ b/src/haptic/SDL_syshaptic.h	Sun Aug 24 17:17:45 2008 +0000
@@ -180,4 +180,17 @@
 extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic,
                                        int autocenter);
 
+/*
+ * Pauses the haptic device.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticPause(SDL_Haptic * haptic);
 
+/*
+ * Unpauses the haptic device.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);
+
--- a/src/haptic/darwin/SDL_syshaptic.c	Tue Aug 12 20:49:31 2008 +0000
+++ b/src/haptic/darwin/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
@@ -376,7 +376,7 @@
    SDL_memcpy( haptic->hwdata->axes, features.ffAxes, haptic->naxes * sizeof(Uint8));
 
    /* Always supported features. */
-   supported |= SDL_HAPTIC_STATUS;
+   supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
 
    haptic->supported = supported;
    return 0;;
@@ -1221,7 +1221,44 @@
    }
   
    return 0;
+}
 
+
+/*
+ * Pauses the device.
+ */
+int
+SDL_SYS_HapticPause(SDL_Haptic * haptic)
+{
+   HRESULT ret;
+
+   ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
+         FFSFFC_PAUSE);
+   if (ret != FF_OK) {
+      SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
+      return -1;
+   }
+
+   return 0;
+}
+
+
+/*
+ * Unpauses the device.
+ */
+int
+SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
+{
+   HRESULT ret;
+
+   ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
+         FFSFFC_CONTINUE);
+   if (ret != FF_OK) {
+      SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
+      return -1;
+   }
+
+   return 0;
 }
 
 
--- a/src/haptic/dummy/SDL_syshaptic.c	Tue Aug 12 20:49:31 2008 +0000
+++ b/src/haptic/dummy/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
@@ -159,5 +159,19 @@
    return -1;
 }
 
+int
+SDL_SYS_HapticPause(SDL_Haptic * haptic)
+{
+   SDL_SetError("Logic error: No haptic devices available.");
+   return -1;
+}
+
+int
+SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
+{
+   SDL_SetError("Logic error: No haptic devices available.");
+   return -1;
+}
+
 
 #endif /* SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED */
--- a/src/haptic/linux/SDL_syshaptic.c	Tue Aug 12 20:49:31 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
@@ -890,4 +890,24 @@
 }
 
 
+/*
+ * Pausing is not supported atm by linux.
+ */
+int
+SDL_SYS_HapticPause(SDL_Haptic * haptic)
+{
+   return -1;
+}
+
+
+/*
+ * Unpausing is not supported atm by linux.
+ */
+int
+SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
+{
+   return -1;
+}
+
+
 #endif /* SDL_HAPTIC_LINUX */
--- a/src/haptic/win32/SDL_syshaptic.c	Tue Aug 12 20:49:31 2008 +0000
+++ b/src/haptic/win32/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
@@ -466,7 +466,7 @@
    }
 
    /* Status is always supported. */
-   haptic->supported |= SDL_HAPTIC_STATUS;
+   haptic->supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
 
    /* Check maximum effects. */
    haptic->neffects = 128; /* This is not actually supported as thus under windows,
@@ -1301,7 +1301,46 @@
    }
   
    return 0;
+}
 
+
+/*
+ * Pauses the device.
+ */
+int
+SDL_SYS_HapticPause(SDL_Haptic * haptic)
+{
+   HRESULT ret;
+
+   /* Pause the device. */
+   ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device,
+                                                       DISFFC_PAUSE );
+   if (FAILED(ret)) {
+      DI_SetError("Pausing the device",ret);
+      return -1;
+   }
+   
+   return 0;
+}
+
+
+/*
+ * Pauses the device.
+ */
+int
+SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
+{
+   HRESULT ret;
+
+   /* Unpause the device. */
+   ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device,
+                                                       DISFFC_CONTINUE );
+   if (FAILED(ret)) {
+      DI_SetError("Pausing the device",ret);
+      return -1;
+   }
+   
+   return 0;
 }