src/joystick/darwin/SDL_sysjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 08 Dec 2008 00:27:32 +0000
changeset 2859 99210400e8b9
parent 2776 caf3d5b2153f
child 3697 f7b03b6838cb
permissions -rw-r--r--
Updated copyright date
slouken@172
     1
/*
slouken@172
     2
	SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 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@2713
    51
/* For force feedback testing. */
slouken@2713
    52
#include <ForceFeedback/ForceFeedback.h>
slouken@2713
    53
#include <ForceFeedback/ForceFeedbackConstants.h>
slouken@2713
    54
slouken@172
    55
#include "SDL_joystick.h"
slouken@1361
    56
#include "../SDL_sysjoystick.h"
slouken@1361
    57
#include "../SDL_joystick_c.h"
slouken@2713
    58
#include "SDL_sysjoystick_c.h"
slouken@172
    59
slouken@172
    60
slouken@172
    61
/* Linked list of all available devices */
slouken@172
    62
static recDevice *gpDeviceList = NULL;
slouken@172
    63
slouken@172
    64
slouken@1895
    65
static void
slouken@1895
    66
HIDReportErrorNum(char *strError, long numError)
slouken@172
    67
{
slouken@1895
    68
    SDL_SetError(strError);
slouken@172
    69
}
slouken@172
    70
slouken@1895
    71
static void HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
slouken@1895
    72
                                     recDevice * pDevice);
slouken@172
    73
slouken@172
    74
/* returns current value for element, polling element
slouken@172
    75
 * will return 0 on error conditions which should be accounted for by application
slouken@172
    76
 */
slouken@172
    77
slouken@1895
    78
static SInt32
slouken@1895
    79
HIDGetElementValue(recDevice * pDevice, recElement * pElement)
slouken@172
    80
{
slouken@1895
    81
    IOReturn result = kIOReturnSuccess;
slouken@1895
    82
    IOHIDEventStruct hidEvent;
slouken@1895
    83
    hidEvent.value = 0;
slouken@172
    84
slouken@1895
    85
    if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface) {
slouken@1895
    86
        result =
slouken@1895
    87
            (*(pDevice->interface))->getElementValue(pDevice->interface,
slouken@1895
    88
                                                     pElement->cookie,
slouken@1895
    89
                                                     &hidEvent);
slouken@1895
    90
        if (kIOReturnSuccess == result) {
slouken@1895
    91
            /* record min and max for auto calibration */
slouken@1895
    92
            if (hidEvent.value < pElement->minReport)
slouken@1895
    93
                pElement->minReport = hidEvent.value;
slouken@1895
    94
            if (hidEvent.value > pElement->maxReport)
slouken@1895
    95
                pElement->maxReport = hidEvent.value;
slouken@1895
    96
        }
slouken@1895
    97
    }
slouken@1895
    98
slouken@1895
    99
    /* auto user scale */
slouken@1895
   100
    return hidEvent.value;
slouken@172
   101
}
slouken@172
   102
slouken@1895
   103
static SInt32
slouken@1895
   104
HIDScaledCalibratedValue(recDevice * pDevice, recElement * pElement,
slouken@1895
   105
                         long min, long max)
slouken@172
   106
{
slouken@1895
   107
    float deviceScale = max - min;
slouken@1895
   108
    float readScale = pElement->maxReport - pElement->minReport;
slouken@1895
   109
    SInt32 value = HIDGetElementValue(pDevice, pElement);
slouken@1895
   110
    if (readScale == 0)
slouken@1895
   111
        return value;           /* no scaling at all */
slouken@1895
   112
    else
slouken@1895
   113
        return ((value - pElement->minReport) * deviceScale / readScale) +
slouken@1895
   114
            min;
slouken@172
   115
}
slouken@172
   116
slouken@858
   117
slouken@1895
   118
static void
slouken@1895
   119
HIDRemovalCallback(void *target, IOReturn result, void *refcon, void *sender)
slouken@858
   120
{
slouken@1895
   121
    recDevice *device = (recDevice *) refcon;
slouken@1895
   122
    device->removed = 1;
slouken@1895
   123
    device->uncentered = 1;
slouken@858
   124
}
slouken@858
   125
slouken@858
   126
slouken@858
   127
slouken@172
   128
/* Create and open an interface to device, required prior to extracting values or building queues.
slouken@172
   129
 * Note: appliction now owns the device and must close and release it prior to exiting
slouken@172
   130
 */
slouken@172
   131
