comparison src/joystick/darwin/SDL_sysjoystick.c @ 2713:0906692aa6a4

Final merge of Google Summer of Code 2008 work... Force Feedback for SDL by Edgar Simo, mentored by Ryan C. Gordon
author Sam Lantinga <slouken@libsdl.org>
date Mon, 25 Aug 2008 09:55:03 +0000
parents dbc6d1893869
children 204be4fc2726
comparison
equal deleted inserted replaced
2712:c4e697245676 2713:0906692aa6a4
46 #endif 46 #endif
47 #include <IOKit/hid/IOHIDKeys.h> 47 #include <IOKit/hid/IOHIDKeys.h>
48 #include <CoreFoundation/CoreFoundation.h> 48 #include <CoreFoundation/CoreFoundation.h>
49 #include <Carbon/Carbon.h> /* for NewPtrClear, DisposePtr */ 49 #include <Carbon/Carbon.h> /* for NewPtrClear, DisposePtr */
50 50
51 /* For force feedback testing. */
52 #include <ForceFeedback/ForceFeedback.h>
53 #include <ForceFeedback/ForceFeedbackConstants.h>
54
51 #include "SDL_joystick.h" 55 #include "SDL_joystick.h"
52 #include "../SDL_sysjoystick.h" 56 #include "../SDL_sysjoystick.h"
53 #include "../SDL_joystick_c.h" 57 #include "../SDL_joystick_c.h"
54 58 #include "SDL_sysjoystick_c.h"
55 struct recElement
56 {
57 IOHIDElementCookie cookie; /* unique value which identifies element, will NOT change */
58 long min; /* reported min value possible */
59 long max; /* reported max value possible */
60 #if 0
61 /* TODO: maybe should handle the following stuff somehow? */
62
63 long scaledMin; /* reported scaled min value possible */
64 long scaledMax; /* reported scaled max value possible */
65 long size; /* size in bits of data return from element */
66 Boolean relative; /* are reports relative to last report (deltas) */
67 Boolean wrapping; /* does element wrap around (one value higher than max is min) */
68 Boolean nonLinear; /* are the values reported non-linear relative to element movement */
69 Boolean preferredState; /* does element have a preferred state (such as a button) */
70 Boolean nullState; /* does element have null state */
71 #endif /* 0 */
72
73 /* runtime variables used for auto-calibration */
74 long minReport; /* min returned value */
75 long maxReport; /* max returned value */
76
77 struct recElement *pNext; /* next element in list */
78 };
79 typedef struct recElement recElement;
80
81 struct joystick_hwdata
82 {
83 IOHIDDeviceInterface **interface; /* interface to device, NULL = no interface */
84
85 char product[256]; /* name of product */
86 long usage; /* usage page from IOUSBHID Parser.h which defines general usage */
87 long usagePage; /* usage within above page from IOUSBHID Parser.h which defines specific usage */
88
89 long axes; /* number of axis (calculated, not reported by device) */
90 long buttons; /* number of buttons (calculated, not reported by device) */
91 long hats; /* number of hat switches (calculated, not reported by device) */
92 long elements; /* number of total elements (shouldbe total of above) (calculated, not reported by device) */
93
94 recElement *firstAxis;
95 recElement *firstButton;
96 recElement *firstHat;
97
98 int removed;
99 int uncentered;
100
101 struct joystick_hwdata *pNext; /* next device */
102 };
103 typedef struct joystick_hwdata recDevice;
104 59
105 60
106 /* Linked list of all available devices */ 61 /* Linked list of all available devices */
107 static recDevice *gpDeviceList = NULL; 62 static recDevice *gpDeviceList = NULL;
108 63
592 recDevice *pDeviceNext = NULL; 547 recDevice *pDeviceNext = NULL;
593 if (*ppDevice) { 548 if (*ppDevice) {
594 /* save next device prior to disposing of this device */ 549 /* save next device prior to disposing of this device */
595 pDeviceNext = (*ppDevice)->pNext; 550 pDeviceNext = (*ppDevice)->pNext;
596 551
552 /* free posible io_service_t */
553 if ((*ppDevice)->ffservice) {
554 IOObjectRelease((*ppDevice)->ffservice);
555 (*ppDevice)->ffservice = 0;
556 }
557
597 /* free element lists */ 558 /* free element lists */
598 HIDDisposeElementList(&(*ppDevice)->firstAxis); 559 HIDDisposeElementList(&(*ppDevice)->firstAxis);
599 HIDDisposeElementList(&(*ppDevice)->firstButton); 560 HIDDisposeElementList(&(*ppDevice)->firstButton);
600 HIDDisposeElementList(&(*ppDevice)->firstHat); 561 HIDDisposeElementList(&(*ppDevice)->firstHat);
601 562
684 /* build a device record */ 645 /* build a device record */
685 device = HIDBuildDevice(ioHIDDeviceObject); 646 device = HIDBuildDevice(ioHIDDeviceObject);
686 if (!device) 647 if (!device)
687 continue; 648 continue;
688 649
689 /* dump device object, it is no longer needed */
690 result = IOObjectRelease(ioHIDDeviceObject);
691 /* if (KERN_SUCCESS != result)
692 HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result);
693 */
694
695 /* Filter device list to non-keyboard/mouse stuff */ 650 /* Filter device list to non-keyboard/mouse stuff */
696 if ((device->usagePage != kHIDPage_GenericDesktop) || 651 if ((device->usagePage != kHIDPage_GenericDesktop) ||
697 ((device->usage != kHIDUsage_GD_Joystick && 652 ((device->usage != kHIDUsage_GD_Joystick &&
698 device->usage != kHIDUsage_GD_GamePad && 653 device->usage != kHIDUsage_GD_GamePad &&
699 device->usage != kHIDUsage_GD_MultiAxisController))) { 654 device->usage != kHIDUsage_GD_MultiAxisController))) {
700 655
701 /* release memory for the device */ 656 /* release memory for the device */
702 HIDDisposeDevice(&device); 657 HIDDisposeDevice(&device);
703 DisposePtr((Ptr) device); 658 DisposePtr((Ptr) device);
704 continue; 659 continue;
660 }
661
662 /* We have to do some storage of the io_service_t for
663 * SDL_HapticOpenFromJoystick */
664 if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {
665 device->ffservice = ioHIDDeviceObject;
666 } else {
667 device->ffservice = 0;
705 } 668 }
706 669
707 /* Add device to the end of the list */ 670 /* Add device to the end of the list */
708 if (lastDevice) 671 if (lastDevice)
709 lastDevice->pNext = device; 672 lastDevice->pNext = device;