comparison src/joystick/linux/SDL_sysjoystick.c @ 589:2e58ece48b61

Removed obsolete Linux joystick code
author Sam Lantinga <slouken@libsdl.org>
date Sat, 01 Feb 2003 20:25:34 +0000
parents 38b1a98aeb11
children b8d311d90021
comparison
equal deleted inserted replaced
588:2c6510c0a304 589:2e58ece48b61
75 75
76 /* The private structure used to keep track of a joystick */ 76 /* The private structure used to keep track of a joystick */
77 struct joystick_hwdata { 77 struct joystick_hwdata {
78 int fd; 78 int fd;
79 /* The current linux joystick driver maps hats to two axes */ 79 /* The current linux joystick driver maps hats to two axes */
80 int analog_hat; /* Well, except for analog hats */
81 struct hwdata_hat { 80 struct hwdata_hat {
82 int axis[2]; 81 int axis[2];
83 } *hats; 82 } *hats;
84 /* The current linux joystick driver maps balls to two axes */ 83 /* The current linux joystick driver maps balls to two axes */
85 struct hwdata_ball { 84 struct hwdata_ball {
364 } 363 }
365 364
366 /* Remap hats and balls */ 365 /* Remap hats and balls */
367 if (handled) { 366 if (handled) {
368 if ( joystick->nhats > 0 ) { 367 if ( joystick->nhats > 0 ) {
369 /* HACK: Analog hats map to only one axis */ 368 if ( allocate_hatdata(joystick) < 0 ) {
370 if (old_axes == (joystick->naxes+joystick->nhats)){ 369 joystick->nhats = 0;
371 joystick->hwdata->analog_hat = 1;
372 } else {
373 if ( allocate_hatdata(joystick) < 0 ) {
374 joystick->nhats = 0;
375 }
376 joystick->hwdata->analog_hat = 0;
377 } 370 }
378 } 371 }
379 if ( joystick->nballs > 0 ) { 372 if ( joystick->nballs > 0 ) {
380 if ( allocate_balldata(joystick) < 0 ) { 373 if ( allocate_balldata(joystick) < 0 ) {
381 joystick->nballs = 0; 374 joystick->nballs = 0;
545 SDL_PrivateJoystickHat(stick, hat, 538 SDL_PrivateJoystickHat(stick, hat,
546 position_map[the_hat->axis[1]][the_hat->axis[0]]); 539 position_map[the_hat->axis[1]][the_hat->axis[0]]);
547 } 540 }
548 } 541 }
549 542
550 /* This was necessary for the Wingman Extreme Analog joystick */
551 static __inline__
552 void HandleAnalogHat(SDL_Joystick *stick, Uint8 hat, int value)
553 {
554 const Uint8 position_map[] = {
555 SDL_HAT_UP,
556 SDL_HAT_RIGHT,
557 SDL_HAT_DOWN,
558 SDL_HAT_LEFT,
559 SDL_HAT_CENTERED
560 };
561 SDL_PrivateJoystickHat(stick, hat, position_map[(value/16000)+2]);
562 }
563
564 static __inline__ 543 static __inline__
565 void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value) 544 void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value)
566 { 545 {
567 stick->hwdata->balls[ball].axis[axis] += value; 546 stick->hwdata->balls[ball].axis[axis] += value;
568 } 547 }
587 SDL_PrivateJoystickAxis(joystick, 566 SDL_PrivateJoystickAxis(joystick,
588 events[i].number, events[i].value); 567 events[i].number, events[i].value);
589 break; 568 break;
590 } 569 }
591 events[i].number -= joystick->naxes; 570 events[i].number -= joystick->naxes;
592 if ( joystick->hwdata->analog_hat ) { 571 other_axis = (events[i].number / 2);
593 other_axis = events[i].number; 572 if ( other_axis < joystick->nhats ) {
594 if ( other_axis < joystick->nhats ) { 573 HandleHat(joystick, other_axis,
595 HandleAnalogHat(joystick, other_axis, 574 events[i].number%2,
596 events[i].value); 575 events[i].value);
597 break; 576 break;
598 }
599 } else {
600 other_axis = (events[i].number / 2);
601 if ( other_axis < joystick->nhats ) {
602 HandleHat(joystick, other_axis,
603 events[i].number%2,
604 events[i].value);
605 break;
606 }
607 } 577 }
608 events[i].number -= joystick->nhats*2; 578 events[i].number -= joystick->nhats*2;
609 other_axis = (events[i].number / 2); 579 other_axis = (events[i].number / 2);
610 if ( other_axis < joystick->nballs ) { 580 if ( other_axis < joystick->nballs ) {
611 HandleBall(joystick, other_axis, 581 HandleBall(joystick, other_axis,