comparison src/haptic/linux/SDL_syshaptic.c @ 2539:b4c41a7eea04 gsoc2008_force_feedback

Properly support INFINITY length haptic effects on linux.
author Edgar Simo <bobbens@gmail.com>
date Sun, 20 Jul 2008 16:21:15 +0000
parents 22ce87690b41
children fe346eddd3fb
comparison
equal deleted inserted replaced
2538:1f9c20580ab4 2539:b4c41a7eea04
513 dest->type = FF_CONSTANT; 513 dest->type = FF_CONSTANT;
514 dest->direction = SDL_SYS_ToDirection(&constant->direction); 514 dest->direction = SDL_SYS_ToDirection(&constant->direction);
515 if (dest->direction < 0) return -1; 515 if (dest->direction < 0) return -1;
516 516
517 /* Replay */ 517 /* Replay */
518 dest->replay.length = CLAMP(constant->length); 518 dest->replay.length = (constant->length == SDL_HAPTIC_INFINITY) ?
519 0 : CLAMP(constant->length);
519 dest->replay.delay = CLAMP(constant->delay); 520 dest->replay.delay = CLAMP(constant->delay);
520 521
521 /* Trigger */ 522 /* Trigger */
522 dest->trigger.button = CLAMP(constant->button); 523 dest->trigger.button = CLAMP(constant->button);
523 dest->trigger.interval = CLAMP(constant->interval); 524 dest->trigger.interval = CLAMP(constant->interval);
544 dest->type = FF_PERIODIC; 545 dest->type = FF_PERIODIC;
545 dest->direction = SDL_SYS_ToDirection(&periodic->direction); 546 dest->direction = SDL_SYS_ToDirection(&periodic->direction);
546 if (dest->direction < 0) return -1; 547 if (dest->direction < 0) return -1;
547 548
548 /* Replay */ 549 /* Replay */
549 dest->replay.length = CLAMP(periodic->length); 550 dest->replay.length = (periodic->length == SDL_HAPTIC_INFINITY) ?
551 0 : CLAMP(periodic->length);
550 dest->replay.delay = CLAMP(periodic->delay); 552 dest->replay.delay = CLAMP(periodic->delay);
551 553
552 /* Trigger */ 554 /* Trigger */
553 dest->trigger.button = CLAMP(periodic->button); 555 dest->trigger.button = CLAMP(periodic->button);
554 dest->trigger.interval = CLAMP(periodic->interval); 556 dest->trigger.interval = CLAMP(periodic->interval);
595 else if (condition->type == SDL_HAPTIC_FRICTION) 597 else if (condition->type == SDL_HAPTIC_FRICTION)
596 dest->type = FF_FRICTION; 598 dest->type = FF_FRICTION;
597 dest->direction = 0; /* Handled by the condition-specifics. */ 599 dest->direction = 0; /* Handled by the condition-specifics. */
598 600
599 /* Replay */ 601 /* Replay */
600 dest->replay.length = CLAMP(condition->length); 602 dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ?
603 0 : CLAMP(condition->length);
601 dest->replay.delay = CLAMP(condition->delay); 604 dest->replay.delay = CLAMP(condition->delay);
602 605
603 /* Trigger */ 606 /* Trigger */
604 dest->trigger.button = CLAMP(condition->button); 607 dest->trigger.button = CLAMP(condition->button);
605 dest->trigger.interval = CLAMP(condition->interval); 608 dest->trigger.interval = CLAMP(condition->interval);
629 dest->type = FF_RAMP; 632 dest->type = FF_RAMP;
630 dest->direction = SDL_SYS_ToDirection(&ramp->direction); 633 dest->direction = SDL_SYS_ToDirection(&ramp->direction);
631 if (dest->direction < 0) return -1; 634 if (dest->direction < 0) return -1;
632 635
633 /* Replay */ 636 /* Replay */
634 dest->replay.length = CLAMP(ramp->length); 637 dest->replay.length = (ramp->length == SDL_HAPTIC_INFINITY) ?
638 0 : CLAMP(ramp->length);
635 dest->replay.delay = CLAMP(ramp->delay); 639 dest->replay.delay = CLAMP(ramp->delay);
636 640
637 /* Trigger */ 641 /* Trigger */
638 dest->trigger.button = CLAMP(ramp->button); 642 dest->trigger.button = CLAMP(ramp->button);
639 dest->trigger.interval = CLAMP(ramp->interval); 643 dest->trigger.interval = CLAMP(ramp->interval);
739 struct input_event run; 743 struct input_event run;
740 744
741 /* Prepare to run the effect */ 745 /* Prepare to run the effect */
742 run.type = EV_FF; 746 run.type = EV_FF;
743 run.code = effect->hweffect->effect.id; 747 run.code = effect->hweffect->effect.id;
748 /* We don't actually have infinity here, so we just do INT_MAX which is pretty damn close. */
744 run.value = (iterations > INT_MAX) ? INT_MAX : iterations; 749 run.value = (iterations > INT_MAX) ? INT_MAX : iterations;
745 750
746 if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) { 751 if (write(haptic->hwdata->fd, (const void*) &run, sizeof(run)) < 0) {
747 SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno)); 752 SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno));
748 return -1; 753 return -1;