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 2517 37c13c12c878
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
--- a/include/SDL_haptic.h	Thu Jul 10 17:52:57 2008 +0000
+++ b/include/SDL_haptic.h	Thu Jul 10 17:54:08 2008 +0000
@@ -70,7 +70,7 @@
  *    effect_id = SDL_HapticNewEffect( haptic, &effect );
  *
  *    // Test the effect
- *    SDL_HapticRunEffect( haptic, effect_id );
+ *    SDL_HapticRunEffect( haptic, effect_id, 1 );
  *    SDL_Delay( 5000); // Wait for the effect to finish
  *
  *    // We destroy the effect, although closing the device also does this
@@ -263,6 +263,19 @@
 #define SDL_HAPTIC_CARTESIAN  1
 
 
+/*
+ * Misc defines.
+ */
+/**
+ * \def SDL_HAPTIC_INFINITY
+ *
+ * \brief Used to play a device an infinite number of times.
+ *
+ * \sa SDL_HapticRunEffect
+ */
+#define SDL_HAPTIC_INFINITY   -1
+
+
 /**
  * \struct SDL_HapticDirection
  *
@@ -681,7 +694,7 @@
  *
  * \sa SDL_HapticOpenFromMouse
  */
-extern DECLSPEC SDL_MouseIsHaptic(void);
+extern DECLSPEC int SDL_MouseIsHaptic(void);
 
 /**
  * \fn SDL_Haptic * SDL_HapticOpenFromMouse(void)
@@ -830,19 +843,21 @@
 extern DECLSPEC int SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data);
 
 /**
- * \fn int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect)
+ * \fn int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, int iterations)
  *
  * \brief Runs the haptic effect on it's assosciated haptic device.
  *
  *    \param haptic Haptic device to run the effect on.
  *    \param effect Identifier of the haptic effect to run.
+ *    \param iterations Number of iterations to run the effect. Use
+ *           SDL_HAPTIC_INFINITY for infinity.
  *    \return 0 on success or -1 on error.
  *
  * \sa SDL_HapticStopEffect
  * \sa SDL_HapticDestroyEffect
  * \sa SDL_HapticGetEffectStatus
  */
-extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect);
+extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, int iterations);
 
 /**
  * \fn int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect)
--- a/src/haptic/SDL_haptic.c	Thu Jul 10 17:52:57 2008 +0000
+++ b/src/haptic/SDL_haptic.c	Thu Jul 10 17:54:08 2008 +0000
@@ -470,14 +470,14 @@
  * Runs the haptic effect on the device.
  */
 int
-SDL_HapticRunEffect(SDL_Haptic * haptic, int effect)
+SDL_HapticRunEffect(SDL_Haptic * haptic, int effect, int iterations)
 {
    if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) {
       return -1;
    }
 
    /* Run the effect */
-   if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect]) < 0) {
+   if (SDL_SYS_HapticRunEffect(haptic,&haptic->effects[effect], iterations) < 0) {
       return -1;
    }
 
--- a/src/haptic/SDL_syshaptic.h	Thu Jul 10 17:52:57 2008 +0000
+++ b/src/haptic/SDL_syshaptic.h	Thu Jul 10 17:54:08 2008 +0000
@@ -38,7 +38,7 @@
 };
 
 /*
- * The real SDL_Haptic event.
+ * The real SDL_Haptic struct.
  */
 struct _SDL_Haptic
 {  
@@ -139,7 +139,8 @@
  * Returns 0 on success, -1 on error.
  */
 extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic,
-                                   struct haptic_effect * effect);
+                                   struct haptic_effect * effect,
+                                   int iterations);
 
 /*
  * Stops the effect on the haptic device.
--- a/src/haptic/dummy/SDL_syshaptic.c	Thu Jul 10 17:52:57 2008 +0000
+++ b/src/haptic/dummy/SDL_syshaptic.c	Thu Jul 10 17:54:08 2008 +0000
@@ -114,7 +114,7 @@
 
 
 int
-SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
+SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, int iterations)
 {
    SDL_SetError("Logic error: No haptic devices available.");
    return -1;
--- a/src/haptic/linux/SDL_syshaptic.c	Thu Jul 10 17:52:57 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Thu Jul 10 17:54:08 2008 +0000
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <linux/limits.h>
+#include <limits.h> /* INT_MAX */
 #include <string.h>
 #include <errno.h>
 #include <math.h>
@@ -672,14 +673,17 @@
  * Runs an effect.
  */
 int
-SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
+SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect, int iterations)
 {
    struct input_event run;
 
    /* Prepare to run the effect */
    run.type = EV_FF;
    run.code = effect->hweffect->effect.id;
-   run.value = 1;
+   if (iterations == SDL_HAPTIC_INFINITY)
+      run.value = INT_MAX;
+   else
+      run.value = iterations;
 
    if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) {
       SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));