From 77cf87784cf494280e5cc84838a3f71b4db73292 Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Thu, 10 Jul 2008 17:54:08 +0000 Subject: [PATCH] Broke API by introducing iterations to SDL_HapticRunEffects(). Fixed minor issues. --- include/SDL_haptic.h | 23 +++++++++++++++++++---- src/haptic/SDL_haptic.c | 4 ++-- src/haptic/SDL_syshaptic.h | 5 +++-- src/haptic/dummy/SDL_syshaptic.c | 2 +- src/haptic/linux/SDL_syshaptic.c | 8 ++++++-- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index b9e6d1e45..9ac8fcb77 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -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 @@ typedef struct _SDL_Haptic SDL_Haptic; #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 @@ extern DECLSPEC int SDL_HapticIndex(SDL_Haptic * haptic); * * \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_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * 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) diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index 6a9e255fa..33afcf717 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -470,14 +470,14 @@ SDL_HapticUpdateEffect(SDL_Haptic * haptic, int effect, SDL_HapticEffect * data) * 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; } diff --git a/src/haptic/SDL_syshaptic.h b/src/haptic/SDL_syshaptic.h index effa7304b..e8aed1b36 100644 --- a/src/haptic/SDL_syshaptic.h +++ b/src/haptic/SDL_syshaptic.h @@ -38,7 +38,7 @@ struct haptic_effect }; /* - * The real SDL_Haptic event. + * The real SDL_Haptic struct. */ struct _SDL_Haptic { @@ -139,7 +139,8 @@ extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, * 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. diff --git a/src/haptic/dummy/SDL_syshaptic.c b/src/haptic/dummy/SDL_syshaptic.c index 0b9767623..3d8870f8c 100644 --- a/src/haptic/dummy/SDL_syshaptic.c +++ b/src/haptic/dummy/SDL_syshaptic.c @@ -114,7 +114,7 @@ SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, 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; diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index 3a1ccc00e..c90442abb 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -36,6 +36,7 @@ #include #include #include +#include /* INT_MAX */ #include #include #include @@ -672,14 +673,17 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, * 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));