Haptic: Fix the saturation and deadband parameters' available range.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 16 Aug 2014 16:47:42 -0400
changeset 90708973a237f360
parent 9069 16b5dda99337
child 9071 8e04e17c7af3
Haptic: Fix the saturation and deadband parameters' available range.

There was a misconception that Linux's saturation and deadband parameters -
on which the corresponding SDL parameters were based - use only half of the
possible range.

Thanks, Elias!

Partially fixes Bugzilla #2686.
include/SDL_haptic.h
src/haptic/darwin/SDL_syshaptic.c
src/haptic/linux/SDL_syshaptic.c
src/haptic/windows/SDL_dinputhaptic.c
test/testhaptic.c
     1.1 --- a/include/SDL_haptic.h	Sat Aug 16 16:42:55 2014 -0400
     1.2 +++ b/include/SDL_haptic.h	Sat Aug 16 16:47:42 2014 -0400
     1.3 @@ -604,11 +604,11 @@
     1.4      Uint16 interval;        /**< How soon it can be triggered again after button. */
     1.5  
     1.6      /* Condition */
     1.7 -    Uint16 right_sat[3];    /**< Level when joystick is to the positive side. */
     1.8 -    Uint16 left_sat[3];     /**< Level when joystick is to the negative side. */
     1.9 +    Uint16 right_sat[3];    /**< Level when joystick is to the positive side; max 0xFFFF. */
    1.10 +    Uint16 left_sat[3];     /**< Level when joystick is to the negative side; max 0xFFFF. */
    1.11      Sint16 right_coeff[3];  /**< How fast to increase the force towards the positive side. */
    1.12      Sint16 left_coeff[3];   /**< How fast to increase the force towards the negative side. */
    1.13 -    Uint16 deadband[3];     /**< Size of the dead zone. */
    1.14 +    Uint16 deadband[3];     /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
    1.15      Sint16 center[3];       /**< Position of the dead zone. */
    1.16  } SDL_HapticCondition;
    1.17  
     2.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Sat Aug 16 16:42:55 2014 -0400
     2.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Sat Aug 16 16:47:42 2014 -0400
     2.3 @@ -924,10 +924,10 @@
     2.4              condition[i].lNegativeCoefficient =
     2.5                  CONVERT(hap_condition->left_coeff[i]);
     2.6              condition[i].dwPositiveSaturation =
     2.7 -                CCONVERT(hap_condition->right_sat[i]);
     2.8 +                CCONVERT(hap_condition->right_sat[i] / 2);
     2.9              condition[i].dwNegativeSaturation =
    2.10 -                CCONVERT(hap_condition->left_sat[i]);
    2.11 -            condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i]);
    2.12 +                CCONVERT(hap_condition->left_sat[i] / 2);
    2.13 +            condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
    2.14          }
    2.15          dest->cbTypeSpecificParams = sizeof(FFCONDITION) * dest->cAxes;
    2.16          dest->lpvTypeSpecificParams = condition;
     3.1 --- a/src/haptic/linux/SDL_syshaptic.c	Sat Aug 16 16:42:55 2014 -0400
     3.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Sat Aug 16 16:47:42 2014 -0400
     3.3 @@ -847,20 +847,18 @@
     3.4  
     3.5          /* Condition */
     3.6          /* X axis */
     3.7 -        dest->u.condition[0].right_saturation =
     3.8 -            CLAMP(condition->right_sat[0]);
     3.9 -        dest->u.condition[0].left_saturation = CLAMP(condition->left_sat[0]);
    3.10 +        dest->u.condition[0].right_saturation = condition->right_sat[0];
    3.11 +        dest->u.condition[0].left_saturation = condition->left_sat[0];
    3.12          dest->u.condition[0].right_coeff = condition->right_coeff[0];
    3.13          dest->u.condition[0].left_coeff = condition->left_coeff[0];
    3.14 -        dest->u.condition[0].deadband = CLAMP(condition->deadband[0]);
    3.15 +        dest->u.condition[0].deadband = condition->deadband[0];
    3.16          dest->u.condition[0].center = condition->center[0];
    3.17          /* Y axis */
    3.18 -        dest->u.condition[1].right_saturation =
    3.19 -            CLAMP(condition->right_sat[1]);
    3.20 -        dest->u.condition[1].left_saturation = CLAMP(condition->left_sat[1]);
    3.21 +        dest->u.condition[1].right_saturation = condition->right_sat[1];
    3.22 +        dest->u.condition[1].left_saturation = condition->left_sat[1];
    3.23          dest->u.condition[1].right_coeff = condition->right_coeff[1];
    3.24          dest->u.condition[1].left_coeff = condition->left_coeff[1];
    3.25 -        dest->u.condition[1].deadband = CLAMP(condition->deadband[1]);
    3.26 +        dest->u.condition[1].deadband = condition->deadband[1];
    3.27          dest->u.condition[1].center = condition->center[1];
    3.28  
    3.29          /*
     4.1 --- a/src/haptic/windows/SDL_dinputhaptic.c	Sat Aug 16 16:42:55 2014 -0400
     4.2 +++ b/src/haptic/windows/SDL_dinputhaptic.c	Sat Aug 16 16:47:42 2014 -0400
     4.3 @@ -763,10 +763,10 @@
     4.4              condition[i].lNegativeCoefficient =
     4.5                  CONVERT(hap_condition->left_coeff[i]);
     4.6              condition[i].dwPositiveSaturation =
     4.7 -                CONVERT(hap_condition->right_sat[i]);
     4.8 +                CONVERT(hap_condition->right_sat[i] / 2);
     4.9              condition[i].dwNegativeSaturation =
    4.10 -                CONVERT(hap_condition->left_sat[i]);
    4.11 -            condition[i].lDeadBand = CONVERT(hap_condition->deadband[i]);
    4.12 +                CONVERT(hap_condition->left_sat[i] / 2);
    4.13 +            condition[i].lDeadBand = CONVERT(hap_condition->deadband[i] / 2);
    4.14          }
    4.15          dest->cbTypeSpecificParams = sizeof(DICONDITION) * dest->cAxes;
    4.16          dest->lpvTypeSpecificParams = condition;
     5.1 --- a/test/testhaptic.c	Sat Aug 16 16:42:55 2014 -0400
     5.2 +++ b/test/testhaptic.c	Sat Aug 16 16:47:42 2014 -0400
     5.3 @@ -172,8 +172,8 @@
     5.4          efx[nefx].type = SDL_HAPTIC_SPRING;
     5.5          efx[nefx].condition.length = 5000;
     5.6          for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
     5.7 -            efx[nefx].condition.right_sat[i] = 0x7FFF;
     5.8 -            efx[nefx].condition.left_sat[i] = 0x7FFF;
     5.9 +            efx[nefx].condition.right_sat[i] = 0xFFFF;
    5.10 +            efx[nefx].condition.left_sat[i] = 0xFFFF;
    5.11              efx[nefx].condition.right_coeff[i] = 0x2000;
    5.12              efx[nefx].condition.left_coeff[i] = 0x2000;
    5.13              efx[nefx].condition.center[i] = 0x1000;     /* Displace the center for it to move. */
    5.14 @@ -191,10 +191,11 @@
    5.15          efx[nefx].type = SDL_HAPTIC_INERTIA;
    5.16          efx[nefx].condition.length = 5000;
    5.17          for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
    5.18 -            efx[nefx].condition.right_sat[i] = 0x7FFF;
    5.19 -            efx[nefx].condition.left_sat[i] = 0x7FFF;
    5.20 +            efx[nefx].condition.right_sat[i] = 0xFFFF;
    5.21 +            efx[nefx].condition.left_sat[i] = 0xFFFF;
    5.22              efx[nefx].condition.right_coeff[i] = 0x2000;
    5.23              efx[nefx].condition.left_coeff[i] = 0x2000;
    5.24 +            efx[nefx].condition.deadband[i] = 0x1000;    /* 1/16th of axis-range around the center is 'dead'. */
    5.25          }
    5.26          id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
    5.27          if (id[nefx] < 0) {