src/joystick/darwin/SDL_sysjoystick.c
author Edgar Simo <bobbens@gmail.com>
Sun, 10 Aug 2008 19:45:38 +0000
branchgsoc2008_force_feedback
changeset 2637 2f826c229d77
parent 2632 9e7f58b1b255
child 2638 db93456d4b26
permissions -rw-r--r--
First draft of darwin haptic<->joystick stuff.
slouken@172
     1
/*
slouken@172
     2
	SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@172
     4
slouken@172
     5
	This library is free software; you can redistribute it and/or
slouken@172
     6
	modify it under the terms of the GNU Library General Public
slouken@172
     7
	License as published by the Free Software Foundation; either
slouken@172
     8
	version 2 of the License, or (at your option) any later version.
slouken@172
     9
slouken@172
    10
	This library is distributed in the hope that it will be useful,
slouken@172
    11
	but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@172
    12
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@172
    13
	Library General Public License for more details.
slouken@172
    14
slouken@172
    15
	You should have received a copy of the GNU Library General Public
slouken@172
    16
	License along with this library; if not, write to the Free
slouken@172
    17
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@172
    18
slouken@172
    19
	Sam Lantinga
slouken@252
    20
	slouken@libsdl.org
slouken@172
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@172
    23
slouken@1635
    24
#ifdef SDL_JOYSTICK_IOKIT
slouken@1635
    25
slouken@1621
    26
/* SDL joystick driver for Darwin / Mac OS X, based on the IOKit HID API */
slouken@172
    27
/* Written 2001 by Max Horn */
slouken@172
    28
slouken@172
    29
#include <unistd.h>
slouken@172
    30
#include <ctype.h>
slouken@172
    31
#include <sysexits.h>
slouken@172
    32
#include <mach/mach.h>
slouken@172
    33
#include <mach/mach_error.h>
slouken@172
    34
#include <IOKit/IOKitLib.h>
slouken@172
    35
#include <IOKit/IOCFPlugIn.h>
slouken@209
    36
#ifdef MACOS_10_0_4
slouken@209
    37
#include <IOKit/hidsystem/IOHIDUsageTables.h>
slouken@209
    38
#else
slouken@1621
    39
/* The header was moved here in Mac OS X 10.1 */
slouken@208
    40
#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
slouken@209
    41
#endif
slouken@2110
    42
#if MAC_OS_X_VERSION_MIN_REQUIRED == 1030
slouken@2110
    43
#include "10.3.9-FIX/IOHIDLib.h"
slouken@2110
    44
#else
slouken@172
    45
#include <IOKit/hid/IOHIDLib.h>
slouken@2110
    46
#endif
slouken@172
    47
#include <IOKit/hid/IOHIDKeys.h>
slouken@172
    48
#include <CoreFoundation/CoreFoundation.h>
slouken@1895
    49
#include <Carbon/Carbon.h>      /* for NewPtrClear, DisposePtr */
slouken@172
    50
slouken@172
    51
#include "SDL_joystick.h"
slouken@1361
    52
#include "../SDL_sysjoystick.h"
slouken@1361
    53
#include "../SDL_joystick_c.h"
bobbens@2632
    54
#include "SDL_sysjoystick_c.h"
slouken@172
    55
slouken@172
    56
slouken@172
    57
/* Linked list of all available devices */
slouken@172
    58
static recDevice *gpDeviceList = NULL;
slouken@172
    59
slouken@172
    60
slouken@1895
    61
static void
slouken@1895
    62
HIDReportErrorNum(char *strError, long numError)
slouken@172
    63
{
slouken@1895
    64
    SDL_SetError(strError);
slouken@172
    65
}
slouken@172
    66
slouken@1895
    67
static void HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
slouken@1895
    68
                                     recDevice * pDevice);
slouken@172
    69
slouken@172
    70
/* returns current value for element, polling element
slouken@172
    71
 * will return 0 on error conditions which should be accounted for by application
slouken@172
    72
 */
slouken@172
    73
slouken@1895
    74
static SInt32
slouken@1895
    75
HIDGetElementValue(recDevice * pDevice, recElement * pElement)
slouken@172
    76
{
slouken@1895
    77
    IOReturn result = kIOReturnSuccess;
slouken@1895
    78
    IOHIDEventStruct hidEvent;
slouken@1895
    79
    hidEvent.value = 0;
slouken@172
    80
slouken@1895
    81
    if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface) {
slouken@1895
    82
        result =
slouken@1895
    83
            (*(pDevice->interface))->getElementValue(pDevice->interface,
slouken@1895
    84
                                                     pElement->cookie,
slouken@1895
    85
                                                     &hidEvent);
slouken@1895
    86
        if (kIOReturnSuccess == result) {
slouken@1895
    87
            /* record min and max for auto calibration */
slouken@1895
    88
            if (hidEvent.value < pElement->minReport)
slouken@1895
    89
                pElement->minReport = hidEvent.value;
slouken@1895
    90
            if (hidEvent.value > pElement->maxReport)
slouken@1895
    91
                pElement->maxReport = hidEvent.value;
slouken@1895
    92
        }
slouken@1895
    93
    }
slouken@1895
    94
slouken@1895
    95
    /* auto user scale */
slouken@1895
    96
    return hidEvent.value;
slouken@172
    97
}
slouken@172
    98
slouken@1895
    99
static SInt32
slouken@1895
   100
HIDScaledCalibratedValue(recDevice * pDevice, recElement * pElement,
slouken@1895
   101
                         long min, long max)
slouken@172
   102
{
slouken@1895
   103
    float deviceScale = max - min;
slouken@1895
   104
    float readScale = pElement->maxReport - pElement->minReport;
slouken@1895
   105
    SInt32 value = HIDGetElementValue(pDevice, pElement);
slouken@1895
   106
    if (readScale == 0)
slouken@1895
   107
        return value;           /* no scaling at all */
slouken@1895
   108
    else
slouken@1895
   109
        return ((value - pElement->minReport) * deviceScale / readScale) +
slouken@1895
   110
            min;
slouken@172
   111
}
slouken@172
   112
