diff src/haptic/linux/SDL_syshaptic.c @ 2483:9d52368ebcf5 gsoc2008_force_feedback

Setting effects memory to 0. Added SDL_HapticSetGain().
author Edgar Simo <bobbens@gmail.com>
date Tue, 01 Jul 2008 14:09:53 +0000
parents b51ad78812d5
children 666472fd4cb0
line wrap: on
line diff
--- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 11:21:36 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 14:09:53 2008 +0000
@@ -35,7 +35,6 @@
 #include <fcntl.h>
 #include <linux/limits.h>
 #include <string.h>
-#include <errno.h>
 
 
 #define MAX_HAPTICS  32
@@ -222,6 +221,9 @@
       SDL_OutOfMemory();
       goto open_err;
    }
+   /* Clear the memory */
+   SDL_memset(haptic->effects, 0,
+         sizeof(struct haptic_effect) * haptic->neffects);
 
    return 0;
 
@@ -435,6 +437,7 @@
    return 0;
 }
 
+
 /*
  * Creates a new haptic effect.
  */
@@ -461,8 +464,7 @@
 
    /* Upload the effect */
    if (ioctl(haptic->hwdata->fd, EVIOCSFF, linux_effect) < 0) {
-      SDL_SetError("Error uploading effect to the haptic device: %s",
-            strerror(errno));
+      SDL_SetError("Error uploading effect to the haptic device.");
       return -1;
    }
 
@@ -506,4 +508,24 @@
 }
 
 
+/*
+ * Sets the gain.
+ */
+int
+SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
+{
+   struct input_event ie;
+
+   ie.type = EV_FF;
+   ie.code = FF_GAIN;
+   ie.value = (0xFFFFUL * gain) / 100;
+   printf("%d\n",ie.value);
+
+   if (write(haptic->hwdata->fd, &ie, sizeof(ie)) == -1) {
+      SDL_SetError("Error setting gain.");
+   }
+
+}
+
+
 #endif /* SDL_HAPTIC_LINUX */