changeset 2556:fe346eddd3fb gsoc2008_force_feedback

Updated button trigger stuff.
author Edgar Simo <bobbens@gmail.com>
date Wed, 30 Jul 2008 15:00:45 +0000
parents f5bcc926bac4
children 30778d9d8bff
files src/haptic/darwin/SDL_syshaptic.c src/haptic/linux/SDL_syshaptic.c
diffstat 2 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/haptic/darwin/SDL_syshaptic.c	Wed Jul 30 14:50:00 2008 +0000
+++ b/src/haptic/darwin/SDL_syshaptic.c	Wed Jul 30 15:00:45 2008 +0000
@@ -524,7 +524,7 @@
    dwTriggerButton = FFEB_NOTRIGGER;
 
    if (button != 0) {
-      dwTriggerButton = FFJOFS_BUTTON(button);
+      dwTriggerButton = FFJOFS_BUTTON(button - 1);
    }
 
    return dwTriggerButton;
--- a/src/haptic/linux/SDL_syshaptic.c	Wed Jul 30 14:50:00 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Wed Jul 30 15:00:45 2008 +0000
@@ -453,6 +453,25 @@
    SDL_hapticlist[0].fname = NULL;
 }
 
+
+/*
+ * Converts an SDL button to a ff_trigger button.
+ */
+static Uint16
+SDL_SYS_ToButton( Uint16 button )
+{
+   Uint16 ff_button;
+
+   ff_button = 0;
+
+   if (button != 0) {
+      ff_button = BTN_GAMEPAD + button - 1;
+   }
+
+   return ff_button;
+}
+
+
 /*
  * Returns the ff_effect usable direction from a SDL_HapticDirection.
  */
@@ -488,6 +507,7 @@
    return 0;
 }
 
+
 #define  CLAMP(x)    (((x) > 32767) ? 32767 : x)
 /*
  * Initializes the linux effect struct from a haptic_effect.
@@ -520,7 +540,7 @@
          dest->replay.delay = CLAMP(constant->delay);
 
          /* Trigger */
-         dest->trigger.button = CLAMP(constant->button);
+         dest->trigger.button = SDL_SYS_ToButton(constant->button);
          dest->trigger.interval = CLAMP(constant->interval);
 
          /* Constant */
@@ -552,7 +572,7 @@
          dest->replay.delay = CLAMP(periodic->delay);
          
          /* Trigger */
-         dest->trigger.button = CLAMP(periodic->button);
+         dest->trigger.button = SDL_SYS_ToButton(periodic->button);
          dest->trigger.interval = CLAMP(periodic->interval);
          
          /* Periodic */
@@ -604,7 +624,7 @@
          dest->replay.delay = CLAMP(condition->delay);
 
          /* Trigger */
-         dest->trigger.button = CLAMP(condition->button);
+         dest->trigger.button = SDL_SYS_ToButton(condition->button);
          dest->trigger.interval = CLAMP(condition->interval);
 
          /* Condition */
@@ -639,7 +659,7 @@
          dest->replay.delay = CLAMP(ramp->delay);
 
          /* Trigger */
-         dest->trigger.button = CLAMP(ramp->button);
+         dest->trigger.button = SDL_SYS_ToButton(ramp->button);
          dest->trigger.interval = CLAMP(ramp->interval);
 
          /* Ramp */