Merged FreeBSD joystick patch SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sun, 08 Jul 2007 22:14:37 +0000
branchSDL-1.2
changeset 4022c5a6dcdaef04
parent 4021 cbad710a6509
child 4023 5ec68276e4de
Merged FreeBSD joystick patch
src/joystick/bsd/SDL_sysjoystick.c
     1.1 --- a/src/joystick/bsd/SDL_sysjoystick.c	Sun Jul 08 20:38:36 2007 +0000
     1.2 +++ b/src/joystick/bsd/SDL_sysjoystick.c	Sun Jul 08 22:14:37 2007 +0000
     1.3 @@ -123,6 +123,12 @@
     1.4  	struct	report_desc *repdesc;
     1.5  	struct	report inreport;
     1.6  	int	axis_map[JOYAXE_count];	/* map present JOYAXE_* to 0,1,..*/
     1.7 +	int	x;
     1.8 +	int	y;
     1.9 +	int	xmin;
    1.10 +	int	ymin;
    1.11 +	int	xmax;
    1.12 +	int	ymax;
    1.13  };
    1.14  
    1.15  static char *joynames[MAX_JOYS];
    1.16 @@ -257,6 +263,12 @@
    1.17  	joy->hwdata = hw;
    1.18  	hw->fd = fd;
    1.19  	hw->path = strdup(path);
    1.20 +	hw->x = 0;
    1.21 +	hw->y = 0;
    1.22 +	hw->xmin = 0xffff;
    1.23 +	hw->ymin = 0xffff;
    1.24 +	hw->xmax = 0;
    1.25 +	hw->ymax = 0;
    1.26  	if (! SDL_strncmp(path, "/dev/joy", 8)) {
    1.27  		hw->type = BSDJOY_JOY;
    1.28  		joy->naxes = 2;
    1.29 @@ -380,43 +392,42 @@
    1.30  
    1.31  #if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
    1.32  	struct joystick gameport;
    1.33 -	static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
    1.34   
    1.35  	if (joy->hwdata->type == BSDJOY_JOY) {
    1.36  		if (read(joy->hwdata->fd, &gameport, sizeof gameport) != sizeof gameport)
    1.37  			return;
    1.38 -		if (abs(x - gameport.x) > 8) {
    1.39 -			x = gameport.x;
    1.40 -			if (x < xmin) {
    1.41 -				xmin = x;
    1.42 +		if (abs(joy->hwdata->x - gameport.x) > 8) {
    1.43 +			joy->hwdata->x = gameport.x;
    1.44 +			if (joy->hwdata->x < joy->hwdata->xmin) {
    1.45 +				joy->hwdata->xmin = joy->hwdata->x;
    1.46  			}
    1.47 -			if (x > xmax) {
    1.48 -				xmax = x;
    1.49 +			if (joy->hwdata->x > joy->hwdata->xmax) {
    1.50 +				joy->hwdata->xmax = joy->hwdata->x;
    1.51  			}
    1.52 -			if (xmin == xmax) {
    1.53 -				xmin--;
    1.54 -				xmax++;
    1.55 +			if (joy->hwdata->xmin == joy->hwdata->xmax) {
    1.56 +				joy->hwdata->xmin--;
    1.57 +				joy->hwdata->xmax++;
    1.58  			}
    1.59 -			v = (Sint32)x;
    1.60 -			v -= (xmax + xmin + 1)/2;
    1.61 -			v *= 32768/((xmax - xmin + 1)/2);
    1.62 +			v = (Sint32)joy->hwdata->x;
    1.63 +			v -= (joy->hwdata->xmax + joy->hwdata->xmin + 1)/2;
    1.64 +			v *= 32768/((joy->hwdata->xmax - joy->hwdata->xmin + 1)/2);
    1.65  			SDL_PrivateJoystickAxis(joy, 0, v);
    1.66  		}
    1.67 -		if (abs(y - gameport.y) > 8) {
    1.68 -			y = gameport.y;
    1.69 -			if (y < ymin) {
    1.70 -				ymin = y;
    1.71 +		if (abs(joy->hwdata->y - gameport.y) > 8) {
    1.72 +			joy->hwdata->y = gameport.y;
    1.73 +			if (joy->hwdata->y < joy->hwdata->ymin) {
    1.74 +				joy->hwdata->ymin = joy->hwdata->y;
    1.75  			}
    1.76 -			if (y > ymax) {
    1.77 -				ymax = y;
    1.78 +			if (joy->hwdata->y > joy->hwdata->ymax) {
    1.79 +				joy->hwdata->ymax = joy->hwdata->y;
    1.80  			}
    1.81 -			if (ymin == ymax) {
    1.82 -				ymin--;
    1.83 -				ymax++;
    1.84 +			if (joy->hwdata->ymin == joy->hwdata->ymax) {
    1.85 +				joy->hwdata->ymin--;
    1.86 +				joy->hwdata->ymax++;
    1.87  			}
    1.88 -			v = (Sint32)y;
    1.89 -			v -= (ymax + ymin + 1)/2;
    1.90 -			v *= 32768/((ymax - ymin + 1)/2);
    1.91 +			v = (Sint32)joy->hwdata->y;
    1.92 +			v -= (joy->hwdata->ymax + joy->hwdata->ymin + 1)/2;
    1.93 +			v *= 32768/((joy->hwdata->ymax - joy->hwdata->ymin + 1)/2);
    1.94  			SDL_PrivateJoystickAxis(joy, 1, v);
    1.95  		}
    1.96  		if (gameport.b1 != joy->buttons[0]) {