slouken@1895
   132
static IOReturn
slouken@1895
   133
HIDCreateOpenDeviceInterface(io_object_t hidDevice, recDevice * pDevice)
slouken@172
   134
{
slouken@1895
   135
    IOReturn result = kIOReturnSuccess;
slouken@1895
   136
    HRESULT plugInResult = S_OK;
slouken@1895
   137
    SInt32 score = 0;
slouken@1895
   138
    IOCFPlugInInterface **ppPlugInInterface = NULL;
slouken@858
   139
slouken@1895
   140
    if (NULL == pDevice->interface) {
slouken@1895
   141
        result =
slouken@1895
   142
            IOCreatePlugInInterfaceForService(hidDevice,
slouken@1895
   143
                                              kIOHIDDeviceUserClientTypeID,
slouken@1895
   144
                                              kIOCFPlugInInterfaceID,
slouken@1895
   145
                                              &ppPlugInInterface, &score);
slouken@1895
   146
        if (kIOReturnSuccess == result) {
slouken@1895
   147
            /* Call a method of the intermediate plug-in to create the device interface */
slouken@1895
   148
            plugInResult =
slouken@1895
   149
                (*ppPlugInInterface)->QueryInterface(ppPlugInInterface,
slouken@1895
   150
                                                     CFUUIDGetUUIDBytes
slouken@1895
   151
                                                     (kIOHIDDeviceInterfaceID),
slouken@2735
   152
                                                     (void *)
slouken@2735
   153
                                                     &(pDevice->interface));
slouken@1895
   154
            if (S_OK != plugInResult)
slouken@1895
   155
                HIDReportErrorNum
slouken@1895
   156
                    ("CouldnŐt query HID class device interface from plugInInterface",
slouken@1895
   157
                     plugInResult);
slouken@1895
   158
            (*ppPlugInInterface)->Release(ppPlugInInterface);
slouken@1895
   159
        } else
slouken@1895
   160
            HIDReportErrorNum
slouken@1895
   161
                ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.",
slouken@1895
   162
                 result);
slouken@1895
   163
    }
slouken@1895
   164
    if (NULL != pDevice->interface) {
slouken@1895
   165
        result = (*(pDevice->interface))->open(pDevice->interface, 0);
slouken@1895
   166
        if (kIOReturnSuccess != result)
slouken@1895
   167
            HIDReportErrorNum
slouken@1895
   168
                ("Failed to open pDevice->interface via open.", result);
slouken@1895
   169
        else
slouken@1895
   170
            (*(pDevice->interface))->setRemovalCallback(pDevice->interface,
slouken@1895
   171
                                                        HIDRemovalCallback,
slouken@1895
   172
                                                        pDevice, pDevice);
slouken@1895
   173
slouken@1895
   174
    }
slouken@1895
   175
    return result;
slouken@172
   176
}
slouken@172
   177
slouken@172
   178
/* Closes and releases interface to device, should be done prior to exting application
slouken@172
   179
 * Note: will have no affect if device or interface do not exist
slouken@172
   180
 * application will "own" the device if interface is not closed
slouken@172
   181
 * (device may have to be plug and re-plugged in different location to get it working again without a restart)
slouken@172
   182
 */
slouken@172
   183
slouken@1895
   184
static IOReturn
slouken@1895
   185
HIDCloseReleaseInterface(recDevice * pDevice)
slouken@172
   186
{
slouken@1895
   187
    IOReturn result = kIOReturnSuccess;
slouken@1895
   188
slouken@1895
   189
    if ((NULL != pDevice) && (NULL != pDevice->interface)) {
slouken@1895
   190
        /* close the interface */
slouken@1895
   191
        result = (*(pDevice->interface))->close(pDevice->interface);
slouken@1895
   192
        if (kIOReturnNotOpen == result) {
slouken@1895
   193
            /* do nothing as device was not opened, thus can't be closed */
slouken@1895
   194
        } else if (kIOReturnSuccess != result)
slouken@1895
   195
            HIDReportErrorNum("Failed to close IOHIDDeviceInterface.",
slouken@1895
   196
                              result);
slouken@1895
   197
        /* release the interface */
slouken@1895
   198
        result = (*(pDevice->interface))->Release(pDevice->interface);
slouken@1895
   199
        if (kIOReturnSuccess != result)
slouken@1895
   200
            HIDReportErrorNum("Failed to release IOHIDDeviceInterface.",
slouken@1895
   201
                              result);
slouken@1895
   202
        pDevice->interface = NULL;
slouken@1895
   203
    }
slouken@1895
   204
    return result;
slouken@172
   205
}
slouken@172
   206
