changeset 2612:63ea27a96a96 gsoc2008_force_feedback

Check for capabilities at init.
author Edgar Simo <bobbens@gmail.com>
date Wed, 06 Aug 2008 07:51:30 +0000
parents cdea9a70dade
children b081c72b739c
files src/haptic/win32/SDL_syshaptic.c
diffstat 1 files changed, 31 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/haptic/win32/SDL_syshaptic.c	Wed Aug 06 07:42:42 2008 +0000
+++ b/src/haptic/win32/SDL_syshaptic.c	Wed Aug 06 07:51:30 2008 +0000
@@ -57,6 +57,7 @@
 {
    DIDEVICEINSTANCE instance;
    SDL_Haptic *haptic;
+   DIDEVCAPS capabilities;
 } SDL_hapticlist[MAX_HAPTICS];
 
 
@@ -67,7 +68,6 @@
 {
    LPDIRECTINPUTDEVICE2 device;
    DWORD axes[3];
-   DIDEVCAPS capabilities;
 };
 
 
@@ -169,10 +169,36 @@
 static BOOL CALLBACK
 EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
 {
+   HRESULT ret;
+   LPDIRECTINPUTDEVICE device;
+
+   /* Copy the instance over, useful for creating devices. */
    SDL_memcpy(&SDL_hapticlist[SDL_numhaptics].instance, pdidInstance,
          sizeof(DIDEVICEINSTANCE));
+
+   /* Open the device */
+   ret = IDirectInput_CreateDevice( dinput, &instance.guidInstance,
+                                    &device, NULL );
+   if (FAILED(ret)) {
+      /* DI_SetError("Creating DirectInput device",ret); */
+      return DIENUM_CONTINUE;
+   }
+
+   /* Get capabilities. */
+   SDL_hapticlist[SDL_numhaptics].capabilities.dwSize = sizeof(DIDEVCAPS);
+   ret = IDirectInputDevice_GetCapabilities( device,
+                                             &SDL_hapticlist[SDL_numhaptics].capabilities );
+   if (FAILED(ret)) {
+      /* DI_SetError("Getting device capabilities",ret); */
+      IDirectInputDevice_Release(device);
+      return DIENUM_CONTINUE;
+   }
+
+   /* Close up device and count it. */
+   IDirectInputDevice_Release(device);
    SDL_numhaptics++;
 
+   /* Watch out for hard limit. */
    if (SDL_numhaptics >= MAX_HAPTICS)
       return DIENUM_STOP;
 
@@ -256,7 +282,6 @@
  *       - Release DirectInputDevice interface.
  *       - Set cooperative level.
  *       - Set data format.
- *       - Get capabilities.
  *       - Acquire exclusiveness.
  *       - Reset actuators.
  *       - Get supported featuers.
@@ -313,15 +338,6 @@
       goto query_err;
    }
 
-   /* Get capabilities. */
-   haptic->hwdata->capabilities.dwSize = sizeof(DIDEVCAPS);
-   ret = IDirectInputDevice2_GetCapabilities( haptic->hwdata->device,
-                                              &haptic->hwdata->capabilities );
-   if (FAILED(ret)) {
-      DI_SetError("Getting device capabilities",ret);
-      goto acquire_err;
-   }
-
    /* Get number of axes. */
    ret = IDirectInputDevice2_EnumObjects( haptic->hwdata->device,
                                           DI_DeviceObjectCallback,
@@ -435,6 +451,10 @@
 int
 SDL_SYS_HapticMouse(void)
 {
+   int i;
+
+   for (i=0; i<SDL_numhaptics; i++) {
+   }
    return -1;
 }