Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Merged seperate waveforms into types to be more compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Jul 1, 2008
1 parent eeda569 commit 4fdd153
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 49 deletions.
39 changes: 15 additions & 24 deletions include/SDL_haptic.h
Expand Up @@ -47,28 +47,20 @@ typedef struct _SDL_Haptic SDL_Haptic;

/* Different effects that can be generated */
#define SDL_HAPTIC_CONSTANT (1<<0)
#define SDL_HAPTIC_PERIODIC (1<<1)
#define SDL_HAPTIC_RAMP (1<<2)
#define SDL_HAPTIC_SPRING (1<<3)
#define SDL_HAPTIC_FRICTION (1<<4)
#define SDL_HAPTIC_DAMPER (1<<5)
#define SDL_HAPTIC_INERTIA (1<<6)
#define SDL_HAPTIC_CUSTOM (1<<7)
#define SDL_HAPTIC_GAIN (1<<8)
#define SDL_HAPTIC_AUTOCENTER (1<<9)


/*
* Different waveforms a SDL_HAPTIC_PERIODIC effect can have.
*/
typedef enum SDL_waveform {
SDL_WAVEFORM_SINE,
SDL_WAVEFORM_SQUARE,
SDL_WAVEFORM_TRIANGLE,
SDL_WAVEFORM_SAWTOOTHUP,
SDL_WAVEFORM_SAWTOOTHDOWN,
SDL_WAVEFORM_CUSTOM
} SDL_waveform;
#define SDL_HAPTIC_SINE (1<<1)
#define SDL_HAPTIC_SQUARE (1<<2)
#define SDL_HAPTIC_TRIANGLE (1<<3)
#define SDL_HAPTIC_SAWTOOTHUP (1<<4)
#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5)
#define SDL_HAPTIC_RAMP (1<<6)
#define SDL_HAPTIC_SPRING (1<<7)
#define SDL_HAPTIC_FRICTION (1<<8)
#define SDL_HAPTIC_DAMPER (1<<9)
#define SDL_HAPTIC_INERTIA (1<<10)
#define SDL_HAPTIC_CUSTOM (1<<11)
/* These last two are features the device has, not effects */
#define SDL_HAPTIC_GAIN (1<<12)
#define SDL_HAPTIC_AUTOCENTER (1<<13)


/*
Expand Down Expand Up @@ -115,7 +107,7 @@ typedef struct SDL_HapticConstant {
} SDL_HapticConstant;
typedef struct SDL_HapticPeriodic {
/* Header */
Uint16 type; /* SDL_HAPTIC_PERIODIC */
Uint16 type; /* SDL_HAPTIC_{SINE,SQUARE,TRIANGLE,SAWTOOTHUP,SAWTOOTHDOWN} */
Uint16 direction;

/* Replay */
Expand All @@ -127,7 +119,6 @@ typedef struct SDL_HapticPeriodic {
Uint16 interval;

/* Periodic */
SDL_waveform waveform; /* Type of effect */
Uint16 period; /* Period of the wave */
Sint16 magnitude; /* Peak value */
Sint16 offset; /* Mean value of the wave */
Expand Down
47 changes: 22 additions & 25 deletions src/haptic/linux/SDL_syshaptic.c
Expand Up @@ -88,7 +88,11 @@ EV_IsHaptic(int fd)
ioctl(fd, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features);

EV_TEST(FF_CONSTANT, SDL_HAPTIC_CONSTANT);
EV_TEST(FF_PERIODIC, SDL_HAPTIC_PERIODIC);
EV_TEST(FF_PERIODIC, SDL_HAPTIC_SINE |
SDL_HAPTIC_SQUARE |
SDL_HAPTIC_TRIANGLE |
SDL_HAPTIC_SAWTOOTHUP |
SDL_HAPTIC_SAWTOOTHDOWN);
EV_TEST(FF_RAMP, SDL_HAPTIC_RAMP);
EV_TEST(FF_SPRING, SDL_HAPTIC_SPRING);
EV_TEST(FF_FRICTION, SDL_HAPTIC_FRICTION);
Expand Down Expand Up @@ -317,7 +321,11 @@ SDL_SYS_ToFFEffect( struct ff_effect * dest, SDL_HapticEffect * src )

break;

case SDL_HAPTIC_PERIODIC:
case SDL_HAPTIC_SINE:
case SDL_HAPTIC_SQUARE:
case SDL_HAPTIC_TRIANGLE:
case SDL_HAPTIC_SAWTOOTHUP:
case SDL_HAPTIC_SAWTOOTHDOWN:
periodic = &src->periodic;

/* Header */
Expand All @@ -332,28 +340,17 @@ SDL_SYS_ToFFEffect( struct ff_effect * dest, SDL_HapticEffect * src )
dest->trigger.button = CLAMP(periodic->button);
dest->trigger.interval = CLAMP(periodic->interval);

/* Constant */
switch (periodic->waveform) {
case SDL_WAVEFORM_SINE:
dest->u.periodic.waveform = FF_SINE;
break;
case SDL_WAVEFORM_SQUARE:
dest->u.periodic.waveform = FF_SQUARE;
break;
case SDL_WAVEFORM_TRIANGLE:
dest->u.periodic.waveform = FF_TRIANGLE;
break;
case SDL_WAVEFORM_SAWTOOTHUP:
dest->u.periodic.waveform = FF_SAW_UP;
break;
case SDL_WAVEFORM_SAWTOOTHDOWN:
dest->u.periodic.waveform = FF_SAW_DOWN;
break;

default:
SDL_SetError("Unknown waveform.");
return -1;
}
/* Periodic */
if (periodic->type == SDL_HAPTIC_SINE)
dest->u.periodic.waveform = FF_SINE;
else if (periodic->type == SDL_HAPTIC_SQUARE)
dest->u.periodic.waveform = FF_SQUARE;
else if (periodic->type == SDL_HAPTIC_TRIANGLE)
dest->u.periodic.waveform = FF_TRIANGLE;
else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP)
dest->u.periodic.waveform = FF_SAW_UP;
else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN)
dest->u.periodic.waveform = FF_SAW_DOWN;
dest->u.periodic.period = CLAMP(periodic->period);
dest->u.periodic.magnitude = periodic->magnitude;
dest->u.periodic.offset = periodic->offset;
Expand Down Expand Up @@ -517,7 +514,7 @@ SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect * effect)


/*
* Frees the effect
* Frees the effect.
*/
void
SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)
Expand Down

0 comments on commit 4fdd153

Please sign in to comment.