slouken@858
   113
slouken@1895
   114
static void
slouken@1895
   115
HIDRemovalCallback(void *target, IOReturn result, void *refcon, void *sender)
slouken@858
   116
{
slouken@1895
   117
    recDevice *device = (recDevice *) refcon;
slouken@1895
   118
    device->removed = 1;
slouken@1895
   119
    device->uncentered = 1;
slouken@858
   120
}
slouken@858
   121
slouken@858
   122
slouken@858
   123
slouken@172
   124
/* Create and open an interface to device, required prior to extracting values or building queues.
slouken@172
   125
 * Note: appliction now owns the device and must close and release it prior to exiting
slouken@172
   126
 */
slouken@172
   127
slouken@1895
   128
static IOReturn
slouken@1895
   129
HIDCreateOpenDeviceInterface(io_object_t hidDevice, recDevice * pDevice)
slouken@172
   130
{
slouken@1895
   131
    IOReturn result = kIOReturnSuccess;
slouken@1895
   132
    HRESULT plugInResult = S_OK;
slouken@1895
   133
    SInt32 score = 0;
slouken@1895
   134
    IOCFPlugInInterface **ppPlugInInterface = NULL;
slouken@858
   135
slouken@1895
   136
    if (NULL == pDevice->interface) {
slouken@1895
   137
        result =
slouken@1895
   138
            IOCreatePlugInInterfaceForService(hidDevice,
slouken@1895
   139
                                              kIOHIDDeviceUserClientTypeID,
slouken@1895
   140
                                              kIOCFPlugInInterfaceID,
slouken@1895
   141
                                              &ppPlugInInterface, &score);
slouken@1895
   142
        if (kIOReturnSuccess == result) {
slouken@1895
   143
            /* Call a method of the intermediate plug-in to create the device interface */
slouken@1895
   144
            plugInResult =
slouken@1895
   145
                (*ppPlugInInterface)->QueryInterface(ppPlugInInterface,
slouken@1895
   146
                                                     CFUUIDGetUUIDBytes
slouken@1895
   147
                                                     (kIOHIDDeviceInterfaceID),
slouken@1895
   148
                                                     (void *) &(pDevice->
slouken@1895
   149
                                                                interface));
slouken@1895
   150
            if (S_OK != plugInResult)
slouken@1895
   151
                HIDReportErrorNum
slouken@1895
   152
                    ("CouldnŐt query HID class device interface from plugInInterface",
slouken@1895
   153
                     plugInResult);
slouken@1895
   154
            (*ppPlugInInterface)->Release(ppPlugInInterface);
slouken@1895
   155
        } else
slouken@1895
   156
            HIDReportErrorNum
slouken@1895
   157
                ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.",
slouken@1895
   158
                 result);
slouken@1895
   159
    }
slouken@1895
   160
    if (NULL != pDevice->interface) {
slouken@1895
   161
        result = (*(pDevice->interface))->open(pDevice->interface, 0);
slouken@1895
   162
        if (kIOReturnSuccess != result)
slouken@1895
   163
            HIDReportErrorNum
slouken@1895
   164
                ("Failed to open pDevice->interface via open.", result);
slouken@1895
   165
        else
slouken@1895
   166
            (*(pDevice->interface))->setRemovalCallback(pDevice->interface,
slouken@1895
   167
                                                        HIDRemovalCallback,
slouken@1895
   168
                                                        pDevice, pDevice);
slouken@1895
   169
slouken@1895
   170
    }
slouken@1895
   171
    return result;
slouken@172
   172
}
slouken@172
   173
slouken@172
   174
/* Closes and releases interface to device, should be done prior to exting application
slouken@172
   175
 * Note: will have no affect if device or interface do not exist
slouken@172
   176
 * application will "own" the device if interface is not closed
slouken@172
   177
 * (device may have to be plug and re-plugged in different location to get it working again without a restart)
slouken@172
   178
 */
slouken@172
   179
slouken@1895
   180
static IOReturn
slouken@1895
   181
HIDCloseReleaseInterface(recDevice * pDevice)
slouken@172
   182
{
slouken@1895
   183
    IOReturn result = kIOReturnSuccess;
slouken@1895
   184
slouken@1895
   185
    if ((NULL != pDevice) && (NULL != pDevice->interface)) {
slouken@1895
   186
        /* close the interface */
slouken@1895
   187
        result = (*(pDevice->interface))->close(pDevice->interface);
slouken@1895
   188
        if (kIOReturnNotOpen == result) {
slouken@1895
   189
            /* do nothing as device was not opened, thus can't be closed */
slouken@1895
   190
        } else if (kIOReturnSuccess != result)
slouken@1895
   191
            HIDReportErrorNum("Failed to close IOHIDDeviceInterface.",
slouken@1895
   192
                              result);
slouken@1895
   193
        /* release the interface */
slouken@1895
   194
        result = (*(pDevice->interface))->Release(pDevice->interface);
slouken@1895
   195
        if (kIOReturnSuccess != result)
slouken@1895
   196
            HIDReportErrorNum("Failed to release IOHIDDeviceInterface.",
slouken@1895
   197
                              result);
slouken@1895
   198
        pDevice->interface = NULL;
slouken@1895
   199
    }
slouken@1895
   200
    return result;
slouken@172
   201
}
slouken@172
   202
slouken@172
   203
/* extracts actual specific element information from each element CF dictionary entry */
slouken@172
   204
slouken@1895
   205
static void
slouken@1895
   206
HIDGetElementInfo(CFTypeRef refElement, recElement * pElement)
slouken@172
   207
{
slouken@1895
   208
    long number;
slouken@1895
   209
    CFTypeRef refType;
slouken@172
   210
slouken@1895
   211
    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementCookieKey));
