diff src/haptic/linux/SDL_syshaptic.c @ 2523:366d84fdf8d1 gsoc2008_force_feedback

Haptic subsystem handles haptic axes now. Support for SDL_HAPTIC_SPHERICAL on linux. More error checking. Improved documentation. Added missing SDLCALLs to SDL_haptic.h.
author Edgar Simo <bobbens@gmail.com>
date Thu, 17 Jul 2008 11:47:48 +0000
parents af9df9662807
children 1a55848ce198
line wrap: on
line diff
--- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 15 17:35:06 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Thu Jul 17 11:47:48 2008 +0000
@@ -255,6 +255,7 @@
    /* Set the data */
    haptic->hwdata->fd = fd;
    haptic->supported = EV_IsHaptic(fd);
+   haptic->naxes = 2; /* Hardcoded for now, not sure if it's possible to find out. */
 
    /* Set the effects */
    if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
@@ -419,6 +420,7 @@
          /* Linux directions are inverted. */
          tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000;
          return (Uint16) tmp;
+
       case SDL_HAPTIC_CARTESIAN:
          /* We must invert "x" and "y" to go clockwise. */
          f = atan2(dir->dir[0], dir->dir[1]);
@@ -426,7 +428,13 @@
          tmp = (tmp * 0xFFFF) / 36000;
          return (Uint16) tmp;
 
+      case SDL_HAPTIC_SPHERICAL:
+         tmp = (36000 - dir->dir[0]) + 27000; /* Convert to polars */
+         tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000;
+         return (Uint16) tmp;
+
       default:
+         SDL_SetError("Haptic: Unsupported direction type.");
          return -1;
    }
 
@@ -456,6 +464,7 @@
          /* Header */
          dest->type = FF_CONSTANT;
          dest->direction = SDL_SYS_ToDirection(&constant->direction);
+         if (dest->direction < 0) return -1;
 
          /* Replay */
          dest->replay.length = CLAMP(constant->length);
@@ -486,6 +495,7 @@
          /* Header */
          dest->type = FF_PERIODIC;
          dest->direction = SDL_SYS_ToDirection(&periodic->direction);
+         if (dest->direction < 0) return -1;
          
          /* Replay */
          dest->replay.length = CLAMP(periodic->length);
@@ -568,6 +578,7 @@
          /* Header */
          dest->type = FF_RAMP;
          dest->direction = SDL_SYS_ToDirection(&ramp->direction);
+         if (dest->direction < 0) return -1;
 
          /* Replay */
          dest->replay.length = CLAMP(ramp->length);