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 2482 b51ad78812d5
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
--- a/include/SDL_haptic.h	Tue Jul 01 10:44:42 2008 +0000
+++ b/include/SDL_haptic.h	Tue Jul 01 11:21:36 2008 +0000
@@ -52,10 +52,9 @@
 #define SDL_HAPTIC_SPRING     (1<<3)
 #define SDL_HAPTIC_FRICTION   (1<<4)
 #define SDL_HAPTIC_DAMPER     (1<<5)
-#define SDL_HAPTIC_RUMBLE     (1<<6)
-#define SDL_HAPTIC_INERTIA    (1<<7)
-#define SDL_HAPTIC_GAIN       (1<<8)
-#define SDL_HAPTIC_AUTOCENTER (1<<9)
+#define SDL_HAPTIC_INERTIA    (1<<6)
+#define SDL_HAPTIC_GAIN       (1<<7)
+#define SDL_HAPTIC_AUTOCENTER (1<<8)
 
 typedef enum SDL_waveform {
    SDL_WAVEFORM_SINE,
@@ -134,12 +133,60 @@
    Uint16 fade_length;
    Uint16 fade_level;
 } SDL_HapticPeriodic;
+typedef struct SDL_HapticCondition {
+   /* Header */
+   Uint16 type; /* SDL_HAPTIC_{SPRING,DAMPER,INERTIA,FRICTION} */
+   Uint16 direction;
+
+   /* Replay */
+   Uint16 length;
+   Uint16 delay;
+
+   /* Trigger */
+   Uint16 button;
+   Uint16 interval;
+
+   /* Condition */
+   Uint16 right_sat; /* Level when joystick is to the right. */
+   Uint16 left_sat; /* Level when joystick is to the left */
+   Sint16 right_coeff; /* How fast to increase the force towards the right */
+   Sint16 left_coeff; /* How fast to increase the force towards the left */
+   Uint16 deadband; /* Size of the dead zone */
+   Sint16 center; /* Position of the dead zone */
+
+} SDL_HapticCondition;
+typedef struct SDL_HapticRamp {
+   /* Header */
+   Uint16 type; /* SDL_HAPTIC_RAMP */
+   Uint16 direction;
+
+   /* Replay */
+   Uint16 length;
+   Uint16 delay;
+
+   /* Trigger */
+   Uint16 button;
+   Uint16 interval;
+
+   /* Ramp */
+   Sint16 start;
+   Sint16 end;
+
+   /* Envelope */
+   Uint16 attack_length;
+   Uint16 attack_level;
+   Uint16 fade_length;
+   Uint16 fade_level;
+
+} SDL_HapticRamp;
 
 typedef union SDL_HapticEffect {
    /* Common for all force feedback effects */
    Uint16 type; /* Effect type */
    SDL_HapticConstant constant; /* Constant effect */
    SDL_HapticPeriodic periodic; /* Periodic effect */
+   SDL_HapticCondition condition; /* Condition effect */
+   SDL_HapticRamp ramp; /* Ramp effect */
 } SDL_HapticEffect;
 
 
--- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 10:44:42 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 11:21:36 2008 +0000
@@ -94,7 +94,6 @@
    EV_TEST(FF_SPRING,     SDL_HAPTIC_SPRING);
    EV_TEST(FF_FRICTION,   SDL_HAPTIC_FRICTION);
    EV_TEST(FF_DAMPER,     SDL_HAPTIC_DAMPER);
-   EV_TEST(FF_RUMBLE,     SDL_HAPTIC_RUMBLE);
    EV_TEST(FF_INERTIA,    SDL_HAPTIC_INERTIA);
    EV_TEST(FF_GAIN,       SDL_HAPTIC_GAIN);
    EV_TEST(FF_AUTOCENTER, SDL_HAPTIC_AUTOCENTER);
@@ -279,8 +278,11 @@
 static int
 SDL_SYS_ToFFEffect( struct ff_effect * dest, SDL_HapticEffect * src )
 {
+   int i;
    SDL_HapticConstant *constant;
    SDL_HapticPeriodic *periodic;
+   SDL_HapticCondition *condition;
+   SDL_HapticRamp *ramp;
 
    /* Clear up */
    SDL_memset(dest, 0, sizeof(struct ff_effect));
@@ -362,6 +364,69 @@
 
          break;
 
+      case SDL_HAPTIC_SPRING:
+      case SDL_HAPTIC_DAMPER:
+      case SDL_HAPTIC_INERTIA:
+      case SDL_HAPTIC_FRICTION:
+         condition = &src->condition;
+
+         /* Header */
+         if (dest->type == SDL_HAPTIC_SPRING)
+            dest->type = FF_SPRING;
+         else if (dest->type == SDL_HAPTIC_DAMPER)
+            dest->type = FF_DAMPER;
+         else if (dest->type == SDL_HAPTIC_INERTIA)
+            dest->type = FF_INERTIA;
+         else if (dest->type == SDL_HAPTIC_FRICTION)
+            dest->type = FF_FRICTION;
+         dest->direction = CLAMP(condition->direction);
+
+         /* Replay */
+         dest->replay.length = CLAMP(condition->length);
+         dest->replay.delay = CLAMP(condition->delay);
+
+         /* Trigger */
+         dest->trigger.button = CLAMP(condition->button);
+         dest->trigger.interval = CLAMP(condition->interval);
+
+         /* Condition - TODO handle axes */
+         dest->u.condition[0].right_saturation = CLAMP(condition->right_sat);
+         dest->u.condition[0].left_saturation = CLAMP(condition->left_sat);
+         dest->u.condition[0].right_coeff = condition->right_coeff;
+         dest->u.condition[0].left_coeff = condition->left_coeff;
+         dest->u.condition[0].deadband = CLAMP(condition->deadband);
+         dest->u.condition[0].center = condition->center;
+
+         break;
+
+      case SDL_HAPTIC_RAMP:
+         ramp = &src->ramp;
+
+         /* Header */
+         dest->type = FF_RAMP;
+         dest->direction = CLAMP(ramp->direction);
+
+         /* Replay */
+         dest->replay.length = CLAMP(ramp->length);
+         dest->replay.delay = CLAMP(ramp->delay);
+
+         /* Trigger */
+         dest->trigger.button = CLAMP(ramp->button);
+         dest->trigger.interval = CLAMP(ramp->interval);
+
+         /* Ramp */
+         dest->u.ramp.start_level = ramp->start;
+         dest->u.ramp.end_level = ramp->end;
+
+         /* Envelope */
+         dest->u.ramp.envelope.attack_length = CLAMP(ramp->attack_length);
+         dest->u.ramp.envelope.attack_level = CLAMP(ramp->attack_level);
+         dest->u.ramp.envelope.fade_length = CLAMP(ramp->fade_length);
+         dest->u.ramp.envelope.fade_level = CLAMP(ramp->fade_level);
+
+         break;
+
+
       default:
          SDL_SetError("Unknown haptic effect type.");
          return -1;