Added SDL_HapticGetEffectStatus(). gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Thu, 03 Jul 2008 09:58:27 +0000
branchgsoc2008_force_feedback
changeset 249566c02abeef0e
parent 2494 a72a5f62d6b7
child 2496 8f840a6cdf01
Added SDL_HapticGetEffectStatus().
More comments.
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 03 09:13:22 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Thu Jul 03 09:58:27 2008 +0000
     1.3 @@ -46,22 +46,25 @@
     1.4  typedef struct _SDL_Haptic SDL_Haptic;
     1.5  
     1.6  
     1.7 -/* Different effects that can be generated */
     1.8 -#define SDL_HAPTIC_CONSTANT   (1<<0)
     1.9 -#define SDL_HAPTIC_SINE       (1<<1)
    1.10 -#define SDL_HAPTIC_SQUARE     (1<<2)
    1.11 -#define SDL_HAPTIC_TRIANGLE   (1<<3)
    1.12 -#define SDL_HAPTIC_SAWTOOTHUP (1<<4)
    1.13 -#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5)
    1.14 -#define SDL_HAPTIC_RAMP       (1<<6)
    1.15 -#define SDL_HAPTIC_SPRING     (1<<7)
    1.16 -#define SDL_HAPTIC_FRICTION   (1<<8)
    1.17 -#define SDL_HAPTIC_DAMPER     (1<<9)
    1.18 -#define SDL_HAPTIC_INERTIA    (1<<10)
    1.19 -#define SDL_HAPTIC_CUSTOM     (1<<11)
    1.20 +/*
    1.21 + * Different haptic features a device can have.
    1.22 + */
    1.23 +#define SDL_HAPTIC_CONSTANT   (1<<0) /* Constant effect supported */
    1.24 +#define SDL_HAPTIC_SINE       (1<<1) /* Sine wave effect supported */
    1.25 +#define SDL_HAPTIC_SQUARE     (1<<2) /* Square wave effect supported */
    1.26 +#define SDL_HAPTIC_TRIANGLE   (1<<3) /* Triangle wave effect supported */
    1.27 +#define SDL_HAPTIC_SAWTOOTHUP (1<<4) /* Sawtoothup wave effect supported */
    1.28 +#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5) /* Sawtoothdown wave effect supported */
    1.29 +#define SDL_HAPTIC_RAMP       (1<<6) /* Ramp effect supported */
    1.30 +#define SDL_HAPTIC_SPRING     (1<<7) /* Spring effect supported - uses axes position */
    1.31 +#define SDL_HAPTIC_DAMPER     (1<<8) /* Damper effect supported - uses axes velocity */
    1.32 +#define SDL_HAPTIC_INERTIA    (1<<9) /* Inertia effect supported - uses axes acceleration */
    1.33 +#define SDL_HAPTIC_FRICTION   (1<<10) /* Friction effect supported - uses axes movement */
    1.34 +#define SDL_HAPTIC_CUSTOM     (1<<11) /* Custom effect is supported */
    1.35  /* These last two are features the device has, not effects */
    1.36 -#define SDL_HAPTIC_GAIN       (1<<12)
    1.37 -#define SDL_HAPTIC_AUTOCENTER (1<<13)
    1.38 +#define SDL_HAPTIC_GAIN       (1<<12) /* Device can set global gain */
    1.39 +#define SDL_HAPTIC_AUTOCENTER (1<<13) /* Device can set autocenter */
    1.40 +#define SDL_HAPTIC_STATUS     (1<<14) /* Device can be queried for effect status */
    1.41  
    1.42  
    1.43  /*
    1.44 @@ -166,8 +169,8 @@
    1.45     Uint16 interval;
    1.46  
    1.47     /* Ramp */
    1.48 -   Sint16 start;
    1.49 -   Sint16 end;
    1.50 +   Sint16 start; /* Beginning strength level. */
    1.51 +   Sint16 end; /* Ending strength level. */
    1.52  
    1.53     /* Envelope */
    1.54     Uint16 attack_length;
    1.55 @@ -288,6 +291,14 @@
    1.56  extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect);
    1.57  
    1.58  /*
    1.59 + * Gets the status of the current effect on the haptic device.
    1.60 + *
    1.61 + * Returns 0 if it isn't playing, SDL_HAPTIC_PLAYING if it is playing
    1.62 + * or -1 on failure.
    1.63 + */
    1.64 +extern DECLSPEC int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect);
    1.65 +
    1.66 +/*
    1.67   * Sets the global gain of the device.  Gain should be between 0 and 100.
    1.68   *
    1.69   * Returns 0 on success or -1 on failure.
     2.1 --- a/src/haptic/SDL_haptic.c	Thu Jul 03 09:13:22 2008 +0000
     2.2 +++ b/src/haptic/SDL_haptic.c	Thu Jul 03 09:58:27 2008 +0000
     2.3 @@ -438,6 +438,24 @@
     2.4  }
     2.5  
     2.6  /*
     2.7 + * Gets the status of a haptic effect.
     2.8 + */
     2.9 +int
    2.10 +SDL_HapticGetEffectStatus(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 +   if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) {
    2.17 +      SDL_SetError("Haptic device does not support status queries.");
    2.18 +      return -1;
    2.19 +   }
    2.20 +
    2.21 +   return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
    2.22 +}
    2.23 +
    2.24 +/*
    2.25   * Sets the global gain of the device.
    2.26   */
    2.27  int
     3.1 --- a/src/haptic/SDL_syshaptic.h	Thu Jul 03 09:13:22 2008 +0000
     3.2 +++ b/src/haptic/SDL_syshaptic.h	Thu Jul 03 09:58:27 2008 +0000
     3.3 @@ -145,6 +145,15 @@
     3.4                                          struct haptic_effect * effect);
     3.5  
     3.6  /*
     3.7 + * Queries the device for the status of effect.
     3.8 + *
     3.9 + * Returns 0 if device is stopped, >0 if device is playing and
    3.10 + * -1 on error.
    3.11 + */
    3.12 +extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
    3.13 +                                         struct haptic_effect * effect);
    3.14 +
    3.15 +/*
    3.16   * Sets the global gain of the haptic device.
    3.17   *
    3.18   * Returns 0 on success, -1 on error.
     4.1 --- a/src/haptic/dummy/SDL_syshaptic.c	Thu Jul 03 09:13:22 2008 +0000
     4.2 +++ b/src/haptic/dummy/SDL_syshaptic.c	Thu Jul 03 09:58:27 2008 +0000
     4.3 @@ -132,6 +132,13 @@
     4.4  }
     4.5  
     4.6  
     4.7 +int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect)
     4.8 +{
     4.9 +   SDL_SetError("Logic error: No Haptic devices available.");
    4.10 +   return -1;
    4.11 +}
    4.12 +
    4.13 +
    4.14  int
    4.15  SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
    4.16  {
     5.1 --- a/src/haptic/linux/SDL_syshaptic.c	Thu Jul 03 09:13:22 2008 +0000
     5.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Thu Jul 03 09:58:27 2008 +0000
     5.3 @@ -612,6 +612,31 @@
     5.4  
     5.5  
     5.6  /*
     5.7 + * Gets the status of a haptic effect.
     5.8 + */
     5.9 +int
    5.10 +SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect)
    5.11 +{
    5.12 +#if 0  /* Not supported atm. */
    5.13 +   struct input_event ie;
    5.14 +
    5.15 +   ie.type = EV_FF;
    5.16 +   ie.type = EV_FF_STATUS;
    5.17 +   ie.code = effect->hweffect->effect.id;
    5.18 +
    5.19 +   if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
    5.20 +      SDL_SetError("Error getting haptic device status.");
    5.21 +      return -1;
    5.22 +   }
    5.23 +
    5.24 +   return 0;
    5.25 +#endif
    5.26 +
    5.27 +   return -1;
    5.28 +}
    5.29 +
    5.30 +
    5.31 +/*
    5.32   * Sets the gain.
    5.33   */
    5.34  int