slouken@1895
   212
    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
slouken@1895
   213
        pElement->cookie = (IOHIDElementCookie) number;
slouken@1895
   214
    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMinKey));
slouken@1895
   215
    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
icculus@2109
   216
        pElement->minReport = pElement->min = number;
slouken@1895
   217
    pElement->maxReport = pElement->min;
slouken@1895
   218
    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMaxKey));
slouken@1895
   219
    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
icculus@2109
   220
        pElement->maxReport = pElement->max = number;
slouken@172
   221
/*
slouken@172
   222
	TODO: maybe should handle the following stuff somehow?
slouken@172
   223
slouken@172
   224
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey));
slouken@172
   225
	if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
slouken@172
   226
		pElement->scaledMin = number;
slouken@172
   227
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey));
slouken@172
   228
	if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
slouken@172
   229
		pElement->scaledMax = number;
slouken@172
   230
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey));
slouken@172
   231
	if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
slouken@172
   232
		pElement->size = number;
slouken@172
   233
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey));
slouken@172
   234
	if (refType)
slouken@172
   235
		pElement->relative = CFBooleanGetValue (refType);
slouken@172
   236
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey));
slouken@172
   237
	if (refType)
slouken@172
   238
		pElement->wrapping = CFBooleanGetValue (refType);
slouken@172
   239
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey));
slouken@172
   240
	if (refType)
slouken@172
   241
		pElement->nonLinear = CFBooleanGetValue (refType);
slouken@172
   242
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey));
slouken@172
   243
	if (refType)
slouken@172
   244
		pElement->preferredState = CFBooleanGetValue (refType);
slouken@172
   245
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey));
slouken@172
   246
	if (refType)
slouken@172
   247
		pElement->nullState = CFBooleanGetValue (refType);
slouken@172
   248
*/
slouken@1895
   249
}
slouken@172
   250
slouken@172
   251
/* examines CF dictionary vlaue in device element hierarchy to determine if it is element of interest or a collection of more elements
slouken@172
   252
 * if element of interest allocate storage, add to list and retrieve element specific info
slouken@172
   253
 * if collection then pass on to deconstruction collection into additional individual elements
slouken@172
   254
 */
slouken@172
   255
slouken@1895
   256
static void
slouken@1895
   257
HIDAddElement(CFTypeRef refElement, recDevice * pDevice)
slouken@172
   258
{
slouken@1895
   259
    recElement *element = NULL;
slouken@1895
   260
    recElement **headElement = NULL;
slouken@1895
   261
    long elementType, usagePage, usage;
slouken@1895
   262
    CFTypeRef refElementType =
slouken@1895
   263
        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementTypeKey));
slouken@1895
   264
    CFTypeRef refUsagePage =
slouken@1895
   265
        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsagePageKey));
slouken@1895
   266
    CFTypeRef refUsage =
slouken@1895
   267
        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsageKey));
slouken@172
   268
slouken@172
   269
slouken@1895
   270
    if ((refElementType)
slouken@1895
   271
        &&
slouken@1895
   272
        (CFNumberGetValue(refElementType, kCFNumberLongType, &elementType))) {
slouken@1895
   273
        /* look at types of interest */
slouken@1895
   274
        if ((elementType == kIOHIDElementTypeInput_Misc)
slouken@1895
   275
            || (elementType == kIOHIDElementTypeInput_Button)
slouken@1895
   276
            || (elementType == kIOHIDElementTypeInput_Axis)) {
slouken@1895
   277
            if (refUsagePage
slouken@1895
   278
                && CFNumberGetValue(refUsagePage, kCFNumberLongType,
slouken@1895
   279
                                    &usagePage) && refUsage
slouken@1895
   280
                && CFNumberGetValue(refUsage, kCFNumberLongType, &usage)) {
slouken@1895
   281
                switch (usagePage) {    /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
slouken@1895
   282
                case kHIDPage_GenericDesktop:
slouken@1895
   283
                    {
slouken@1895
   284
                        switch (usage) {        /* look at usage to determine function */
slouken@1895
   285
                        case kHIDUsage_GD_X:
slouken@1895
   286
                        case kHIDUsage_GD_Y:
slouken@1895
   287
                        case kHIDUsage_GD_Z:
slouken@1895
   288
                        case kHIDUsage_GD_Rx:
slouken@1895
   289
                        case kHIDUsage_GD_Ry:
slouken@1895
   290
                        case kHIDUsage_GD_Rz:
slouken@1895
   291
                        case kHIDUsage_GD_Slider:
slouken@1895
   292
                        case kHIDUsage_GD_Dial:
slouken@1895
   293
                        case kHIDUsage_GD_Wheel:
slouken@1895
   294
                            element = (recElement *)
slouken@1895
   295
                                NewPtrClear(sizeof(recElement));
slouken@1895
   296
                            if (element) {
slouken@1895
   297
                                pDevice->axes++;
slouken@1895
   298
                                headElement = &(pDevice->firstAxis);
slouken@1895
   299
                            }
slouken@1895
   300
                            break;
slouken@1895
   301
                        case kHIDUsage_GD_Hatswitch:
slouken@1895
   302
                            element = (recElement *)
slouken@1895
   303
                                NewPtrClear(sizeof(recElement));
slouken@1895
   304
                            if (element) {
slouken@1895
   305
                                pDevice->hats++;
slouken@1895
   306
                                headElement = &(pDevice->firstHat);
slouken@1895
   307
                            }
slouken@1895
   308
                            break;
slouken@1895
   309
                        }
slouken@1895
   310
                    }
slouken@1895
   311
                    break;
slouken@1895
   312
                case kHIDPage_Button:
slouken@1895
   313
                    element = (recElement *)
slouken@1895
   314
                        NewPtrClear(sizeof(recElement));
slouken@1895
   315
                    if (element) {
slouken@1895
   316
                        pDevice->buttons++;
slouken@1895
   317
                        headElement = &(pDevice->firstButton);
slouken@1895
   318
                    }
slouken@1895
   319
                    break;
slouken@1895
   320
                default:
slouken@1895
   321
                    break;
slouken@1895
   322
                }
slouken@1895
   323
            }
slouken@1895
   324
        } else if (kIOHIDElementTypeCollection == elementType)
slouken@1895
   325
            HIDGetCollectionElements((CFMutableDictionaryRef) refElement,
slouken@1895
   326
                                     pDevice);
slouken@1895
   327
    }
