Date: Thu, 18 Jul 2002 23:51:40 +0200 (MEST)
authorSam Lantinga <slouken@libsdl.org>
Tue, 20 Aug 2002 06:08:42 +0000
changeset 4611d36f593078a
parent 460 a888b3ae31ff
child 462 1be0cdaf8092
Date: Thu, 18 Jul 2002 23:51:40 +0200 (MEST)
From: Krister Walfridsson
Subject: [SDL] src/joystick/bsd/SDL_sysjoystick.c patch

The *BSD USB HID joystick code has two serious bugs:

1. If a joystick reports unhandled hid_input usage (for example HUG_RZ or
HUG_DIAL), then the last handled value will be overwritten with an
arbitrary value. (Fixed in the patch below by adding a default case.)

2. The current code does only handle logical coordinates in the range 0-255,
while a big part of available joysticks report -128 - 127. (This is solved
in the patch below by first center the range around 0, and then stretch
it to the correct range.)
src/joystick/bsd/SDL_sysjoystick.c
     1.1 --- a/src/joystick/bsd/SDL_sysjoystick.c	Tue Aug 20 06:01:20 2002 +0000
     1.2 +++ b/src/joystick/bsd/SDL_sysjoystick.c	Tue Aug 20 06:08:42 2002 +0000
     1.3 @@ -332,23 +332,14 @@
     1.4  				case HUG_WHEEL:
     1.5  					naxe = JOYAXE_WHEEL;
     1.6  					goto scaleaxe;
     1.7 +				default:
     1.8 +					continue;
     1.9  				}
    1.10  scaleaxe:
    1.11  				v = (Sint32)hid_get_data(REP_BUF_DATA(rep),
    1.12  				    &hitem);
    1.13 -				if (v != 127) {
    1.14 -					if (v < 127) {
    1.15 -						v = -(256 - v);
    1.16 -						v <<= 7;
    1.17 -						v++;
    1.18 -					} else {
    1.19 -						v++;
    1.20 -						v <<= 7;
    1.21 -						v--;
    1.22 -					}
    1.23 -				} else {
    1.24 -					v = 0;
    1.25 -				}
    1.26 +				v -= (hitem.logical_maximum + hitem.logical_minimum + 1)/2;
    1.27 +				v *= 32768/((hitem.logical_maximum - hitem.logical_minimum + 1)/2);
    1.28  				if (v != joy->axes[naxe]) {
    1.29  					SDL_PrivateJoystickAxis(joy, naxe, v);
    1.30  				}