comparison src/joystick/bsd/SDL_sysjoystick.c @ 4022:c5a6dcdaef04 SDL-1.2

Merged FreeBSD joystick patch
author Sam Lantinga <slouken@libsdl.org>
date Sun, 08 Jul 2007 22:14:37 +0000
parents 92947e3a18db
children a1b03ba2fcd0
comparison
equal deleted inserted replaced
4021:cbad710a6509 4022:c5a6dcdaef04
121 BSDJOY_JOY /* joy(4) */ 121 BSDJOY_JOY /* joy(4) */
122 } type; 122 } type;
123 struct report_desc *repdesc; 123 struct report_desc *repdesc;
124 struct report inreport; 124 struct report inreport;
125 int axis_map[JOYAXE_count]; /* map present JOYAXE_* to 0,1,..*/ 125 int axis_map[JOYAXE_count]; /* map present JOYAXE_* to 0,1,..*/
126 int x;
127 int y;
128 int xmin;
129 int ymin;
130 int xmax;
131 int ymax;
126 }; 132 };
127 133
128 static char *joynames[MAX_JOYS]; 134 static char *joynames[MAX_JOYS];
129 static char *joydevnames[MAX_JOYS]; 135 static char *joydevnames[MAX_JOYS];
130 136
255 return (-1); 261 return (-1);
256 } 262 }
257 joy->hwdata = hw; 263 joy->hwdata = hw;
258 hw->fd = fd; 264 hw->fd = fd;
259 hw->path = strdup(path); 265 hw->path = strdup(path);
266 hw->x = 0;
267 hw->y = 0;
268 hw->xmin = 0xffff;
269 hw->ymin = 0xffff;
270 hw->xmax = 0;
271 hw->ymax = 0;
260 if (! SDL_strncmp(path, "/dev/joy", 8)) { 272 if (! SDL_strncmp(path, "/dev/joy", 8)) {
261 hw->type = BSDJOY_JOY; 273 hw->type = BSDJOY_JOY;
262 joy->naxes = 2; 274 joy->naxes = 2;
263 joy->nbuttons = 2; 275 joy->nbuttons = 2;
264 joy->nhats = 0; 276 joy->nhats = 0;
378 int nbutton, naxe = -1; 390 int nbutton, naxe = -1;
379 Sint32 v; 391 Sint32 v;
380 392
381 #if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 393 #if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
382 struct joystick gameport; 394 struct joystick gameport;
383 static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
384 395
385 if (joy->hwdata->type == BSDJOY_JOY) { 396 if (joy->hwdata->type == BSDJOY_JOY) {
386 if (read(joy->hwdata->fd, &gameport, sizeof gameport) != sizeof gameport) 397 if (read(joy->hwdata->fd, &gameport, sizeof gameport) != sizeof gameport)
387 return; 398 return;
388 if (abs(x - gameport.x) > 8) { 399 if (abs(joy->hwdata->x - gameport.x) > 8) {
389 x = gameport.x; 400 joy->hwdata->x = gameport.x;
390 if (x < xmin) { 401 if (joy->hwdata->x < joy->hwdata->xmin) {
391 xmin = x; 402 joy->hwdata->xmin = joy->hwdata->x;
392 } 403 }
393 if (x > xmax) { 404 if (joy->hwdata->x > joy->hwdata->xmax) {
394 xmax = x; 405 joy->hwdata->xmax = joy->hwdata->x;
395 } 406 }
396 if (xmin == xmax) { 407 if (joy->hwdata->xmin == joy->hwdata->xmax) {
397 xmin--; 408 joy->hwdata->xmin--;
398 xmax++; 409 joy->hwdata->xmax++;
399 } 410 }
400 v = (Sint32)x; 411 v = (Sint32)joy->hwdata->x;
401 v -= (xmax + xmin + 1)/2; 412 v -= (joy->hwdata->xmax + joy->hwdata->xmin + 1)/2;
402 v *= 32768/((xmax - xmin + 1)/2); 413 v *= 32768/((joy->hwdata->xmax - joy->hwdata->xmin + 1)/2);
403 SDL_PrivateJoystickAxis(joy, 0, v); 414 SDL_PrivateJoystickAxis(joy, 0, v);
404 } 415 }
405 if (abs(y - gameport.y) > 8) { 416 if (abs(joy->hwdata->y - gameport.y) > 8) {
406 y = gameport.y; 417 joy->hwdata->y = gameport.y;
407 if (y < ymin) { 418 if (joy->hwdata->y < joy->hwdata->ymin) {
408 ymin = y; 419 joy->hwdata->ymin = joy->hwdata->y;
409 } 420 }
410 if (y > ymax) { 421 if (joy->hwdata->y > joy->hwdata->ymax) {
411 ymax = y; 422 joy->hwdata->ymax = joy->hwdata->y;
412 } 423 }
413 if (ymin == ymax) { 424 if (joy->hwdata->ymin == joy->hwdata->ymax) {
414 ymin--; 425 joy->hwdata->ymin--;
415 ymax++; 426 joy->hwdata->ymax++;
416 } 427 }
417 v = (Sint32)y; 428 v = (Sint32)joy->hwdata->y;
418 v -= (ymax + ymin + 1)/2; 429 v -= (joy->hwdata->ymax + joy->hwdata->ymin + 1)/2;
419 v *= 32768/((ymax - ymin + 1)/2); 430 v *= 32768/((joy->hwdata->ymax - joy->hwdata->ymin + 1)/2);
420 SDL_PrivateJoystickAxis(joy, 1, v); 431 SDL_PrivateJoystickAxis(joy, 1, v);
421 } 432 }
422 if (gameport.b1 != joy->buttons[0]) { 433 if (gameport.b1 != joy->buttons[0]) {
423 SDL_PrivateJoystickButton(joy, 0, gameport.b1); 434 SDL_PrivateJoystickButton(joy, 0, gameport.b1);
424 } 435 }