annotate src/joystick/darwin/SDL_sysjoystick.c @ 2097:b0048df1701a

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