slouken@172
   207
/* extracts actual specific element information from each element CF dictionary entry */
slouken@172
   208
slouken@1895
   209
static void
slouken@1895
   210
HIDGetElementInfo(CFTypeRef refElement, recElement * pElement)
slouken@172
   211
{
slouken@1895
   212
    long number;
slouken@1895
   213
    CFTypeRef refType;
slouken@172
   214
slouken@1895
   215
    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementCookieKey));
slouken@1895
   216
    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
slouken@1895
   217
        pElement->cookie = (IOHIDElementCookie) number;
slouken@1895
   218
    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMinKey));
slouken@1895
   219
    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
icculus@2109
   220
        pElement->minReport = pElement->min = number;
slouken@1895
   221
    pElement->maxReport = pElement->min;
slouken@1895
   222
    refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMaxKey));
slouken@1895
   223
    if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
icculus@2109
   224
        pElement->maxReport = pElement->max = number;
slouken@172
   225
/*
slouken@172
   226
	TODO: maybe should handle the following stuff somehow?
slouken@172
   227
slouken@172
   228
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey));
slouken@172
   229
	if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
slouken@172
   230
		pElement->scaledMin = number;
slouken@172
   231
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey));
slouken@172
   232
	if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
slouken@172
   233
		pElement->scaledMax = number;
slouken@172
   234
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey));
slouken@172
   235
	if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
slouken@172
   236
		pElement->size = number;
slouken@172
   237
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey));
slouken@172
   238
	if (refType)
slouken@172
   239
		pElement->relative = CFBooleanGetValue (refType);
slouken@172
   240
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey));
slouken@172
   241
	if (refType)
slouken@172
   242
		pElement->wrapping = CFBooleanGetValue (refType);
slouken@172
   243
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey));
slouken@172
   244
	if (refType)
slouken@172
   245
		pElement->nonLinear = CFBooleanGetValue (refType);
slouken@172
   246
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey));
slouken@172
   247
	if (refType)
slouken@172
   248
		pElement->preferredState = CFBooleanGetValue (refType);
slouken@172
   249
	refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey));
slouken@172
   250
	if (refType)
slouken@172
   251
		pElement->nullState = CFBooleanGetValue (refType);
slouken@172
   252
*/
slouken@1895
   253
}
slouken@172
   254
slouken@172
   255
/* examines CF dictionary vlaue in device element hierarchy to determine if it is element of interest or a collection of more elements
slouken@172
   256
 * if element of interest allocate storage, add to list and retrieve element specific info
slouken@172
   257
 * if collection then pass on to deconstruction collection into additional individual elements
slouken@172
   258
 */
slouken@172
   259
slouken@1895
   260
static void
slouken@1895
   261
HIDAddElement(CFTypeRef refElement, recDevice * pDevice)
slouken@172
   262
{
slouken@1895
   263
    recElement *element = NULL;
slouken@1895
   264
    recElement **headElement = NULL;
slouken@1895
   265
    long elementType, usagePage, usage;
slouken@1895
   266
    CFTypeRef refElementType =
slouken@1895
   267
        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementTypeKey));
slouken@1895
   268
    CFTypeRef refUsagePage =
slouken@1895
   269
        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsagePageKey));
slouken@1895
   270
    CFTypeRef refUsage =
slouken@1895
   271
        CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsageKey));
slouken@172
   272
slouken@172
   273
slouken@1895
   274
    if ((refElementType)
slouken@1895
   275
        &&
slouken@1895
   276
        (CFNumberGetValue(refElementType, kCFNumberLongType, &elementType))) {
slouken@1895
   277
        /* look at types of interest */
slouken@1895
   278
        if ((elementType == kIOHIDElementTypeInput_Misc)
slouken@1895
   279
            || (elementType == kIOHIDElementTypeInput_Button)
slouken@1895
   280
            || (elementType == kIOHIDElementTypeInput_Axis)) {
slouken@1895
   281
            if (refUsagePage
slouken@1895
   282
                && CFNumberGetValue(refUsagePage, kCFNumberLongType,
slouken@1895
   283
                                    &usagePage) && refUsage
slouken@1895
   284
                && CFNumberGetValue(refUsage, kCFNumberLongType, &usage)) {
slouken@1895
   285
                switch (usagePage) {    /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
slouken@1895
   286
                case kHIDPage_GenericDesktop:
slouken@1895
   287
                    {
slouken@1895
   288
                        switch (usage) {        /* look at usage to determine function */
slouken@1895
   289
                        case kHIDUsage_GD_X:
slouken@1895
   290
                        case kHIDUsage_GD_Y:
slouken@1895
   291
                        case kHIDUsage_GD_Z:
slouken@1895
   292
                        case kHIDUsage_GD_Rx:
slouken@1895
   293
                        case kHIDUsage_GD_Ry:
slouken@1895
   294
                        case kHIDUsage_GD_Rz:
slouken@1895
   295
                        case kHIDUsage_GD_Slider:
slouken@1895
   296
                        case kHIDUsage_GD_Dial:
slouken@1895
   297
                        case kHIDUsage_GD_Wheel:
slouken@1895
   298
                            element = (recElement *)
slouken@1895
   299
                                NewPtrClear(sizeof(recElement));
slouken@1895
   300
                            if (element) {
slouken@1895
   301
                                pDevice->axes++;
slouken@1895
   302
                                headElement = &(pDevice->firstAxis);
slouken@1895
   303
                            }
slouken@1895
   304
                            break;
slouken@1895
   305
                        case kHIDUsage_GD_Hatswitch:
slouken@1895
   306
                            element = (recElement *)
slouken@1895
   307
                                NewPtrClear(sizeof(recElement));
slouken@1895
   308
                            if (element) {
slouken@1895
   309
                                pDevice->hats++;
slouken@1895
   310
                                headElement = &(pDevice->firstHat);
slouken@1895
   311
                            }
slouken@1895
   312
                            break;
slouken@1895
   313
                        }
slouken@1895
   314
                    }
slouken@1895
   315
                    break;
slouken@1895
   316
                case kHIDPage_Button:
slouken@1895
   317
                    element = (recElement *)
slouken@1895
   318
                        NewPtrClear(sizeof(recElement));
slouken@1895
   319
                    if (element) {
slouken@1895
   320
                        pDevice->buttons++;
slouken@1895
   321
                        headElement = &(pDevice->firstButton);
slouken@1895
   322
                    }
slouken@1895
   323
                    break;
slouken@1895
   324
                default:
slouken@1895
   325
                    break;
slouken@1895
   326
                }
slouken@1895
   327
            }
slouken@1895
   328
        } else if (kIOHIDElementTypeCollection == elementType)
slouken@1895
   329
            HIDGetCollectionElements((CFMutableDictionaryRef) refElement,
slouken@1895
   330
                                     pDevice);
slouken@1895
   331
    }
slouken@172
   332
slouken@1895
   333
    if (element && headElement) {       /* add to list */
slouken@2776
   334
        recElement *elementPrevious = NULL;
slouken@2776
   335
        recElement *elementCurrent = *headElement;
slouken@2776
   336
        while (elementCurrent && usage >= elementCurrent->usage) {
slouken@2776
   337
            elementPrevious = elementCurrent;
slouken@2776
   338
            elementCurrent = elementCurrent->pNext;
slouken@2776
   339
        }
slouken@2776
   340
        if (elementPrevious) {
slouken@2776
   341
            elementPrevious->pNext = element;
slouken@2776
   342
        } else {
slouken@2776
   343
            *headElement = element;
slouken@2776
   344
        }
slouken@2776
   345
        element->usagePage = usagePage;
slouken@2776
   346
        element->usage = usage;
slouken@2776
   347
        element->pNext = elementCurrent;
slouken@2776
   348
        HIDGetElementInfo(refElement, element);
slouken@1895
   349
        pDevice->elements++;
slouken@1895
   350
    }
slouken@172
   351
}
slouken@172
   352
slouken@172
   353
/* collects information from each array member in device element list (each array memeber = element) */
slouken@172
   354
slouken@1895
   355
static void
slouken@1895
   356
HIDGetElementsCFArrayHandler(const void *value, void *parameter)
slouken@172
   357
{
slouken@1895
   358
    if (CFGetTypeID(value) == CFDictionaryGetTypeID())
slouken@1895
   359
        HIDAddElement((CFTypeRef) value, (recDevice *) parameter);
slouken@172
   360
}
slouken@172
   361
slouken@172
   362
/* handles retrieval of element information from arrays of elements in device IO registry information */
slouken@172
   363
slouken@1895
   364
static void
slouken@1895
   365
