comparison src/haptic/linux/SDL_syshaptic.c @ 2556:fe346eddd3fb gsoc2008_force_feedback

Updated button trigger stuff.
author Edgar Simo <bobbens@gmail.com>
date Wed, 30 Jul 2008 15:00:45 +0000
parents b4c41a7eea04
children 3696b9ce8a37
comparison
equal deleted inserted replaced
2555:f5bcc926bac4 2556:fe346eddd3fb
451 SDL_free(SDL_hapticlist[i].fname); 451 SDL_free(SDL_hapticlist[i].fname);
452 } 452 }
453 SDL_hapticlist[0].fname = NULL; 453 SDL_hapticlist[0].fname = NULL;
454 } 454 }
455 455
456
457 /*
458 * Converts an SDL button to a ff_trigger button.
459 */
460 static Uint16
461 SDL_SYS_ToButton( Uint16 button )
462 {
463 Uint16 ff_button;
464
465 ff_button = 0;
466
467 if (button != 0) {
468 ff_button = BTN_GAMEPAD + button - 1;
469 }
470
471 return ff_button;
472 }
473
474
456 /* 475 /*
457 * Returns the ff_effect usable direction from a SDL_HapticDirection. 476 * Returns the ff_effect usable direction from a SDL_HapticDirection.
458 */ 477 */
459 static Uint16 478 static Uint16
460 SDL_SYS_ToDirection( SDL_HapticDirection * dir ) 479 SDL_SYS_ToDirection( SDL_HapticDirection * dir )
486 } 505 }
487 506
488 return 0; 507 return 0;
489 } 508 }
490 509
510
491 #define CLAMP(x) (((x) > 32767) ? 32767 : x) 511 #define CLAMP(x) (((x) > 32767) ? 32767 : x)
492 /* 512 /*
493 * Initializes the linux effect struct from a haptic_effect. 513 * Initializes the linux effect struct from a haptic_effect.
494 * Values above 32767 (for unsigned) are unspecified so we must clamp. 514 * Values above 32767 (for unsigned) are unspecified so we must clamp.
495 */ 515 */
518 dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ? 538 dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ?
519 0 : CLAMP(constant->length); 539 0 : CLAMP(constant->length);
520 dest->replay.delay = CLAMP(constant->delay); 540 dest->replay.delay = CLAMP(constant->delay);
521 541
522 /* Trigger */ 542 /* Trigger */
523 dest->trigger.button = CLAMP(constant->button); 543 dest->trigger.button = SDL_SYS_ToButton(constant->button);
524 dest->trigger.interval = CLAMP(constant->interval); 544 dest->trigger.interval = CLAMP(constant->interval);
525 545
526 /* Constant */ 546 /* Constant */
527 dest->u.constant.level = constant->level; 547 dest->u.constant.level = constant->level;
528 548
550 dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ? 570 dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ?
551 0 : CLAMP(periodic->length); 571 0 : CLAMP(periodic->length);
552 dest->replay.delay = CLAMP(periodic->delay); 572 dest->replay.delay = CLAMP(periodic->delay);
553 573
554 /* Trigger */ 574 /* Trigger */
555 dest->trigger.button = CLAMP(periodic->button); 575 dest->trigger.button = SDL_SYS_ToButton(periodic->button);
556 dest->trigger.interval = CLAMP(periodic->interval); 576 dest->trigger.interval = CLAMP(periodic->interval);
557 577
558 /* Periodic */ 578 /* Periodic */
559 if (periodic->type == SDL_HAPTIC_SINE) 579 if (periodic->type == SDL_HAPTIC_SINE)
560 dest->u.periodic.waveform = FF_SINE; 580 dest->u.periodic.waveform = FF_SINE;
602 dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ? 622 dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ?
603 0 : CLAMP(condition->length); 623 0 : CLAMP(condition->length);
604 dest->replay.delay = CLAMP(condition->delay); 624 dest->replay.delay = CLAMP(condition->delay);
605 625
606 /* Trigger */ 626 /* Trigger */
607 dest->trigger.button = CLAMP(condition->button); 627 dest->trigger.button = SDL_SYS_ToButton(condition->button);
608 dest->trigger.interval = CLAMP(condition->interval); 628 dest->trigger.interval = CLAMP(condition->interval);
609 629
610 /* Condition */ 630 /* Condition */
611 /* X axis */ 631 /* X axis */
612 dest->u.condition[0].right_saturation = CLAMP(condition->right_sat[0]); 632 dest->u.condition[0].right_saturation = CLAMP(condition->right_sat[0]);
637 dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ? 657 dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ?
638 0 : CLAMP(ramp->length); 658 0 : CLAMP(ramp->length);
639 dest->replay.delay = CLAMP(ramp->delay); 659 dest->replay.delay = CLAMP(ramp->delay);
640 660
641 /* Trigger */ 661 /* Trigger */
642 dest->trigger.button = CLAMP(ramp->button); 662 dest->trigger.button = SDL_SYS_ToButton(ramp->button);
643 dest->trigger.interval = CLAMP(ramp->interval); 663 dest->trigger.interval = CLAMP(ramp->interval);
644 664
645 /* Ramp */ 665 /* Ramp */
646 dest->u.ramp.start_level = ramp->start; 666 dest->u.ramp.start_level = ramp->start;
647 dest->u.ramp.end_level = ramp->end; 667 dest->u.ramp.end_level = ramp->end;