src/haptic/linux/SDL_syshaptic.c
branchgsoc2008_force_feedback
changeset 2483 9d52368ebcf5
parent 2482 b51ad78812d5
child 2484 666472fd4cb0
     1.1 --- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 11:21:36 2008 +0000
     1.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 14:09:53 2008 +0000
     1.3 @@ -35,7 +35,6 @@
     1.4  #include <fcntl.h>
     1.5  #include <linux/limits.h>
     1.6  #include <string.h>
     1.7 -#include <errno.h>
     1.8  
     1.9  
    1.10  #define MAX_HAPTICS  32
    1.11 @@ -222,6 +221,9 @@
    1.12        SDL_OutOfMemory();
    1.13        goto open_err;
    1.14     }
    1.15 +   /* Clear the memory */
    1.16 +   SDL_memset(haptic->effects, 0,
    1.17 +         sizeof(struct haptic_effect) * haptic->neffects);
    1.18  
    1.19     return 0;
    1.20  
    1.21 @@ -435,6 +437,7 @@
    1.22     return 0;
    1.23  }
    1.24  
    1.25 +
    1.26  /*
    1.27   * Creates a new haptic effect.
    1.28   */
    1.29 @@ -461,8 +464,7 @@
    1.30  
    1.31     /* Upload the effect */
    1.32     if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
    1.33 -      SDL_SetError("Error uploading effect to the haptic device: %s",
    1.34 -            strerror(errno));
    1.35 +      SDL_SetError("Error uploading effect to the haptic device.");
    1.36        return -1;
    1.37     }
    1.38  
    1.39 @@ -506,4 +508,24 @@
    1.40  }
    1.41  
    1.42  
    1.43 +/*
    1.44 + * Sets the gain.
    1.45 + */
    1.46 +int
    1.47 +SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
    1.48 +{
    1.49 +   struct input_event ie;
    1.50 +
    1.51 +   ie.type = EV_FF;
    1.52 +   ie.code = FF_GAIN;
    1.53 +   ie.value = (0xFFFFUL * gain) / 100;
    1.54 +   printf("%d\n",ie.value);
    1.55 +
    1.56 +   if (write(haptic->hwdata->fd, &ie, sizeof(ie)) == -1) {
    1.57 +      SDL_SetError("Error setting gain.");
    1.58 +   }
    1.59 +
    1.60 +}
    1.61 +
    1.62 +
    1.63  #endif /* SDL_HAPTIC_LINUX */