HIDGetElements(CFTypeRef refElementCurrent, recDevice * pDevice)
slouken@172
   366
{
slouken@1895
   367
    CFTypeID type = CFGetTypeID(refElementCurrent);
slouken@1895
   368
    if (type == CFArrayGetTypeID()) {   /* if element is an array */
slouken@1895
   369
        CFRange range = { 0, CFArrayGetCount(refElementCurrent) };
slouken@1895
   370
        /* CountElementsCFArrayHandler called for each array member */
slouken@1895
   371
        CFArrayApplyFunction(refElementCurrent, range,
slouken@1895
   372
                             HIDGetElementsCFArrayHandler, pDevice);
slouken@1895
   373
    }
slouken@1895
   374
}
slouken@172
   375
slouken@172
   376
/* handles extracting element information from element collection CF types
slouken@172
   377
 * used from top level element decoding and hierarchy deconstruction to flatten device element list
slouken@172
   378
 */
slouken@172
   379
slouken@1895
   380
static void
slouken@1895
   381
HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
slouken@1895
   382
                         recDevice * pDevice)
slouken@172
   383
{
slouken@1895
   384
    CFTypeRef refElementTop =
slouken@1895
   385
        CFDictionaryGetValue(deviceProperties, CFSTR(kIOHIDElementKey));
slouken@1895
   386
    if (refElementTop)
slouken@1895
   387
        HIDGetElements(refElementTop, pDevice);
slouken@172
   388
}
slouken@172
   389
slouken@172
   390
/* use top level element usage page and usage to discern device usage page and usage setting appropriate vlaues in device record */
slouken@172
   391
slouken@1895
   392
static void
slouken@1895
   393
HIDTopLevelElementHandler(const void *value, void *parameter)
slouken@172
   394
{
slouken@1895
   395
    CFTypeRef refCF = 0;
slouken@1895
   396
    if (CFGetTypeID(value) != CFDictionaryGetTypeID())
slouken@1895
   397
        return;
slouken@1895
   398
    refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsagePageKey));
slouken@1895
   399
    if (!CFNumberGetValue
slouken@1895
   400
        (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage))
slouken@1895
   401
        SDL_SetError("CFNumberGetValue error retrieving pDevice->usagePage.");
slouken@1895
   402
    refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsageKey));
slouken@1895
   403
    if (!CFNumberGetValue
slouken@1895
   404
        (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage))
slouken@1895
   405
        SDL_SetError("CFNumberGetValue error retrieving pDevice->usage.");
slouken@172
   406
}
slouken@172
   407
slouken@172
   408
/* extracts device info from CF dictionary records in IO registry */
slouken@172
   409
slouken@1895
   410
static void
slouken@1895
   411
HIDGetDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties,
slouken@1895
   412
                 recDevice * pDevice)
slouken@172
   413
{
slouken@1895
   414
    CFMutableDictionaryRef usbProperties = 0;
slouken@1895
   415
    io_registry_entry_t parent1, parent2;
slouken@172
   416
slouken@1895
   417
    /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
slouken@1895
   418
     * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties
slouken@1895
   419
     */
slouken@1895
   420
    if ((KERN_SUCCESS ==
slouken@1895
   421
         IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1))
slouken@1895
   422
        && (KERN_SUCCESS ==
slouken@1895
   423
            IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2))
