Added query functions for haptic devices. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Mon, 30 Jun 2008 17:28:34 +0000
branchgsoc2008_force_feedback
changeset 24784fd783e0f34b
parent 2477 97f75ea43a93
child 2479 b9eb2cfe16cd
Added query functions for haptic devices.
include/SDL_haptic.h
src/haptic/SDL_haptic.c
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/include/SDL_haptic.h	Mon Jun 30 16:48:16 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Mon Jun 30 17:28:34 2008 +0000
     1.3 @@ -100,6 +100,19 @@
     1.4  extern DECLSPEC void SDL_HapticClose(SDL_Haptic * haptic);
     1.5  
     1.6  /*
     1.7 + * Returns the number of effects a haptic device can store.
     1.8 + */
     1.9 +extern DECLSPEC int SDL_HapticNumEffects(SDL_Haptic * haptic);
    1.10 +
    1.11 +/*
    1.12 + * Returns the supported effects.  Individual effects can be queried by
    1.13 + * bitwise operators.
    1.14 + *
    1.15 + * Example:  (SDL_HapticQueryEffects(haptic) & SDL_HAPTIC_CONSTANT)
    1.16 + */
    1.17 +extern DECLSPEC unsigned int SDL_HapticQueryEffects(SDL_Haptic * haptic);
    1.18 +
    1.19 +/*
    1.20   * Creates a new haptic effect on the device.
    1.21   */
    1.22  extern DECLSPEC int SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect);
     2.1 --- a/src/haptic/SDL_haptic.c	Mon Jun 30 16:48:16 2008 +0000
     2.2 +++ b/src/haptic/SDL_haptic.c	Mon Jun 30 17:28:34 2008 +0000
     2.3 @@ -197,6 +197,43 @@
     2.4     }
     2.5  }
     2.6  
     2.7 +/*
     2.8 + * Returns the number of effects a haptic device has.
     2.9 + */
    2.10 +int
    2.11 +SDL_HapticNumEffects(SDL_Haptic * haptic)
    2.12 +{
    2.13 +   if (!ValidHaptic(&haptic)) {
    2.14 +      return -1;
    2.15 +   }
    2.16 +
    2.17 +   return haptic->neffects;
    2.18 +}
    2.19 +
    2.20 +/*
    2.21 + * Returns supported effects by the device.
    2.22 + */
    2.23 +unsigned int
    2.24 +SDL_HapticQueryEffects(SDL_Haptic * haptic)
    2.25 +{
    2.26 +   if (!ValidHaptic(&haptic)) {
    2.27 +      return -1;
    2.28 +   }
    2.29 +
    2.30 +   return haptic->supported;
    2.31 +}
    2.32 +
    2.33 +int
    2.34 +SDL_HapticEffectSupported(SDL_Haptic * haptic, SDL_HapticEffect * effect)
    2.35 +{
    2.36 +   if (!ValidHaptic(&haptic)) {
    2.37 +      return -1;
    2.38 +   }
    2.39 +
    2.40 +   if ((haptic->supported & effect->type) != 0)
    2.41 +      return SDL_TRUE;
    2.42 +   return SDL_FALSE;
    2.43 +}
    2.44  
    2.45  /*
    2.46   * Creates a new haptic effect.
     3.1 --- a/src/haptic/linux/SDL_syshaptic.c	Mon Jun 30 16:48:16 2008 +0000
     3.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Mon Jun 30 17:28:34 2008 +0000
     3.3 @@ -207,8 +207,9 @@
     3.4        goto open_err;
     3.5     }
     3.6     SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
     3.7 -   /* Set the hwdata */
     3.8 +   /* Set the data */
     3.9     haptic->hwdata->fd = fd;
    3.10 +   haptic->supported = EV_IsHaptic(fd);
    3.11  
    3.12     /* Set the effects */
    3.13     if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {