From 1ee2ff181d9bc7c18fe8608573979becf5d99c3d Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Thu, 3 Jul 2008 09:58:27 +0000 Subject: [PATCH] Added SDL_HapticGetEffectStatus(). More comments. --- include/SDL_haptic.h | 45 ++++++++++++++++++++------------ src/haptic/SDL_haptic.c | 18 +++++++++++++ src/haptic/SDL_syshaptic.h | 9 +++++++ src/haptic/dummy/SDL_syshaptic.c | 7 +++++ src/haptic/linux/SDL_syshaptic.c | 25 ++++++++++++++++++ 5 files changed, 87 insertions(+), 17 deletions(-) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index d25d56371..67f203c8c 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -46,22 +46,25 @@ struct _SDL_Haptic; typedef struct _SDL_Haptic SDL_Haptic; -/* Different effects that can be generated */ -#define SDL_HAPTIC_CONSTANT (1<<0) -#define SDL_HAPTIC_SINE (1<<1) -#define SDL_HAPTIC_SQUARE (1<<2) -#define SDL_HAPTIC_TRIANGLE (1<<3) -#define SDL_HAPTIC_SAWTOOTHUP (1<<4) -#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5) -#define SDL_HAPTIC_RAMP (1<<6) -#define SDL_HAPTIC_SPRING (1<<7) -#define SDL_HAPTIC_FRICTION (1<<8) -#define SDL_HAPTIC_DAMPER (1<<9) -#define SDL_HAPTIC_INERTIA (1<<10) -#define SDL_HAPTIC_CUSTOM (1<<11) +/* + * Different haptic features a device can have. + */ +#define SDL_HAPTIC_CONSTANT (1<<0) /* Constant effect supported */ +#define SDL_HAPTIC_SINE (1<<1) /* Sine wave effect supported */ +#define SDL_HAPTIC_SQUARE (1<<2) /* Square wave effect supported */ +#define SDL_HAPTIC_TRIANGLE (1<<3) /* Triangle wave effect supported */ +#define SDL_HAPTIC_SAWTOOTHUP (1<<4) /* Sawtoothup wave effect supported */ +#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5) /* Sawtoothdown wave effect supported */ +#define SDL_HAPTIC_RAMP (1<<6) /* Ramp effect supported */ +#define SDL_HAPTIC_SPRING (1<<7) /* Spring effect supported - uses axes position */ +#define SDL_HAPTIC_DAMPER (1<<8) /* Damper effect supported - uses axes velocity */ +#define SDL_HAPTIC_INERTIA (1<<9) /* Inertia effect supported - uses axes acceleration */ +#define SDL_HAPTIC_FRICTION (1<<10) /* Friction effect supported - uses axes movement */ +#define SDL_HAPTIC_CUSTOM (1<<11) /* Custom effect is supported */ /* These last two are features the device has, not effects */ -#define SDL_HAPTIC_GAIN (1<<12) -#define SDL_HAPTIC_AUTOCENTER (1<<13) +#define SDL_HAPTIC_GAIN (1<<12) /* Device can set global gain */ +#define SDL_HAPTIC_AUTOCENTER (1<<13) /* Device can set autocenter */ +#define SDL_HAPTIC_STATUS (1<<14) /* Device can be queried for effect status */ /* @@ -166,8 +169,8 @@ typedef struct SDL_HapticRamp { Uint16 interval; /* Ramp */ - Sint16 start; - Sint16 end; + Sint16 start; /* Beginning strength level. */ + Sint16 end; /* Ending strength level. */ /* Envelope */ Uint16 attack_length; @@ -287,6 +290,14 @@ extern DECLSPEC int SDL_HapticStopEffect(SDL_Haptic * haptic, int effect); */ extern DECLSPEC void SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect); +/* + * Gets the status of the current effect on the haptic device. + * + * Returns 0 if it isn't playing, SDL_HAPTIC_PLAYING if it is playing + * or -1 on failure. + */ +extern DECLSPEC int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect); + /* * Sets the global gain of the device. Gain should be between 0 and 100. * diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index 0e51311eb..58b5eb5bc 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -437,6 +437,24 @@ SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect) SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]); } +/* + * Gets the status of a haptic effect. + */ +int +SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect) +{ + if (!ValidHaptic(&haptic) || !ValidEffect(haptic,effect)) { + return -1; + } + + if ((haptic->supported & SDL_HAPTIC_STATUS) == 0) { + SDL_SetError("Haptic device does not support status queries."); + return -1; + } + + return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]); +} + /* * Sets the global gain of the device. */ diff --git a/src/haptic/SDL_syshaptic.h b/src/haptic/SDL_syshaptic.h index 296e60217..3c4d7a296 100644 --- a/src/haptic/SDL_syshaptic.h +++ b/src/haptic/SDL_syshaptic.h @@ -144,6 +144,15 @@ extern int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect); +/* + * Queries the device for the status of effect. + * + * Returns 0 if device is stopped, >0 if device is playing and + * -1 on error. + */ +extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, + struct haptic_effect * effect); + /* * Sets the global gain of the haptic device. * diff --git a/src/haptic/dummy/SDL_syshaptic.c b/src/haptic/dummy/SDL_syshaptic.c index b8fe9cfb7..910121901 100644 --- a/src/haptic/dummy/SDL_syshaptic.c +++ b/src/haptic/dummy/SDL_syshaptic.c @@ -132,6 +132,13 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect) } +int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect) +{ + SDL_SetError("Logic error: No Haptic devices available."); + return -1; +} + + 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 1a4550a98..35e4b2dc1 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -611,6 +611,31 @@ SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect) } +/* + * Gets the status of a haptic effect. + */ +int +SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect * effect) +{ +#if 0 /* Not supported atm. */ + struct input_event ie; + + ie.type = EV_FF; + ie.type = EV_FF_STATUS; + ie.code = effect->hweffect->effect.id; + + if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { + SDL_SetError("Error getting haptic device status."); + return -1; + } + + return 0; +#endif + + return -1; +} + + /* * Sets the gain. */