slouken@1895
   424
        && (KERN_SUCCESS ==
slouken@1895
   425
            IORegistryEntryCreateCFProperties(parent2, &usbProperties,
slouken@1895
   426
                                              kCFAllocatorDefault,
slouken@1895
   427
                                              kNilOptions))) {
slouken@1895
   428
        if (usbProperties) {
slouken@1895
   429
            CFTypeRef refCF = 0;
slouken@1895
   430
            /* get device info
slouken@1895
   431
             * try hid dictionary first, if fail then go to usb dictionary
slouken@1895
   432
             */
slouken@172
   433
slouken@172
   434
slouken@1895
   435
            /* get product name */
slouken@1895
   436
            refCF =
slouken@1895
   437
                CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
slouken@1895
   438
            if (!refCF)
slouken@1895
   439
                refCF =
slouken@1895
   440
                    CFDictionaryGetValue(usbProperties,
slouken@1895
   441
                                         CFSTR("USB Product Name"));
slouken@1895
   442
            if (refCF) {
slouken@1895
   443
                if (!CFStringGetCString
slouken@1895
   444
                    (refCF, pDevice->product, 256,
slouken@1895
   445
                     CFStringGetSystemEncoding()))
slouken@1895
   446
                    SDL_SetError
slouken@1895
   447
                        ("CFStringGetCString error retrieving pDevice->product.");
slouken@1895
   448
            }
slouken@1895
   449
slouken@1895
   450
            /* get usage page and usage */
slouken@1895
   451
            refCF =
slouken@1895
   452
                CFDictionaryGetValue(hidProperties,
slouken@1895
   453
                                     CFSTR(kIOHIDPrimaryUsagePageKey));
slouken@1895
   454
            if (refCF) {
slouken@1895
   455
                if (!CFNumberGetValue
slouken@1895
   456
                    (refCF, kCFNumberLongType, &pDevice->usagePage))
slouken@1895
   457
                    SDL_SetError
slouken@1895
   458
                        ("CFNumberGetValue error retrieving pDevice->usagePage.");
slouken@1895
   459
                refCF =
slouken@1895
   460
                    CFDictionaryGetValue(hidProperties,
slouken@1895
   461
                                         CFSTR(kIOHIDPrimaryUsageKey));
slouken@1895
   462
                if (refCF)
slouken@1895
   463
                    if (!CFNumberGetValue
slouken@1895
   464
                        (refCF, kCFNumberLongType, &pDevice->usage))
slouken@1895
   465
                        SDL_SetError
slouken@1895
   466
                            ("CFNumberGetValue error retrieving pDevice->usage.");
slouken@1895
   467
            }
slouken@1895
   468
slouken@1895
   469
            if (NULL == refCF) {        /* get top level element HID usage page or usage */
slouken@1895
   470
                /* use top level element instead */
slouken@1895
   471
                CFTypeRef refCFTopElement = 0;
slouken@1895
   472
                refCFTopElement =
slouken@1895
   473
                    CFDictionaryGetValue(hidProperties,
slouken@1895
   474
                                         CFSTR(kIOHIDElementKey));
slouken@1895
   475
                {
slouken@1895
   476
                    /* refCFTopElement points to an array of element dictionaries */
slouken@1895
   477
                    CFRange range = { 0, CFArrayGetCount(refCFTopElement) };
slouken@1895
   478
                    CFArrayApplyFunction(refCFTopElement, range,
slouken@1895
   479
                                         HIDTopLevelElementHandler, pDevice);
slouken@1895
   480
                }
slouken@1895
   481
            }
slouken@1895
   482
slouken@1895
   483
            CFRelease(usbProperties);
slouken@1895
   484
        } else
slouken@1895
   485
            SDL_SetError
slouken@1895
   486
                ("IORegistryEntryCreateCFProperties failed to create usbProperties.");
slouken@1895
   487
slouken@1895
   488
        if (kIOReturnSuccess != IOObjectRelease(parent2))
slouken@1895
   489
            SDL_SetError("IOObjectRelease error with parent2.");
slouken@1895
   490
        if (kIOReturnSuccess != IOObjectRelease(parent1))
slouken@1895
   491
            SDL_SetError("IOObjectRelease error with parent1.");
slouken@1895
   492
    }
slouken@172
   493
}
slouken@172
   494
slouken@172
   495
slouken@1895
   496
static recDevice *
slouken@1895
   497
HIDBuildDevice(io_object_t hidDevice)
slouken@172
   498
{
slouken@1895
   499
    recDevice *pDevice = (recDevice *) NewPtrClear(sizeof(recDevice));
slouken@1895
   500
    if (pDevice) {
slouken@1895
   501
        /* get dictionary for HID properties */
slouken@1895
   502
        CFMutableDictionaryRef hidProperties = 0;
slouken@1895
   503
        kern_return_t result =
slouken@1895
   504
            IORegistryEntryCreateCFProperties(hidDevice, &hidProperties,
slouken@1895
   505
                                              kCFAllocatorDefault,
slouken@1895
   506
                                              kNilOptions);
slouken@1895
   507
        if ((result == KERN_SUCCESS) && hidProperties) {
slouken@1895
   508
            /* create device interface */
slouken@1895
   509
            result = HIDCreateOpenDeviceInterface(hidDevice, pDevice);
slouken@1895
   510
            if (kIOReturnSuccess == result) {
slouken@1895
   511
                HIDGetDeviceInfo(hidDevice, hidProperties, pDevice);    /* hidDevice used to find parents in registry tree */
slouken@1895
   512
                HIDGetCollectionElements(hidProperties, pDevice);
slouken@1895
   513
            } else {
slouken@1895
   514
                DisposePtr((Ptr) pDevice);
slouken@1895
   515
                pDevice = NULL;
slouken@1895
   516
            }
slouken@1895
   517
            CFRelease(hidProperties);
slouken@1895
   518
        } else {
slouken@1895
   519
            DisposePtr((Ptr) pDevice);
slouken@1895
   520
            pDevice = NULL;
slouken@1895
   521
        }
slouken@1895
   522
    }
slouken@1895
   523
    return pDevice;
slouken@172
   524
}
slouken@172
   525
