Merged seperate waveforms into types to be more compatible. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Tue, 01 Jul 2008 16:42:12 +0000
branchgsoc2008_force_feedback
changeset 24874c8e25ef2d97
parent 2486 24dd8b8669fa
child 2488 8e2bdbccf7ff
Merged seperate waveforms into types to be more compatible.
include/SDL_haptic.h
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/include/SDL_haptic.h	Tue Jul 01 16:19:54 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Tue Jul 01 16:42:12 2008 +0000
     1.3 @@ -47,28 +47,20 @@
     1.4  
     1.5  /* Different effects that can be generated */
     1.6  #define SDL_HAPTIC_CONSTANT   (1<<0)
     1.7 -#define SDL_HAPTIC_PERIODIC   (1<<1)
     1.8 -#define SDL_HAPTIC_RAMP       (1<<2)
     1.9 -#define SDL_HAPTIC_SPRING     (1<<3)
    1.10 -#define SDL_HAPTIC_FRICTION   (1<<4)
    1.11 -#define SDL_HAPTIC_DAMPER     (1<<5)
    1.12 -#define SDL_HAPTIC_INERTIA    (1<<6)
    1.13 -#define SDL_HAPTIC_CUSTOM     (1<<7)
    1.14 -#define SDL_HAPTIC_GAIN       (1<<8)
    1.15 -#define SDL_HAPTIC_AUTOCENTER (1<<9)
    1.16 -
    1.17 -
    1.18 -/*
    1.19 - * Different waveforms a SDL_HAPTIC_PERIODIC effect can have.
    1.20 - */
    1.21 -typedef enum SDL_waveform {
    1.22 -   SDL_WAVEFORM_SINE,
    1.23 -   SDL_WAVEFORM_SQUARE,
    1.24 -   SDL_WAVEFORM_TRIANGLE,
    1.25 -   SDL_WAVEFORM_SAWTOOTHUP,
    1.26 -   SDL_WAVEFORM_SAWTOOTHDOWN,
    1.27 -   SDL_WAVEFORM_CUSTOM
    1.28 -} SDL_waveform;
    1.29 +#define SDL_HAPTIC_SINE       (1<<1)
    1.30 +#define SDL_HAPTIC_SQUARE     (1<<2)
    1.31 +#define SDL_HAPTIC_TRIANGLE   (1<<3)
    1.32 +#define SDL_HAPTIC_SAWTOOTHUP (1<<4)
    1.33 +#define SDL_HAPTIC_SAWTOOTHDOWN (1<<5)
    1.34 +#define SDL_HAPTIC_RAMP       (1<<6)
    1.35 +#define SDL_HAPTIC_SPRING     (1<<7)
    1.36 +#define SDL_HAPTIC_FRICTION   (1<<8)
    1.37 +#define SDL_HAPTIC_DAMPER     (1<<9)
    1.38 +#define SDL_HAPTIC_INERTIA    (1<<10)
    1.39 +#define SDL_HAPTIC_CUSTOM     (1<<11)
    1.40 +/* These last two are features the device has, not effects */
    1.41 +#define SDL_HAPTIC_GAIN       (1<<12)
    1.42 +#define SDL_HAPTIC_AUTOCENTER (1<<13)
    1.43  
    1.44  
    1.45  /*
    1.46 @@ -115,7 +107,7 @@
    1.47  } SDL_HapticConstant;
    1.48  typedef struct SDL_HapticPeriodic {
    1.49     /* Header */
    1.50 -   Uint16 type; /* SDL_HAPTIC_PERIODIC */
    1.51 +   Uint16 type; /* SDL_HAPTIC_{SINE,SQUARE,TRIANGLE,SAWTOOTHUP,SAWTOOTHDOWN} */
    1.52     Uint16 direction;
    1.53  
    1.54     /* Replay */
    1.55 @@ -127,7 +119,6 @@
    1.56     Uint16 interval;
    1.57  
    1.58     /* Periodic */
    1.59 -   SDL_waveform waveform; /* Type of effect */
    1.60     Uint16 period; /* Period of the wave */
    1.61     Sint16 magnitude; /* Peak value */
    1.62     Sint16 offset; /* Mean value of the wave */
     2.1 --- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 16:19:54 2008 +0000
     2.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 16:42:12 2008 +0000
     2.3 @@ -88,7 +88,11 @@
     2.4     ioctl(fd, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features);
     2.5  
     2.6     EV_TEST(FF_CONSTANT,   SDL_HAPTIC_CONSTANT);
     2.7 -   EV_TEST(FF_PERIODIC,   SDL_HAPTIC_PERIODIC);
     2.8 +   EV_TEST(FF_PERIODIC,   SDL_HAPTIC_SINE |
     2.9 +                          SDL_HAPTIC_SQUARE |
    2.10 +                          SDL_HAPTIC_TRIANGLE |
    2.11 +                          SDL_HAPTIC_SAWTOOTHUP |
    2.12 +                          SDL_HAPTIC_SAWTOOTHDOWN);
    2.13     EV_TEST(FF_RAMP,       SDL_HAPTIC_RAMP);
    2.14     EV_TEST(FF_SPRING,     SDL_HAPTIC_SPRING);
    2.15     EV_TEST(FF_FRICTION,   SDL_HAPTIC_FRICTION);
    2.16 @@ -317,7 +321,11 @@
    2.17  
    2.18           break;
    2.19  
    2.20 -      case SDL_HAPTIC_PERIODIC:
    2.21 +      case SDL_HAPTIC_SINE:
    2.22 +      case SDL_HAPTIC_SQUARE:
    2.23 +      case SDL_HAPTIC_TRIANGLE:
    2.24 +      case SDL_HAPTIC_SAWTOOTHUP:
    2.25 +      case SDL_HAPTIC_SAWTOOTHDOWN:
    2.26           periodic = &src->periodic;
    2.27  
    2.28           /* Header */
    2.29 @@ -332,28 +340,17 @@
    2.30           dest->trigger.button = CLAMP(periodic->button);
    2.31           dest->trigger.interval = CLAMP(periodic->interval);
    2.32           
    2.33 -         /* Constant */
    2.34 -         switch (periodic->waveform) {
    2.35 -            case SDL_WAVEFORM_SINE:
    2.36 -               dest->u.periodic.waveform = FF_SINE;
    2.37 -               break;
    2.38 -            case SDL_WAVEFORM_SQUARE:
    2.39 -               dest->u.periodic.waveform = FF_SQUARE;
    2.40 -               break;
    2.41 -            case SDL_WAVEFORM_TRIANGLE:
    2.42 -               dest->u.periodic.waveform = FF_TRIANGLE;
    2.43 -               break;
    2.44 -            case SDL_WAVEFORM_SAWTOOTHUP:
    2.45 -               dest->u.periodic.waveform = FF_SAW_UP;
    2.46 -               break;
    2.47 -            case SDL_WAVEFORM_SAWTOOTHDOWN:
    2.48 -               dest->u.periodic.waveform = FF_SAW_DOWN;
    2.49 -               break;
    2.50 -
    2.51 -            default:
    2.52 -               SDL_SetError("Unknown waveform.");
    2.53 -               return -1;
    2.54 -         }
    2.55 +         /* Periodic */
    2.56 +         if (periodic->type == SDL_HAPTIC_SINE)
    2.57 +            dest->u.periodic.waveform = FF_SINE;
    2.58 +         else if (periodic->type == SDL_HAPTIC_SQUARE)
    2.59 +            dest->u.periodic.waveform = FF_SQUARE;
    2.60 +         else if (periodic->type == SDL_HAPTIC_TRIANGLE)       
    2.61 +            dest->u.periodic.waveform = FF_TRIANGLE;
    2.62 +         else if (periodic->type == SDL_HAPTIC_SAWTOOTHUP)       
    2.63 +            dest->u.periodic.waveform = FF_SAW_UP;
    2.64 +         else if (periodic->type == SDL_HAPTIC_SAWTOOTHDOWN)       
    2.65 +            dest->u.periodic.waveform = FF_SAW_DOWN;
    2.66           dest->u.periodic.period = CLAMP(periodic->period);
    2.67           dest->u.periodic.magnitude = periodic->magnitude;
    2.68           dest->u.periodic.offset = periodic->offset;
    2.69 @@ -517,7 +514,7 @@
    2.70  
    2.71  
    2.72  /*
    2.73 - * Frees the effect
    2.74 + * Frees the effect.
    2.75   */
    2.76  void
    2.77  SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)