slouken@172
   328
slouken@1895
   329
    if (element && headElement) {       /* add to list */
slouken@1895
   330
        pDevice->elements++;
slouken@1895
   331
        if (NULL == *headElement)
slouken@1895
   332
            *headElement = element;
slouken@1895
   333
        else {
slouken@1895
   334
            recElement *elementPrevious, *elementCurrent;
slouken@1895
   335
            elementCurrent = *headElement;
slouken@1895
   336
            while (elementCurrent) {
slouken@1895
   337
                elementPrevious = elementCurrent;
slouken@1895
   338
                elementCurrent = elementPrevious->pNext;
slouken@1895
   339
            }
slouken@1895
   340
            elementPrevious->pNext = element;
slouken@1895
   341
        }
slouken@1895
   342
        element->pNext = NULL;
slouken@1895
   343
        HIDGetElementInfo(refElement, element);
slouken@1895
   344
    }
slouken@172
   345
}
slouken@172
   346
slouken@172
   347
/* collects information from each array member in device element list (each array memeber = element) */
slouken@172
   348
slouken@1895
   349
static void
slouken@1895
   350
HIDGetElementsCFArrayHandler(const void *value, void *parameter)
slouken@172
   351
{
slouken@1895
   352
    if (CFGetTypeID(value) == CFDictionaryGetTypeID())
slouken@1895
   353
        HIDAddElement((CFTypeRef) value, (recDevice *) parameter);
slouken@172
   354
}
slouken@172
   355
slouken@172
   356
/* handles retrieval of element information from arrays of elements in device IO registry information */
slouken@172
   357
slouken@1895
   358
static void
slouken@1895
   359
HIDGetElements(CFTypeRef refElementCurrent, recDevice * pDevice)
slouken@172
   360
{
slouken@1895
   361
    CFTypeID type = CFGetTypeID(refElementCurrent);
slouken@1895
   362
    if (type == CFArrayGetTypeID()) {   /* if element is an array */
slouken@1895
   363
        CFRange range = { 0, CFArrayGetCount(refElementCurrent) };
slouken@1895
   364
        /* CountElementsCFArrayHandler called for each array member */
slouken@1895
   365
        CFArrayApplyFunction(refElementCurrent, range,
slouken@1895
   366
                             HIDGetElementsCFArrayHandler, pDevice);
slouken@1895
   367
    }
slouken@1895
   368
}
slouken@172
   369
slouken@172
   370
/* handles extracting element information from element collection CF types
slouken@172
   371
 * used from top level element decoding and hierarchy deconstruction to flatten device element list
slouken@172
   372
 */
slouken@172
   373
slouken@1895
   374
static void
slouken@1895
   375
HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
slouken@1895
   376
                         recDevice * pDevice)
slouken@172
   377
{
slouken@1895
   378
    CFTypeRef refElementTop =
slouken@1895
   379
        CFDictionaryGetValue(deviceProperties, CFSTR(kIOHIDElementKey));
slouken@1895
   380
    if (refElementTop)
slouken@1895
   381
        HIDGetElements(refElementTop, pDevice);
slouken@172
   382
}
slouken@172
   383
slouken@172
   384
/* use top level element usage page and usage to discern device usage page and usage setting appropriate vlaues in device record */
slouken@172
   385
slouken@1895
   386
static void
slouken@1895
   387
HIDTopLevelElementHandler(const void *value, void *parameter)
slouken@172
   388
{
slouken@1895
   389
    CFTypeRef refCF = 0;
slouken@1895
   390
    if (CFGetTypeID(value) != CFDictionaryGetTypeID())
slouken@1895
   391
        return;
slouken@1895
   392
    refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsagePageKey));
slouken@1895
   393
    if (!CFNumberGetValue
slouken@1895
   394
        (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage))
slouken@1895
   395
        SDL_SetError("CFNumberGetValue error retrieving pDevice->usagePage.");
slouken@1895
   396
    refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsageKey));
slouken@1895
   397
    if (!CFNumberGetValue
slouken@1895
   398
        (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage))
slouken@1895
   399
        SDL_SetError("CFNumberGetValue error retrieving pDevice->usage.");
slouken@172
   400
}
slouken@172
   401
slouken@172
   402
/* extracts device info from CF dictionary records in IO registry */
slouken@172
   403
slouken@1895
   404
static void
slouken@1895
   405
HIDGetDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties,
slouken@1895
   406
                 recDevice * pDevice)
slouken@172
   407
{
slouken@1895
   408
    CFMutableDictionaryRef usbProperties = 0;
slouken@1895
   409
    io_registry_entry_t parent1, parent2;
slouken@172
   410
slouken@1895
   411
    /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
slouken@1895
   412
     * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties
slouken@1895
   413
     */
slouken@1895
   414
    if ((KERN_SUCCESS ==
slouken@1895
   415
         IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1))
slouken@1895
   416
        && (KERN_SUCCESS ==
slouken@1895
   417
            IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2))
