Added SDL_HapticStopAll. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Sun, 24 Aug 2008 17:32:50 +0000
branchgsoc2008_force_feedback
changeset 26469408be170bff
parent 2645 269ba4f28d0e
child 2647 e871cff1e3d2
Added SDL_HapticStopAll.
Cleaned up the dummy haptic driver a bit.
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	Sun Aug 24 17:17:45 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Sun Aug 24 17:32:50 2008 +0000
     1.3 @@ -764,6 +764,8 @@
     1.4   * \sa SDL_HapticClose
     1.5   * \sa SDL_HapticSetGain
     1.6   * \sa SDL_HapticSetAutocenter
     1.7 + * \sa SDL_HapticPause
     1.8 + * \sa SDL_HapticStopAll
     1.9   */
    1.10  extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);
    1.11  
    1.12 @@ -1080,7 +1082,7 @@
    1.13  /**
    1.14   * \fn extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic)
    1.15   *
    1.16 - * \brief Pauses the haptic device.
    1.17 + * \brief Pauses a haptic device.
    1.18   *
    1.19   * Device must support the SDL_HAPTIC_PAUSE feature.  Call SDL_HapticUnpause
    1.20   *  to resume playback.
    1.21 @@ -1098,17 +1100,27 @@
    1.22  /**
    1.23   * \fn extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic)
    1.24   *
    1.25 - * \brief Unpauses the haptic device.
    1.26 + * \brief Unpauses a haptic device.
    1.27   *
    1.28   * Call to unpause after SDL_HapticPause.
    1.29   *
    1.30   *    \param haptic Haptic device to pause.
    1.31 - *     \return 0 on success or -1 on error.
    1.32 + *    \return 0 on success or -1 on error.
    1.33   *
    1.34   * \sa SDL_HapticPause
    1.35   */
    1.36  extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
    1.37  
    1.38 +/**
    1.39 + * \fn extern DECSLPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic)
    1.40 + *
    1.41 + * \brief Stops all the currently playing effects on a haptic device.
    1.42 + *
    1.43 + *    \param haptic Haptic device to stop.
    1.44 + *    \return 0 on success or -1 on error.
    1.45 + */
    1.46 +extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);
    1.47 +
    1.48  
    1.49  /* Ends C function definitions when using C++ */
    1.50  #ifdef __cplusplus
     2.1 --- a/src/haptic/SDL_haptic.c	Sun Aug 24 17:17:45 2008 +0000
     2.2 +++ b/src/haptic/SDL_haptic.c	Sun Aug 24 17:32:50 2008 +0000
     2.3 @@ -673,3 +673,16 @@
     2.4     return SDL_SYS_HapticUnpause(haptic);
     2.5  }
     2.6  
     2.7 +/*
     2.8 + * Stops all the currently playing effects.
     2.9 + */
    2.10 +int
    2.11 +SDL_HapticStopAll(SDL_Haptic * haptic)
    2.12 +{
    2.13 +   if (!ValidHaptic(haptic)) {
    2.14 +      return -1;
    2.15 +   }
    2.16 +
    2.17 +   return SDL_SYS_HapticStopAll(haptic);
    2.18 +}
    2.19 +
     3.1 --- a/src/haptic/SDL_syshaptic.h	Sun Aug 24 17:17:45 2008 +0000
     3.2 +++ b/src/haptic/SDL_syshaptic.h	Sun Aug 24 17:32:50 2008 +0000
     3.3 @@ -194,3 +194,10 @@
     3.4   */
     3.5  extern int SDL_SYS_HapticUnpause(SDL_Haptic * haptic);
     3.6  
     3.7 +/*
     3.8 + * Stops all the currently playing haptic effects on the device.
     3.9 + *
    3.10 + * Returns 0 on success, -1 on error.
    3.11 + */
    3.12 +extern int SDL_SYS_HapticStopAll(SDL_Haptic * haptic);
    3.13 +
     4.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
     4.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Sun Aug 24 17:32:50 2008 +0000
     4.3 @@ -1233,7 +1233,7 @@
     4.4     HRESULT ret;
     4.5  
     4.6     ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
     4.7 -         FFSFFC_PAUSE);
     4.8 +                                          FFSFFC_PAUSE);
     4.9     if (ret != FF_OK) {
    4.10        SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
    4.11        return -1;
    4.12 @@ -1252,7 +1252,7 @@
    4.13     HRESULT ret;
    4.14  
    4.15     ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
    4.16 -         FFSFFC_CONTINUE);
    4.17 +                                          FFSFFC_CONTINUE);
    4.18     if (ret != FF_OK) {
    4.19        SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret));
    4.20        return -1;
    4.21 @@ -1262,4 +1262,23 @@
    4.22  }
    4.23  
    4.24  
    4.25 +/*
    4.26 + * Stops all currently playing effects.
    4.27 + */
    4.28 +int
    4.29 +SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
    4.30 +{
    4.31 +   HRESULT ret;
    4.32 +
    4.33 +   ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device,
    4.34 +                                          FFSFFC_STOPALL); 
    4.35 +   if (ret != FF_OK) {
    4.36 +      SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret));
    4.37 +      return -1;
    4.38 +   }
    4.39 +
    4.40 +   return 0;
    4.41 +}
    4.42 +
    4.43 +
    4.44  #endif /* SDL_HAPTIC_IOKIT */
     5.1 --- a/src/haptic/dummy/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
     5.2 +++ b/src/haptic/dummy/SDL_syshaptic.c	Sun Aug 24 17:32:50 2008 +0000
     5.3 @@ -27,6 +27,13 @@
     5.4  #include "../SDL_syshaptic.h"
     5.5  
     5.6  
     5.7 +static int
     5.8 +SDL_SYS_LogicError(void)
     5.9 +{
    5.10 +   SDL_SetError("Logic error: No haptic devices available.");;
    5.11 +}
    5.12 +
    5.13 +
    5.14  int
    5.15  SDL_SYS_HapticInit(void)
    5.16  {
    5.17 @@ -37,7 +44,7 @@
    5.18  const char *
    5.19  SDL_SYS_HapticName(int index)
    5.20  {
    5.21 -   SDL_SetError("Logic error: No haptic devices available.");
    5.22 +   SDL_SYS_LogicError();
    5.23     return NULL;
    5.24  }
    5.25  
    5.26 @@ -45,7 +52,7 @@
    5.27  int
    5.28  SDL_SYS_HapticOpen(SDL_Haptic * haptic)
    5.29  {
    5.30 -   SDL_SetError("Logic error: No haptic devices available.");
    5.31 +   SDL_SYS_LogicError();
    5.32     return -1;
    5.33  }
    5.34  
    5.35 @@ -67,7 +74,7 @@
    5.36  int
    5.37  SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
    5.38  {
    5.39 -   SDL_SetError("Logic error: No haptic devices available.");
    5.40 +   SDL_SYS_LogicError();
    5.41     return -1;
    5.42  }
    5.43  
    5.44 @@ -98,7 +105,7 @@
    5.45                          struct haptic_effect * effect,
    5.46                          SDL_HapticEffect * base)
    5.47  {
    5.48 -   SDL_SetError("Logic error: No haptic devices available.");
    5.49 +   SDL_SYS_LogicError();
    5.50     return -1;
    5.51  }
    5.52  
    5.53 @@ -108,7 +115,7 @@
    5.54                             struct haptic_effect * effect,
    5.55                             SDL_HapticEffect * data)
    5.56  {
    5.57 -   SDL_SetError("Logic error: No haptic devices available.");
    5.58 +   SDL_SYS_LogicError();
    5.59     return -1;
    5.60  }
    5.61  
    5.62 @@ -116,7 +123,7 @@
    5.63  int
    5.64  SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, Uint32 iterations)
    5.65  {
    5.66 -   SDL_SetError("Logic error: No haptic devices available.");
    5.67 +   SDL_SYS_LogicError();
    5.68     return -1;
    5.69  }
    5.70  
    5.71 @@ -124,7 +131,7 @@
    5.72  int
    5.73  SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
    5.74  {
    5.75 -   SDL_SetError("Logic error: No haptic devices available.");
    5.76 +   SDL_SYS_LogicError();
    5.77     return -1;
    5.78  }
    5.79  
    5.80 @@ -132,14 +139,14 @@
    5.81  void
    5.82  SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
    5.83  {
    5.84 -   SDL_SetError("Logic error: No haptic devices available.");
    5.85 +   SDL_SYS_LogicError();
    5.86     return;
    5.87  }
    5.88  
    5.89  
    5.90  int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect)
    5.91  {
    5.92 -   SDL_SetError("Logic error: No Haptic devices available.");
    5.93 +   SDL_SYS_LogicError();
    5.94     return -1;
    5.95  }
    5.96  
    5.97 @@ -147,7 +154,7 @@
    5.98  int
    5.99  SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
   5.100  {
   5.101 -   SDL_SetError("Logic error: No haptic devices available.");
   5.102 +   SDL_SYS_LogicError();
   5.103     return -1;
   5.104  }
   5.105  
   5.106 @@ -155,23 +162,31 @@
   5.107  int
   5.108  SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
   5.109  {
   5.110 -   SDL_SetError("Logic error: No haptic devices available.");
   5.111 +   SDL_SYS_LogicError();
   5.112     return -1;
   5.113  }
   5.114  
   5.115  int
   5.116  SDL_SYS_HapticPause(SDL_Haptic * haptic)
   5.117  {
   5.118 -   SDL_SetError("Logic error: No haptic devices available.");
   5.119 +   SDL_SYS_LogicError();
   5.120     return -1;
   5.121  }
   5.122  
   5.123  int
   5.124  SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
   5.125  {
   5.126 -   SDL_SetError("Logic error: No haptic devices available.");
   5.127 +   SDL_SYS_LogicError();
   5.128     return -1;
   5.129  }
   5.130  
   5.131 +int
   5.132 +SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
   5.133 +{
   5.134 +   SDL_SYS_LogicError();
   5.135 +   return -1;
   5.136 +}
   5.137 +
   5.138 +
   5.139  
   5.140  #endif /* SDL_HAPTIC_DUMMY || SDL_HAPTIC_DISABLED */
     6.1 --- a/src/haptic/linux/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
     6.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Sun Aug 24 17:32:50 2008 +0000
     6.3 @@ -910,4 +910,24 @@
     6.4  }
     6.5  
     6.6  
     6.7 +/*
     6.8 + * Stops all the currently playing effects.
     6.9 + */
    6.10 +int
    6.11 +SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
    6.12 +{
    6.13 +   int i, ret;;
    6.14 +
    6.15 +   for (i=0; i<haptic->neffects; i++) {
    6.16 +      ret = SDL_SYS_HapticStopEffect(haptic, &haptic->effects[i]);
    6.17 +      if (ret < 0) {
    6.18 +         SDL_SetError("Haptic: Error while trying to stop all playing effects.");
    6.19 +         return -1;
    6.20 +      }
    6.21 +   }
    6.22 +
    6.23 +   return 0;
    6.24 +}
    6.25 +
    6.26 +
    6.27  #endif /* SDL_HAPTIC_LINUX */
     7.1 --- a/src/haptic/win32/SDL_syshaptic.c	Sun Aug 24 17:17:45 2008 +0000
     7.2 +++ b/src/haptic/win32/SDL_syshaptic.c	Sun Aug 24 17:32:50 2008 +0000
     7.3 @@ -1344,4 +1344,24 @@
     7.4  }
     7.5  
     7.6  
     7.7 +/*
     7.8 + * Stops all the playing effects on the device.
     7.9 + */
    7.10 +int
    7.11 +SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
    7.12 +{
    7.13 +   HRESULT ret;
    7.14 +
    7.15 +   /* Try to stop the effects. */
    7.16 +   ret = IDirectInputDevice2_SendForceFeedbackCommand( haptic->hwdata->device,
    7.17 +                                                       DISFFC_STOPALL );
    7.18 +   if (FAILED(ret)) {
    7.19 +      DI_SetError("Stopping the device",ret);
    7.20 +      return -1;
    7.21 +   }
    7.22 +   
    7.23 +   return 0;
    7.24 +}
    7.25 +
    7.26 +
    7.27  #endif /* SDL_HAPTIC_DINPUT */