2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2010 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 #ifdef SDL_JOYSTICK_IOKIT
26 /* SDL joystick driver for Darwin / Mac OS X, based on the IOKit HID API */
27 /* Written 2001 by Max Horn */
32 #include <mach/mach.h>
33 #include <mach/mach_error.h>
34 #include <IOKit/IOKitLib.h>
35 #include <IOKit/IOCFPlugIn.h>
37 #include <IOKit/hidsystem/IOHIDUsageTables.h>
39 /* The header was moved here in Mac OS X 10.1 */
40 #include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
42 #include <IOKit/hid/IOHIDLib.h>
43 #include <IOKit/hid/IOHIDKeys.h>
44 #include <CoreFoundation/CoreFoundation.h>
45 #include <Carbon/Carbon.h> /* for NewPtrClear, DisposePtr */
47 /* For force feedback testing. */
48 #include <ForceFeedback/ForceFeedback.h>
49 #include <ForceFeedback/ForceFeedbackConstants.h>
51 #include "SDL_joystick.h"
52 #include "../SDL_sysjoystick.h"
53 #include "../SDL_joystick_c.h"
54 #include "SDL_sysjoystick_c.h"
57 /* Linked list of all available devices */
58 static recDevice *gpDeviceList = NULL;
62 HIDReportErrorNum(char *strError, long numError)
64 SDL_SetError(strError);
67 static void HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
70 /* returns current value for element, polling element
71 * will return 0 on error conditions which should be accounted for by application
75 HIDGetElementValue(recDevice * pDevice, recElement * pElement)
77 IOReturn result = kIOReturnSuccess;
78 IOHIDEventStruct hidEvent;
81 if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface) {
83 (*(pDevice->interface))->getElementValue(pDevice->interface,
86 if (kIOReturnSuccess == result) {
87 /* record min and max for auto calibration */
88 if (hidEvent.value < pElement->minReport)
89 pElement->minReport = hidEvent.value;
90 if (hidEvent.value > pElement->maxReport)
91 pElement->maxReport = hidEvent.value;
96 return hidEvent.value;
100 HIDScaledCalibratedValue(recDevice * pDevice, recElement * pElement,
103 float deviceScale = max - min;
104 float readScale = pElement->maxReport - pElement->minReport;
105 SInt32 value = HIDGetElementValue(pDevice, pElement);
107 return value; /* no scaling at all */
109 return ((value - pElement->minReport) * deviceScale / readScale) +
115 HIDRemovalCallback(void *target, IOReturn result, void *refcon, void *sender)
117 recDevice *device = (recDevice *) refcon;
119 device->uncentered = 1;
124 /* Create and open an interface to device, required prior to extracting values or building queues.
125 * Note: appliction now owns the device and must close and release it prior to exiting
129 HIDCreateOpenDeviceInterface(io_object_t hidDevice, recDevice * pDevice)
131 IOReturn result = kIOReturnSuccess;
132 HRESULT plugInResult = S_OK;
134 IOCFPlugInInterface **ppPlugInInterface = NULL;
136 if (NULL == pDevice->interface) {
138 IOCreatePlugInInterfaceForService(hidDevice,
139 kIOHIDDeviceUserClientTypeID,
140 kIOCFPlugInInterfaceID,
141 &ppPlugInInterface, &score);
142 if (kIOReturnSuccess == result) {
143 /* Call a method of the intermediate plug-in to create the device interface */
145 (*ppPlugInInterface)->QueryInterface(ppPlugInInterface,
147 (kIOHIDDeviceInterfaceID),
149 &(pDevice->interface));
150 if (S_OK != plugInResult)
152 ("CouldnÕt query HID class device interface from plugInInterface",
154 (*ppPlugInInterface)->Release(ppPlugInInterface);
157 ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.",
160 if (NULL != pDevice->interface) {
161 result = (*(pDevice->interface))->open(pDevice->interface, 0);
162 if (kIOReturnSuccess != result)
164 ("Failed to open pDevice->interface via open.", result);
166 (*(pDevice->interface))->setRemovalCallback(pDevice->interface,
174 /* Closes and releases interface to device, should be done prior to exting application
175 * Note: will have no affect if device or interface do not exist
176 * application will "own" the device if interface is not closed
177 * (device may have to be plug and re-plugged in different location to get it working again without a restart)
181 HIDCloseReleaseInterface(recDevice * pDevice)
183 IOReturn result = kIOReturnSuccess;
185 if ((NULL != pDevice) && (NULL != pDevice->interface)) {
186 /* close the interface */
187 result = (*(pDevice->interface))->close(pDevice->interface);
188 if (kIOReturnNotOpen == result) {
189 /* do nothing as device was not opened, thus can't be closed */
190 } else if (kIOReturnSuccess != result)
191 HIDReportErrorNum("Failed to close IOHIDDeviceInterface.",
193 /* release the interface */
194 result = (*(pDevice->interface))->Release(pDevice->interface);
195 if (kIOReturnSuccess != result)
196 HIDReportErrorNum("Failed to release IOHIDDeviceInterface.",
198 pDevice->interface = NULL;
203 /* extracts actual specific element information from each element CF dictionary entry */
206 HIDGetElementInfo(CFTypeRef refElement, recElement * pElement)
211 refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementCookieKey));
212 if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
213 pElement->cookie = (IOHIDElementCookie) number;
214 refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMinKey));
215 if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
216 pElement->minReport = pElement->min = number;
217 pElement->maxReport = pElement->min;
218 refType = CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementMaxKey));
219 if (refType && CFNumberGetValue(refType, kCFNumberLongType, &number))
220 pElement->maxReport = pElement->max = number;
222 TODO: maybe should handle the following stuff somehow?
224 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey));
225 if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
226 pElement->scaledMin = number;
227 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey));
228 if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
229 pElement->scaledMax = number;
230 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey));
231 if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number))
232 pElement->size = number;
233 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey));
235 pElement->relative = CFBooleanGetValue (refType);
236 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey));
238 pElement->wrapping = CFBooleanGetValue (refType);
239 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey));
241 pElement->nonLinear = CFBooleanGetValue (refType);
242 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey));
244 pElement->preferredState = CFBooleanGetValue (refType);
245 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey));
247 pElement->nullState = CFBooleanGetValue (refType);
251 /* examines CF dictionary vlaue in device element hierarchy to determine if it is element of interest or a collection of more elements
252 * if element of interest allocate storage, add to list and retrieve element specific info
253 * if collection then pass on to deconstruction collection into additional individual elements
257 HIDAddElement(CFTypeRef refElement, recDevice * pDevice)
259 recElement *element = NULL;
260 recElement **headElement = NULL;
261 long elementType, usagePage, usage;
262 CFTypeRef refElementType =
263 CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementTypeKey));
264 CFTypeRef refUsagePage =
265 CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsagePageKey));
267 CFDictionaryGetValue(refElement, CFSTR(kIOHIDElementUsageKey));
272 (CFNumberGetValue(refElementType, kCFNumberLongType, &elementType))) {
273 /* look at types of interest */
274 if ((elementType == kIOHIDElementTypeInput_Misc)
275 || (elementType == kIOHIDElementTypeInput_Button)
276 || (elementType == kIOHIDElementTypeInput_Axis)) {
278 && CFNumberGetValue(refUsagePage, kCFNumberLongType,
279 &usagePage) && refUsage
280 && CFNumberGetValue(refUsage, kCFNumberLongType, &usage)) {
281 switch (usagePage) { /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
282 case kHIDPage_GenericDesktop:
284 switch (usage) { /* look at usage to determine function */
288 case kHIDUsage_GD_Rx:
289 case kHIDUsage_GD_Ry:
290 case kHIDUsage_GD_Rz:
291 case kHIDUsage_GD_Slider:
292 case kHIDUsage_GD_Dial:
293 case kHIDUsage_GD_Wheel:
294 element = (recElement *)
295 NewPtrClear(sizeof(recElement));
298 headElement = &(pDevice->firstAxis);
301 case kHIDUsage_GD_Hatswitch:
302 element = (recElement *)
303 NewPtrClear(sizeof(recElement));
306 headElement = &(pDevice->firstHat);
312 case kHIDPage_Button:
313 element = (recElement *)
314 NewPtrClear(sizeof(recElement));
317 headElement = &(pDevice->firstButton);
324 } else if (kIOHIDElementTypeCollection == elementType)
325 HIDGetCollectionElements((CFMutableDictionaryRef) refElement,
329 if (element && headElement) { /* add to list */
330 recElement *elementPrevious = NULL;
331 recElement *elementCurrent = *headElement;
332 while (elementCurrent && usage >= elementCurrent->usage) {
333 elementPrevious = elementCurrent;
334 elementCurrent = elementCurrent->pNext;
336 if (elementPrevious) {
337 elementPrevious->pNext = element;
339 *headElement = element;
341 element->usagePage = usagePage;
342 element->usage = usage;
343 element->pNext = elementCurrent;
344 HIDGetElementInfo(refElement, element);
349 /* collects information from each array member in device element list (each array memeber = element) */
352 HIDGetElementsCFArrayHandler(const void *value, void *parameter)
354 if (CFGetTypeID(value) == CFDictionaryGetTypeID())
355 HIDAddElement((CFTypeRef) value, (recDevice *) parameter);
358 /* handles retrieval of element information from arrays of elements in device IO registry information */
361 HIDGetElements(CFTypeRef refElementCurrent, recDevice * pDevice)
363 CFTypeID type = CFGetTypeID(refElementCurrent);
364 if (type == CFArrayGetTypeID()) { /* if element is an array */
365 CFRange range = { 0, CFArrayGetCount(refElementCurrent) };
366 /* CountElementsCFArrayHandler called for each array member */
367 CFArrayApplyFunction(refElementCurrent, range,
368 HIDGetElementsCFArrayHandler, pDevice);
372 /* handles extracting element information from element collection CF types
373 * used from top level element decoding and hierarchy deconstruction to flatten device element list
377 HIDGetCollectionElements(CFMutableDictionaryRef deviceProperties,
380 CFTypeRef refElementTop =
381 CFDictionaryGetValue(deviceProperties, CFSTR(kIOHIDElementKey));
383 HIDGetElements(refElementTop, pDevice);
386 /* use top level element usage page and usage to discern device usage page and usage setting appropriate vlaues in device record */
389 HIDTopLevelElementHandler(const void *value, void *parameter)
392 if (CFGetTypeID(value) != CFDictionaryGetTypeID())
394 refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsagePageKey));
395 if (!CFNumberGetValue
396 (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage))
397 SDL_SetError("CFNumberGetValue error retrieving pDevice->usagePage.");
398 refCF = CFDictionaryGetValue(value, CFSTR(kIOHIDElementUsageKey));
399 if (!CFNumberGetValue
400 (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage))
401 SDL_SetError("CFNumberGetValue error retrieving pDevice->usage.");
404 /* extracts device info from CF dictionary records in IO registry */
407 HIDGetDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties,
410 CFMutableDictionaryRef usbProperties = 0;
411 io_registry_entry_t parent1, parent2;
413 /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
414 * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties
417 IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1))
419 IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2))
421 IORegistryEntryCreateCFProperties(parent2, &usbProperties,
427 * try hid dictionary first, if fail then go to usb dictionary
431 /* get product name */
433 CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey));
436 CFDictionaryGetValue(usbProperties,
437 CFSTR("USB Product Name"));
439 if (!CFStringGetCString
440 (refCF, pDevice->product, 256,
441 CFStringGetSystemEncoding()))
443 ("CFStringGetCString error retrieving pDevice->product.");
446 /* get usage page and usage */
448 CFDictionaryGetValue(hidProperties,
449 CFSTR(kIOHIDPrimaryUsagePageKey));
451 if (!CFNumberGetValue
452 (refCF, kCFNumberLongType, &pDevice->usagePage))
454 ("CFNumberGetValue error retrieving pDevice->usagePage.");
456 CFDictionaryGetValue(hidProperties,
457 CFSTR(kIOHIDPrimaryUsageKey));
459 if (!CFNumberGetValue
460 (refCF, kCFNumberLongType, &pDevice->usage))
462 ("CFNumberGetValue error retrieving pDevice->usage.");
465 if (NULL == refCF) { /* get top level element HID usage page or usage */
466 /* use top level element instead */
467 CFTypeRef refCFTopElement = 0;
469 CFDictionaryGetValue(hidProperties,
470 CFSTR(kIOHIDElementKey));
472 /* refCFTopElement points to an array of element dictionaries */
473 CFRange range = { 0, CFArrayGetCount(refCFTopElement) };
474 CFArrayApplyFunction(refCFTopElement, range,
475 HIDTopLevelElementHandler, pDevice);
479 CFRelease(usbProperties);
482 ("IORegistryEntryCreateCFProperties failed to create usbProperties.");
484 if (kIOReturnSuccess != IOObjectRelease(parent2))
485 SDL_SetError("IOObjectRelease error with parent2.");
486 if (kIOReturnSuccess != IOObjectRelease(parent1))
487 SDL_SetError("IOObjectRelease error with parent1.");
493 HIDBuildDevice(io_object_t hidDevice)
495 recDevice *pDevice = (recDevice *) NewPtrClear(sizeof(recDevice));
497 /* get dictionary for HID properties */
498 CFMutableDictionaryRef hidProperties = 0;
499 kern_return_t result =
500 IORegistryEntryCreateCFProperties(hidDevice, &hidProperties,
503 if ((result == KERN_SUCCESS) && hidProperties) {
504 /* create device interface */
505 result = HIDCreateOpenDeviceInterface(hidDevice, pDevice);
506 if (kIOReturnSuccess == result) {
507 HIDGetDeviceInfo(hidDevice, hidProperties, pDevice); /* hidDevice used to find parents in registry tree */
508 HIDGetCollectionElements(hidProperties, pDevice);
510 DisposePtr((Ptr) pDevice);
513 CFRelease(hidProperties);
515 DisposePtr((Ptr) pDevice);
522 /* disposes of the element list associated with a device and the memory associated with the list
526 HIDDisposeElementList(recElement ** elementList)
528 recElement *pElement = *elementList;
530 recElement *pElementNext = pElement->pNext;
531 DisposePtr((Ptr) pElement);
532 pElement = pElementNext;
537 /* disposes of a single device, closing and releaseing interface, freeing memory fro device and elements, setting device pointer to NULL
538 * all your device no longer belong to us... (i.e., you do not 'own' the device anymore)
542 HIDDisposeDevice(recDevice ** ppDevice)
544 kern_return_t result = KERN_SUCCESS;
545 recDevice *pDeviceNext = NULL;
547 /* save next device prior to disposing of this device */
548 pDeviceNext = (*ppDevice)->pNext;
550 /* free posible io_service_t */
551 if ((*ppDevice)->ffservice) {
552 IOObjectRelease((*ppDevice)->ffservice);
553 (*ppDevice)->ffservice = 0;
556 /* free element lists */
557 HIDDisposeElementList(&(*ppDevice)->firstAxis);
558 HIDDisposeElementList(&(*ppDevice)->firstButton);
559 HIDDisposeElementList(&(*ppDevice)->firstHat);
561 result = HIDCloseReleaseInterface(*ppDevice); /* function sanity checks interface value (now application does not own device) */
562 if (kIOReturnSuccess != result)
564 ("HIDCloseReleaseInterface failed when trying to dipose device.",
566 DisposePtr((Ptr) * ppDevice);
573 /* Function to scan the system for joysticks.
574 * Joystick 0 should be the system default joystick.
575 * This function should return the number of available joysticks, or -1
576 * on an unrecoverable fatal error.
579 SDL_SYS_JoystickInit(void)
581 IOReturn result = kIOReturnSuccess;
582 mach_port_t masterPort = 0;
583 io_iterator_t hidObjectIterator = 0;
584 CFMutableDictionaryRef hidMatchDictionary = NULL;
585 recDevice *device, *lastDevice;
586 io_object_t ioHIDDeviceObject = 0;
588 SDL_numjoysticks = 0;
591 SDL_SetError("Joystick: Device list already inited.");
595 result = IOMasterPort(bootstrap_port, &masterPort);
596 if (kIOReturnSuccess != result) {
597 SDL_SetError("Joystick: IOMasterPort error with bootstrap_port.");
601 /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */
602 hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
603 if (hidMatchDictionary) {
604 /* Add key for device type (joystick, in this case) to refine the matching dictionary. */
606 /* NOTE: we now perform this filtering later
607 UInt32 usagePage = kHIDPage_GenericDesktop;
608 UInt32 usage = kHIDUsage_GD_Joystick;
609 CFNumberRef refUsage = NULL, refUsagePage = NULL;
611 refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage);
612 CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage);
613 refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage);
614 CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage);
618 ("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching.");
622 /*/ Now search I/O Registry for matching devices. */
624 IOServiceGetMatchingServices(masterPort, hidMatchDictionary,
626 /* Check for errors */
627 if (kIOReturnSuccess != result) {
628 SDL_SetError("Joystick: Couldn't create a HID object iterator.");
631 if (!hidObjectIterator) { /* there are no joysticks */
633 SDL_numjoysticks = 0;
636 /* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */
638 /* build flat linked list of devices from device iterator */
640 gpDeviceList = lastDevice = NULL;
642 while ((ioHIDDeviceObject = IOIteratorNext(hidObjectIterator))) {
643 /* build a device record */
644 device = HIDBuildDevice(ioHIDDeviceObject);
648 /* Filter device list to non-keyboard/mouse stuff */
649 if ((device->usagePage != kHIDPage_GenericDesktop) ||
650 ((device->usage != kHIDUsage_GD_Joystick &&
651 device->usage != kHIDUsage_GD_GamePad &&
652 device->usage != kHIDUsage_GD_MultiAxisController))) {
654 /* release memory for the device */
655 HIDDisposeDevice(&device);
656 DisposePtr((Ptr) device);
660 /* We have to do some storage of the io_service_t for
661 * SDL_HapticOpenFromJoystick */
662 if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {
663 device->ffservice = ioHIDDeviceObject;
665 device->ffservice = 0;
668 /* Add device to the end of the list */
670 lastDevice->pNext = device;
672 gpDeviceList = device;
675 result = IOObjectRelease(hidObjectIterator); /* release the iterator */
677 /* Count the total number of devices we found */
678 device = gpDeviceList;
681 device = device->pNext;
684 return SDL_numjoysticks;
687 /* Function to get the device-dependent name of a joystick */
689 SDL_SYS_JoystickName(int index)
691 recDevice *device = gpDeviceList;
693 for (; index > 0; index--)
694 device = device->pNext;
696 return device->product;
699 /* Function to open a joystick for use.
700 * The joystick to open is specified by the index field of the joystick.
701 * This should fill the nbuttons and naxes fields of the joystick structure.
702 * It returns 0, or -1 if there is an error.
705 SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
707 recDevice *device = gpDeviceList;
710 for (index = joystick->index; index > 0; index--)
711 device = device->pNext;
713 joystick->hwdata = device;
714 joystick->name = device->product;
716 joystick->naxes = device->axes;
717 joystick->nhats = device->hats;
718 joystick->nballs = 0;
719 joystick->nbuttons = device->buttons;
724 /* Function to update the state of a joystick - called as a device poll.
725 * This function shouldn't update the joystick structure directly,
726 * but instead should call SDL_PrivateJoystick*() to deliver events
727 * and update joystick device state.
730 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
732 recDevice *device = joystick->hwdata;
737 if (device->removed) { /* device was unplugged; ignore it. */
738 if (device->uncentered) {
739 device->uncentered = 0;
741 /* Tell the app that everything is centered/unpressed... */
742 for (i = 0; i < device->axes; i++)
743 SDL_PrivateJoystickAxis(joystick, i, 0);
745 for (i = 0; i < device->buttons; i++)
746 SDL_PrivateJoystickButton(joystick, i, 0);
748 for (i = 0; i < device->hats; i++)
749 SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
755 element = device->firstAxis;
758 value = HIDScaledCalibratedValue(device, element, -32768, 32767);
759 if (value != joystick->axes[i])
760 SDL_PrivateJoystickAxis(joystick, i, value);
761 element = element->pNext;
765 element = device->firstButton;
768 value = HIDGetElementValue(device, element);
769 if (value > 1) /* handle pressure-sensitive buttons */
771 if (value != joystick->buttons[i])
772 SDL_PrivateJoystickButton(joystick, i, value);
773 element = element->pNext;
777 element = device->firstHat;
782 range = (element->max - element->min + 1);
783 value = HIDGetElementValue(device, element) - element->min;
784 if (range == 4) /* 4 position hatswitch - scale up value */
786 else if (range != 8) /* Neither a 4 nor 8 positions - fall back to default position (centered) */
793 pos = SDL_HAT_RIGHTUP;
799 pos = SDL_HAT_RIGHTDOWN;
805 pos = SDL_HAT_LEFTDOWN;
811 pos = SDL_HAT_LEFTUP;
814 /* Every other value is mapped to center. We do that because some
815 * joysticks use 8 and some 15 for this value, and apparently
816 * there are even more variants out there - so we try to be generous.
818 pos = SDL_HAT_CENTERED;
821 if (pos != joystick->hats[i])
822 SDL_PrivateJoystickHat(joystick, i, pos);
823 element = element->pNext;
830 /* Function to close a joystick after use */
832 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
834 /* Should we do anything here? */
838 /* Function to perform any system-specific joystick related cleanup */
840 SDL_SYS_JoystickQuit(void)
842 while (NULL != gpDeviceList)
843 gpDeviceList = HIDDisposeDevice(&gpDeviceList);
846 #endif /* SDL_JOYSTICK_IOKIT */
847 /* vi: set ts=4 sw=4 expandtab: */