Proper axes support for darwin haptic. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Wed, 06 Aug 2008 10:26:47 +0000
branchgsoc2008_force_feedback
changeset 2627265ced2079bd
parent 2626 53dd30491c71
child 2628 bfbda6c656e5
Proper axes support for darwin haptic.
src/haptic/darwin/SDL_syshaptic.c
     1.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Wed Aug 06 10:11:35 2008 +0000
     1.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Wed Aug 06 10:26:47 2008 +0000
     1.3 @@ -55,6 +55,7 @@
     1.4  struct haptic_hwdata
     1.5  {
     1.6     FFDeviceObjectReference device; /* Hardware device. */
     1.7 +   UInt8 axes[3];
     1.8  };
     1.9  
    1.10  
    1.11 @@ -275,25 +276,27 @@
    1.12   * Gets supported features.
    1.13   */
    1.14  static unsigned int
    1.15 -GetSupportedFeatures(FFDeviceObjectReference device,
    1.16 -                     int *neffects, int *nplaying, int *naxes)
    1.17 +GetSupportedFeatures(SDL_Haptic* haptic)
    1.18  {
    1.19     HRESULT ret;
    1.20 +   FFDeviceObjectReference device;
    1.21     FFCAPABILITIES features;
    1.22     unsigned int supported;
    1.23     Uint32 val;
    1.24  
    1.25 +   device = haptic->hwdata->device;
    1.26 +
    1.27     ret = FFDeviceGetForceFeedbackCapabilities(device, &features);
    1.28     if (ret != FF_OK) {
    1.29        SDL_SetError("Haptic: Unable to get device's supported features.");
    1.30 -      return 0;
    1.31 +      return -1;
    1.32     }
    1.33  
    1.34     supported = 0;
    1.35  
    1.36     /* Get maximum effects. */
    1.37 -   *neffects = features.storageCapacity;
    1.38 -   *nplaying = features.playbackCapacity;
    1.39 +   haptic->neffects = features.storageCapacity;
    1.40 +   haptic->nplaying = features.playbackCapacity;
    1.41  
    1.42     /* Test for effects. */
    1.43     FF_TEST(FFCAP_ET_CONSTANTFORCE, SDL_HAPTIC_CONSTANT);
    1.44 @@ -316,7 +319,7 @@
    1.45     else if (ret != FFERR_UNSUPPORTED) {
    1.46        SDL_SetError("Haptic: Unable to get if device supports gain: %s.",
    1.47                     FFStrError(ret));
    1.48 -      return 0;
    1.49 +      return -1;
    1.50     }
    1.51  
    1.52     /* Checks if supports autocenter. */
    1.53 @@ -326,16 +329,20 @@
    1.54     else if (ret != FFERR_UNSUPPORTED) {
    1.55        SDL_SetError("Haptic: Unable to get if device supports autocenter: %s.",
    1.56                     FFStrError(ret));
    1.57 -      return 0;
    1.58 +      return -1;
    1.59     }
    1.60  
    1.61     /* Check for axes, we have an artificial limit on axes */
    1.62 -   *naxes = ((features.numFfAxes) > 3) ?
    1.63 +   haptic->naxes = ((features.numFfAxes) > 3) ?
    1.64           3 : features.numFfAxes;
    1.65 +   /* Actually store the axes we want to use */
    1.66 +   SDL_memcpy( haptic->hwdata->axes, features.ffAxes, haptic->naxes * sizeof(Uint8));
    1.67  
    1.68     /* Always supported features. */
    1.69     supported |= SDL_HAPTIC_STATUS;
    1.70 -   return supported;
    1.71 +
    1.72 +   haptic->supported = supported;
    1.73 +   return 0;;
    1.74  }
    1.75  
    1.76  
    1.77 @@ -346,6 +353,7 @@
    1.78  SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
    1.79  {
    1.80     HRESULT ret;
    1.81 +   int ret2;
    1.82  
    1.83     /* Allocate the hwdata */
    1.84     haptic->hwdata = (struct haptic_hwdata *)
    1.85 @@ -365,10 +373,8 @@
    1.86     }
    1.87  
    1.88     /* Get supported features. */
    1.89 -   haptic->supported = GetSupportedFeatures( haptic->hwdata->device,
    1.90 -                                             &haptic->neffects, &haptic->nplaying,
    1.91 -                                             &haptic->naxes );
    1.92 -   if (haptic->supported == 0) { /* Error since device supports nothing. */
    1.93 +   ret2 = GetSupportedFeatures( haptic );
    1.94 +   if (haptic->supported < 0) {
    1.95        goto open_err;
    1.96     }
    1.97  
    1.98 @@ -622,12 +628,12 @@
    1.99           SDL_OutOfMemory();
   1.100           return -1;
   1.101        }
   1.102 -      axes[0] = FFJOFS_X; /* Always at least one axis. */
   1.103 +      axes[0] = haptic->hwdata->axes[0]; /* Always at least one axis. */
   1.104        if (dest->cAxes > 1) {
   1.105 -         axes[1] = FFJOFS_Y;
   1.106 +         axes[1] = haptic->hwdata->axes[1];
   1.107        }
   1.108        if (dest->cAxes > 2) {
   1.109 -         axes[2] = FFJOFS_Z;
   1.110 +         axes[2] = haptic->hwdata->axes[2];
   1.111        }
   1.112        dest->rgdwAxes = axes;
   1.113     }