Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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.
- Loading branch information
Showing
with
36 additions
and
3 deletions.
-
+10
−2
include/SDL_haptic.h
-
+26
−1
src/haptic/SDL_haptic.c
|
@@ -630,15 +630,18 @@ extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index); |
|
|
* \brief Opens a Haptic device for usage - the index passed as an |
|
|
* argument refers to the N'th Haptic device on this system. |
|
|
* |
|
|
* This function returns a Haptic device identifier, or Null |
|
|
* if an error occurred. |
|
|
* When opening a haptic device, it's gain will be set to maximum and |
|
|
* autocenter will be disabled. To modify these values use |
|
|
* SDL_HapticSetGain and SDL_HapticSetAutocenter |
|
|
* |
|
|
* \param device_index Index of the device to open. |
|
|
* \return Device identifier or NULL on error. |
|
|
* |
|
|
* \sa SDL_HapticIndex |
|
|
* \sa SDL_HapticOpenFromJoystick |
|
|
* \sa SDL_HapticClose |
|
|
* \sa SDL_HapticSetGain |
|
|
* \sa SDL_HapticSetAutocenter |
|
|
*/ |
|
|
extern DECLSPEC SDL_Haptic * SDL_HapticOpen(int device_index); |
|
|
|
|
@@ -854,6 +857,11 @@ extern DECLSPEC int SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect); |
|
|
* |
|
|
* Device must support the SDL_HAPTIC_GAIN feature. |
|
|
* |
|
|
* The user may specify the maxmimum gain by setting the environment variable |
|
|
* SDL_HAPTIC_GAIN_MAX which should be between 0 and 100. All calls to |
|
|
* SDL_HapticSetGain will scale linearly using SDL_HAPTIC_GAIN_MAX as the |
|
|
* maximum. |
|
|
* |
|
|
* \param haptic Haptic device to set the gain on. |
|
|
* \param gain Value to set the gain to, should be between 0 and 100. |
|
|
* \return 0 on success or -1 on error. |
|
|
|
@@ -138,6 +138,12 @@ SDL_HapticOpen(int device_index) |
|
|
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 @@ SDL_HapticGetEffectStatus(SDL_Haptic *haptic, int effect) |
|
|
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 @@ SDL_HapticSetGain(SDL_Haptic * haptic, int gain ) |
|
|
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; |
|
|
} |
|
|
|
|
|