Added SDL_HapticStopEffect(). gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Tue, 01 Jul 2008 14:31:04 +0000
branchgsoc2008_force_feedback
changeset 248567978eea6d10
parent 2484 666472fd4cb0
child 2486 24dd8b8669fa
Added SDL_HapticStopEffect().
include/SDL_haptic.h
src/haptic/SDL_haptic.c
src/haptic/SDL_syshaptic.h
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/include/SDL_haptic.h	Tue Jul 01 14:21:09 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Tue Jul 01 14:31:04 2008 +0000
     1.3 @@ -245,7 +245,15 @@
     1.4  extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
     1.5  
     1.6  /*
     1.7 - * Destroys a haptic effect on the device.
     1.8 + * Stops the haptic effect on it's assosciated haptic device.
     1.9 + *
    1.10 + * Returns 0 on success or -1 on failure.
    1.11 + */
    1.12 +extern DECLSPEC int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect);
    1.13 +
    1.14 +/*
    1.15 + * Destroys a haptic effect on the device.  This will stop the effect if it's
    1.16 + * running.
    1.17   */
    1.18  extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
    1.19  
     2.1 --- a/src/haptic/SDL_haptic.c	Tue Jul 01 14:21:09 2008 +0000
     2.2 +++ b/src/haptic/SDL_haptic.c	Tue Jul 01 14:31:04 2008 +0000
     2.3 @@ -307,6 +307,24 @@
     2.4  }
     2.5  
     2.6  /*
     2.7 + * Stops the haptic effect on the device.
     2.8 + */
     2.9 +int
    2.10 +SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
    2.11 +{
    2.12 +   if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
    2.13 +      return -1;
    2.14 +   }
    2.15 +
    2.16 +   /* Stop the effect */
    2.17 +   if (SDL_SYS_HapticStopEffect(haptic,&haptic->effects[effect]) < 0) {
    2.18 +      return -1;
    2.19 +   }
    2.20 +
    2.21 +   return 0;
    2.22 +}
    2.23 +
    2.24 +/*
    2.25   * Gets rid of a haptic effect.
    2.26   */
    2.27  void
     3.1 --- a/src/haptic/SDL_syshaptic.h	Tue Jul 01 14:21:09 2008 +0000
     3.2 +++ b/src/haptic/SDL_syshaptic.h	Tue Jul 01 14:31:04 2008 +0000
     3.3 @@ -56,6 +56,8 @@
     3.4        struct haptic_effect * effect, SDL_HapticEffect * base);
     3.5  extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
     3.6        struct haptic_effect * effect);
     3.7 +extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic,
     3.8 +      struct haptic_effect * effect);
     3.9  extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic,
    3.10        struct haptic_effect * effect);
    3.11  extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain);
     4.1 --- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 14:21:09 2008 +0000
     4.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 14:31:04 2008 +0000
     4.3 @@ -495,6 +495,27 @@
     4.4  
     4.5  
     4.6  /*
     4.7 + * Stops an effect.
     4.8 + */
     4.9 +int
    4.10 +SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
    4.11 +{
    4.12 +   struct input_event stop;
    4.13 +
    4.14 +   stop.type = EV_FF;
    4.15 +   stop.code = effect->hweffect->effect.id;
    4.16 +   stop.value = 0;
    4.17 +
    4.18 +   if (write(haptic->hwdata->fd, (const void*) &stop, sizeof(stop)) < 0) {
    4.19 +      SDL_SetError("Unable to stop the haptic effect.");
    4.20 +      return -1;
    4.21 +   }
    4.22 +
    4.23 +   return 0;
    4.24 +}
    4.25 +
    4.26 +
    4.27 +/*
    4.28   * Frees the effect
    4.29   */
    4.30  void