Added support for pausing/unpausing haptic devices.
1.1 --- a/include/SDL_haptic.h Tue Aug 12 20:49:31 2008 +0000
1.2 +++ b/include/SDL_haptic.h Sun Aug 24 17:17:45 2008 +0000
1.3 @@ -240,6 +240,15 @@
1.4 * \sa SDL_HapticGetEffectStatus
1.5 */
1.6 #define SDL_HAPTIC_STATUS (1<<14) /* Device can be queried for effect status */
1.7 +/**
1.8 + * \def SDL_HAPTIC_PAUSE
1.9 + *
1.10 + * \brief Device can be paused.
1.11 + *
1.12 + * \sa SDL_HapticPause
1.13 + * \sa SDL_HapticUnpause
1.14 + */
1.15 +#define SDL_HAPTIC_PAUSE (1<<15) /* Device can be paused. */
1.16
1.17
1.18 /*
1.19 @@ -1068,6 +1077,38 @@
1.20 */
1.21 extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
1.22
1.23 +/**
1.24 + * \fn extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic)
1.25 + *
1.26 + * \brief Pauses the haptic device.
1.27 + *
1.28 + * Device must support the SDL_HAPTIC_PAUSE feature. Call SDL_HapticUnpause
1.29 + * to resume playback.
1.30 + *
1.31 + * Do not modify the effects nor add new ones while the device is paused.
1.32 + * That can cause all sorts of weird errors.
1.33 + *
1.34 + * \param haptic Haptic device to pause.
1.35 + * \return 0 on success or -1 on error.
1.36 + *
1.37 + * \sa SDL_HapticUnpause
1.38 + */
1.39 +extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
1.40 +
1.41 +/**
1.42 + * \fn extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic)
1.43 + *
1.44 + * \brief Unpauses the haptic device.
1.45 + *
1.46 + * Call to unpause after SDL_HapticPause.
1.47 + *
1.48 + * \param haptic Haptic device to pause.
1.49 + * \return 0 on success or -1 on error.
1.50 + *
1.51 + * \sa SDL_HapticPause
1.52 + */
1.53 +extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
1.54 +
1.55
1.56 /* Ends C function definitions when using C++ */
1.57 #ifdef __cplusplus
2.1 --- a/src/haptic/SDL_haptic.c Tue Aug 12 20:49:31 2008 +0000
2.2 +++ b/src/haptic/SDL_haptic.c Sun Aug 24 17:17:45 2008 +0000
2.3 @@ -638,4 +638,38 @@
2.4 return 0;
2.5 }
2.6
2.7 +/*
2.8 + * Pauses the haptic device.
2.9 + */
2.10 +int
2.11 +SDL_HapticPause(SDL_Haptic * haptic)
2.12 +{
2.13 + if (!ValidHaptic(haptic)) {
2.14 + return -1;
2.15 + }
2.16
2.17 + if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
2.18 + SDL_SetError("Haptic: Device does not support setting pausing.");
2.19 + return -1;
2.20 + }
2.21 +
2.22 + return SDL_SYS_HapticPause(haptic);
2.23 +}
2.24 +
2.25 +/*
2.26 + * Unpauses the haptic device.
2.27 + */
2.28 +int
2.29 +SDL_HapticUnpause(SDL_Haptic * haptic)
2.30 +{
2.31 + if (!ValidHaptic(haptic)) {
2.32 + return -1;
2.33 + }
2.34 +
2.35 + if ((haptic->supported & SDL_HAPTIC_PAUSE) == 0) {
2.36 + return 0; /* Not going to be paused, so we pretend it's unpaused. */
2.37 + }
2.38 +
2.39 + return SDL_SYS_HapticUnpause(haptic);
2.40 +}
2.41 +
3.1 --- a/src/haptic/SDL_syshaptic.h Tue Aug 12 20:49:31 2008 +0000
3.2 +++ b/src/haptic/SDL_syshaptic.h Sun Aug 24 17:17:45 2008 +0000
3.3 @@ -180,4 +180,17 @@
3.4 extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic,
3.5 int autocenter);
3.6
3.7 +/*
3.8 + * Pauses the haptic device.
3.9 + *
3.10 + * Returns 0 on success, -1 on error.
3.11 + */
3.12 +extern int SDL_SYS_HapticPause(SDL_Haptic * haptic);
3.13
3.14 +/*
3.15 + * Unpauses the haptic device.
3.16 + *
3.17 + * Returns 0 on success, -1 on error.
3.18 + */
3.19 +extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);
3.20 +
4.1 --- a/src/haptic/darwin/SDL_syshaptic.c Tue Aug 12 20:49:31 2008 +0000
4.2 +++ b/src/haptic/darwin/SDL_syshaptic.c Sun Aug 24 17:17:45 2008 +0000
4.3 @@ -376,7 +376,7 @@
4.4 SDL_memcpy( haptic->hwdata->axes, features.ffAxes, haptic->naxes * sizeof(Uint8));
4.5
4.6 /* Always supported features. */
4.7 - supported |= SDL_HAPTIC_STATUS;
4.8 + supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
4.9
4.10 haptic->supported = supported;
4.11 return 0;;
4.12 @@ -1221,7 +1221,44 @@
4.13 }
4.14
4.15 return 0;
4.16 +}
4.17
4.18 +
4.19 +/*
4.20 + * Pauses the device.
4.21 + */
4.22 +int
4.23 +SDL_SYS_HapticPause(SDL_Haptic * haptic)
4.24 +{
4.25 + HRESULT ret;
4.26 +
4.27 + ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
4.28 + FFSFFC_PAUSE);
4.29 + if (ret != FF_OK) {
4.30 + SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
4.31 + return -1;
4.32 + }
4.33 +
4.34 + return 0;
4.35 +}
4.36 +
4.37 +
4.38 +/*
4.39 + * Unpauses the device.
4.40 + */
4.41 +int
4.42 +SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
4.43 +{
4.44 + HRESULT ret;
4.45 +
4.46 + ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
4.47 + FFSFFC_CONTINUE);
4.48 + if (ret != FF_OK) {
4.49 + SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
4.50 + return -1;
4.51 + }
4.52 +
4.53 + return 0;
4.54 }
4.55
4.56
5.1 --- a/src/haptic/dummy/SDL_syshaptic.c Tue Aug 12 20:49:31 2008 +0000
5.2 +++ b/src/haptic/dummy/SDL_syshaptic.c Sun Aug 24 17:17:45 2008 +0000
5.3 @@ -159,5 +159,19 @@
5.4 return -1;
5.5 }
5.6
5.7 +int
5.8 +SDL_SYS_HapticPause(SDL_Haptic * haptic)
5.9 +{
5.10 + SDL_SetError("Logic error: No haptic devices available.");
5.11 + return -1;
5.12 +}
5.13 +
5.14 +int
5.15 +SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
5.16 +{
5.17 + SDL_SetError("Logic error: No haptic devices available.");
5.18 + return -1;
5.19 +}
5.20 +
5.21
5.22 #endif /* SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED */
6.1 --- a/src/haptic/linux/SDL_syshaptic.c Tue Aug 12 20:49:31 2008 +0000
6.2 +++ b/src/haptic/linux/SDL_syshaptic.c Sun Aug 24 17:17:45 2008 +0000
6.3 @@ -890,4 +890,24 @@
6.4 }
6.5
6.6
6.7 +/*
6.8 + * Pausing is not supported atm by linux.
6.9 + */
6.10 +int
6.11 +SDL_SYS_HapticPause(SDL_Haptic * haptic)
6.12 +{
6.13 + return -1;
6.14 +}
6.15 +
6.16 +
6.17 +/*
6.18 + * Unpausing is not supported atm by linux.
6.19 + */
6.20 +int
6.21 +SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
6.22 +{
6.23 + return -1;
6.24 +}
6.25 +
6.26 +
6.27 #endif /* SDL_HAPTIC_LINUX */
7.1 --- a/src/haptic/win32/SDL_syshaptic.c Tue Aug 12 20:49:31 2008 +0000
7.2 +++ b/src/haptic/win32/SDL_syshaptic.c Sun Aug 24 17:17:45 2008 +0000
7.3 @@ -466,7 +466,7 @@
7.4 }
7.5
7.6 /* Status is always supported. */
7.7 - haptic->supported |= SDL_HAPTIC_STATUS;
7.8 + haptic->supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
7.9
7.10 /* Check maximum effects. */
7.11 haptic->neffects = 128; /* This is not actually supported as thus under windows,
7.12 @@ -1301,7 +1301,46 @@
7.13 }
7.14
7.15 return 0;
7.16 +}
7.17
7.18 +
7.19 +/*
7.20 + * Pauses the device.
7.21 + */
7.22 +int
7.23 +SDL_SYS_HapticPause(SDL_Haptic * haptic)
7.24 +{
7.25 + HRESULT ret;
7.26 +
7.27 + /* Pause the device. */
7.28 + ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device,
7.29 + DISFFC_PAUSE );
7.30 + if (FAILED(ret)) {
7.31 + DI_SetError("Pausing the device",ret);
7.32 + return -1;
7.33 + }
7.34 +
7.35 + return 0;
7.36 +}
7.37 +
7.38 +
7.39 +/*
7.40 + * Pauses the device.
7.41 + */
7.42 +int
7.43 +SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
7.44 +{
7.45 + HRESULT ret;
7.46 +
7.47 + /* Unpause the device. */
7.48 + ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device,
7.49 + DISFFC_CONTINUE );
7.50 + if (FAILED(ret)) {
7.51 + DI_SetError("Pausing the device",ret);
7.52 + return -1;
7.53 + }
7.54 +
7.55 + return 0;
7.56 }
7.57
7.58