slouken@1895
   418
        && (KERN_SUCCESS ==
slouken@1895
   419
            IORegistryEntryCreateCFProperties(parent2, &usbProperties,
slouken@1895
   420
                                              kCFAllocatorDefault,
slouken@1895
   421
                                              kNilOptions))) {
slouken@1895
   422
        if (usbProperties) {
slouken@1895
   423
            CFTypeRef refCF = 0;
slouken@1895
   424
            /* get device info
slouken@1895
   425
             * try hid dictionary first, if fail then go to usb dictionary
slouken@1895
   426
             */
slouken@172
   427
slouken@172
   428
slouken@1895
   429
            /* get product name */
slouken@1895
   430
            refCF =
slouken@1895
   431
                CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
slouken@1895
   432
            if (!refCF)
slouken@1895
   433
                refCF =
slouken@1895
   434
                    CFDictionaryGetValue(usbProperties,
slouken@1895
   435
                                         CFSTR("USB Product Name"));
slouken@1895
   436
            if (refCF) {
slouken@1895
   437
                if (!CFStringGetCString
slouken@1895
   438
                    (refCF, pDevice->product, 256,
slouken@1895
   439
                     CFStringGetSystemEncoding()))
slouken@1895
   440
                    SDL_SetError
slouken@1895
   441
                        ("CFStringGetCString error retrieving pDevice->product.");
slouken@1895
   442
            }
slouken@1895
   443
slouken@1895
   444
            /* get usage page and usage */
slouken@1895
   445
            refCF =
slouken@1895
   446
                CFDictionaryGetValue(hidProperties,
slouken@1895
   447
                                     CFSTR(kIOHIDPrimaryUsagePageKey));
slouken@1895
   448
            if (refCF) {
slouken@1895
   449
                if (!CFNumberGetValue
slouken@1895
   450
                    (refCF, kCFNumberLongType, &pDevice->usagePage))
slouken@1895
   451
                    SDL_SetError
slouken@1895
   452
                        ("CFNumberGetValue error retrieving pDevice->usagePage.");
slouken@1895
   453
                refCF =
slouken@1895
   454
                    CFDictionaryGetValue(hidProperties,
slouken@1895
   455
                                         CFSTR(kIOHIDPrimaryUsageKey));
slouken@1895
   456
                if (refCF)
slouken@1895
   457
                    if (!CFNumberGetValue
slouken@1895
   458
                        (refCF, kCFNumberLongType, &pDevice->usage))
slouken@1895
   459
                        SDL_SetError
slouken@1895
   460
                            ("CFNumberGetValue error retrieving pDevice->usage.");
slouken@1895
   461
            }
slouken@1895
   462
slouken@1895
   463
            if (NULL == refCF) {        /* get top level element HID usage page or usage */
slouken@1895
   464
                /* use top level element instead */
slouken@1895
   465
                CFTypeRef refCFTopElement = 0;
slouken@1895
   466
                refCFTopElement =
slouken@1895
   467
                    CFDictionaryGetValue(hidProperties,
slouken@1895
   468
                                         CFSTR(kIOHIDElementKey));
slouken@1895
   469
                {
slouken@1895
   470
                    /* refCFTopElement points to an array of element dictionaries */
slouken@1895
   471
                    CFRange range = { 0, CFArrayGetCount(refCFTopElement) };
slouken@1895
   472
                    CFArrayApplyFunction(refCFTopElement, range,
slouken@1895
   473
                                         HIDTopLevelElementHandler, pDevice);
slouken@1895
   474
                }
slouken@1895
   475
            }
slouken@1895
   476
slouken@1895
   477
            CFRelease(usbProperties);
slouken@1895
   478
        } else
slouken@1895
   479
            SDL_SetError
slouken@1895
   480
                ("IORegistryEntryCreateCFProperties failed to create usbProperties.");
slouken@1895
   481
slouken@1895
   482
        if (kIOReturnSuccess != IOObjectRelease(parent2))
slouken@1895
   483
            SDL_SetError("IOObjectRelease error with parent2.");
slouken@1895
   484
        if (kIOReturnSuccess != IOObjectRelease(parent1))
slouken@1895
   485
            SDL_SetError("IOObjectRelease error with parent1.");
slouken@1895
   486
    }
slouken@172
   487
}
slouken@172
   488
slouken@172
   489
slouken@1895
   490
static recDevice *
slouken@1895
   491
HIDBuildDevice(io_object_t hidDevice)
slouken@172
   492
{
slouken@1895
   493
    recDevice *pDevice = (recDevice *) NewPtrClear(sizeof(recDevice));
slouken@1895
   494
    if (pDevice) {
slouken@1895
   495
        /* get dictionary for HID properties */
slouken@1895
   496
        CFMutableDictionaryRef hidProperties = 0;
slouken@1895
   497
        kern_return_t result =
slouken@1895
   498
            IORegistryEntryCreateCFProperties(hidDevice, &hidProperties,
slouken@1895
   499
                                              kCFAllocatorDefault,
slouken@1895
   500
                                              kNilOptions);
slouken@1895
   501
        if ((result == KERN_SUCCESS) && hidProperties) {
slouken@1895
   502
            /* create device interface */
slouken@1895
   503
            result = HIDCreateOpenDeviceInterface(hidDevice, pDevice);
slouken@1895
   504
            if (kIOReturnSuccess == result) {
slouken@1895
   505
                HIDGetDeviceInfo(hidDevice, hidProperties, pDevice);    /* hidDevice used to find parents in registry tree */
slouken@1895
   506
                HIDGetCollectionElements(hidProperties, pDevice);
slouken@1895
   507
            } else {
slouken@1895
   508
                DisposePtr((Ptr) pDevice);
slouken@1895
   509
                pDevice = NULL;
slouken@1895
   510
            }
slouken@1895
   511
            CFRelease(hidProperties);
slouken@1895
   512
        } else {
slouken@1895
   513
            DisposePtr((Ptr) pDevice);
slouken@1895
   514
            pDevice = NULL;
slouken@1895
   515
        }
slouken@1895
   516
    }
slouken@1895
   517
    return pDevice;
slouken@172
   518
}
slouken@172
   519
