[SVN] r4023 - in branches/gsoc2008_force_feedback: include src/haptic src/haptic/darwin src/haptic/dummy src/haptic/linux src/haptic/win32
svn-owner at libsdl.org
svn-owner at libsdl.org
Sun Aug 24 10:17:46 PDT 2008
Author: bobbens
Date: 2008-08-24 10:17:45 -0700 (Sun, 24 Aug 2008)
New Revision: 4023
Modified:
branches/gsoc2008_force_feedback/include/SDL_haptic.h
branches/gsoc2008_force_feedback/src/haptic/SDL_haptic.c
branches/gsoc2008_force_feedback/src/haptic/SDL_syshaptic.h
branches/gsoc2008_force_feedback/src/haptic/darwin/SDL_syshaptic.c
branches/gsoc2008_force_feedback/src/haptic/dummy/SDL_syshaptic.c
branches/gsoc2008_force_feedback/src/haptic/linux/SDL_syshaptic.c
branches/gsoc2008_force_feedback/src/haptic/win32/SDL_syshaptic.c
Log:
Added support for pausing/unpausing haptic devices.
Modified: branches/gsoc2008_force_feedback/include/SDL_haptic.h
===================================================================
--- branches/gsoc2008_force_feedback/include/SDL_haptic.h 2008-08-22 22:38:49 UTC (rev 4022)
+++ branches/gsoc2008_force_feedback/include/SDL_haptic.h 2008-08-24 17:17:45 UTC (rev 4023)
@@ -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,7 +1077,39 @@
*/
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
/* *INDENT-OFF* */
Modified: branches/gsoc2008_force_feedback/src/haptic/SDL_haptic.c
===================================================================
--- branches/gsoc2008_force_feedback/src/haptic/SDL_haptic.c 2008-08-22 22:38:49 UTC (rev 4022)
+++ branches/gsoc2008_force_feedback/src/haptic/SDL_haptic.c 2008-08-24 17:17:45 UTC (rev 4023)
@@ -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);
+}
+
Modified: branches/gsoc2008_force_feedback/src/haptic/SDL_syshaptic.h
===================================================================
--- branches/gsoc2008_force_feedback/src/haptic/SDL_syshaptic.h 2008-08-22 22:38:49 UTC (rev 4022)
+++ branches/gsoc2008_force_feedback/src/haptic/SDL_syshaptic.h 2008-08-24 17:17:45 UTC (rev 4023)
@@ -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);
+
Modified: branches/gsoc2008_force_feedback/src/haptic/darwin/SDL_syshaptic.c
===================================================================
--- branches/gsoc2008_force_feedback/src/haptic/darwin/SDL_syshaptic.c 2008-08-22 22:38:49 UTC (rev 4022)
+++ branches/gsoc2008_force_feedback/src/haptic/darwin/SDL_syshaptic.c 2008-08-24 17:17:45 UTC (rev 4023)
@@ -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,8 +1221,45 @@
}
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;
+}
+
+
#endif /* SDL_HAPTIC_IOKIT */
Modified: branches/gsoc2008_force_feedback/src/haptic/dummy/SDL_syshaptic.c
===================================================================
--- branches/gsoc2008_force_feedback/src/haptic/dummy/SDL_syshaptic.c 2008-08-22 22:38:49 UTC (rev 4022)
+++ branches/gsoc2008_force_feedback/src/haptic/dummy/SDL_syshaptic.c 2008-08-24 17:17:45 UTC (rev 4023)
@@ -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 */
Modified: branches/gsoc2008_force_feedback/src/haptic/linux/SDL_syshaptic.c
===================================================================
--- branches/gsoc2008_force_feedback/src/haptic/linux/SDL_syshaptic.c 2008-08-22 22:38:49 UTC (rev 4022)
+++ branches/gsoc2008_force_feedback/src/haptic/linux/SDL_syshaptic.c 2008-08-24 17:17:45 UTC (rev 4023)
@@ -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 */
Modified: branches/gsoc2008_force_feedback/src/haptic/win32/SDL_syshaptic.c
===================================================================
--- branches/gsoc2008_force_feedback/src/haptic/win32/SDL_syshaptic.c 2008-08-22 22:38:49 UTC (rev 4022)
+++ branches/gsoc2008_force_feedback/src/haptic/win32/SDL_syshaptic.c 2008-08-24 17:17:45 UTC (rev 4023)
@@ -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,8 +1301,47 @@
}
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;
+}
+
+
#endif /* SDL_HAPTIC_DINPUT */
More information about the commits
mailing list