Broke API by introducing iterations to SDL_HapticRunEffects(). gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Thu, 10 Jul 2008 17:54:08 +0000
branchgsoc2008_force_feedback
changeset 251737c13c12c878
parent 2516 6da022b18314
child 2518 07a5b225b9c9
Broke API by introducing iterations to SDL_HapticRunEffects().
Fixed minor issues.
include/SDL_haptic.h
src/haptic/SDL_haptic.c
src/haptic/SDL_syshaptic.h
src/haptic/dummy/SDL_syshaptic.c
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/include/SDL_haptic.h	Thu Jul 10 17:52:57 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Thu Jul 10 17:54:08 2008 +0000
     1.3 @@ -70,7 +70,7 @@
     1.4   *    effect_id = SDL_HapticNewEffect( haptic, &effect );
     1.5   *
     1.6   *    // Test the effect
     1.7 - *    SDL_HapticRunEffect( haptic, effect_id );
     1.8 + *    SDL_HapticRunEffect( haptic, effect_id, 1 );
     1.9   *    SDL_Delay( 5000); // Wait for the effect to finish
    1.10   *
    1.11   *    // We destroy the effect, although closing the device also does this
    1.12 @@ -263,6 +263,19 @@
    1.13  #define SDL_HAPTIC_CARTESIAN  1
    1.14  
    1.15  
    1.16 +/*
    1.17 + * Misc defines.
    1.18 + */
    1.19 +/**
    1.20 + * \def SDL_HAPTIC_INFINITY
    1.21 + *
    1.22 + * \brief Used to play a device an infinite number of times.
    1.23 + *
    1.24 + * \sa SDL_HapticRunEffect
    1.25 + */
    1.26 +#define SDL_HAPTIC_INFINITY   -1
    1.27 +
    1.28 +
    1.29  /**
    1.30   * \struct SDL_HapticDirection
    1.31   *
    1.32 @@ -681,7 +694,7 @@
    1.33   *
    1.34   * \sa SDL_HapticOpenFromMouse
    1.35   */
    1.36 -extern DECLSPEC SDL_MouseIsHaptic(void);
    1.37 +extern DECLSPEC int SDL_MouseIsHaptic(void);
    1.38  
    1.39  /**
    1.40   * \fn SDL_Haptic * SDL_HapticOpenFromMouse(void)
    1.41 @@ -830,19 +843,21 @@
    1.42  extern DECLSPEC int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data);
    1.43  
    1.44  /**
    1.45 - * \fn int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect)
    1.46 + * \fn int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, int iterations)
    1.47   *
    1.48   * \brief Runs the haptic effect on it's assosciated haptic device.
    1.49   *
    1.50   *    \param haptic Haptic device to run the effect on.
    1.51   *    \param effect Identifier of the haptic effect to run.
    1.52 + *    \param iterations Number of iterations to run the effect. Use
    1.53 + *           SDL_HAPTIC_INFINITY for infinity.
    1.54   *    \return 0 on success or -1 on error.
    1.55   *
    1.56   * \sa SDL_HapticStopEffect
    1.57   * \sa SDL_HapticDestroyEffect
    1.58   * \sa SDL_HapticGetEffectStatus
    1.59   */
    1.60 -extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
    1.61 +extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, int iterations);
    1.62  
    1.63  /**
    1.64   * \fn int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
     2.1 --- a/src/haptic/SDL_haptic.c	Thu Jul 10 17:52:57 2008 +0000
     2.2 +++ b/src/haptic/SDL_haptic.c	Thu Jul 10 17:54:08 2008 +0000
     2.3 @@ -470,14 +470,14 @@
     2.4   * Runs the haptic effect on the device.
     2.5   */
     2.6  int
     2.7 -SDL_HapticRunEffect(SDL_Haptic * haptic, int effect)
     2.8 +SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, int iterations)
     2.9  {
    2.10     if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
    2.11        return -1;
    2.12     }
    2.13  
    2.14     /* Run the effect */
    2.15 -   if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect]) < 0) {
    2.16 +   if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect], iterations) < 0) {
    2.17        return -1;
    2.18     }
    2.19  
     3.1 --- a/src/haptic/SDL_syshaptic.h	Thu Jul 10 17:52:57 2008 +0000
     3.2 +++ b/src/haptic/SDL_syshaptic.h	Thu Jul 10 17:54:08 2008 +0000
     3.3 @@ -38,7 +38,7 @@
     3.4  };
     3.5  
     3.6  /*
     3.7 - * The real SDL_Haptic event.
     3.8 + * The real SDL_Haptic struct.
     3.9   */
    3.10  struct _SDL_Haptic
    3.11  {  
    3.12 @@ -139,7 +139,8 @@
    3.13   * Returns 0 on success, -1 on error.
    3.14   */
    3.15  extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
    3.16 -                                   struct haptic_effect * effect);
    3.17 +                                   struct haptic_effect * effect,
    3.18 +                                   int iterations);
    3.19  
    3.20  /*
    3.21   * Stops the effect on the haptic device.
     4.1 --- a/src/haptic/dummy/SDL_syshaptic.c	Thu Jul 10 17:52:57 2008 +0000
     4.2 +++ b/src/haptic/dummy/SDL_syshaptic.c	Thu Jul 10 17:54:08 2008 +0000
     4.3 @@ -114,7 +114,7 @@
     4.4  
     4.5  
     4.6  int
     4.7 -SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
     4.8 +SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, int iterations)
     4.9  {
    4.10     SDL_SetError("Logic error: No haptic devices available.");
    4.11     return -1;
     5.1 --- a/src/haptic/linux/SDL_syshaptic.c	Thu Jul 10 17:52:57 2008 +0000
     5.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Thu Jul 10 17:54:08 2008 +0000
     5.3 @@ -36,6 +36,7 @@
     5.4  #include <sys/stat.h>
     5.5  #include <fcntl.h>
     5.6  #include <linux/limits.h>
     5.7 +#include <limits.h> /* INT_MAX */
     5.8  #include <string.h>
     5.9  #include <errno.h>
    5.10  #include <math.h>
    5.11 @@ -672,14 +673,17 @@
    5.12   * Runs an effect.
    5.13   */
    5.14  int
    5.15 -SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
    5.16 +SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, int iterations)
    5.17  {
    5.18     struct input_event run;
    5.19  
    5.20     /* Prepare to run the effect */
    5.21     run.type = EV_FF;
    5.22     run.code = effect->hweffect->effect.id;
    5.23 -   run.value = 1;
    5.24 +   if (iterations == SDL_HAPTIC_INFINITY)
    5.25 +      run.value = INT_MAX;
    5.26 +   else
    5.27 +      run.value = iterations;
    5.28  
    5.29     if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) {
    5.30        SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));