Mercurial > sdl-ios-xcode
changeset 2495:66c02abeef0e gsoc2008_force_feedback
Added SDL_HapticGetEffectStatus().
More comments.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Thu, 03 Jul 2008 09:58:27 +0000 |
parents | a72a5f62d6b7 |
children | 8f840a6cdf01 |
files | 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 |
diffstat | 5 files changed, 87 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/include/SDL_haptic.h Thu Jul 03 09:13:22 2008 +0000 +++ b/include/SDL_haptic.h Thu Jul 03 09:58:27 2008 +0000 @@ -46,22 +46,25 @@ 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 @@ Uint16 interval; /* Ramp */ - Sint16 start; - Sint16 end; + Sint16 start; /* Beginning strength level. */ + Sint16 end; /* Ending strength level. */ /* Envelope */ Uint16 attack_length; @@ -288,6 +291,14 @@ 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. * * Returns 0 on success or -1 on failure.
--- a/src/haptic/SDL_haptic.c Thu Jul 03 09:13:22 2008 +0000 +++ b/src/haptic/SDL_haptic.c Thu Jul 03 09:58:27 2008 +0000 @@ -438,6 +438,24 @@ } /* + * 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. */ int
--- a/src/haptic/SDL_syshaptic.h Thu Jul 03 09:13:22 2008 +0000 +++ b/src/haptic/SDL_syshaptic.h Thu Jul 03 09:58:27 2008 +0000 @@ -145,6 +145,15 @@ 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. * * Returns 0 on success, -1 on error.
--- a/src/haptic/dummy/SDL_syshaptic.c Thu Jul 03 09:13:22 2008 +0000 +++ b/src/haptic/dummy/SDL_syshaptic.c Thu Jul 03 09:58:27 2008 +0000 @@ -132,6 +132,13 @@ } +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) {
--- a/src/haptic/linux/SDL_syshaptic.c Thu Jul 03 09:13:22 2008 +0000 +++ b/src/haptic/linux/SDL_syshaptic.c Thu Jul 03 09:58:27 2008 +0000 @@ -612,6 +612,31 @@ /* + * 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. */ int