From e54cc6103a0057ad9b5a149f94d37a25f1c6e9b2 Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Tue, 1 Jul 2008 14:31:04 +0000 Subject: [PATCH] Added SDL_HapticStopEffect(). --- include/SDL_haptic.h | 10 +++++++++- src/haptic/SDL_haptic.c | 18 ++++++++++++++++++ src/haptic/SDL_syshaptic.h | 2 ++ src/haptic/linux/SDL_syshaptic.c | 21 +++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index 51a158ca3..4a13c82af 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -245,7 +245,15 @@ extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * extern DECLSPEC int SDL_HapticRunEffect(SDL_Haptic * haptic, int effect); /* - * Destroys a haptic effect on the device. + * Stops the haptic effect on it's assosciated haptic device. + * + * Returns 0 on success or -1 on failure. + */ +extern DECLSPEC int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect); + +/* + * Destroys a haptic effect on the device. This will stop the effect if it's + * running. */ extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect); diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index bc246b02d..7d846d4f9 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -306,6 +306,24 @@ SDL_HapticRunEffect(SDL_Haptic * haptic, int effect) return 0; } +/* + * Stops the haptic effect on the device. + */ +int +SDL_HapticStopEffect(SDL_Haptic * haptic, int effect) +{ + if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) { + return -1; + } + + /* Stop the effect */ + if (SDL_SYS_HapticStopEffect(haptic,&haptic->effects[effect]) < 0) { + return -1; + } + + return 0; +} + /* * Gets rid of a haptic effect. */ diff --git a/src/haptic/SDL_syshaptic.h b/src/haptic/SDL_syshaptic.h index 6a2487bfc..71aa66ac3 100644 --- a/src/haptic/SDL_syshaptic.h +++ b/src/haptic/SDL_syshaptic.h @@ -56,6 +56,8 @@ extern int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect * effect, SDL_HapticEffect * base); extern int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect); +extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, + struct haptic_effect * effect); extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect); extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain); diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index d23ee8cc9..33d2961ca 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -494,6 +494,27 @@ SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect * effect) } +/* + * Stops an effect. + */ +int +SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect) +{ + struct input_event stop; + + stop.type = EV_FF; + stop.code = effect->hweffect->effect.id; + stop.value = 0; + + if (write(haptic->hwdata->fd, (const void*) &stop, sizeof(stop)) < 0) { + SDL_SetError("Unable to stop the haptic effect."); + return -1; + } + + return 0; +} + + /* * Frees the effect */