Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Removed the linux only SDL_HAPTIC_RUMBLE (use PERIODIC instead).

Added and partially implemented CONDITION and RAMP effects.
  • Loading branch information
bobbens committed Jul 1, 2008
1 parent f84a0cd commit c43ee9e527fc6830f851cd6c8c900bbea2b5690f
Showing with 117 additions and 5 deletions.
  1. +51 −4 include/SDL_haptic.h
  2. +66 −1 src/haptic/linux/SDL_syshaptic.c
@@ -52,10 +52,9 @@ typedef struct _SDL_Haptic SDL_Haptic;
#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 @@ typedef struct SDL_HapticPeriodic {
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;


@@ -94,7 +94,6 @@ EV_IsHaptic(int fd)
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 @@ SDL_SYS_HapticQuit(void)
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 @@ SDL_SYS_ToFFEffect( struct ff_effect * dest, SDL_HapticEffect * src )

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;

0 comments on commit c43ee9e

Please sign in to comment.