comparison 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
comparison
equal deleted inserted replaced
2506:ba8e99fe92c1 2507:8ef1d0f4d0c1
136 if (SDL_SYS_HapticOpen(haptic) < 0) { 136 if (SDL_SYS_HapticOpen(haptic) < 0) {
137 SDL_free(haptic); 137 SDL_free(haptic);
138 return NULL; 138 return NULL;
139 } 139 }
140 140
141 /* Disable autocenter and set gain to max. */
142 if (haptic->supported & SDL_HAPTIC_GAIN)
143 SDL_HapticSetGain(haptic,100);
144 if (haptic->supported & SDL_HAPTIC_AUTOCENTER)
145 SDL_HapticSetAutocenter(haptic,0);
146
141 /* Add haptic to list */ 147 /* Add haptic to list */
142 ++haptic->ref_count; 148 ++haptic->ref_count;
143 for (i=0; SDL_haptics[i]; i++) 149 for (i=0; SDL_haptics[i]; i++)
144 /* Skip to next haptic */ ; 150 /* Skip to next haptic */ ;
145 SDL_haptics[i] = haptic; 151 SDL_haptics[i] = haptic;
492 * Sets the global gain of the device. 498 * Sets the global gain of the device.
493 */ 499 */
494 int 500 int
495 SDL_HapticSetGain(SDL_Haptic * haptic, int gain ) 501 SDL_HapticSetGain(SDL_Haptic * haptic, int gain )
496 { 502 {
503 const char *env;
504 int real_gain, max_gain;
505
497 if (!ValidHaptic(&haptic)) { 506 if (!ValidHaptic(&haptic)) {
498 return -1; 507 return -1;
499 } 508 }
500 509
501 if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) { 510 if ((haptic->supported & SDL_HAPTIC_GAIN) == 0) {
506 if ((gain < 0) || (gain > 100)) { 515 if ((gain < 0) || (gain > 100)) {
507 SDL_SetError("Haptic gain must be between 0 and 100."); 516 SDL_SetError("Haptic gain must be between 0 and 100.");
508 return -1; 517 return -1;
509 } 518 }
510 519
511 if (SDL_SYS_HapticSetGain(haptic,gain) < 0) { 520 /* We use the envvar to get the maximum gain. */
521 env = SDL_getenv("SDL_HAPTIC_GAIN_MAX");
522 if (env != NULL) {
523 max_gain = SDL_atoi(env);
524
525 /* Check for sanity. */
526 if (max_gain < 0) max_gain = 0;
527 else if (max_gain > 100) max_gain = 100;
528
529 /* We'll scale it linearly with SDL_HAPTIC_GAIN_MAX */
530 real_gain = (gain * max_gain) / 100;
531 }
532 else {
533 real_gain = gain;
534 }
535
536 if (SDL_SYS_HapticSetGain(haptic,real_gain) < 0) {
512 return -1; 537 return -1;
513 } 538 }
514 539
515 return 0; 540 return 0;
516 } 541 }