src/joystick/darwin/SDL_sysjoystick.c
changeset 2713 0906692aa6a4
parent 2295 dbc6d1893869
child 2735 204be4fc2726
     1.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Mon Aug 25 08:50:37 2008 +0000
     1.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Mon Aug 25 09:55:03 2008 +0000
     1.3 @@ -48,59 +48,14 @@
     1.4  #include <CoreFoundation/CoreFoundation.h>
     1.5  #include <Carbon/Carbon.h>      /* for NewPtrClear, DisposePtr */
     1.6  
     1.7 +/* For force feedback testing. */
     1.8 +#include <ForceFeedback/ForceFeedback.h>
     1.9 +#include <ForceFeedback/ForceFeedbackConstants.h>
    1.10 +
    1.11  #include "SDL_joystick.h"
    1.12  #include "../SDL_sysjoystick.h"
    1.13  #include "../SDL_joystick_c.h"
    1.14 -
    1.15 -struct recElement
    1.16 -{
    1.17 -    IOHIDElementCookie cookie;  /* unique value which identifies element, will NOT change */
    1.18 -    long min;                   /* reported min value possible */
    1.19 -    long max;                   /* reported max value possible */
    1.20 -#if 0
    1.21 -    /* TODO: maybe should handle the following stuff somehow? */
    1.22 -
    1.23 -    long scaledMin;             /* reported scaled min value possible */
    1.24 -    long scaledMax;             /* reported scaled max value possible */
    1.25 -    long size;                  /* size in bits of data return from element */
    1.26 -    Boolean relative;           /* are reports relative to last report (deltas) */
    1.27 -    Boolean wrapping;           /* does element wrap around (one value higher than max is min) */
    1.28 -    Boolean nonLinear;          /* are the values reported non-linear relative to element movement */
    1.29 -    Boolean preferredState;     /* does element have a preferred state (such as a button) */
    1.30 -    Boolean nullState;          /* does element have null state */
    1.31 -#endif                          /* 0 */
    1.32 -
    1.33 -    /* runtime variables used for auto-calibration */
    1.34 -    long minReport;             /* min returned value */
    1.35 -    long maxReport;             /* max returned value */
    1.36 -
    1.37 -    struct recElement *pNext;   /* next element in list */
    1.38 -};
    1.39 -typedef struct recElement recElement;
    1.40 -
    1.41 -struct joystick_hwdata
    1.42 -{
    1.43 -    IOHIDDeviceInterface **interface;   /* interface to device, NULL = no interface */
    1.44 -
    1.45 -    char product[256];          /* name of product */
    1.46 -    long usage;                 /* usage page from IOUSBHID Parser.h which defines general usage */
    1.47 -    long usagePage;             /* usage within above page from IOUSBHID Parser.h which defines specific usage */
    1.48 -
    1.49 -    long axes;                  /* number of axis (calculated, not reported by device) */
    1.50 -    long buttons;               /* number of buttons (calculated, not reported by device) */
    1.51 -    long hats;                  /* number of hat switches (calculated, not reported by device) */
    1.52 -    long elements;              /* number of total elements (shouldbe total of above) (calculated, not reported by device) */
    1.53 -
    1.54 -    recElement *firstAxis;
    1.55 -    recElement *firstButton;
    1.56 -    recElement *firstHat;
    1.57 -
    1.58 -    int removed;
    1.59 -    int uncentered;
    1.60 -
    1.61 -    struct joystick_hwdata *pNext;      /* next device */
    1.62 -};
    1.63 -typedef struct joystick_hwdata recDevice;
    1.64 +#include "SDL_sysjoystick_c.h"
    1.65  
    1.66  
    1.67  /* Linked list of all available devices */
    1.68 @@ -594,6 +549,12 @@
    1.69          /* save next device prior to disposing of this device */
    1.70          pDeviceNext = (*ppDevice)->pNext;
    1.71  
    1.72 +        /* free posible io_service_t */
    1.73 +        if ((*ppDevice)->ffservice) {
    1.74 +            IOObjectRelease((*ppDevice)->ffservice);
    1.75 +            (*ppDevice)->ffservice = 0;
    1.76 +        }
    1.77 +
    1.78          /* free element lists */
    1.79          HIDDisposeElementList(&(*ppDevice)->firstAxis);
    1.80          HIDDisposeElementList(&(*ppDevice)->firstButton);
    1.81 @@ -686,12 +647,6 @@
    1.82          if (!device)
    1.83              continue;
    1.84  
    1.85 -        /* dump device object, it is no longer needed */
    1.86 -        result = IOObjectRelease(ioHIDDeviceObject);
    1.87 -/*		if (KERN_SUCCESS != result)
    1.88 -			HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result);
    1.89 -*/
    1.90 -
    1.91          /* Filter device list to non-keyboard/mouse stuff */
    1.92          if ((device->usagePage != kHIDPage_GenericDesktop) ||
    1.93              ((device->usage != kHIDUsage_GD_Joystick &&
    1.94 @@ -704,6 +659,14 @@
    1.95              continue;
    1.96          }
    1.97  
    1.98 +        /* We have to do some storage of the io_service_t for
    1.99 +         * SDL_HapticOpenFromJoystick */
   1.100 +        if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {
   1.101 +            device->ffservice = ioHIDDeviceObject;
   1.102 +        } else {
   1.103 +            device->ffservice = 0;
   1.104 +        }
   1.105 +
   1.106          /* Add device to the end of the list */
   1.107          if (lastDevice)
   1.108              lastDevice->pNext = device;