src/joystick/linux/SDL_sysjoystick.c
changeset 6845 e14535915e3e
parent 6844 e09997fb33cc
child 6852 424a6a791947
equal deleted inserted replaced
6844:e09997fb33cc 6845:e14535915e3e
   666                 if (absinfo.minimum == absinfo.maximum) {
   666                 if (absinfo.minimum == absinfo.maximum) {
   667                     joystick->hwdata->abs_correct[i].used = 0;
   667                     joystick->hwdata->abs_correct[i].used = 0;
   668                 } else {
   668                 } else {
   669                     joystick->hwdata->abs_correct[i].used = 1;
   669                     joystick->hwdata->abs_correct[i].used = 1;
   670                     joystick->hwdata->abs_correct[i].coef[0] =
   670                     joystick->hwdata->abs_correct[i].coef[0] =
   671                         (absinfo.maximum + absinfo.minimum) / 2 - absinfo.flat;
   671                         (absinfo.maximum + absinfo.minimum) - 2 * absinfo.flat;
   672                     joystick->hwdata->abs_correct[i].coef[1] =
   672                     joystick->hwdata->abs_correct[i].coef[1] =
   673                         (absinfo.maximum + absinfo.minimum) / 2 + absinfo.flat;
   673                         (absinfo.maximum + absinfo.minimum) + 2 * absinfo.flat;
   674                     t = ((absinfo.maximum - absinfo.minimum) / 2 - 2 * absinfo.flat);
   674                     t = ((absinfo.maximum - absinfo.minimum) - 4 * absinfo.flat);
   675                     if (t != 0) {
   675                     if (t != 0) {
   676                         joystick->hwdata->abs_correct[i].coef[2] =
   676                         joystick->hwdata->abs_correct[i].coef[2] =
   677                             (1 << 29) / t;
   677                             (1 << 28) / t;
   678                     } else {
   678                     } else {
   679                         joystick->hwdata->abs_correct[i].coef[2] = 0;
   679                         joystick->hwdata->abs_correct[i].coef[2] = 0;
   680                     }
   680                     }
   681                 }
   681                 }
   682                 ++joystick->naxes;
   682                 ++joystick->naxes;
   813 {
   813 {
   814     struct axis_correct *correct;
   814     struct axis_correct *correct;
   815 
   815 
   816     correct = &joystick->hwdata->abs_correct[which];
   816     correct = &joystick->hwdata->abs_correct[which];
   817     if (correct->used) {
   817     if (correct->used) {
       
   818         value *= 2;
   818         if (value > correct->coef[0]) {
   819         if (value > correct->coef[0]) {
   819             if (value < correct->coef[1]) {
   820             if (value < correct->coef[1]) {
   820                 return 0;
   821                 return 0;
   821             }
   822             }
   822             value -= correct->coef[1];
   823             value -= correct->coef[1];
   823         } else {
   824         } else {
   824             value -= correct->coef[0];
   825             value -= correct->coef[0];
   825         }
   826         }
   826         value *= correct->coef[2];
   827         value *= correct->coef[2];
   827         value >>= 14;
   828         value >>= 13;
   828     }
   829     }
   829 
   830 
   830     /* Clamp and return */
   831     /* Clamp and return */
   831     if (value < -32768)
   832     if (value < -32768)
   832         return -32768;
   833         return -32768;