src/haptic/SDL_haptic.c
branchgsoc2008_force_feedback
changeset 2507 8ef1d0f4d0c1
parent 2506 ba8e99fe92c1
child 2512 ef147ee4896c
     1.1 --- a/src/haptic/SDL_haptic.c	Tue Jul 08 19:35:10 2008 +0000
     1.2 +++ b/src/haptic/SDL_haptic.c	Tue Jul 08 19:55:12 2008 +0000
     1.3 @@ -138,6 +138,12 @@
     1.4        return NULL;
     1.5     }
     1.6  
     1.7 +   /* Disable autocenter and set gain to max. */
     1.8 +   if (haptic->supported & SDL_HAPTIC_GAIN)
     1.9 +      SDL_HapticSetGain(haptic,100);
    1.10 +   if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
    1.11 +      SDL_HapticSetAutocenter(haptic,0);
    1.12 +
    1.13     /* Add haptic to list */
    1.14     ++haptic->ref_count;
    1.15     for (i=0; SDL_haptics[i]; i++)
    1.16 @@ -494,6 +500,9 @@
    1.17  int
    1.18  SDL_HapticSetGain(SDL_Haptic * haptic, int gain )
    1.19  {
    1.20 +   const char *env;
    1.21 +   int real_gain, max_gain;
    1.22 +
    1.23     if (!ValidHaptic(&haptic)) {
    1.24        return -1;
    1.25     }
    1.26 @@ -508,7 +517,23 @@
    1.27        return -1;
    1.28     }
    1.29  
    1.30 -   if (SDL_SYS_HapticSetGain(haptic,gain) < 0) {
    1.31 +   /* We use the envvar to get the maximum gain. */
    1.32 +   env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
    1.33 +   if (env != NULL) {
    1.34 +      max_gain = SDL_atoi(env);
    1.35 +
    1.36 +      /* Check for sanity. */
    1.37 +      if (max_gain < 0) max_gain = 0;
    1.38 +      else if (max_gain > 100) max_gain = 100;
    1.39 +
    1.40 +      /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
    1.41 +      real_gain = (gain * max_gain) / 100;
    1.42 +   }
    1.43 +   else {
    1.44 +      real_gain = gain;
    1.45 +   }
    1.46 +
    1.47 +   if (SDL_SYS_HapticSetGain(haptic,real_gain) < 0) {
    1.48        return -1;
    1.49     }
    1.50