diff src/haptic/darwin/SDL_syshaptic.c @ 2627:265ced2079bd gsoc2008_force_feedback

Proper axes support for darwin haptic.
author Edgar Simo <bobbens@gmail.com>
date Wed, 06 Aug 2008 10:26:47 +0000
parents 71a835ee438a
children bfbda6c656e5
line wrap: on
line diff
--- a/src/haptic/darwin/SDL_syshaptic.c	Wed Aug 06 10:11:35 2008 +0000
+++ b/src/haptic/darwin/SDL_syshaptic.c	Wed Aug 06 10:26:47 2008 +0000
@@ -55,6 +55,7 @@
 struct haptic_hwdata
 {
    FFDeviceObjectReference device; /* Hardware device. */
+   UInt8 axes[3];
 };
 
 
@@ -275,25 +276,27 @@
  * Gets supported features.
  */
 static unsigned int
-GetSupportedFeatures(FFDeviceObjectReference device,
-                     int *neffects, int *nplaying, int *naxes)
+GetSupportedFeatures(SDL_Haptic* haptic)
 {
    HRESULT ret;
+   FFDeviceObjectReference device;
    FFCAPABILITIES features;
    unsigned int supported;
    Uint32 val;
 
+   device = haptic->hwdata->device;
+
    ret = FFDeviceGetForceFeedbackCapabilities(device, &features);
    if (ret != FF_OK) {
       SDL_SetError("Haptic: Unable to get device's supported features.");
-      return 0;
+      return -1;
    }
 
    supported = 0;
 
    /* Get maximum effects. */
-   *neffects = features.storageCapacity;
-   *nplaying = features.playbackCapacity;
+   haptic->neffects = features.storageCapacity;
+   haptic->nplaying = features.playbackCapacity;
 
    /* Test for effects. */
    FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT);
@@ -316,7 +319,7 @@
    else if (ret != FFERR_UNSUPPORTED) {
       SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
                    FFStrError(ret));
-      return 0;
+      return -1;
    }
 
    /* Checks if supports autocenter. */
@@ -326,16 +329,20 @@
    else if (ret != FFERR_UNSUPPORTED) {
       SDL_SetError("Haptic: Unable to get if device supports autocenter: %s.",
                    FFStrError(ret));
-      return 0;
+      return -1;
    }
 
    /* Check for axes, we have an artificial limit on axes */
-   *naxes = ((features.numFfAxes) > 3) ?
+   haptic->naxes = ((features.numFfAxes) > 3) ?
          3 : features.numFfAxes;
+   /* Actually store the axes we want to use */
+   SDL_memcpy( haptic->hwdata->axes, features.ffAxes, haptic->naxes * sizeof(Uint8));
 
    /* Always supported features. */
    supported |= SDL_HAPTIC_STATUS;
-   return supported;
+
+   haptic->supported = supported;
+   return 0;;
 }
 
 
@@ -346,6 +353,7 @@
 SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
 {
    HRESULT ret;
+   int ret2;
 
    /* Allocate the hwdata */
    haptic->hwdata = (struct haptic_hwdata *)
@@ -365,10 +373,8 @@
    }
 
    /* Get supported features. */
-   haptic->supported = GetSupportedFeatures( haptic->hwdata->device,
-                                             &haptic->neffects, &haptic->nplaying,
-                                             &haptic->naxes );
-   if (haptic->supported == 0) { /* Error since device supports nothing. */
+   ret2 = GetSupportedFeatures( haptic );
+   if (haptic->supported < 0) {
       goto open_err;
    }
 
@@ -622,12 +628,12 @@
          SDL_OutOfMemory();
          return -1;
       }
-      axes[0] = FFJOFS_X; /* Always at least one axis. */
+      axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
       if (dest->cAxes > 1) {
-         axes[1] = FFJOFS_Y;
+         axes[1] = haptic->hwdata->axes[1];
       }
       if (dest->cAxes > 2) {
-         axes[2] = FFJOFS_Z;
+         axes[2] = haptic->hwdata->axes[2];
       }
       dest->rgdwAxes = axes;
    }