diff src/haptic/SDL_haptic.c @ 2507:8ef1d0f4d0c1 gsoc2008_force_feedback

Gain is set to max on haptic device open. Autocenter is disabled on haptic device open. Maximum gain can be set by SDL_HAPTIC_GAIN_MAX.
author Edgar Simo <bobbens@gmail.com>
date Tue, 08 Jul 2008 19:55:12 +0000
parents ba8e99fe92c1
children ef147ee4896c
line wrap: on
line diff
--- a/src/haptic/SDL_haptic.c	Tue Jul 08 19:35:10 2008 +0000
+++ b/src/haptic/SDL_haptic.c	Tue Jul 08 19:55:12 2008 +0000
@@ -138,6 +138,12 @@
       return NULL;
    }
 
+   /* Disable autocenter and set gain to max. */
+   if (haptic->supported & SDL_HAPTIC_GAIN)
+      SDL_HapticSetGain(haptic,100);
+   if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
+      SDL_HapticSetAutocenter(haptic,0);
+
    /* Add haptic to list */
    ++haptic->ref_count;
    for (i=0; SDL_haptics[i]; i++)
@@ -494,6 +500,9 @@
 int
 SDL_HapticSetGain(SDL_Haptic * haptic, int gain )
 {
+   const char *env;
+   int real_gain, max_gain;
+
    if (!ValidHaptic(&haptic)) {
       return -1;
    }
@@ -508,7 +517,23 @@
       return -1;
    }
 
-   if (SDL_SYS_HapticSetGain(haptic,gain) < 0) {
+   /* We use the envvar to get the maximum gain. */
+   env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
+   if (env != NULL) {
+      max_gain = SDL_atoi(env);
+
+      /* Check for sanity. */
+      if (max_gain < 0) max_gain = 0;
+      else if (max_gain > 100) max_gain = 100;
+
+      /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
+      real_gain = (gain * max_gain) / 100;
+   }
+   else {
+      real_gain = gain;
+   }
+
+   if (SDL_SYS_HapticSetGain(haptic,real_gain) < 0) {
       return -1;
    }