Get number of axes. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Tue, 05 Aug 2008 11:39:51 +0000
branchgsoc2008_force_feedback
changeset 2601 4915cd01d0e7
parent 2600 d1140f0ebedf
child 2602 f578389c9ead
Get number of axes. Should fix the autocenter issue.
src/haptic/win32/SDL_syshaptic.c
--- a/src/haptic/win32/SDL_syshaptic.c	Tue Aug 05 11:21:21 2008 +0000
+++ b/src/haptic/win32/SDL_syshaptic.c	Tue Aug 05 11:39:51 2008 +0000
@@ -224,6 +224,28 @@
 
 
 /*
+ * Callback to get supported axes.
+ */
+static BOOL CALLBACK
+DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
+{
+   SDL_Haptic *haptic = (SDL_Hapti *) pvRef;
+
+   if (dev->dwType & DIDFT_AXIS) {
+
+      haptic->naxes++;
+
+      /* Currently using the artificial limit of 3 axes. */
+      if (haptic->naxes >= 3) {
+         return DIENUM_STOP;
+      }
+   }
+
+   return DIENUM_CONTINUE;
+}
+
+
+/*
  * Opens the haptic device from the file descriptor.
  *
  *    Steps:
@@ -299,6 +321,15 @@
    }
 #endif
 
+   /* Get number of axes. */
+   ret = IDirectInputDevice2_EnumObjects( haptic->hwdata->device,
+                                          DI_DeviceObjectCallback,
+                                          haptic, DIDFT_AXIS );
+   if (FAILED(ret)) {
+      DI_SetError("Getting device axes",ret);
+      goto query_err;
+   }
+
    /* Acquire the device. */
    ret = IDirectInputDevice2_Acquire(haptic->hwdata->device);
    if (FAILED(ret)) {
@@ -352,6 +383,8 @@
    else { /* Gain is supported. */
       haptic->supported |= SDL_HAPTIC_GAIN;
    }
+   dipdw.diph.dwObj        = 0;
+   dipdw.diph.dwHow        = DIPH_DEVICE;
    dipdw.dwData            = DIPROPAUTOCENTER_OFF;
    ret = IDirectInputDevice2_SetProperty( haptic->hwdata->device,
                                           DIPROP_AUTOCENTER, &dipdw.diph );