From 62590a89a5474abf7ea6d87fbb50823f308a96a0 Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Mon, 30 Jun 2008 17:28:34 +0000 Subject: [PATCH] Added query functions for haptic devices. --- include/SDL_haptic.h | 13 +++++++++++ src/haptic/SDL_haptic.c | 37 ++++++++++++++++++++++++++++++++ src/haptic/linux/SDL_syshaptic.c | 3 ++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index db6b4ac22..b98c05e97 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -99,6 +99,19 @@ extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index); */ 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. */ diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index dc380f64c..a987ac65b 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -197,6 +197,43 @@ SDL_HapticQuit(void) } } +/* + * 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. diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index 8a01e0a66..df08ce5fa 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -207,8 +207,9 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic) 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) {