changeset 2487:4c8e25ef2d97 gsoc2008_force_feedback

Merged seperate waveforms into types to be more compatible.
author Edgar Simo <bobbens@gmail.com>
date Tue, 01 Jul 2008 16:42:12 +0000
parents 24dd8b8669fa
children 8e2bdbccf7ff
files include/SDL_haptic.h src/haptic/linux/SDL_syshaptic.c
diffstat 2 files changed, 37 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_haptic.h	Tue Jul 01 16:19:54 2008 +0000
+++ b/include/SDL_haptic.h	Tue Jul 01 16:42:12 2008 +0000
@@ -47,28 +47,20 @@
 
 /* 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)
 
 
 /*
@@ -115,7 +107,7 @@
 } SDL_HapticConstant;
 typedef struct SDL_HapticPeriodic {
    /* Header */
-   Uint16 type; /* SDL_HAPTIC_PERIODIC */
+   Uint16 type; /* SDL_HAPTIC_{SINE,SQUARE,TRIANGLE,SAWTOOTHUP,SAWTOOTHDOWN} */
    Uint16 direction;
 
    /* Replay */
@@ -127,7 +119,6 @@
    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 */
--- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 16:19:54 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Tue Jul 01 16:42:12 2008 +0000
@@ -88,7 +88,11 @@
    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);
@@ -317,7 +321,11 @@
 
          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 */
@@ -332,28 +340,17 @@
          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;
@@ -517,7 +514,7 @@
 
 
 /*
- * Frees the effect
+ * Frees the effect.
  */
 void
 SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect * effect)