Mercurial > sdl-ios-xcode
annotate src/joystick/darwin/SDL_sysjoystick.c @ 1446:47bf1767c4ca
Date: Mon, 27 Feb 2006 02:17:29 +0100
From: "William Petiot [exoide]"
Subject: Re: [SDL] cvs version: questions regarding HAVE_STDIO_H in standard w
I managed to get a first implementation of it, which I tested for "simple" use
with tests sample apps, they work ok. I think this needs more tests.
Here is the diff against CVS/SDL12, attached.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 27 Feb 2006 03:48:48 +0000 |
parents | ebc8b5855040 |
children | dc6b59e925a2 |
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 |
196
c4c4b221a5e5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
172
diff
changeset
|
24 /* SDL joystick driver for Darwin / MacOS 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
|
25 /* Written 2001 by Max Horn */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 #include <unistd.h> |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #include <ctype.h> |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #include <sysexits.h> |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #include <mach/mach.h> |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 #include <mach/mach_error.h> |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 #include <IOKit/IOKitLib.h> |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 #include <IOKit/IOCFPlugIn.h> |
209
c995b877bc5b
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
208
diff
changeset
|
34 #ifdef MACOS_10_0_4 |
c995b877bc5b
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
208
diff
changeset
|
35 #include <IOKit/hidsystem/IOHIDUsageTables.h> |
c995b877bc5b
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
208
diff
changeset
|
36 #else |
c995b877bc5b
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
208
diff
changeset
|
37 /* The header was moved here in MacOS X 10.1 */ |
208
ab4abaf66814
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
196
diff
changeset
|
38 #include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h> |
209
c995b877bc5b
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
208
diff
changeset
|
39 #endif |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 #include <IOKit/hid/IOHIDLib.h> |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 #include <IOKit/hid/IOHIDKeys.h> |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 #include <CoreFoundation/CoreFoundation.h> |
475
429fe382fe4f
Darrell's Jag joystick fix
Sam Lantinga <slouken@libsdl.org>
parents:
427
diff
changeset
|
43 #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
|
44 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 #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
|
46 #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
|
47 #include "../SDL_joystick_c.h" |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 struct recElement |
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 IOHIDElementCookie cookie; // unique value which identifies element, will NOT change |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 long min; // reported min value possible |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 long max; // reported max value possible |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 /* |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 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
|
56 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 long scaledMin; // reported scaled min value possible |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 long scaledMax; // reported scaled max value possible |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 long size; // size in bits of data return from element |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 Boolean relative; // are reports relative to last report (deltas) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 Boolean wrapping; // does element wrap around (one value higher than max is min) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 Boolean nonLinear; // are the values reported non-linear relative to element movement |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 Boolean preferredState; // does element have a preferred state (such as a button) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 Boolean nullState; // does element have null state |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 /* runtime variables used for auto-calibration */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 long minReport; // min returned value |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 long maxReport; // max returned value |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 struct recElement * pNext; // next element in list |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 }; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 typedef struct recElement recElement; |
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 struct joystick_hwdata |
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 IOHIDDeviceInterface ** interface; // interface to device, NULL = no interface |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 char product[256]; // name of product |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 long usage; // usage page from IOUSBHID Parser.h which defines general usage |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 long usagePage; // usage within above page from IOUSBHID Parser.h which defines specific usage |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 long axes; // number of axis (calculated, not reported by device) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 long buttons; // number of buttons (calculated, not reported by device) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 long hats; // number of hat switches (calculated, not reported by device) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 long elements; // number of total elements (shouldbe total of above) (calculated, not reported by device) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 recElement* firstAxis; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 recElement* firstButton; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 recElement* firstHat; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 |
858
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
92 int removed; |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
93 int uncentered; |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
94 |
210
582abf60e21e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
209
diff
changeset
|
95 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
|
96 }; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 typedef struct joystick_hwdata recDevice; |
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 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 /* Linked list of all available devices */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 static recDevice *gpDeviceList = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 |
1077
f122afdfa025
The Darwin/MacOSX joystick code is largely copied from the HID Utilities
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
104 static void HIDReportErrorNum (char * strError, long numError) |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 SDL_SetError(strError); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 static void HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, recDevice *pDevice); |
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 /* 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
|
112 * 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
|
113 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
1077
f122afdfa025
The Darwin/MacOSX joystick code is largely copied from the HID Utilities
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
115 static SInt32 HIDGetElementValue (recDevice *pDevice, recElement *pElement) |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 IOReturn result = kIOReturnSuccess; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 IOHIDEventStruct hidEvent; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 hidEvent.value = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 if (NULL != pDevice && NULL != pElement && NULL != pDevice->interface) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 result = (*(pDevice->interface))->getElementValue(pDevice->interface, pElement->cookie, &hidEvent); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 if (kIOReturnSuccess == result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 /* record min and max for auto calibration */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 if (hidEvent.value < pElement->minReport) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 pElement->minReport = hidEvent.value; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 if (hidEvent.value > pElement->maxReport) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 pElement->maxReport = hidEvent.value; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 // auto user scale |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 return hidEvent.value; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 /* similiar to HIDGetElementValue, but auto-calibrates the value before returning it */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 |
1077
f122afdfa025
The Darwin/MacOSX joystick code is largely copied from the HID Utilities
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
140 static SInt32 HIDCalibratedValue (recDevice *pDevice, recElement *pElement) |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 float deviceScale = pElement->max - pElement->min; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 float readScale = pElement->maxReport - pElement->minReport; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 SInt32 value = HIDGetElementValue(pDevice, pElement); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 if (readScale == 0) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 return value; // no scaling at all |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 else |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 return ((value - pElement->minReport) * deviceScale / readScale) + pElement->min; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 /* similiar to HIDCalibratedValue but calibrates to an arbitrary scale instead of the elements default scale */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 |
1077
f122afdfa025
The Darwin/MacOSX joystick code is largely copied from the HID Utilities
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
153 static SInt32 HIDScaledCalibratedValue (recDevice *pDevice, recElement *pElement, long min, long max) |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 float deviceScale = max - min; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 float readScale = pElement->maxReport - pElement->minReport; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 SInt32 value = HIDGetElementValue(pDevice, pElement); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 if (readScale == 0) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 return value; // no scaling at all |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 else |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 return ((value - pElement->minReport) * deviceScale / readScale) + min; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 |
858
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
164 |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
165 static void HIDRemovalCallback(void * target, |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
166 IOReturn result, |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
167 void * refcon, |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
168 void * sender) |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
169 { |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
170 recDevice *device = (recDevice *) refcon; |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
171 device->removed = 1; |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
172 device->uncentered = 1; |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
173 } |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
174 |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
175 |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
176 |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 /* 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
|
178 * 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
|
179 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 |
1077
f122afdfa025
The Darwin/MacOSX joystick code is largely copied from the HID Utilities
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
181 static IOReturn 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
|
182 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 IOReturn result = kIOReturnSuccess; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 HRESULT plugInResult = S_OK; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 SInt32 score = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 IOCFPlugInInterface ** ppPlugInInterface = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 if (NULL == pDevice->interface) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 result = IOCreatePlugInInterfaceForService (hidDevice, kIOHIDDeviceUserClientTypeID, |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 kIOCFPlugInInterfaceID, &ppPlugInInterface, &score); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 if (kIOReturnSuccess == result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 // Call a method of the intermediate plug-in to create the device interface |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface, |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void *) &(pDevice->interface)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 if (S_OK != plugInResult) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 HIDReportErrorNum ("CouldnÕt query HID class device interface from plugInInterface", plugInResult); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 (*ppPlugInInterface)->Release (ppPlugInInterface); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 else |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 HIDReportErrorNum ("Failed to create **plugInInterface via IOCreatePlugInInterfaceForService.", result); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 if (NULL != pDevice->interface) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 result = (*(pDevice->interface))->open (pDevice->interface, 0); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 if (kIOReturnSuccess != result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 HIDReportErrorNum ("Failed to open pDevice->interface via open.", result); |
858
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
209 else |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
210 (*(pDevice->interface))->setRemovalCallback (pDevice->interface, HIDRemovalCallback, pDevice, pDevice); |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
211 |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 return result; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 /* 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
|
217 * 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
|
218 * 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
|
219 * (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
|
220 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 |
1077
f122afdfa025
The Darwin/MacOSX joystick code is largely copied from the HID Utilities
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
222 static IOReturn HIDCloseReleaseInterface (recDevice *pDevice) |
172
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 IOReturn result = kIOReturnSuccess; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 if ((NULL != pDevice) && (NULL != pDevice->interface)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 // close the interface |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 result = (*(pDevice->interface))->close (pDevice->interface); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 if (kIOReturnNotOpen == result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 // do nothing as device was not opened, thus can't be closed |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 else if (kIOReturnSuccess != result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 HIDReportErrorNum ("Failed to close IOHIDDeviceInterface.", result); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 //release the interface |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 result = (*(pDevice->interface))->Release (pDevice->interface); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 if (kIOReturnSuccess != result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 HIDReportErrorNum ("Failed to release IOHIDDeviceInterface.", result); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 pDevice->interface = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 return result; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 /* 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
|
246 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 static void HIDGetElementInfo (CFTypeRef refElement, recElement *pElement) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 long number; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 CFTypeRef refType; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementCookieKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 pElement->cookie = (IOHIDElementCookie) number; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMinKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 pElement->min = number; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 pElement->maxReport = pElement->min; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementMaxKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 pElement->max = number; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 pElement->minReport = pElement->max; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 /* |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 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
|
265 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMinKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 pElement->scaledMin = number; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementScaledMaxKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 pElement->scaledMax = number; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementSizeKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 if (refType && CFNumberGetValue (refType, kCFNumberLongType, &number)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 pElement->size = number; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsRelativeKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 if (refType) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 pElement->relative = CFBooleanGetValue (refType); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsWrappingKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 if (refType) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 pElement->wrapping = CFBooleanGetValue (refType); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementIsNonLinearKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 if (refType) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 pElement->nonLinear = CFBooleanGetValue (refType); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasPreferedStateKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 if (refType) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 pElement->preferredState = CFBooleanGetValue (refType); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 refType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementHasNullStateKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 if (refType) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 pElement->nullState = CFBooleanGetValue (refType); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 /* 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
|
294 * 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
|
295 * 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
|
296 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 static void HIDAddElement (CFTypeRef refElement, recDevice* pDevice) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 recElement* element = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 recElement** headElement = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 long elementType, usagePage, usage; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 CFTypeRef refElementType = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementTypeKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 CFTypeRef refUsagePage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsagePageKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 CFTypeRef refUsage = CFDictionaryGetValue (refElement, CFSTR(kIOHIDElementUsageKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 if ((refElementType) && (CFNumberGetValue (refElementType, kCFNumberLongType, &elementType))) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 /* look at types of interest */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 if ((elementType == kIOHIDElementTypeInput_Misc) || (elementType == kIOHIDElementTypeInput_Button) || |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 (elementType == kIOHIDElementTypeInput_Axis)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 if (refUsagePage && CFNumberGetValue (refUsagePage, kCFNumberLongType, &usagePage) && |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 refUsage && CFNumberGetValue (refUsage, kCFNumberLongType, &usage)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 switch (usagePage) /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 case kHIDPage_GenericDesktop: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 switch (usage) /* look at usage to determine function */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 case kHIDUsage_GD_X: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 case kHIDUsage_GD_Y: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 case kHIDUsage_GD_Z: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 case kHIDUsage_GD_Rx: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 case kHIDUsage_GD_Ry: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 case kHIDUsage_GD_Rz: |
594
a71ce390adeb
Added support for HID sliders wheels and dials on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
495
diff
changeset
|
329 case kHIDUsage_GD_Slider: |
a71ce390adeb
Added support for HID sliders wheels and dials on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
495
diff
changeset
|
330 case kHIDUsage_GD_Dial: |
a71ce390adeb
Added support for HID sliders wheels and dials on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
495
diff
changeset
|
331 case kHIDUsage_GD_Wheel: |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 element = (recElement *) NewPtrClear (sizeof (recElement)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 if (element) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 pDevice->axes++; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 headElement = &(pDevice->firstAxis); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 case kHIDUsage_GD_Hatswitch: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 element = (recElement *) NewPtrClear (sizeof (recElement)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 if (element) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 pDevice->hats++; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 headElement = &(pDevice->firstHat); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 case kHIDPage_Button: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 element = (recElement *) NewPtrClear (sizeof (recElement)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 if (element) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 pDevice->buttons++; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 headElement = &(pDevice->firstButton); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 default: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 else if (kIOHIDElementTypeCollection == elementType) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 HIDGetCollectionElements ((CFMutableDictionaryRef) refElement, pDevice); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 if (element && headElement) /* add to list */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 pDevice->elements++; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 if (NULL == *headElement) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 *headElement = element; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 else |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 recElement *elementPrevious, *elementCurrent; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 elementCurrent = *headElement; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 while (elementCurrent) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 elementPrevious = elementCurrent; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 elementCurrent = elementPrevious->pNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 elementPrevious->pNext = element; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 element->pNext = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 HIDGetElementInfo (refElement, element); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
387 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 /* 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
|
389 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 static void HIDGetElementsCFArrayHandler (const void * value, void * parameter) |
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 if (CFGetTypeID (value) == CFDictionaryGetTypeID ()) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 HIDAddElement ((CFTypeRef) value, (recDevice *) parameter); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
394 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
395 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 /* 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
|
397 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 static void HIDGetElements (CFTypeRef refElementCurrent, recDevice *pDevice) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 CFTypeID type = CFGetTypeID (refElementCurrent); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 if (type == CFArrayGetTypeID()) /* if element is an array */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
402 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 CFRange range = {0, CFArrayGetCount (refElementCurrent)}; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 /* CountElementsCFArrayHandler called for each array member */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 CFArrayApplyFunction (refElementCurrent, range, HIDGetElementsCFArrayHandler, pDevice); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 /* 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
|
410 * 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
|
411 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 static void HIDGetCollectionElements (CFMutableDictionaryRef deviceProperties, recDevice *pDevice) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 CFTypeRef refElementTop = CFDictionaryGetValue (deviceProperties, CFSTR(kIOHIDElementKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 if (refElementTop) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 HIDGetElements (refElementTop, pDevice); |
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 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 /* 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
|
421 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 static void HIDTopLevelElementHandler (const void * value, void * parameter) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
424 CFTypeRef refCF = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 if (CFGetTypeID (value) != CFDictionaryGetTypeID ()) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 return; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsagePageKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 if (!CFNumberGetValue (refCF, kCFNumberLongType, &((recDevice *) parameter)->usagePage)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 SDL_SetError ("CFNumberGetValue error retrieving pDevice->usagePage."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 refCF = CFDictionaryGetValue (value, CFSTR(kIOHIDElementUsageKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 if (!CFNumberGetValue (refCF, kCFNumberLongType, &((recDevice *) parameter)->usage)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
432 SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
434 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
435 /* 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
|
436 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
437 static void HIDGetDeviceInfo (io_object_t hidDevice, CFMutableDictionaryRef hidProperties, recDevice *pDevice) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
438 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
439 CFMutableDictionaryRef usbProperties = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
440 io_registry_entry_t parent1, parent2; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
442 /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 if ((KERN_SUCCESS == IORegistryEntryGetParentEntry (hidDevice, kIOServicePlane, &parent1)) && |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
446 (KERN_SUCCESS == IORegistryEntryGetParentEntry (parent1, kIOServicePlane, &parent2)) && |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 (KERN_SUCCESS == IORegistryEntryCreateCFProperties (parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
448 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
449 if (usbProperties) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
450 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 CFTypeRef refCF = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
452 /* get device info |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
453 * try hid dictionary first, if fail then go to usb dictionary |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
454 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
455 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
456 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
457 /* get product name */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
458 refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDProductKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
459 if (!refCF) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
460 refCF = CFDictionaryGetValue (usbProperties, CFSTR("USB Product Name")); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
461 if (refCF) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
462 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
463 if (!CFStringGetCString (refCF, pDevice->product, 256, CFStringGetSystemEncoding ())) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
464 SDL_SetError ("CFStringGetCString error retrieving pDevice->product."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
465 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
466 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
467 /* get usage page and usage */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
468 refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
469 if (refCF) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
470 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
471 if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usagePage)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
472 SDL_SetError ("CFNumberGetValue error retrieving pDevice->usagePage."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
473 refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 if (refCF) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
475 if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usage)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
476 SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
477 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
478 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
479 if (NULL == refCF) /* get top level element HID usage page or usage */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
480 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
481 /* use top level element instead */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
482 CFTypeRef refCFTopElement = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
483 refCFTopElement = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
484 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
485 /* refCFTopElement points to an array of element dictionaries */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
486 CFRange range = {0, CFArrayGetCount (refCFTopElement)}; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
487 CFArrayApplyFunction (refCFTopElement, range, HIDTopLevelElementHandler, pDevice); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
488 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
489 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
490 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
491 CFRelease (usbProperties); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
492 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
493 else |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
494 SDL_SetError ("IORegistryEntryCreateCFProperties failed to create usbProperties."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
495 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
496 if (kIOReturnSuccess != IOObjectRelease (parent2)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
497 SDL_SetError ("IOObjectRelease error with parent2."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 if (kIOReturnSuccess != IOObjectRelease (parent1)) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
499 SDL_SetError ("IOObjectRelease error with parent1."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
500 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
502 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
503 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
504 static recDevice *HIDBuildDevice (io_object_t hidDevice) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
506 recDevice *pDevice = (recDevice *) NewPtrClear (sizeof (recDevice)); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
507 if (pDevice) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 /* get dictionary for HID properties */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 CFMutableDictionaryRef hidProperties = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 kern_return_t result = IORegistryEntryCreateCFProperties (hidDevice, &hidProperties, kCFAllocatorDefault, kNilOptions); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
512 if ((result == KERN_SUCCESS) && hidProperties) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
513 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
514 /* create device interface */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
515 result = HIDCreateOpenDeviceInterface (hidDevice, pDevice); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
516 if (kIOReturnSuccess == result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
517 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
518 HIDGetDeviceInfo (hidDevice, hidProperties, pDevice); /* hidDevice used to find parents in registry tree */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
519 HIDGetCollectionElements (hidProperties, pDevice); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
520 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
521 else |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
522 { |
210
582abf60e21e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
209
diff
changeset
|
523 DisposePtr((Ptr)pDevice); |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
524 pDevice = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
525 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
526 CFRelease (hidProperties); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
527 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
528 else |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
529 { |
210
582abf60e21e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
209
diff
changeset
|
530 DisposePtr((Ptr)pDevice); |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
531 pDevice = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
532 } |
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 return pDevice; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
535 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
536 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
537 /* 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
|
538 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
539 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
540 static void HIDDisposeElementList (recElement **elementList) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
541 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
542 recElement *pElement = *elementList; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
543 while (pElement) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
544 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
545 recElement *pElementNext = pElement->pNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
546 DisposePtr ((Ptr) pElement); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
547 pElement = pElementNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
548 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
549 *elementList = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
550 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
551 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
552 /* 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
|
553 * 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
|
554 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
555 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
556 static recDevice *HIDDisposeDevice (recDevice **ppDevice) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
557 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
558 kern_return_t result = KERN_SUCCESS; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
559 recDevice *pDeviceNext = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
560 if (*ppDevice) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
561 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
562 // save next device prior to disposing of this device |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
563 pDeviceNext = (*ppDevice)->pNext; |
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 /* free element lists */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
566 HIDDisposeElementList (&(*ppDevice)->firstAxis); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
567 HIDDisposeElementList (&(*ppDevice)->firstButton); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
568 HIDDisposeElementList (&(*ppDevice)->firstHat); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
569 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
570 result = HIDCloseReleaseInterface (*ppDevice); /* function sanity checks interface value (now application does not own device) */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
571 if (kIOReturnSuccess != result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
572 HIDReportErrorNum ("HIDCloseReleaseInterface failed when trying to dipose device.", result); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
573 DisposePtr ((Ptr)*ppDevice); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
574 *ppDevice = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
575 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
576 return pDeviceNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
577 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
578 |
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 /* 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
|
581 * 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
|
582 * 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
|
583 * on an unrecoverable fatal error. |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
584 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
585 int SDL_SYS_JoystickInit(void) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
586 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
587 IOReturn result = kIOReturnSuccess; |
1409
ebc8b5855040
Fixed build warnings on Intel Mac
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
588 mach_port_t masterPort = 0; |
ebc8b5855040
Fixed build warnings on Intel Mac
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
589 io_iterator_t hidObjectIterator = 0; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
590 CFMutableDictionaryRef hidMatchDictionary = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
591 recDevice *device, *lastDevice; |
1409
ebc8b5855040
Fixed build warnings on Intel Mac
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
592 io_object_t ioHIDDeviceObject = 0; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
593 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
594 SDL_numjoysticks = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
595 |
1409
ebc8b5855040
Fixed build warnings on Intel Mac
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
596 if (!gpDeviceList) |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
597 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
598 SDL_SetError("Joystick: Device list already inited."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
599 return -1; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
600 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
601 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
602 result = IOMasterPort (bootstrap_port, &masterPort); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
603 if (kIOReturnSuccess != result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
604 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
605 SDL_SetError("Joystick: IOMasterPort error with bootstrap_port."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
606 return -1; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
607 } |
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 /* Set up a matching dictionary to search I/O Registry by class name for all HID class devices. */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
610 hidMatchDictionary = IOServiceMatching (kIOHIDDeviceKey); |
1409
ebc8b5855040
Fixed build warnings on Intel Mac
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
611 if (hidMatchDictionary) |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
612 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
613 /* Add key for device type (joystick, in this case) to refine the matching dictionary. */ |
495
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
614 |
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
615 /* NOTE: we now perform this filtering later |
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
616 UInt32 usagePage = kHIDPage_GenericDesktop; |
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
617 UInt32 usage = kHIDUsage_GD_Joystick; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
618 CFNumberRef refUsage = NULL, refUsagePage = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
619 |
475
429fe382fe4f
Darrell's Jag joystick fix
Sam Lantinga <slouken@libsdl.org>
parents:
427
diff
changeset
|
620 refUsage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usage); |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
621 CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsageKey), refUsage); |
475
429fe382fe4f
Darrell's Jag joystick fix
Sam Lantinga <slouken@libsdl.org>
parents:
427
diff
changeset
|
622 refUsagePage = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &usagePage); |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
623 CFDictionarySetValue (hidMatchDictionary, CFSTR (kIOHIDPrimaryUsagePageKey), refUsagePage); |
495
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
624 */ |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
625 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
626 else |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
627 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
628 SDL_SetError("Joystick: Failed to get HID CFMutableDictionaryRef via IOServiceMatching."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
629 return -1; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
630 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
631 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
632 /*/ Now search I/O Registry for matching devices. */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
633 result = IOServiceGetMatchingServices (masterPort, hidMatchDictionary, &hidObjectIterator); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
634 /* Check for errors */ |
427
027ae30b867f
Date: Mon, 29 Jul 2002 15:07:22 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
635 if (kIOReturnSuccess != result) |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
636 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
637 SDL_SetError("Joystick: Couldn't create a HID object iterator."); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
638 return -1; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
639 } |
1409
ebc8b5855040
Fixed build warnings on Intel Mac
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
640 if (!hidObjectIterator) /* there are no joysticks */ |
427
027ae30b867f
Date: Mon, 29 Jul 2002 15:07:22 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
641 { |
027ae30b867f
Date: Mon, 29 Jul 2002 15:07:22 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
642 gpDeviceList = NULL; |
027ae30b867f
Date: Mon, 29 Jul 2002 15:07:22 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
643 SDL_numjoysticks = 0; |
027ae30b867f
Date: Mon, 29 Jul 2002 15:07:22 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
644 return 0; |
027ae30b867f
Date: Mon, 29 Jul 2002 15:07:22 +1000
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
645 } |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
646 /* IOServiceGetMatchingServices consumes a reference to the dictionary, so we don't need to release the dictionary ref. */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
647 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
648 /* build flat linked list of devices from device iterator */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
649 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
650 gpDeviceList = lastDevice = NULL; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
651 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
652 while ((ioHIDDeviceObject = IOIteratorNext (hidObjectIterator))) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
653 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
654 /* build a device record */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
655 device = HIDBuildDevice (ioHIDDeviceObject); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
656 if (!device) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
657 continue; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
658 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
659 /* dump device object, it is no longer needed */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
660 result = IOObjectRelease (ioHIDDeviceObject); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
661 // if (KERN_SUCCESS != result) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
662 // HIDReportErrorNum ("IOObjectRelease error with ioHIDDeviceObject.", result); |
495
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
663 |
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
664 /* Filter device list to non-keyboard/mouse stuff */ |
623
477917048b91
God, this is the never-ending patch. Another USB joystick detection fix for
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
665 if ( (device->usagePage != kHIDPage_GenericDesktop) || |
477917048b91
God, this is the never-ending patch. Another USB joystick detection fix for
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
666 ((device->usage != kHIDUsage_GD_Joystick && |
477917048b91
God, this is the never-ending patch. Another USB joystick detection fix for
Ryan C. Gordon <icculus@icculus.org>
parents:
622
diff
changeset
|
667 device->usage != kHIDUsage_GD_GamePad)) ) { |
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
|
668 |
495
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
669 /* release memory for the device */ |
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
670 HIDDisposeDevice (&device); |
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
671 DisposePtr((Ptr)device); |
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
672 continue; |
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
673 } |
4503f9475cf2
Date: Thu, 12 Sep 2002 20:35:51 -0400
Sam Lantinga <slouken@libsdl.org>
parents:
475
diff
changeset
|
674 |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
675 /* Add device to the end of the list */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
676 if (lastDevice) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
677 lastDevice->pNext = device; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
678 else |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
679 gpDeviceList = device; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
680 lastDevice = device; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
681 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
682 result = IOObjectRelease (hidObjectIterator); /* release the iterator */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
683 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
684 /* Count the total number of devices we found */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
685 device = gpDeviceList; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
686 while (device) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
687 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
688 SDL_numjoysticks++; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
689 device = device->pNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
690 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
691 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
692 return SDL_numjoysticks; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
693 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
694 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
695 /* Function to get the device-dependent name of a joystick */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
696 const char *SDL_SYS_JoystickName(int index) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
697 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
698 recDevice *device = gpDeviceList; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
699 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
700 for (; index > 0; index--) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
701 device = device->pNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
702 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
703 return device->product; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
704 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
705 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
706 /* 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
|
707 * 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
|
708 * 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
|
709 * 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
|
710 */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
711 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
712 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
713 recDevice *device = gpDeviceList; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
714 int index; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
715 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
716 for (index = joystick->index; index > 0; index--) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
717 device = device->pNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
718 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
719 joystick->hwdata = device; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
720 joystick->name = device->product; |
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 joystick->naxes = device->axes; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
723 joystick->nhats = device->hats; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
724 joystick->nballs = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
725 joystick->nbuttons = device->buttons; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
726 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
727 return 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
728 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
729 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
730 /* 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
|
731 * 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
|
732 * 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
|
733 * and update joystick device state. |
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 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
736 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
737 recDevice *device = joystick->hwdata; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
738 recElement *element; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
739 SInt32 value; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
740 int i; |
858
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
741 |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
742 if (device->removed) /* device was unplugged; ignore it. */ |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
743 { |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
744 if (device->uncentered) |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
745 { |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
746 device->uncentered = 0; |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
747 |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
748 /* Tell the app that everything is centered/unpressed... */ |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
749 for (i = 0; i < device->axes; i++) |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
750 SDL_PrivateJoystickAxis(joystick, i, 0); |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
751 |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
752 for (i = 0; i < device->buttons; i++) |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
753 SDL_PrivateJoystickButton(joystick, i, 0); |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
754 |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
755 for (i = 0; i < device->hats; i++) |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
756 SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED); |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
757 } |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
758 |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
759 return; |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
760 } |
5db50aa5bf08
Date: Wed, 25 Feb 2004 06:41:17 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
761 |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
762 element = device->firstAxis; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
763 i = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
764 while (element) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
765 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
766 value = HIDScaledCalibratedValue(device, element, -32768, 32767); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
767 if ( value != joystick->axes[i] ) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
768 SDL_PrivateJoystickAxis(joystick, i, value); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
769 element = element->pNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
770 ++i; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
771 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
772 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
773 element = device->firstButton; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
774 i = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
775 while (element) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
776 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
777 value = HIDGetElementValue(device, element); |
629
3fa401bb4bb5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
623
diff
changeset
|
778 if (value > 1) /* handle pressure-sensitive buttons */ |
3fa401bb4bb5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
623
diff
changeset
|
779 value = 1; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
780 if ( value != joystick->buttons[i] ) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
781 SDL_PrivateJoystickButton(joystick, i, value); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
782 element = element->pNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
783 ++i; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
784 } |
629
3fa401bb4bb5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
623
diff
changeset
|
785 |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
786 element = device->firstHat; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
787 i = 0; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
788 while (element) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
789 { |
210
582abf60e21e
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
209
diff
changeset
|
790 Uint8 pos = 0; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
791 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
792 value = HIDGetElementValue(device, element); |
617 | 793 if (element->max == 3) /* 4 position hatswitch - scale up value */ |
794 value *= 2; | |
795 else if (element->max != 7) /* Neither a 4 nor 8 positions - fall back to default position (centered) */ | |
796 value = -1; | |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
797 switch(value) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
798 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
799 case 0: |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
800 pos = SDL_HAT_UP; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
801 break; |
617 | 802 case 1: |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
803 pos = SDL_HAT_RIGHTUP; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
804 break; |
617 | 805 case 2: |
806 pos = SDL_HAT_RIGHT; | |
807 break; | |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
808 case 3: |
617 | 809 pos = SDL_HAT_RIGHTDOWN; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
810 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
811 case 4: |
617 | 812 pos = SDL_HAT_DOWN; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
813 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
814 case 5: |
617 | 815 pos = SDL_HAT_LEFTDOWN; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
816 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
817 case 6: |
617 | 818 pos = SDL_HAT_LEFT; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
819 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
820 case 7: |
617 | 821 pos = SDL_HAT_LEFTUP; |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
822 break; |
617 | 823 default: |
824 /* Every other value is mapped to center. We do that because some | |
825 * joysticks use 8 and some 15 for this value, and apparently | |
826 * there are even more variants out there - so we try to be generous. | |
827 */ | |
828 pos = SDL_HAT_CENTERED; | |
172
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
829 break; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
830 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
831 if ( pos != joystick->hats[i] ) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
832 SDL_PrivateJoystickHat(joystick, i, pos); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
833 element = element->pNext; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
834 ++i; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
835 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
836 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
837 return; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
838 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
839 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
840 /* Function to close a joystick after use */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
841 void SDL_SYS_JoystickClose(SDL_Joystick *joystick) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
842 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
843 /* Should we do anything here? */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
844 return; |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
845 } |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
846 |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
847 /* Function to perform any system-specific joystick related cleanup */ |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
848 void SDL_SYS_JoystickQuit(void) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
849 { |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
850 while (NULL != gpDeviceList) |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
851 gpDeviceList = HIDDisposeDevice (&gpDeviceList); |
37e3ca9254c7
Date: Sat, 8 Sep 2001 04:42:23 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
852 } |