src/haptic/linux/SDL_syshaptic.c
branchgsoc2008_force_feedback
changeset 2523 366d84fdf8d1
parent 2519 af9df9662807
child 2524 1a55848ce198
     1.1 --- a/src/haptic/linux/SDL_syshaptic.c	Tue Jul 15 17:35:06 2008 +0000
     1.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Thu Jul 17 11:47:48 2008 +0000
     1.3 @@ -255,6 +255,7 @@
     1.4     /* Set the data */
     1.5     haptic->hwdata->fd = fd;
     1.6     haptic->supported = EV_IsHaptic(fd);
     1.7 +   haptic->naxes = 2; /* Hardcoded for now, not sure if it's possible to find out. */
     1.8  
     1.9     /* Set the effects */
    1.10     if (ioctl(fd, EVIOCGEFFECTS, &haptic->neffects) < 0) {
    1.11 @@ -419,6 +420,7 @@
    1.12           /* Linux directions are inverted. */
    1.13           tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000;
    1.14           return (Uint16) tmp;
    1.15 +
    1.16        case SDL_HAPTIC_CARTESIAN:
    1.17           /* We must invert "x" and "y" to go clockwise. */
    1.18           f = atan2(dir->dir[0], dir->dir[1]);
    1.19 @@ -426,7 +428,13 @@
    1.20           tmp = (tmp * 0xFFFF) / 36000;
    1.21           return (Uint16) tmp;
    1.22  
    1.23 +      case SDL_HAPTIC_SPHERICAL:
    1.24 +         tmp = (36000 - dir->dir[0]) + 27000; /* Convert to polars */
    1.25 +         tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000;
    1.26 +         return (Uint16) tmp;
    1.27 +
    1.28        default:
    1.29 +         SDL_SetError("Haptic: Unsupported direction type.");
    1.30           return -1;
    1.31     }
    1.32  
    1.33 @@ -456,6 +464,7 @@
    1.34           /* Header */
    1.35           dest->type = FF_CONSTANT;
    1.36           dest->direction = SDL_SYS_ToDirection(&constant->direction);
    1.37 +         if (dest->direction < 0) return -1;
    1.38  
    1.39           /* Replay */
    1.40           dest->replay.length = CLAMP(constant->length);
    1.41 @@ -486,6 +495,7 @@
    1.42           /* Header */
    1.43           dest->type = FF_PERIODIC;
    1.44           dest->direction = SDL_SYS_ToDirection(&periodic->direction);
    1.45 +         if (dest->direction < 0) return -1;
    1.46           
    1.47           /* Replay */
    1.48           dest->replay.length = CLAMP(periodic->length);
    1.49 @@ -568,6 +578,7 @@
    1.50           /* Header */
    1.51           dest->type = FF_RAMP;
    1.52           dest->direction = SDL_SYS_ToDirection(&ramp->direction);
    1.53 +         if (dest->direction < 0) return -1;
    1.54  
    1.55           /* Replay */
    1.56           dest->replay.length = CLAMP(ramp->length);