Mercurial > sdl-ios-xcode
changeset 2478:4fd783e0f34b gsoc2008_force_feedback
Added query functions for haptic devices.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Mon, 30 Jun 2008 17:28:34 +0000 |
parents | 97f75ea43a93 |
children | b9eb2cfe16cd |
files | include/SDL_haptic.h src/haptic/SDL_haptic.c src/haptic/linux/SDL_syshaptic.c |
diffstat | 3 files changed, 52 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/include/SDL_haptic.h Mon Jun 30 16:48:16 2008 +0000 +++ b/include/SDL_haptic.h Mon Jun 30 17:28:34 2008 +0000 @@ -100,6 +100,19 @@ extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic); /* + * Returns the number of effects a haptic device can store. + */ +extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic); + +/* + * Returns the supported effects. Individual effects can be queried by + * bitwise operators. + * + * Example: (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT) + */ +extern DECLSPEC unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic); + +/* * Creates a new haptic effect on the device. */ extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
--- a/src/haptic/SDL_haptic.c Mon Jun 30 16:48:16 2008 +0000 +++ b/src/haptic/SDL_haptic.c Mon Jun 30 17:28:34 2008 +0000 @@ -197,6 +197,43 @@ } } +/* + * Returns the number of effects a haptic device has. + */ +int +SDL_HapticNumEffects(SDL_Haptic * haptic) +{ + if (!ValidHaptic(&haptic)) { + return -1; + } + + return haptic->neffects; +} + +/* + * Returns supported effects by the device. + */ +unsigned int +SDL_HapticQueryEffects(SDL_Haptic * haptic) +{ + if (!ValidHaptic(&haptic)) { + return -1; + } + + return haptic->supported; +} + +int +SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect) +{ + if (!ValidHaptic(&haptic)) { + return -1; + } + + if ((haptic->supported & effect->type) != 0) + return SDL_TRUE; + return SDL_FALSE; +} /* * Creates a new haptic effect.
--- a/src/haptic/linux/SDL_syshaptic.c Mon Jun 30 16:48:16 2008 +0000 +++ b/src/haptic/linux/SDL_syshaptic.c Mon Jun 30 17:28:34 2008 +0000 @@ -207,8 +207,9 @@ goto open_err; } SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata)); - /* Set the hwdata */ + /* Set the data */ haptic->hwdata->fd = fd; + haptic->supported = EV_IsHaptic(fd); /* Set the effects */ if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {