# HG changeset patch # User Edgar Simo # Date 1214922664 0 # Node ID 67978eea6d103964069a7c1b736ff9f7f43d53b5 # Parent 666472fd4cb098f73a6a3df5b867e9a89764c435 Added SDL_HapticStopEffect(). diff -r 666472fd4cb0 -r 67978eea6d10 include/SDL_haptic.h --- a/include/SDL_haptic.h Tue Jul 01 14:21:09 2008 +0000 +++ b/include/SDL_haptic.h Tue Jul 01 14:31:04 2008 +0000 @@ -245,7 +245,15 @@ 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 -r 666472fd4cb0 -r 67978eea6d10 src/haptic/SDL_haptic.c --- a/src/haptic/SDL_haptic.c Tue Jul 01 14:21:09 2008 +0000 +++ b/src/haptic/SDL_haptic.c Tue Jul 01 14:31:04 2008 +0000 @@ -307,6 +307,24 @@ } /* + * 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. */ void diff -r 666472fd4cb0 -r 67978eea6d10 src/haptic/SDL_syshaptic.h --- a/src/haptic/SDL_syshaptic.h Tue Jul 01 14:21:09 2008 +0000 +++ b/src/haptic/SDL_syshaptic.h Tue Jul 01 14:31:04 2008 +0000 @@ -56,6 +56,8 @@ 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 -r 666472fd4cb0 -r 67978eea6d10 src/haptic/linux/SDL_syshaptic.c --- a/src/haptic/linux/SDL_syshaptic.c Tue Jul 01 14:21:09 2008 +0000 +++ b/src/haptic/linux/SDL_syshaptic.c Tue Jul 01 14:31:04 2008 +0000 @@ -495,6 +495,27 @@ /* + * 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 */ void