slouken@172
   526
/* disposes of the element list associated with a device and the memory associated with the list
slouken@172
   527
 */
slouken@172
   528
slouken@1895
   529
static void
slouken@1895
   530
HIDDisposeElementList(recElement ** elementList)
slouken@172
   531
{
slouken@1895
   532
    recElement *pElement = *elementList;
slouken@1895
   533
    while (pElement) {
slouken@1895
   534
        recElement *pElementNext = pElement->pNext;
slouken@1895
   535
        DisposePtr((Ptr) pElement);
slouken@1895
   536
        pElement = pElementNext;
slouken@1895
   537
    }
slouken@1895
   538
    *elementList = NULL;
slouken@172
   539
}
slouken@172
   540
slouken@172
   541
/* disposes of a single device, closing and releaseing interface, freeing memory fro device and elements, setting device pointer to NULL
slouken@172
   542
 * all your device no longer belong to us... (i.e., you do not 'own' the device anymore)
slouken@172
   543
 */
slouken@172
   544
slouken@1895
   545
static recDevice *
slouken@1895
   546
HIDDisposeDevice(recDevice ** ppDevice)
slouken@172
   547
{
slouken@1895
   548
    kern_return_t result = KERN_SUCCESS;
slouken@1895
   549
    recDevice *pDeviceNext = NULL;
slouken@1895
   550
    if (*ppDevice) {
slouken@1895
   551
        /* save next device prior to disposing of this device */
slouken@1895
   552
        pDeviceNext = (*ppDevice)->pNext;
slouken@1895
   553
slouken@2713
   554
        /* free posible io_service_t */
slouken@2713
   555
        if ((*ppDevice)->ffservice) {
slouken@2713
   556
            IOObjectRelease((*ppDevice)->ffservice);
slouken@2713
   557
            (*ppDevice)->ffservice = 0;
slouken@2713
   558
        }
slouken@2713
   559
slouken@1895
   560
        /* free element lists */
slouken@1895
   561
        HIDDisposeElementList(&(*ppDevice)->firstAxis);
slouken@1895
   562
        HIDDisposeElementList(&(*ppDevice)->firstButton);
slouken@1895
   563
        HIDDisposeElementList(&(*ppDevice)->firstHat);
slouken@1895
   564
slouken@1895
   565
        result = HIDCloseReleaseInterface(*ppDevice);   /* function sanity checks interface value (now application does not own device) */
slouken@1895
   566
        if (kIOReturnSuccess != result)
slouken@1895
   567
            HIDReportErrorNum
slouken@1895
   568
                ("HIDCloseReleaseInterface failed when trying to dipose device.",
slouken@1895
   569
                 result);
slouken@1895
   570
        DisposePtr((Ptr) * ppDevice);
slouken@1895
   571
        *ppDevice = NULL;
slouken@1895
   572
    }
slouken@1895
   573
    return pDeviceNext;
slouken@172
   574
}
slouken@172
   575
slouken@172
   576
slouken@172
   577
/* Function to scan the system for joysticks.
slouken@172
   578
 * Joystick 0 should be the system default joystick.
slouken@172
   579
 * This function should return the number of available joysticks, or -1
slouken@172
   580
 * on an unrecoverable fatal error.
slouken@172
   581
 */
slouken@1895
   582
int
slouken@1895
   583