slouken@172
   520
/* disposes of the element list associated with a device and the memory associated with the list
slouken@172
   521
 */
slouken@172
   522
slouken@1895
   523
static void
slouken@1895
   524
HIDDisposeElementList(recElement ** elementList)
slouken@172
   525
{
slouken@1895
   526
    recElement *pElement = *elementList;
slouken@1895
   527
    while (pElement) {
slouken@1895
   528
        recElement *pElementNext = pElement->pNext;
slouken@1895
   529
        DisposePtr((Ptr) pElement);
slouken@1895
   530
        pElement = pElementNext;
slouken@1895
   531
    }
slouken@1895
   532
    *elementList = NULL;
slouken@172
   533
}
slouken@172
   534
slouken@172
   535
/* disposes of a single device, closing and releaseing interface, freeing memory fro device and elements, setting device pointer to NULL
slouken@172
   536
 * all your device no longer belong to us... (i.e., you do not 'own' the device anymore)
slouken@172
   537
 */
slouken@172
   538
slouken@1895
   539
static recDevice *
slouken@1895
   540
HIDDisposeDevice(recDevice ** ppDevice)
slouken@172
   541
{
slouken@1895
   542
    kern_return_t result = KERN_SUCCESS;
slouken@1895
   543
    recDevice *pDeviceNext = NULL;
slouken@1895
   544
    if (*ppDevice) {
slouken@1895
   545
        /* save next device prior to disposing of this device */
slouken@1895
   546
        pDeviceNext = (*ppDevice)->pNext;
slouken@1895
   547
bobbens@2637
   548
        /* free posible io_service_t */
bobbens@2637
   549
        if ((*ppDevice)->ffservice) {
bobbens@2637
   550
            IOObjectRelease((*ppDevice)->ffservice);
bobbens@2637
   551
            (*ppDevice)->ffservice = 0;
bobbens@2637
   552
        }
bobbens@2637
   553
slouken@1895
   554
        /* free element lists */
slouken@1895
   555
        HIDDisposeElementList(&(*ppDevice)->firstAxis);
slouken@1895
   556
        HIDDisposeElementList(&(*ppDevice)->firstButton);
slouken@1895
   557
        HIDDisposeElementList(&(*ppDevice)->firstHat);
slouken@1895
   558
slouken@1895
   559
        result = HIDCloseReleaseInterface(*ppDevice);   /* function sanity checks interface value (now application does not own device) */
slouken@1895
   560
        if (kIOReturnSuccess != result)
slouken@1895
   561
            HIDReportErrorNum
slouken@1895
   562
                ("HIDCloseReleaseInterface failed when trying to dipose device.",
slouken@1895
   563
                 result);
slouken@1895
   564
        DisposePtr((Ptr) * ppDevice);
slouken@1895
   565
        *ppDevice = NULL;
slouken@1895
   566
    }
slouken@1895
   567
    return pDeviceNext;
slouken@172
   568
}
slouken@172
   569
slouken@172
   570
slouken@172
   571
/* Function to scan the system for joysticks.
slouken@172
   572
 * Joystick 0 should be the system default joystick.
slouken@172
   573
 * This function should return the number of available joysticks, or -1
slouken@172
   574
 * on an unrecoverable fatal error.
slouken@172
   575
 */
slouken@1895
   576
int
slouken@1895
   577
