Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead). gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Tue, 01 Jul 2008 11:21:36 +0000
branchgsoc2008_force_feedback
changeset 2482b51ad78812d5
parent 2481 5d0ea4576f20
child 2483 9d52368ebcf5
Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).
Added and partially implemented CONDITION and RAMP effects.
include/SDL_haptic.h
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/include/SDL_haptic.h	Tue Jul 01 10:44:42 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Tue Jul 01 11:21:36 2008 +0000
     1.3 @@ -52,10 +52,9 @@
     1.4  #define SDL_HAPTIC_SPRING     (1<<3)
     1.5  #define SDL_HAPTIC_FRICTION   (1<<4)
     1.6  #define SDL_HAPTIC_DAMPER     (1<<5)
     1.7 -#define SDL_HAPTIC_RUMBLE     (1<<6)
     1.8 -#define SDL_HAPTIC_INERTIA    (1<<7)
     1.9 -#define SDL_HAPTIC_GAIN       (1<<8)
    1.10 -#define SDL_HAPTIC_AUTOCENTER (1<<9)
    1.11 +#define SDL_HAPTIC_INERTIA    (1<<6)
    1.12 +#define SDL_HAPTIC_GAIN       (1<<7)
    1.13 +#define SDL_HAPTIC_AUTOCENTER (1<<8)
    1.14  
    1.15  typedef enum SDL_waveform {
    1.16     SDL_WAVEFORM_SINE,
    1.17 @@ -134,12 +133,60 @@
    1.18     Uint16 fade_length;
    1.19     Uint16 fade_level;
    1.20  } SDL_HapticPeriodic;
    1.21 +typedef struct SDL_HapticCondition {
    1.22 +   /* Header */
    1.23 +   Uint16 type; /* SDL_HAPTIC_{SPRING,DAMPER,INERTIA,FRICTION} */
    1.24 +   Uint16 direction;
    1.25 +
    1.26 +   /* Replay */
    1.27 +   Uint16 length;
    1.28 +   Uint16 delay;
    1.29 +
    1.30 +   /* Trigger */
    1.31 +   Uint16 button;
    1.32 +   Uint16 interval;
    1.33 +
    1.34 +   /* Condition */
    1.35 +   Uint16 right_sat; /* Level when joystick is to the right. */
    1.36 +   Uint16 left_sat; /* Level when joystick is to the left */
    1.37 +   Sint16 right_coeff; /* How fast to increase the force towards the right */
    1.38 +   Sint16 left_coeff; /* How fast to increase the force towards the left */
    1.39 +   Uint16 deadband; /* Size of the dead zone */
    1.40 +   Sint16 center; /* Position of the dead zone */
    1.41 +
    1.42 +} SDL_HapticCondition;
    1.43 +typedef struct SDL_HapticRamp {
    1.44 +   /* Header */
    1.45 +   Uint16 type; /* SDL_HAPTIC_RAMP */
    1.46 +   Uint16 direction;
    1.47 +
    1.48 +   /* Replay */
    1.49 +   Uint16 length;
    1.50 +   Uint16 delay;
    1.51 +
    1.52 +   /* Trigger */
    1.53 +   Uint16 button;
    1.54 +   Uint16 interval;
    1.55 +
    1.56 +   /* Ramp */
    1.57 +   Sint16 start;
    1.58 +   Sint16 end;
    1.59 +
    1.60 +   /* Envelope */
    1.61 +   Uint16 attack_length;
    1.62 +   Uint16 attack_level;
    1.63 +   Uint16 fade_length;
    1.64 +   Uint16 fade_level;
    1.65 +
    1.66 +} SDL_HapticRamp;
    1.67  
    1.68  typedef union SDL_HapticEffect {
    1.69     /* Common for all force feedback effects */
    1.70     Uint16 type; /* Effect type */
    1.71     SDL_HapticConstant constant; /* Constant effect */
    1.72     SDL_HapticPeriodic periodic; /* Periodic effect */
    1.73 +   SDL_HapticCondition condition; /* Condition effect */
    1.74 +   SDL_HapticRamp ramp; /* Ramp effect */
    1.75  } SDL_HapticEffect;
    1.76  
    1.77  
     2.1 --- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 10:44:42 2008 +0000
     2.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 11:21:36 2008 +0000
     2.3 @@ -94,7 +94,6 @@
     2.4     EV_TEST(FF_SPRING,     SDL_HAPTIC_SPRING);
     2.5     EV_TEST(FF_FRICTION,   SDL_HAPTIC_FRICTION);
     2.6     EV_TEST(FF_DAMPER,     SDL_HAPTIC_DAMPER);
     2.7 -   EV_TEST(FF_RUMBLE,     SDL_HAPTIC_RUMBLE);
     2.8     EV_TEST(FF_INERTIA,    SDL_HAPTIC_INERTIA);
     2.9     EV_TEST(FF_GAIN,       SDL_HAPTIC_GAIN);
    2.10     EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER);
    2.11 @@ -279,8 +278,11 @@
    2.12  static int
    2.13  SDL_SYS_ToFFEffect( struct ff_effect * dest, SDL_HapticEffect * src )
    2.14  {
    2.15 +   int i;
    2.16     SDL_HapticConstant *constant;
    2.17     SDL_HapticPeriodic *periodic;
    2.18 +   SDL_HapticCondition *condition;
    2.19 +   SDL_HapticRamp *ramp;
    2.20  
    2.21     /* Clear up */
    2.22     SDL_memset(dest, 0, sizeof(struct ff_effect));
    2.23 @@ -362,6 +364,69 @@
    2.24  
    2.25           break;
    2.26  
    2.27 +      case SDL_HAPTIC_SPRING:
    2.28 +      case SDL_HAPTIC_DAMPER:
    2.29 +      case SDL_HAPTIC_INERTIA:
    2.30 +      case SDL_HAPTIC_FRICTION:
    2.31 +         condition = &src->condition;
    2.32 +
    2.33 +         /* Header */
    2.34 +         if (dest->type == SDL_HAPTIC_SPRING)
    2.35 +            dest->type = FF_SPRING;
    2.36 +         else if (dest->type == SDL_HAPTIC_DAMPER)
    2.37 +            dest->type = FF_DAMPER;
    2.38 +         else if (dest->type == SDL_HAPTIC_INERTIA)
    2.39 +            dest->type = FF_INERTIA;
    2.40 +         else if (dest->type == SDL_HAPTIC_FRICTION)
    2.41 +            dest->type = FF_FRICTION;
    2.42 +         dest->direction = CLAMP(condition->direction);
    2.43 +
    2.44 +         /* Replay */
    2.45 +         dest->replay.length = CLAMP(condition->length);
    2.46 +         dest->replay.delay = CLAMP(condition->delay);
    2.47 +
    2.48 +         /* Trigger */
    2.49 +         dest->trigger.button = CLAMP(condition->button);
    2.50 +         dest->trigger.interval = CLAMP(condition->interval);
    2.51 +
    2.52 +         /* Condition - TODO handle axes */
    2.53 +         dest->u.condition[0].right_saturation = CLAMP(condition->right_sat);
    2.54 +         dest->u.condition[0].left_saturation = CLAMP(condition->left_sat);
    2.55 +         dest->u.condition[0].right_coeff = condition->right_coeff;
    2.56 +         dest->u.condition[0].left_coeff = condition->left_coeff;
    2.57 +         dest->u.condition[0].deadband = CLAMP(condition->deadband);
    2.58 +         dest->u.condition[0].center = condition->center;
    2.59 +
    2.60 +         break;
    2.61 +
    2.62 +      case SDL_HAPTIC_RAMP:
    2.63 +         ramp = &src->ramp;
    2.64 +
    2.65 +         /* Header */
    2.66 +         dest->type = FF_RAMP;
    2.67 +         dest->direction = CLAMP(ramp->direction);
    2.68 +
    2.69 +         /* Replay */
    2.70 +         dest->replay.length = CLAMP(ramp->length);
    2.71 +         dest->replay.delay = CLAMP(ramp->delay);
    2.72 +
    2.73 +         /* Trigger */
    2.74 +         dest->trigger.button = CLAMP(ramp->button);
    2.75 +         dest->trigger.interval = CLAMP(ramp->interval);
    2.76 +
    2.77 +         /* Ramp */
    2.78 +         dest->u.ramp.start_level = ramp->start;
    2.79 +         dest->u.ramp.end_level = ramp->end;
    2.80 +
    2.81 +         /* Envelope */
    2.82 +         dest->u.ramp.envelope.attack_length = CLAMP(ramp->attack_length);
    2.83 +         dest->u.ramp.envelope.attack_level = CLAMP(ramp->attack_level);
    2.84 +         dest->u.ramp.envelope.fade_length = CLAMP(ramp->fade_length);
    2.85 +         dest->u.ramp.envelope.fade_level = CLAMP(ramp->fade_level);
    2.86 +
    2.87 +         break;
    2.88 +
    2.89 +
    2.90        default:
    2.91           SDL_SetError("Unknown haptic effect type.");
    2.92           return -1;