SDL_SYS_JoystickInit(void)
slouken@172
   584
{
slouken@1895
   585
    IOReturn result = kIOReturnSuccess;
slouken@1895
   586
    mach_port_t masterPort = 0;
slouken@1895
   587
    io_iterator_t hidObjectIterator = 0;
slouken@1895
   588
    CFMutableDictionaryRef hidMatchDictionary = NULL;
slouken@1895
   589
    recDevice *device, *lastDevice;
slouken@1895
   590
    io_object_t ioHIDDeviceObject = 0;
slouken@172
   591
slouken@1895
   592
    SDL_numjoysticks = 0;
slouken@172
   593
slouken@1895
   594
    if (gpDeviceList) {
slouken@1895
   595
        SDL_SetError("Joystick: Device list already inited.");
slouken@1895
   596
        return -1;
slouken@1895
   597
    }
slouken@172
   598
slouken@1895
   599
    result = IOMasterPort(bootstrap_port, &masterPort);
slouken@1895
   600
    if (kIOReturnSuccess != result) {
slouken@1895
   601
        SDL_SetError("Joystick: IOMasterPort error with bootstrap_port.");
slouken@1895
   602
        return -1;
slouken@1895
   603
    }
slouken@172
   604
slouken@1895
   605
    /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
slouken@1895
   606
    hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
slouken@1895
   607
    if (hidMatchDictionary) {
slouken@1895
   608
        /* Add key for device type (joystick, in this case) to refine the matching dictionary. */
slouken@172
   609
slouken@1895
   610
        /* NOTE: we now perform this filtering later
slouken@1895
   611
           UInt32 usagePage = kHIDPage_GenericDesktop;
slouken@1895
   612
           UInt32 usage = kHIDUsage_GD_Joystick;
slouken@1895
   613
           CFNumberRef refUsage = NULL, refUsagePage = NULL;
slouken@1895
   614
slouken@1895
   615
           refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage);
slouken@1895
   616
           CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage);
slouken@1895
   617
           refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage);
slouken@1895
   618
           CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage);
slouken@1895
   619
         */
slouken@1895
   620
    } else {
slouken@1895
   621
        SDL_SetError
slouken@1895
   622
            ("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching.");
slouken@1895
   623
        return -1;
slouken@1895
   624
    }
slouken@1895
   625
slouken@1895
   626
    /*/ Now search I/O Registry for matching devices. */
slouken@1895
   627
    result =
slouken@1895
   628
        IOServiceGetMatchingServices(masterPort, hidMatchDictionary,
slouken@1895
   629
                                     &hidObjectIterator);
slouken@1895
   630
    /* Check for errors */
slouken@1895
   631
    if (kIOReturnSuccess != result) {
slouken@1895
   632
        SDL_SetError("Joystick: Couldn't create a HID object iterator.");
slouken@1895
   633
        return -1;
slouken@1895
   634
    }
slouken@1895
   635
    if (!hidObjectIterator) {   /* there are no joysticks */
slouken@1895
   636
        gpDeviceList = NULL;
slouken@1895
   637
        SDL_numjoysticks = 0;
slouken@1895
   638
        return 0;
slouken@1895
   639
    }
slouken@1895
   640
    /* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */
slouken@1895
   641
slouken@1895
   642
    /* build flat linked list of devices from device iterator */
slouken@1895
   643
slouken@1895
   644
    gpDeviceList = lastDevice = NULL;
slouken@1895
   645
slouken@1895
   646
    while ((ioHIDDeviceObject = IOIteratorNext(hidObjectIterator))) {
slouken@1895
   647
        /* build a device record */
slouken@1895
   648
        device = HIDBuildDevice(ioHIDDeviceObject);
slouken@1895
   649
        if (!device)
slouken@1895
   650
            continue;
slouken@1895
   651
slouken@1895
   652
        /* Filter device list to non-keyboard/mouse stuff */
slouken@2120
   653
        if ((device->usagePage != kHIDPage_GenericDesktop) ||
slouken@2120
   654
            ((device->usage != kHIDUsage_GD_Joystick &&
slouken@2120
   655
              device->usage != kHIDUsage_GD_GamePad &&
slouken@2120
   656
              device->usage != kHIDUsage_GD_MultiAxisController))) {
icculus@620
   657
slouken@1895
   658
            /* release memory for the device */
slouken@1895
   659
            HIDDisposeDevice(&device);
slouken@1895
   660
            DisposePtr((Ptr) device);
slouken@1895
   661
            continue;
slouken@1895
   662
        }
slouken@172
   663
slouken@2713
   664
        /* We have to do some storage of the io_service_t for
slouken@2713
   665
         * SDL_HapticOpenFromJoystick */
slouken@2713
   666
        if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {
slouken@2713
   667
            device->ffservice = ioHIDDeviceObject;
slouken@2713
   668
        } else {
slouken@2713
   669
            device->ffservice = 0;
slouken@2713
   670
        }
slouken@2713
   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: */