SDL_SYS_JoystickInit(void)
slouken@172
   578
{
slouken@1895
   579
    IOReturn result = kIOReturnSuccess;
slouken@1895
   580
    mach_port_t masterPort = 0;
slouken@1895
   581
    io_iterator_t hidObjectIterator = 0;
slouken@1895
   582
    CFMutableDictionaryRef hidMatchDictionary = NULL;
slouken@1895
   583
    recDevice *device, *lastDevice;
slouken@1895
   584
    io_object_t ioHIDDeviceObject = 0;
slouken@172
   585
slouken@1895
   586
    SDL_numjoysticks = 0;
slouken@172
   587
slouken@1895
   588
    if (gpDeviceList) {
slouken@1895
   589
        SDL_SetError("Joystick: Device list already inited.");
slouken@1895
   590
        return -1;
slouken@1895
   591
    }
slouken@172
   592
slouken@1895
   593
    result = IOMasterPort(bootstrap_port, &masterPort);
slouken@1895
   594
    if (kIOReturnSuccess != result) {
slouken@1895
   595
        SDL_SetError("Joystick: IOMasterPort error with bootstrap_port.");
slouken@1895
   596
        return -1;
slouken@1895
   597
    }
slouken@172
   598
slouken@1895
   599
    /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
slouken@1895
   600
    hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
slouken@1895
   601
    if (hidMatchDictionary) {
slouken@1895
   602
        /* Add key for device type (joystick, in this case) to refine the matching dictionary. */
slouken@172
   603
slouken@1895
   604
        /* NOTE: we now perform this filtering later
slouken@1895
   605
           UInt32 usagePage = kHIDPage_GenericDesktop;
slouken@1895
   606
           UInt32 usage = kHIDUsage_GD_Joystick;
slouken@1895
   607
           CFNumberRef refUsage = NULL, refUsagePage = NULL;
slouken@1895
   608
slouken@1895
   609
           refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage);
slouken@1895
   610
           CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage);
slouken@1895
   611
           refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage);
slouken@1895
   612
           CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage);
slouken@1895
   613
         */
slouken@1895
   614
    } else {
slouken@1895
   615
        SDL_SetError
slouken@1895
   616
            ("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching.");
slouken@1895
   617
        return -1;
slouken@1895
   618
    }
slouken@1895
   619
slouken@1895
   620
    /*/ Now search I/O Registry for matching devices. */
slouken@1895
   621
    result =
slouken@1895
   622
        IOServiceGetMatchingServices(masterPort, hidMatchDictionary,
slouken@1895
   623
                                     &hidObjectIterator);
slouken@1895
   624
    /* Check for errors */
slouken@1895
   625
    if (kIOReturnSuccess != result) {
slouken@1895
   626
        SDL_SetError("Joystick: Couldn't create a HID object iterator.");
slouken@1895
   627
        return -1;
slouken@1895
   628
    }
slouken@1895
   629
    if (!hidObjectIterator) {   /* there are no joysticks */
slouken@1895
   630
        gpDeviceList = NULL;
slouken@1895
   631
        SDL_numjoysticks = 0;
slouken@1895
   632
        return 0;
slouken@1895
   633
    }
slouken@1895
   634
    /* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */
slouken@1895
   635
slouken@1895
   636
    /* build flat linked list of devices from device iterator */
slouken@1895
   637
slouken@1895
   638
    gpDeviceList = lastDevice = NULL;
slouken@1895
   639
slouken@1895
   640
    while ((ioHIDDeviceObject = IOIteratorNext(hidObjectIterator))) {
slouken@1895
   641
        /* build a device record */
slouken@1895
   642
        device = HIDBuildDevice(ioHIDDeviceObject);
slouken@1895
   643
        if (!device)
slouken@1895
   644
            continue;
slouken@1895
   645
bobbens@2637
   646
        /* We have to do some storage of the io_service_t for
bobbens@2637
   647
         * SDL_HapticOpenFromJoystick */
bobbens@2637
   648
        if (FFIsForceFeedback(device) == FF_OK) {
bobbens@2637
   649
           device->ffservice = ioHIDDeviceObject;
bobbens@2637
   650
        }
bobbens@2637
   651
        else {
bobbens@2637
   652
           device->ffservice = 0;
bobbens@2637
   653
           /* dump device object, it is no longer needed */
bobbens@2637
   654
           result = IOObjectRelease(ioHIDDeviceObject);
bobbens@2637
   655
        }
slouken@1487
   656
/*		if (KERN_SUCCESS != result)
slouken@1487
   657
			HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result);
slouken@1487
   658
*/
slouken@495
   659
slouken@1895
   660
        /* Filter device list to non-keyboard/mouse stuff */
slouken@2120
   661
        if ((device->usagePage != kHIDPage_GenericDesktop) ||
slouken@2120
   662
            ((device->usage != kHIDUsage_GD_Joystick &&
slouken@2120
   663
              device->usage != kHIDUsage_GD_GamePad &&
slouken@2120
   664
              device->usage != kHIDUsage_GD_MultiAxisController))) {
icculus@620
   665
slouken@1895
   666
            /* release memory for the device */
slouken@1895
   667
            HIDDisposeDevice(&device);
slouken@1895
   668
            DisposePtr((Ptr) device);
slouken@1895
   669
            continue;
slouken@1895
   670
        }
slouken@172
   671
slouken@1895
   672
        /* Add device to the end of the list */
slouken@1895
   673
        if (lastDevice)
slouken@1895
   674
            lastDevice->pNext = device;
slouken@1895
   675
        else
slouken@1895
   676
            gpDeviceList = device;
slouken@1895
   677
        lastDevice = device;
slouken@1895
   678
    }
slouken@1895
   679
    result = IOObjectRelease(hidObjectIterator);        /* release the iterator */
slouken@1895
   680
slouken@1895
   681
    /* Count the total number of devices we found */
slouken@1895
   682
    device = gpDeviceList;
slouken@1895
   683
    while (device) {
slouken@1895
   684
        SDL_numjoysticks++;
slouken@1895
   685
        device = device->pNext;
slouken@1895
   686
    }
slouken@1895
   687
slouken@1895
   688
    return SDL_numjoysticks;
slouken@172
   689
}
slouken@172
   690
slouken@172
   691
/* Function to get the device-dependent name of a joystick */
slouken@1895
   692
const char *
slouken@1895
   693
SDL_SYS_JoystickName(int index)
slouken@172
   694
{
slouken@1895
   695
    recDevice *device = gpDeviceList;
slouken@172
   696
slouken@1895
   697
    for (; index > 0; index--)
slouken@1895
   698
        device = device->pNext;
slouken@1895
   699
slouken@1895
   700
    return device->product;
slouken@172
   701
}
slouken@172
   702
slouken@172
   703
/* Function to open a joystick for use.
slouken@172
   704
 * The joystick to open is specified by the index field of the joystick.
slouken@172
   705
 * This should fill the nbuttons and naxes fields of the joystick structure.
slouken@172
   706
 * It returns 0, or -1 if there is an error.
slouken@172
   707
 */
slouken@1895
   708
int
slouken@1895
   709
SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
slouken@172
   710
{
slouken@1895
   711
    recDevice *device = gpDeviceList;
slouken@1895
   712
    int index;
slouken@172
   713
slouken@1895
   714
    for (index = joystick->index; index > 0; index--)
slouken@1895
   715
        device = device->pNext;
slouken@172
   716
slouken@1895
   717
    joystick->hwdata = device;
slouken@1895
   718
    joystick->name = device->product;
slouken@172
   719
slouken@1895
   720
    joystick->naxes = device->axes;
slouken@1895
   721
    joystick->nhats = device->hats;
slouken@1895
   722
    joystick->nballs = 0;
slouken@1895
   723
    joystick->nbuttons = device->buttons;
slouken@1895
   724
slouken@1895
   725
    return 0;
slouken@172
   726
}
slouken@172
   727
slouken@172
   728
/* Function to update the state of a joystick - called as a device poll.
slouken@172
   729
 * This function shouldn't update the joystick structure directly,
slouken@172
   730
 * but instead should call SDL_PrivateJoystick*() to deliver events
slouken@172
   731
 * and update joystick device state.
slouken@172
   732
 */
slouken@1895
   733
