Added support for pausing/unpausing haptic devices. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Sun, 24 Aug 2008 17:17:45 +0000
branchgsoc2008_force_feedback
changeset 2645269ba4f28d0e
parent 2644 ef0ba67154c1
child 2646 9408be170bff
Added support for pausing/unpausing haptic devices.
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
     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,8 +1221,45 @@
    4.13     }
    4.14    
    4.15     return 0;
    4.16 -
    4.17  }
    4.18  
    4.19  
    4.20 +/*
    4.21 + * Pauses the device.
    4.22 + */
    4.23 +int
    4.24 +SDL_SYS_HapticPause(SDL_Haptic * haptic)
    4.25 +{
    4.26 +   HRESULT ret;
    4.27 +
    4.28 +   ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
    4.29 +         FFSFFC_PAUSE);
    4.30 +   if (ret != FF_OK) {
    4.31 +      SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
    4.32 +      return -1;
    4.33 +   }
    4.34 +
    4.35 +   return 0;
    4.36 +}
    4.37 +
    4.38 +
    4.39 +/*
    4.40 + * Unpauses the device.
    4.41 + */
    4.42 +int
    4.43 +SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
    4.44 +{
    4.45 +   HRESULT ret;
    4.46 +
    4.47 +   ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
    4.48 +         FFSFFC_CONTINUE);
    4.49 +   if (ret != FF_OK) {
    4.50 +      SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
    4.51 +      return -1;
    4.52 +   }
    4.53 +
    4.54 +   return 0;
    4.55 +}
    4.56 +
    4.57 +
    4.58  #endif /* SDL_HAPTIC_IOKIT */
     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,8 +1301,47 @@
    7.13     }
    7.14    
    7.15     return 0;
    7.16 -
    7.17  }
    7.18  
    7.19  
    7.20 +/*
    7.21 + * Pauses the device.
    7.22 + */
    7.23 +int
    7.24 +SDL_SYS_HapticPause(SDL_Haptic * haptic)
    7.25 +{
    7.26 +   HRESULT ret;
    7.27 +
    7.28 +   /* Pause the device. */
    7.29 +   ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device,
    7.30 +                                                       DISFFC_PAUSE );
    7.31 +   if (FAILED(ret)) {
    7.32 +      DI_SetError("Pausing the device",ret);
    7.33 +      return -1;
    7.34 +   }
    7.35 +   
    7.36 +   return 0;
    7.37 +}
    7.38 +
    7.39 +
    7.40 +/*
    7.41 + * Pauses the device.
    7.42 + */
    7.43 +int
    7.44 +SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
    7.45 +{
    7.46 +   HRESULT ret;
    7.47 +
    7.48 +   /* Unpause the device. */
    7.49 +   ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device,
    7.50 +                                                       DISFFC_CONTINUE );
    7.51 +   if (FAILED(ret)) {
    7.52 +      DI_SetError("Pausing the device",ret);
    7.53 +      return -1;
    7.54 +   }
    7.55 +   
    7.56 +   return 0;
    7.57 +}
    7.58 +
    7.59 +
    7.60  #endif /* SDL_HAPTIC_DINPUT */