HapticSetGain checks to see if device supports it. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Tue, 01 Jul 2008 14:21:09 +0000
branchgsoc2008_force_feedback
changeset 2484666472fd4cb0
parent 2483 9d52368ebcf5
child 2485 67978eea6d10
HapticSetGain checks to see if device supports it.
Added HapticSetAutocenter().
include/SDL_haptic.h
src/haptic/SDL_haptic.c
src/haptic/SDL_syshaptic.h
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/include/SDL_haptic.h	Tue Jul 01 14:09:53 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Tue Jul 01 14:21:09 2008 +0000
     1.3 @@ -256,6 +256,14 @@
     1.4   */
     1.5  extern DECLSPEC int SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
     1.6  
     1.7 +/*
     1.8 + * Sets the global autocenter of the device.  Autocenter should be between
     1.9 + * 0 and 100.  Setting it to 0 will disable autocentering.
    1.10 + *
    1.11 + * Returns 0 on success or -1 on failure.
    1.12 + */
    1.13 +extern DECLSPEC int SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
    1.14 +
    1.15  
    1.16  /* Ends C function definitions when using C++ */
    1.17  #ifdef __cplusplus
     2.1 --- a/src/haptic/SDL_haptic.c	Tue Jul 01 14:09:53 2008 +0000
     2.2 +++ b/src/haptic/SDL_haptic.c	Tue Jul 01 14:21:09 2008 +0000
     2.3 @@ -334,6 +334,11 @@
     2.4        return -1;
     2.5     }
     2.6  
     2.7 +   if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
     2.8 +      SDL_SetError("Haptic device does not support setting gain.");
     2.9 +      return -1;
    2.10 +   }
    2.11 +
    2.12     if ((gain < 0) || (gain > 100)) {
    2.13        SDL_SetError("Haptic gain must be between 0 and 100.");
    2.14        return -1;
    2.15 @@ -346,4 +351,31 @@
    2.16     return 0;
    2.17  }
    2.18  
    2.19 +/*
    2.20 + * Makes the device autocenter, 0 disables.
    2.21 + */
    2.22 +int
    2.23 +SDL_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter )
    2.24 +{
    2.25 +   if (!ValidHaptic(&haptic)) {
    2.26 +      return -1;
    2.27 +   }
    2.28  
    2.29 +   if ((haptic->supported & SDL_HAPTIC_AUTOCENTER) == 0) {
    2.30 +      SDL_SetError("Haptic device does not support setting autocenter.");
    2.31 +      return -1;
    2.32 +   }
    2.33 +
    2.34 +   if ((autocenter < 0) || (autocenter > 100)) {
    2.35 +      SDL_SetError("Haptic autocenter must be between 0 and 100.");
    2.36 +      return -1;
    2.37 +   }                                           
    2.38 +
    2.39 +   if (SDL_SYS_HapticSetAutocenter(haptic,autocenter) < 0) {
    2.40 +      return -1;
    2.41 +   }
    2.42 +
    2.43 +   return 0;
    2.44 +}
    2.45 +
    2.46 +
     3.1 --- a/src/haptic/SDL_syshaptic.h	Tue Jul 01 14:09:53 2008 +0000
     3.2 +++ b/src/haptic/SDL_syshaptic.h	Tue Jul 01 14:21:09 2008 +0000
     3.3 @@ -59,5 +59,6 @@
     3.4  extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic,
     3.5        struct haptic_effect * effect);
     3.6  extern int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain);
     3.7 +extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter);
     3.8  
     3.9  
     4.1 --- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 14:09:53 2008 +0000
     4.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 14:21:09 2008 +0000
     4.3 @@ -519,13 +519,36 @@
     4.4     ie.type = EV_FF;
     4.5     ie.code = FF_GAIN;
     4.6     ie.value = (0xFFFFUL * gain) / 100;
     4.7 -   printf("%d\n",ie.value);
     4.8  
     4.9 -   if (write(haptic->hwdata->fd, &ie, sizeof(ie)) == -1) {
    4.10 +   if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
    4.11        SDL_SetError("Error setting gain.");
    4.12 +      return -1;
    4.13     }
    4.14  
    4.15 +   return 0;
    4.16  }
    4.17  
    4.18  
    4.19 +/*
    4.20 + * Sets the autocentering.
    4.21 + */
    4.22 +int
    4.23 +SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
    4.24 +{
    4.25 +   struct input_event ie;
    4.26 +
    4.27 +   ie.type = EV_FF;
    4.28 +   ie.code = FF_AUTOCENTER;
    4.29 +   ie.value = (0xFFFFUL * autocenter) / 100;
    4.30 +
    4.31 +   if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) {
    4.32 +      SDL_SetError("Error setting autocenter.");
    4.33 +      return -1;
    4.34 +   }
    4.35 +
    4.36 +   return 0;
    4.37 +}
    4.38 +
    4.39 +
    4.40 +
    4.41  #endif /* SDL_HAPTIC_LINUX */