void
slouken@1895
   734
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
slouken@172
   735
{
slouken@1895
   736
    recDevice *device = joystick->hwdata;
slouken@1895
   737
    recElement *element;
slouken@2287
   738
    SInt32 value, range;
slouken@1895
   739
    int i;
slouken@858
   740
slouken@1895
   741
    if (device->removed) {      /* device was unplugged; ignore it. */
slouken@1895
   742
        if (device->uncentered) {
slouken@1895
   743
            device->uncentered = 0;
slouken@858
   744
slouken@1895
   745
            /* Tell the app that everything is centered/unpressed... */
slouken@1895
   746
            for (i = 0; i < device->axes; i++)
slouken@1895
   747
                SDL_PrivateJoystickAxis(joystick, i, 0);
slouken@858
   748
slouken@1895
   749
            for (i = 0; i < device->buttons; i++)
slouken@1895
   750
                SDL_PrivateJoystickButton(joystick, i, 0);
slouken@858
   751
slouken@1895
   752
            for (i = 0; i < device->hats; i++)
slouken@1895
   753
                SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
slouken@1895
   754
        }
slouken@858
   755
slouken@1895
   756
        return;
slouken@1895
   757
    }
slouken@858
   758
slouken@1895
   759
    element = device->firstAxis;
slouken@1895
   760
    i = 0;
slouken@1895
   761
    while (element) {
slouken@1895
   762
        value = HIDScaledCalibratedValue(device, element, -32768, 32767);
slouken@1895
   763
        if (value != joystick->axes[i])
slouken@1895
   764
            SDL_PrivateJoystickAxis(joystick, i, value);
slouken@1895
   765
        element = element->pNext;
slouken@1895
   766
        ++i;
slouken@1895
   767
    }
slouken@1895
   768
slouken@1895
   769
    element = device->firstButton;
slouken@1895
   770
    i = 0;
slouken@1895
   771
    while (element) {
slouken@1895
   772
        value = HIDGetElementValue(device, element);
slouken@1895
   773
        if (value > 1)          /* handle pressure-sensitive buttons */
slouken@629
   774
            value = 1;
slouken@1895
   775
        if (value != joystick->buttons[i])
slouken@1895
   776
            SDL_PrivateJoystickButton(joystick, i, value);
slouken@1895
   777
        element = element->pNext;
slouken@1895
   778
        ++i;
slouken@1895
   779
    }
slouken@172
   780
slouken@1895
   781
    element = device->firstHat;
slouken@1895
   782
    i = 0;
slouken@1895
   783
    while (element) {
slouken@1895
   784
        Uint8 pos = 0;
slouken@1895
   785
slouken@2287
   786
        range = (element->max - element->min + 1);
slouken@2287
   787
        value = HIDGetElementValue(device, element) - element->min;
bob@2295
   788
        if (range == 4)         /* 4 position hatswitch - scale up value */
slouken@1895
   789
            value *= 2;
bob@2295
   790
        else if (range != 8)    /* Neither a 4 nor 8 positions - fall back to default position (centered) */
slouken@1895
   791
            value = -1;
slouken@1895
   792
        switch (value) {
slouken@1895
   793
        case 0:
slouken@1895
   794
            pos = SDL_HAT_UP;
slouken@1895
   795
            break;
slouken@1895
   796
        case 1:
slouken@1895
   797
            pos = SDL_HAT_RIGHTUP;
slouken@1895
   798
            break;
slouken@1895
   799
        case 2:
slouken@1895
   800
            pos = SDL_HAT_RIGHT;
slouken@1895
   801
            break;
slouken@1895
   802
        case 3:
slouken@1895
   803
            pos = SDL_HAT_RIGHTDOWN;
slouken@1895
   804
            break;
slouken@1895
   805
        case 4:
slouken@1895
   806
            pos = SDL_HAT_DOWN;
slouken@1895
   807
            break;
slouken@1895
   808
        case 5:
slouken@1895
   809
            pos = SDL_HAT_LEFTDOWN;
slouken@1895
   810
            break;
slouken@1895
   811
        case 6:
slouken@1895
   812
            pos = SDL_HAT_LEFT;
slouken@1895
   813
            break;
slouken@1895
   814
        case 7:
slouken@1895
   815
            pos = SDL_HAT_LEFTUP;
slouken@1895
   816
            break;
slouken@1895
   817
        default:
slouken@1895
   818
            /* Every other value is mapped to center. We do that because some
slouken@1895
   819
             * joysticks use 8 and some 15 for this value, and apparently
slouken@1895
   820
             * there are even more variants out there - so we try to be generous.
slouken@1895
   821
             */
slouken@1895
   822
            pos = SDL_HAT_CENTERED;
slouken@1895
   823
            break;
slouken@1895
   824
        }
slouken@1895
   825
        if (pos != joystick->hats[i])
slouken@1895
   826
            SDL_PrivateJoystickHat(joystick, i, pos);
slouken@1895
   827
        element = element->pNext;
slouken@1895
   828
        ++i;
slouken@1895
   829
    }
slouken@1895
   830
slouken@1895
   831
    return;
slouken@172
   832
}
slouken@172
   833
slouken@172
   834
/* Function to close a joystick after use */
slouken@1895
   835
void
slouken@1895
   836
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
slouken@172
   837
{
slouken@1895
   838
    /* Should we do anything here? */
slouken@1895
   839
    return;
slouken@172
   840
}
slouken@172
   841
slouken@172
   842
/* Function to perform any system-specific joystick related cleanup */
slouken@1895
   843
void
slouken@1895
   844
SDL_SYS_JoystickQuit(void)
slouken@172
   845
{
slouken@1895
   846
    while (NULL != gpDeviceList)
slouken@1895
   847
        gpDeviceList = HIDDisposeDevice(&gpDeviceList);
slouken@172
   848
}
slouken@1635
   849
slouken@1635
   850
#endif /* SDL_JOYSTICK_IOKIT */
slouken@1895
   851
/* vi: set ts=4 sw=4 expandtab: */