First draft of darwin haptic<->joystick stuff. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Sun, 10 Aug 2008 19:45:38 +0000
branchgsoc2008_force_feedback
changeset 26372f826c229d77
parent 2636 57ac1594164e
child 2638 db93456d4b26
First draft of darwin haptic<->joystick stuff.
src/haptic/darwin/SDL_syshaptic.c
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/darwin/SDL_sysjoystick_c.h
     1.1 --- a/src/haptic/darwin/SDL_syshaptic.c	Wed Aug 06 17:14:54 2008 +0000
     1.2 +++ b/src/haptic/darwin/SDL_syshaptic.c	Sun Aug 10 19:45:38 2008 +0000
     1.3 @@ -447,6 +447,8 @@
     1.4  int
     1.5  SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
     1.6  {
     1.7 +   if (joystick->hwdata->ffservice != 0)
     1.8 +      return SDL_TRUE;
     1.9     return SDL_FALSE;
    1.10  }
    1.11  
    1.12 @@ -457,6 +459,8 @@
    1.13  int
    1.14  SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
    1.15  {
    1.16 +   if (IOObjectIsEqualTo(haptic->hwdata->device, joystick->hwdata->ffservice))
    1.17 +      return 1;
    1.18     return 0;
    1.19  }
    1.20  
    1.21 @@ -467,7 +471,8 @@
    1.22  int
    1.23  SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
    1.24  {
    1.25 -   return -1;
    1.26 +   return SDL_SYS_HapticOpenFromService(haptic,
    1.27 +                joystick->hwdata->ffservice);
    1.28  }
    1.29  
    1.30  
     2.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Wed Aug 06 17:14:54 2008 +0000
     2.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Sun Aug 10 19:45:38 2008 +0000
     2.3 @@ -545,6 +545,12 @@
     2.4          /* save next device prior to disposing of this device */
     2.5          pDeviceNext = (*ppDevice)->pNext;
     2.6  
     2.7 +        /* free posible io_service_t */
     2.8 +        if ((*ppDevice)->ffservice) {
     2.9 +            IOObjectRelease((*ppDevice)->ffservice);
    2.10 +            (*ppDevice)->ffservice = 0;
    2.11 +        }
    2.12 +
    2.13          /* free element lists */
    2.14          HIDDisposeElementList(&(*ppDevice)->firstAxis);
    2.15          HIDDisposeElementList(&(*ppDevice)->firstButton);
    2.16 @@ -637,8 +643,16 @@
    2.17          if (!device)
    2.18              continue;
    2.19  
    2.20 -        /* dump device object, it is no longer needed */
    2.21 -        result = IOObjectRelease(ioHIDDeviceObject);
    2.22 +        /* We have to do some storage of the io_service_t for
    2.23 +         * SDL_HapticOpenFromJoystick */
    2.24 +        if (FFIsForceFeedback(device) == FF_OK) {
    2.25 +           device->ffservice = ioHIDDeviceObject;
    2.26 +        }
    2.27 +        else {
    2.28 +           device->ffservice = 0;
    2.29 +           /* dump device object, it is no longer needed */
    2.30 +           result = IOObjectRelease(ioHIDDeviceObject);
    2.31 +        }
    2.32  /*		if (KERN_SUCCESS != result)
    2.33  			HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result);
    2.34  */
     3.1 --- a/src/joystick/darwin/SDL_sysjoystick_c.h	Wed Aug 06 17:14:54 2008 +0000
     3.2 +++ b/src/joystick/darwin/SDL_sysjoystick_c.h	Sun Aug 10 19:45:38 2008 +0000
     3.3 @@ -60,6 +60,7 @@
     3.4  
     3.5  struct joystick_hwdata
     3.6  {
     3.7 +    io_service_t ffservice;             /* Interface for force feedback, 0 = no ff */
     3.8      IOHIDDeviceInterface **interface;   /* interface to device, NULL = no interface */
     3.9  
    3.10      char product[256];          /* name of product */