Mercurial > sdl-ios-xcode
annotate src/joystick/linux/SDL_sysjoystick.c @ 1752:97f20f2a1d85
SDL_sysjoystick.c:983: warning: 'return' with a value, in function returning void
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 01 May 2006 06:40:00 +0000 |
parents | 92947e3a18db |
children | 2f381b48b05c |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1305
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1305
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1305
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1305
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1305
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1305
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1305
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
245
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1551
diff
changeset
|
24 #ifdef SDL_JOYSTICK_LINUX |
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1551
diff
changeset
|
25 |
0 | 26 /* This is the system specific header for the SDL joystick API */ |
27 | |
28 #include <sys/stat.h> | |
29 #include <unistd.h> | |
30 #include <fcntl.h> | |
31 #include <sys/ioctl.h> | |
32 #include <limits.h> /* For the definition of PATH_MAX */ | |
377
f6987c9f04e4
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
33 #ifdef __arm__ |
f6987c9f04e4
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
34 #include <linux/limits.h> /* Arm cross-compiler needs this */ |
f6987c9f04e4
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
35 #endif |
0 | 36 #include <linux/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
|
37 #if SDL_INPUT_LINUXEV |
0 | 38 #include <linux/input.h> |
39 #endif | |
40 | |
41 #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
|
42 #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
|
43 #include "../SDL_joystick_c.h" |
0 | 44 |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
45 /* Special joystick configurations */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
46 static struct { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
47 const char *name; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
48 int naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
49 int nhats; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
50 int nballs; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
51 } special_joysticks[] = { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
52 { "MadCatz Panther XL", 3, 2, 1 }, /* We don't handle rudder (axis 8) */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
53 { "SideWinder Precision Pro", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
54 { "SideWinder 3D Pro", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
55 { "Microsoft SideWinder 3D Pro", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
56 { "Microsoft SideWinder Dual Strike USB version 1.0", 2, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
57 { "WingMan Interceptor", 3, 3, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
58 { "WingMan Extreme Digital 3D", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
59 { "Microsoft SideWinder Precision 2 Joystick", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
60 { "Logitech Inc. WingMan Extreme Digital 3D", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
61 { "Saitek Saitek X45", 6, 1, 0 } |
0 | 62 }; |
63 | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
64 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
65 |
1551 | 66 /* |
67 Some USB HIDs show up as a single joystick even though they actually | |
68 control 2 or more joysticks. | |
69 */ | |
70 /* | |
71 This code handles the MP-8800 (Quad) and MP-8866 (Dual), which can | |
72 be identified by their transparent blue design. It's quite trivial | |
73 to add other joysticks with similar quirky behavior. | |
74 -id | |
75 */ | |
76 | |
77 struct joystick_logical_mapping { | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
78 int njoy; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
79 int nthing; |
1551 | 80 }; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
81 |
1551 | 82 /* |
83 {logical joy, logical axis}, | |
84 {logical joy, logical hat}, | |
85 {logical joy, logical ball}, | |
86 {logical joy, logical button} | |
87 */ | |
88 | |
89 static struct joystick_logical_mapping mp88xx_1_logical_axismap[] = { | |
90 {0,0},{0,1},{0,2},{0,3},{0,4},{0,5} | |
91 }; | |
92 static struct joystick_logical_mapping mp88xx_1_logical_buttonmap[] = { | |
93 {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11} | |
94 }; | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
95 |
1551 | 96 static struct joystick_logical_mapping mp88xx_2_logical_axismap[] = { |
97 {0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, | |
98 {1,2},{1,3},{0,4},{0,5},{1,4},{1,5} | |
99 }; | |
100 static struct joystick_logical_mapping mp88xx_2_logical_buttonmap[] = { | |
101 {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, | |
102 {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11} | |
103 }; | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
104 |
1551 | 105 static struct joystick_logical_mapping mp88xx_3_logical_axismap[] = { |
106 {0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, | |
107 {1,2},{1,3},{2,0},{2,1},{2,2},{2,3}, | |
108 {0,4},{0,5},{1,4},{1,5},{2,4},{2,5} | |
109 }; | |
110 static struct joystick_logical_mapping mp88xx_3_logical_buttonmap[] = { | |
111 {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, | |
112 {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11}, | |
113 {2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11} | |
114 }; | |
115 | |
116 static struct joystick_logical_mapping mp88xx_4_logical_axismap[] = { | |
117 {0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, | |
118 {1,2},{1,3},{2,0},{2,1},{2,2},{2,3}, | |
119 {3,0},{3,1},{3,2},{3,3},{0,4},{0,5}, | |
120 {1,4},{1,5},{2,4},{2,5},{3,4},{3,5} | |
121 }; | |
122 static struct joystick_logical_mapping mp88xx_4_logical_buttonmap[] = { | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
123 {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
124 {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11}, |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
125 {2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11}, |
1305
babc963b6f8d
Reverted in favor of this one:
Sam Lantinga <slouken@libsdl.org>
parents:
1302
diff
changeset
|
126 {3,0},{3,1},{3,2},{3,3},{3,4},{3,5},{3,6},{3,7},{3,8},{3,9},{3,10},{3,11} |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
127 }; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
128 |
1551 | 129 struct joystick_logical_layout { |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
130 int naxes; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
131 int nhats; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
132 int nballs; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
133 int nbuttons; |
1551 | 134 }; |
135 | |
136 static struct joystick_logical_layout mp88xx_1_logical_layout[] = { | |
137 {6, 0, 0, 12} | |
138 }; | |
139 static struct joystick_logical_layout mp88xx_2_logical_layout[] = { | |
140 {6, 0, 0, 12}, | |
141 {6, 0, 0, 12} | |
142 }; | |
143 static struct joystick_logical_layout mp88xx_3_logical_layout[] = { | |
144 {6, 0, 0, 12}, | |
145 {6, 0, 0, 12}, | |
146 {6, 0, 0, 12} | |
147 }; | |
148 static struct joystick_logical_layout mp88xx_4_logical_layout[] = { | |
149 {6, 0, 0, 12}, | |
150 {6, 0, 0, 12}, | |
151 {6, 0, 0, 12}, | |
152 {6, 0, 0, 12} | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
153 }; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
154 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
155 /* |
1551 | 156 This array sets up a means of mapping a single physical joystick to |
157 multiple logical joysticks. (djm) | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
158 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
159 njoys |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
160 the number of logical joysticks |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
161 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
162 layouts |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
163 an array of layout structures, one to describe each logical joystick |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
164 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
165 axes, hats, balls, buttons |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
166 arrays that map a physical thingy to a logical thingy |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
167 */ |
1551 | 168 struct joystick_logicalmap { |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
169 const char *name; |
1551 | 170 int nbuttons; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
171 int njoys; |
1551 | 172 struct joystick_logical_layout *layout; |
173 struct joystick_logical_mapping *axismap; | |
174 struct joystick_logical_mapping *hatmap; | |
175 struct joystick_logical_mapping *ballmap; | |
176 struct joystick_logical_mapping *buttonmap; | |
177 }; | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
178 |
1551 | 179 static struct joystick_logicalmap joystick_logicalmap[] = { |
180 { | |
181 "WiseGroup.,Ltd MP-8866 Dual USB Joypad", | |
182 12, | |
183 1, | |
184 mp88xx_1_logical_layout, | |
185 mp88xx_1_logical_axismap, | |
186 NULL, | |
187 NULL, | |
188 mp88xx_1_logical_buttonmap | |
189 }, | |
190 { | |
191 "WiseGroup.,Ltd MP-8866 Dual USB Joypad", | |
192 24, | |
193 2, | |
194 mp88xx_2_logical_layout, | |
195 mp88xx_2_logical_axismap, | |
196 NULL, | |
197 NULL, | |
198 mp88xx_2_logical_buttonmap | |
199 }, | |
200 { | |
201 "WiseGroup.,Ltd MP-8800 Quad USB Joypad", | |
202 12, | |
203 1, | |
204 mp88xx_1_logical_layout, | |
205 mp88xx_1_logical_axismap, | |
206 NULL, | |
207 NULL, | |
208 mp88xx_1_logical_buttonmap | |
209 }, | |
210 { | |
211 "WiseGroup.,Ltd MP-8800 Quad USB Joypad", | |
212 24, | |
213 2, | |
214 mp88xx_2_logical_layout, | |
215 mp88xx_2_logical_axismap, | |
216 NULL, | |
217 NULL, | |
218 mp88xx_2_logical_buttonmap | |
219 }, | |
220 { | |
221 "WiseGroup.,Ltd MP-8800 Quad USB Joypad", | |
222 36, | |
223 3, | |
224 mp88xx_3_logical_layout, | |
225 mp88xx_3_logical_axismap, | |
226 NULL, | |
227 NULL, | |
228 mp88xx_3_logical_buttonmap | |
229 }, | |
230 { | |
231 "WiseGroup.,Ltd MP-8800 Quad USB Joypad", | |
232 48, | |
233 4, | |
234 mp88xx_4_logical_layout, | |
235 mp88xx_4_logical_axismap, | |
236 NULL, | |
237 NULL, | |
238 mp88xx_4_logical_buttonmap | |
239 } | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
240 }; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
241 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
242 /* find the head of a linked list, given a point in it |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
243 */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
244 #define SDL_joylist_head(i, start)\ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
245 for(i = start; SDL_joylist[i].fname == NULL;) i = SDL_joylist[i].prev; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
246 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
247 #define SDL_logical_joydecl(d) d |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
248 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
249 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
250 #else |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
251 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
252 #define SDL_logical_joydecl(d) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
253 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
254 #endif /* USE_LOGICAL_JOYSTICKS */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
255 |
0 | 256 /* The maximum number of joysticks we'll detect */ |
257 #define MAX_JOYSTICKS 32 | |
258 | |
259 /* A list of available joysticks */ | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
260 static struct |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
261 { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
262 char* fname; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
263 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
264 SDL_Joystick* joy; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
265 struct joystick_logicalmap* map; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
266 int prev; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
267 int next; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
268 int logicalno; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
269 #endif /* USE_LOGICAL_JOYSTICKS */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
270 } SDL_joylist[MAX_JOYSTICKS]; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
271 |
0 | 272 |
273 /* The private structure used to keep track of a joystick */ | |
274 struct joystick_hwdata { | |
275 int fd; | |
276 /* The current linux joystick driver maps hats to two axes */ | |
277 struct hwdata_hat { | |
278 int axis[2]; | |
279 } *hats; | |
280 /* The current linux joystick driver maps balls to two axes */ | |
281 struct hwdata_ball { | |
282 int axis[2]; | |
283 } *balls; | |
284 | |
285 /* Support for the Linux 2.4 unified input interface */ | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
286 #if SDL_INPUT_LINUXEV |
0 | 287 SDL_bool is_hid; |
288 Uint8 key_map[KEY_MAX-BTN_MISC]; | |
289 Uint8 abs_map[ABS_MAX]; | |
290 struct axis_correct { | |
291 int used; | |
292 int coef[3]; | |
293 } abs_correct[ABS_MAX]; | |
294 #endif | |
295 }; | |
296 | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
297 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
298 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
299 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
300 static int CountLogicalJoysticks(int max) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
301 { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
302 register int i, j, k, ret, prev; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
303 const char* name; |
1551 | 304 int nbuttons, fd; |
305 unsigned char n; | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
306 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
307 ret = 0; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
308 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
309 for(i = 0; i < max; i++) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
310 name = SDL_SYS_JoystickName(i); |
1551 | 311 |
312 fd = open(SDL_joylist[i].fname, O_RDONLY, 0); | |
313 if ( fd >= 0 ) { | |
314 if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) { | |
315 nbuttons = -1; | |
316 } else { | |
317 nbuttons = n; | |
318 } | |
319 close(fd); | |
320 } | |
321 else { | |
322 nbuttons=-1; | |
323 } | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
324 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
325 if (name) { |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
326 for(j = 0; j < SDL_arraysize(joystick_logicalmap); j++) { |
1551 | 327 if (!SDL_strcmp(name, joystick_logicalmap[j].name) && (nbuttons==-1 || nbuttons==joystick_logicalmap[j].nbuttons)) { |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
328 prev = i; |
1551 | 329 SDL_joylist[prev].map = &(joystick_logicalmap[j]); |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
330 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
331 for(k = 1; k < joystick_logicalmap[j].njoys; k++) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
332 SDL_joylist[prev].next = max + ret; |
1551 | 333 SDL_joylist[max+ret].prev = prev; |
334 | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
335 prev = max + ret; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
336 SDL_joylist[prev].logicalno = k; |
1551 | 337 SDL_joylist[prev].map = &(joystick_logicalmap[j]); |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
338 ret++; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
339 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
340 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
341 break; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
342 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
343 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
344 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
345 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
346 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
347 return ret; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
348 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
349 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
350 static void LogicalSuffix(int logicalno, char* namebuf, int len) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
351 { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
352 register int slen; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
353 const static char suffixs[] = |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
354 "01020304050607080910111213141516171819" |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
355 "20212223242526272829303132"; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
356 const char* suffix; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
357 slen = SDL_strlen(namebuf); |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
358 suffix = NULL; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
359 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
360 if (logicalno*2<sizeof(suffixs)) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
361 suffix = suffixs + (logicalno*2); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
362 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
363 if (slen + 4 < len && suffix) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
364 namebuf[slen++] = ' '; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
365 namebuf[slen++] = '#'; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
366 namebuf[slen++] = suffix[0]; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
367 namebuf[slen++] = suffix[1]; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
368 namebuf[slen++] = 0; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
369 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
370 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
371 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
372 #endif /* USE_LOGICAL_JOYSTICKS */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
373 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
374 #if SDL_INPUT_LINUXEV |
0 | 375 #define test_bit(nr, addr) \ |
376 (((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0) | |
377 | |
378 static int EV_IsJoystick(int fd) | |
379 { | |
380 unsigned long evbit[40]; | |
381 unsigned long keybit[40]; | |
382 unsigned long absbit[40]; | |
383 | |
384 if ( (ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) || | |
385 (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) || | |
386 (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0) ) { | |
387 return(0); | |
388 } | |
389 if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) && | |
390 test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit) && | |
391 (test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_A, keybit) || test_bit(BTN_1, keybit)))) return 0; | |
392 return(1); | |
393 } | |
394 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
395 #endif /* SDL_INPUT_LINUXEV */ |
0 | 396 |
397 /* Function to scan the system for joysticks */ | |
398 int SDL_SYS_JoystickInit(void) | |
399 { | |
400 /* The base path of the joystick devices */ | |
245
ab781a7dd82f
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
221
diff
changeset
|
401 const char *joydev_pattern[] = { |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
402 #if SDL_INPUT_LINUXEV |
245
ab781a7dd82f
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
221
diff
changeset
|
403 "/dev/input/event%d", |
211
0cc95f442f3a
If we're looking at the /dev/input event devices, and we found
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
404 #endif |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
405 "/dev/input/js%d", |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
406 "/dev/js%d" |
0 | 407 }; |
408 int numjoysticks; | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
409 int i, j; |
0 | 410 int fd; |
411 char path[PATH_MAX]; | |
412 dev_t dev_nums[MAX_JOYSTICKS]; /* major/minor device numbers */ | |
413 struct stat sb; | |
414 int n, duplicate; | |
415 | |
416 numjoysticks = 0; | |
417 | |
418 /* First see if the user specified a joystick to use */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
419 if ( SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL ) { |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
420 SDL_strlcpy(path, SDL_getenv("SDL_JOYSTICK_DEVICE"), sizeof(path)); |
0 | 421 if ( stat(path, &sb) == 0 ) { |
422 fd = open(path, O_RDONLY, 0); | |
423 if ( fd >= 0 ) { | |
424 /* Assume the user knows what they're doing. */ | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
425 SDL_joylist[numjoysticks].fname = SDL_strdup(path); |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
426 if ( SDL_joylist[numjoysticks].fname ) { |
0 | 427 dev_nums[numjoysticks] = sb.st_rdev; |
428 ++numjoysticks; | |
429 } | |
430 close(fd); | |
431 } | |
432 } | |
433 } | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
434 |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
435 for ( i=0; i<SDL_arraysize(joydev_pattern); ++i ) { |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
436 for ( j=0; j < MAX_JOYSTICKS; ++j ) { |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
437 SDL_snprintf(path, SDL_arraysize(path), joydev_pattern[i], j); |
0 | 438 |
439 /* rcg06302000 replaced access(F_OK) call with stat(). | |
440 * stat() will fail if the file doesn't exist, so it's | |
441 * equivalent behaviour. | |
442 */ | |
443 if ( stat(path, &sb) == 0 ) { | |
444 /* Check to make sure it's not already in list. | |
445 * This happens when we see a stick via symlink. | |
446 */ | |
447 duplicate = 0; | |
448 for (n=0; (n<numjoysticks) && !duplicate; ++n) { | |
449 if ( sb.st_rdev == dev_nums[n] ) { | |
450 duplicate = 1; | |
451 } | |
452 } | |
453 if (duplicate) { | |
454 continue; | |
455 } | |
456 | |
457 fd = open(path, O_RDONLY, 0); | |
458 if ( fd < 0 ) { | |
459 continue; | |
460 } | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
461 #if SDL_INPUT_LINUXEV |
0 | 462 #ifdef DEBUG_INPUT_EVENTS |
463 printf("Checking %s\n", path); | |
464 #endif | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
465 if ( (i == 0) && ! EV_IsJoystick(fd) ) { |
0 | 466 close(fd); |
467 continue; | |
468 } | |
469 #endif | |
470 close(fd); | |
471 | |
472 /* We're fine, add this joystick */ | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
473 SDL_joylist[numjoysticks].fname = SDL_strdup(path); |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
474 if ( SDL_joylist[numjoysticks].fname ) { |
0 | 475 dev_nums[numjoysticks] = sb.st_rdev; |
476 ++numjoysticks; | |
477 } | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
478 } else |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
479 break; |
0 | 480 } |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
481 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
482 #if SDL_INPUT_LINUXEV |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
483 /* This is a special case... |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
484 If the event devices are valid then the joystick devices |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
485 will be duplicates but without extra information about their |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
486 hats or balls. Unfortunately, the event devices can't |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
487 currently be calibrated, so it's a win-lose situation. |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
488 So : /dev/input/eventX = /dev/input/jsY = /dev/jsY |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
489 */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
490 if ( (i == 0) && (numjoysticks > 0) ) |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
491 break; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
492 #endif |
0 | 493 } |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
494 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
495 numjoysticks += CountLogicalJoysticks(numjoysticks); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
496 #endif |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
497 |
0 | 498 return(numjoysticks); |
499 } | |
500 | |
501 /* Function to get the device-dependent name of a joystick */ | |
502 const char *SDL_SYS_JoystickName(int index) | |
503 { | |
504 int fd; | |
505 static char namebuf[128]; | |
506 char *name; | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
507 SDL_logical_joydecl(int oindex = index); |
0 | 508 |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
509 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
510 SDL_joylist_head(index, index); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
511 #endif |
0 | 512 name = NULL; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
513 fd = open(SDL_joylist[index].fname, O_RDONLY, 0); |
0 | 514 if ( fd >= 0 ) { |
515 if ( | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
516 #if SDL_INPUT_LINUXEV |
0 | 517 (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) && |
518 #endif | |
519 (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0) ) { | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
520 name = SDL_joylist[index].fname; |
0 | 521 } else { |
522 name = namebuf; | |
523 } | |
524 close(fd); | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
525 |
1551 | 526 |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
527 #ifndef NO_LOGICAL_JOYSTICKS |
1551 | 528 if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next || index!=oindex) |
529 { | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
530 LogicalSuffix(SDL_joylist[oindex].logicalno, namebuf, 128); |
1551 | 531 } |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
532 #endif |
0 | 533 } |
534 return name; | |
535 } | |
536 | |
537 static int allocate_hatdata(SDL_Joystick *joystick) | |
538 { | |
539 int i; | |
540 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
541 joystick->hwdata->hats = (struct hwdata_hat *)SDL_malloc( |
0 | 542 joystick->nhats * sizeof(struct hwdata_hat)); |
543 if ( joystick->hwdata->hats == NULL ) { | |
544 return(-1); | |
545 } | |
546 for ( i=0; i<joystick->nhats; ++i ) { | |
547 joystick->hwdata->hats[i].axis[0] = 1; | |
548 joystick->hwdata->hats[i].axis[1] = 1; | |
549 } | |
550 return(0); | |
551 } | |
552 | |
553 static int allocate_balldata(SDL_Joystick *joystick) | |
554 { | |
555 int i; | |
556 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
557 joystick->hwdata->balls = (struct hwdata_ball *)SDL_malloc( |
0 | 558 joystick->nballs * sizeof(struct hwdata_ball)); |
559 if ( joystick->hwdata->balls == NULL ) { | |
560 return(-1); | |
561 } | |
562 for ( i=0; i<joystick->nballs; ++i ) { | |
563 joystick->hwdata->balls[i].axis[0] = 0; | |
564 joystick->hwdata->balls[i].axis[1] = 0; | |
565 } | |
566 return(0); | |
567 } | |
568 | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
569 static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd) |
0 | 570 { |
571 SDL_bool handled; | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
572 unsigned char n; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
573 int old_axes, tmp_naxes, tmp_nhats, tmp_nballs; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
574 const char *name; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
575 char *env, env_name[128]; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
576 int i; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
577 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
578 handled = SDL_FALSE; |
0 | 579 |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
580 /* Default joystick device settings */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
581 if ( ioctl(fd, JSIOCGAXES, &n) < 0 ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
582 joystick->naxes = 2; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
583 } else { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
584 joystick->naxes = n; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
585 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
586 if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
587 joystick->nbuttons = 2; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
588 } else { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
589 joystick->nbuttons = n; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
590 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
591 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
592 name = SDL_SYS_JoystickName(joystick->index); |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
593 old_axes = joystick->naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
594 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
595 /* Generic analog joystick support */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
596 if ( SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat") ) { |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
597 if ( SDL_sscanf(name,"Analog %d-axis %*d-button %d-hat", |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
598 &tmp_naxes, &tmp_nhats) == 2 ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
599 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
600 joystick->naxes = tmp_naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
601 joystick->nhats = tmp_nhats; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
602 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
603 handled = SDL_TRUE; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
604 } |
0 | 605 } |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
606 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
607 /* Special joystick support */ |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
608 for ( i=0; i < SDL_arraysize(special_joysticks); ++i ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
609 if ( SDL_strcmp(name, special_joysticks[i].name) == 0 ) { |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
610 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
611 joystick->naxes = special_joysticks[i].naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
612 joystick->nhats = special_joysticks[i].nhats; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
613 joystick->nballs = special_joysticks[i].nballs; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
614 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
615 handled = SDL_TRUE; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
616 break; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
617 } |
0 | 618 } |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
619 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
620 /* User environment joystick support */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
621 if ( (env = SDL_getenv("SDL_LINUX_JOYSTICK")) ) { |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
622 *env_name = '\0'; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
623 if ( *env == '\'' && SDL_sscanf(env, "'%[^']s'", env_name) == 1 ) |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
624 env += SDL_strlen(env_name)+2; |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
625 else if ( SDL_sscanf(env, "%s", env_name) == 1 ) |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
626 env += SDL_strlen(env_name); |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
627 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
628 if ( SDL_strcmp(name, env_name) == 0 ) { |
0 | 629 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
630 if ( SDL_sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats, |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
631 &tmp_nballs) == 3 ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
632 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
633 joystick->naxes = tmp_naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
634 joystick->nhats = tmp_nhats; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
635 joystick->nballs = tmp_nballs; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
636 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
637 handled = SDL_TRUE; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
638 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
639 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
640 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
641 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
642 /* Remap hats and balls */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
643 if (handled) { |
0 | 644 if ( joystick->nhats > 0 ) { |
589
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
645 if ( allocate_hatdata(joystick) < 0 ) { |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
646 joystick->nhats = 0; |
0 | 647 } |
648 } | |
649 if ( joystick->nballs > 0 ) { | |
650 if ( allocate_balldata(joystick) < 0 ) { | |
651 joystick->nballs = 0; | |
652 } | |
653 } | |
654 } | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
655 |
0 | 656 return(handled); |
657 } | |
658 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
659 #if SDL_INPUT_LINUXEV |
0 | 660 |
661 static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd) | |
662 { | |
871 | 663 int i, t; |
0 | 664 unsigned long keybit[40]; |
665 unsigned long absbit[40]; | |
666 unsigned long relbit[40]; | |
667 | |
668 /* See if this device uses the new unified event API */ | |
669 if ( (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) && | |
670 (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) && | |
671 (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0) ) { | |
672 joystick->hwdata->is_hid = SDL_TRUE; | |
673 | |
674 /* Get the number of buttons, axes, and other thingamajigs */ | |
675 for ( i=BTN_JOYSTICK; i < KEY_MAX; ++i ) { | |
676 if ( test_bit(i, keybit) ) { | |
677 #ifdef DEBUG_INPUT_EVENTS | |
678 printf("Joystick has button: 0x%x\n", i); | |
679 #endif | |
680 joystick->hwdata->key_map[i-BTN_MISC] = | |
681 joystick->nbuttons; | |
682 ++joystick->nbuttons; | |
683 } | |
684 } | |
685 for ( i=BTN_MISC; i < BTN_JOYSTICK; ++i ) { | |
686 if ( test_bit(i, keybit) ) { | |
687 #ifdef DEBUG_INPUT_EVENTS | |
688 printf("Joystick has button: 0x%x\n", i); | |
689 #endif | |
690 joystick->hwdata->key_map[i-BTN_MISC] = | |
691 joystick->nbuttons; | |
692 ++joystick->nbuttons; | |
693 } | |
694 } | |
695 for ( i=0; i<ABS_MAX; ++i ) { | |
696 /* Skip hats */ | |
697 if ( i == ABS_HAT0X ) { | |
698 i = ABS_HAT3Y; | |
699 continue; | |
700 } | |
701 if ( test_bit(i, absbit) ) { | |
702 int values[5]; | |
703 | |
896
b56dc586a5ef
Date: Tue, 16 Mar 2004 12:40:33 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
892
diff
changeset
|
704 if ( ioctl(fd, EVIOCGABS(i), values) < 0 ) |
b56dc586a5ef
Date: Tue, 16 Mar 2004 12:40:33 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
892
diff
changeset
|
705 continue; |
0 | 706 #ifdef DEBUG_INPUT_EVENTS |
707 printf("Joystick has absolute axis: %x\n", i); | |
708 printf("Values = { %d, %d, %d, %d, %d }\n", | |
709 values[0], values[1], | |
710 values[2], values[3], values[4]); | |
711 #endif /* DEBUG_INPUT_EVENTS */ | |
712 joystick->hwdata->abs_map[i] = joystick->naxes; | |
713 if ( values[1] == values[2] ) { | |
714 joystick->hwdata->abs_correct[i].used = 0; | |
715 } else { | |
716 joystick->hwdata->abs_correct[i].used = 1; | |
872
e7be95d758e8
Date: Fri, 05 Mar 2004 16:08:01 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
871
diff
changeset
|
717 joystick->hwdata->abs_correct[i].coef[0] = |
e7be95d758e8
Date: Fri, 05 Mar 2004 16:08:01 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
871
diff
changeset
|
718 (values[2] + values[1]) / 2 - values[4]; |
e7be95d758e8
Date: Fri, 05 Mar 2004 16:08:01 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
871
diff
changeset
|
719 joystick->hwdata->abs_correct[i].coef[1] = |
e7be95d758e8
Date: Fri, 05 Mar 2004 16:08:01 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
871
diff
changeset
|
720 (values[2] + values[1]) / 2 + values[4]; |
871 | 721 t = ((values[2] - values[1]) / 2 - 2 * values[4]); |
722 if ( t != 0 ) { | |
723 joystick->hwdata->abs_correct[i].coef[2] = (1 << 29) / t; | |
872
e7be95d758e8
Date: Fri, 05 Mar 2004 16:08:01 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
871
diff
changeset
|
724 } else { |
e7be95d758e8
Date: Fri, 05 Mar 2004 16:08:01 +0000
Sam Lantinga <slouken@libsdl.org>
parents:
871
diff
changeset
|
725 joystick->hwdata->abs_correct[i].coef[2] = 0; |
871 | 726 } |
0 | 727 } |
728 ++joystick->naxes; | |
729 } | |
730 } | |
731 for ( i=ABS_HAT0X; i <= ABS_HAT3Y; i += 2 ) { | |
732 if ( test_bit(i, absbit) || test_bit(i+1, absbit) ) { | |
733 #ifdef DEBUG_INPUT_EVENTS | |
734 printf("Joystick has hat %d\n",(i-ABS_HAT0X)/2); | |
735 #endif | |
736 ++joystick->nhats; | |
737 } | |
738 } | |
739 if ( test_bit(REL_X, relbit) || test_bit(REL_Y, relbit) ) { | |
740 ++joystick->nballs; | |
741 } | |
742 | |
743 /* Allocate data to keep track of these thingamajigs */ | |
744 if ( joystick->nhats > 0 ) { | |
745 if ( allocate_hatdata(joystick) < 0 ) { | |
746 joystick->nhats = 0; | |
747 } | |
748 } | |
749 if ( joystick->nballs > 0 ) { | |
750 if ( allocate_balldata(joystick) < 0 ) { | |
751 joystick->nballs = 0; | |
752 } | |
753 } | |
754 } | |
755 return(joystick->hwdata->is_hid); | |
756 } | |
757 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
758 #endif /* SDL_INPUT_LINUXEV */ |
0 | 759 |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
760 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
761 static void ConfigLogicalJoystick(SDL_Joystick *joystick) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
762 { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
763 struct joystick_logical_layout* layout; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
764 |
1551 | 765 layout = SDL_joylist[joystick->index].map->layout + |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
766 SDL_joylist[joystick->index].logicalno; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
767 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
768 joystick->nbuttons = layout->nbuttons; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
769 joystick->nhats = layout->nhats; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
770 joystick->naxes = layout->naxes; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
771 joystick->nballs = layout->nballs; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
772 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
773 #endif |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
774 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
775 |
0 | 776 /* Function to open a joystick for use. |
777 The joystick to open is specified by the index field of the joystick. | |
778 This should fill the nbuttons and naxes fields of the joystick structure. | |
779 It returns 0, or -1 if there is an error. | |
780 */ | |
781 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) | |
782 { | |
783 int fd; | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
784 SDL_logical_joydecl(int realindex); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
785 SDL_logical_joydecl(SDL_Joystick *realjoy = NULL); |
0 | 786 |
787 /* Open the joystick and set the joystick file descriptor */ | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
788 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
789 if (SDL_joylist[joystick->index].fname == NULL) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
790 SDL_joylist_head(realindex, joystick->index); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
791 realjoy = SDL_JoystickOpen(realindex); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
792 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
793 if (realjoy == NULL) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
794 return(-1); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
795 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
796 fd = realjoy->hwdata->fd; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
797 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
798 } else { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
799 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
800 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
801 SDL_joylist[joystick->index].joy = joystick; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
802 #else |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
803 fd = open(SDL_joylist[joystick->index].fname, O_RDONLY, 0); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
804 #endif |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
805 |
0 | 806 if ( fd < 0 ) { |
807 SDL_SetError("Unable to open %s\n", | |
808 SDL_joylist[joystick->index]); | |
809 return(-1); | |
810 } | |
811 joystick->hwdata = (struct joystick_hwdata *) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
812 SDL_malloc(sizeof(*joystick->hwdata)); |
0 | 813 if ( joystick->hwdata == NULL ) { |
814 SDL_OutOfMemory(); | |
815 close(fd); | |
816 return(-1); | |
817 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
818 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); |
0 | 819 joystick->hwdata->fd = fd; |
820 | |
821 /* Set the joystick to non-blocking read mode */ | |
822 fcntl(fd, F_SETFL, O_NONBLOCK); | |
823 | |
824 /* Get the number of buttons and axes on the joystick */ | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
825 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
826 if (realjoy) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
827 ConfigLogicalJoystick(joystick); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
828 else |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
829 #endif |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
830 #if SDL_INPUT_LINUXEV |
0 | 831 if ( ! EV_ConfigJoystick(joystick, fd) ) |
832 #endif | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
833 JS_ConfigJoystick(joystick, fd); |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
834 |
0 | 835 return(0); |
836 } | |
837 | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
838 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
839 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
840 static SDL_Joystick* FindLogicalJoystick( |
1551 | 841 SDL_Joystick *joystick, struct joystick_logical_mapping* v) |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
842 { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
843 SDL_Joystick *logicaljoy; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
844 register int i; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
845 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
846 i = joystick->index; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
847 logicaljoy = NULL; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
848 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
849 /* get the fake joystick that will receive the event |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
850 */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
851 for(;;) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
852 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
853 if (SDL_joylist[i].logicalno == v->njoy) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
854 logicaljoy = SDL_joylist[i].joy; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
855 break; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
856 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
857 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
858 if (SDL_joylist[i].next == 0) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
859 break; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
860 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
861 i = SDL_joylist[i].next; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
862 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
863 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
864 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
865 return logicaljoy; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
866 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
867 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
868 static int LogicalJoystickButton( |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
869 SDL_Joystick *joystick, Uint8 button, Uint8 state){ |
1551 | 870 struct joystick_logical_mapping* buttons; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
871 SDL_Joystick *logicaljoy = NULL; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
872 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
873 /* if there's no map then this is just a regular joystick |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
874 */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
875 if (SDL_joylist[joystick->index].map == NULL) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
876 return 0; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
877 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
878 /* get the logical joystick that will receive the event |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
879 */ |
1551 | 880 buttons = SDL_joylist[joystick->index].map->buttonmap+button; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
881 logicaljoy = FindLogicalJoystick(joystick, buttons); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
882 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
883 if (logicaljoy == NULL) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
884 return 1; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
885 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
886 SDL_PrivateJoystickButton(logicaljoy, buttons->nthing, state); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
887 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
888 return 1; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
889 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
890 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
891 static int LogicalJoystickAxis( |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
892 SDL_Joystick *joystick, Uint8 axis, Sint16 value) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
893 { |
1551 | 894 struct joystick_logical_mapping* axes; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
895 SDL_Joystick *logicaljoy = NULL; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
896 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
897 /* if there's no map then this is just a regular joystick |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
898 */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
899 if (SDL_joylist[joystick->index].map == NULL) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
900 return 0; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
901 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
902 /* get the logical joystick that will receive the event |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
903 */ |
1551 | 904 axes = SDL_joylist[joystick->index].map->axismap+axis; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
905 logicaljoy = FindLogicalJoystick(joystick, axes); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
906 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
907 if (logicaljoy == NULL) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
908 return 1; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
909 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
910 SDL_PrivateJoystickAxis(logicaljoy, axes->nthing, value); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
911 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
912 return 1; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
913 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
914 #endif /* USE_LOGICAL_JOYSTICKS */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
915 |
0 | 916 static __inline__ |
917 void HandleHat(SDL_Joystick *stick, Uint8 hat, int axis, int value) | |
918 { | |
919 struct hwdata_hat *the_hat; | |
920 const Uint8 position_map[3][3] = { | |
921 { SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP }, | |
922 { SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT }, | |
923 { SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN } | |
924 }; | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
925 SDL_logical_joydecl(SDL_Joystick *logicaljoy = NULL); |
1551 | 926 SDL_logical_joydecl(struct joystick_logical_mapping* hats = NULL); |
0 | 927 |
928 the_hat = &stick->hwdata->hats[hat]; | |
929 if ( value < 0 ) { | |
930 value = 0; | |
931 } else | |
932 if ( value == 0 ) { | |
933 value = 1; | |
934 } else | |
935 if ( value > 0 ) { | |
936 value = 2; | |
937 } | |
938 if ( value != the_hat->axis[axis] ) { | |
939 the_hat->axis[axis] = value; | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
940 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
941 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
942 /* if there's no map then this is just a regular joystick |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
943 */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
944 if (SDL_joylist[stick->index].map != NULL) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
945 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
946 /* get the fake joystick that will receive the event |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
947 */ |
1551 | 948 hats = SDL_joylist[stick->index].map->hatmap+hat; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
949 logicaljoy = FindLogicalJoystick(stick, hats); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
950 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
951 |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
952 if (logicaljoy) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
953 stick = logicaljoy; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
954 hat = hats->nthing; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
955 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
956 #endif /* USE_LOGICAL_JOYSTICKS */ |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
957 |
0 | 958 SDL_PrivateJoystickHat(stick, hat, |
959 position_map[the_hat->axis[1]][the_hat->axis[0]]); | |
960 } | |
961 } | |
962 | |
963 static __inline__ | |
964 void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value) | |
965 { | |
966 stick->hwdata->balls[ball].axis[axis] += value; | |
967 } | |
968 | |
969 /* Function to update the state of a joystick - called as a device poll. | |
970 * This function shouldn't update the joystick structure directly, | |
971 * but instead should call SDL_PrivateJoystick*() to deliver events | |
972 * and update joystick device state. | |
973 */ | |
974 static __inline__ void JS_HandleEvents(SDL_Joystick *joystick) | |
975 { | |
976 struct js_event events[32]; | |
977 int i, len; | |
978 Uint8 other_axis; | |
979 | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
980 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
981 if (SDL_joylist[joystick->index].fname == NULL) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
982 SDL_joylist_head(i, joystick->index); |
1752
97f20f2a1d85
SDL_sysjoystick.c:983: warning: 'return' with a value, in function returning void
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
983 JS_HandleEvents(SDL_joylist[i].joy); |
97f20f2a1d85
SDL_sysjoystick.c:983: warning: 'return' with a value, in function returning void
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
984 return; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
985 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
986 #endif |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
987 |
0 | 988 while ((len=read(joystick->hwdata->fd, events, (sizeof events))) > 0) { |
989 len /= sizeof(events[0]); | |
990 for ( i=0; i<len; ++i ) { | |
991 switch (events[i].type & ~JS_EVENT_INIT) { | |
992 case JS_EVENT_AXIS: | |
993 if ( events[i].number < joystick->naxes ) { | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
994 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
995 if (!LogicalJoystickAxis(joystick, |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
996 events[i].number, events[i].value)) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
997 #endif |
0 | 998 SDL_PrivateJoystickAxis(joystick, |
999 events[i].number, events[i].value); | |
1000 break; | |
1001 } | |
1002 events[i].number -= joystick->naxes; | |
589
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
1003 other_axis = (events[i].number / 2); |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
1004 if ( other_axis < joystick->nhats ) { |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
1005 HandleHat(joystick, other_axis, |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
1006 events[i].number%2, |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
1007 events[i].value); |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
1008 break; |
0 | 1009 } |
1010 events[i].number -= joystick->nhats*2; | |
1011 other_axis = (events[i].number / 2); | |
1012 if ( other_axis < joystick->nballs ) { | |
1013 HandleBall(joystick, other_axis, | |
1014 events[i].number%2, | |
1015 events[i].value); | |
1016 break; | |
1017 } | |
1018 break; | |
1019 case JS_EVENT_BUTTON: | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1020 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1021 if (!LogicalJoystickButton(joystick, |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1022 events[i].number, events[i].value)) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1023 #endif |
0 | 1024 SDL_PrivateJoystickButton(joystick, |
1025 events[i].number, events[i].value); | |
1026 break; | |
1027 default: | |
1028 /* ?? */ | |
1029 break; | |
1030 } | |
1031 } | |
1032 } | |
1033 } | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
1034 #if SDL_INPUT_LINUXEV |
0 | 1035 static __inline__ int EV_AxisCorrect(SDL_Joystick *joystick, int which, int value) |
1036 { | |
1037 struct axis_correct *correct; | |
1038 | |
1039 correct = &joystick->hwdata->abs_correct[which]; | |
1040 if ( correct->used ) { | |
1041 if ( value > correct->coef[0] ) { | |
1042 if ( value < correct->coef[1] ) { | |
1043 return 0; | |
1044 } | |
1045 value -= correct->coef[1]; | |
1046 } else { | |
1047 value -= correct->coef[0]; | |
1048 } | |
1049 value *= correct->coef[2]; | |
1050 value >>= 14; | |
1051 } | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
1052 |
0 | 1053 /* Clamp and return */ |
1275 | 1054 if ( value < -32768 ) return -32768; |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
1055 if ( value > 32767 ) return 32767; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
1056 |
0 | 1057 return value; |
1058 } | |
1059 | |
1060 static __inline__ void EV_HandleEvents(SDL_Joystick *joystick) | |
1061 { | |
1062 struct input_event events[32]; | |
1063 int i, len; | |
1064 int code; | |
1065 | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1066 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1067 if (SDL_joylist[joystick->index].fname == NULL) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1068 SDL_joylist_head(i, joystick->index); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1069 return EV_HandleEvents(SDL_joylist[i].joy); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1070 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1071 #endif |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1072 |
0 | 1073 while ((len=read(joystick->hwdata->fd, events, (sizeof events))) > 0) { |
1074 len /= sizeof(events[0]); | |
1075 for ( i=0; i<len; ++i ) { | |
1076 code = events[i].code; | |
1077 switch (events[i].type) { | |
1078 case EV_KEY: | |
1079 if ( code >= BTN_MISC ) { | |
1080 code -= BTN_MISC; | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1081 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1082 if (!LogicalJoystickButton(joystick, |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1083 joystick->hwdata->key_map[code], |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1084 events[i].value)) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1085 #endif |
0 | 1086 SDL_PrivateJoystickButton(joystick, |
1087 joystick->hwdata->key_map[code], | |
1088 events[i].value); | |
1089 } | |
1090 break; | |
1091 case EV_ABS: | |
1092 switch (code) { | |
1093 case ABS_HAT0X: | |
1094 case ABS_HAT0Y: | |
1095 case ABS_HAT1X: | |
1096 case ABS_HAT1Y: | |
1097 case ABS_HAT2X: | |
1098 case ABS_HAT2Y: | |
1099 case ABS_HAT3X: | |
1100 case ABS_HAT3Y: | |
1101 code -= ABS_HAT0X; | |
1102 HandleHat(joystick, code/2, code%2, | |
1103 events[i].value); | |
1104 break; | |
1105 default: | |
1106 events[i].value = EV_AxisCorrect(joystick, code, events[i].value); | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1107 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1108 if (!LogicalJoystickAxis(joystick, |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1109 joystick->hwdata->abs_map[code], |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1110 events[i].value)) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1111 #endif |
0 | 1112 SDL_PrivateJoystickAxis(joystick, |
1113 joystick->hwdata->abs_map[code], | |
1114 events[i].value); | |
1115 break; | |
1116 } | |
1117 break; | |
1118 case EV_REL: | |
1119 switch (code) { | |
1120 case REL_X: | |
1121 case REL_Y: | |
1122 code -= REL_X; | |
1123 HandleBall(joystick, code/2, code%2, | |
1124 events[i].value); | |
1125 break; | |
1126 default: | |
1127 break; | |
1128 } | |
1129 break; | |
1130 default: | |
1131 break; | |
1132 } | |
1133 } | |
1134 } | |
1135 } | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
1136 #endif /* SDL_INPUT_LINUXEV */ |
0 | 1137 |
1138 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) | |
1139 { | |
1140 int i; | |
1141 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
1142 #if SDL_INPUT_LINUXEV |
0 | 1143 if ( joystick->hwdata->is_hid ) |
1144 EV_HandleEvents(joystick); | |
1145 else | |
1146 #endif | |
1147 JS_HandleEvents(joystick); | |
1148 | |
1149 /* Deliver ball motion updates */ | |
1150 for ( i=0; i<joystick->nballs; ++i ) { | |
1151 int xrel, yrel; | |
1152 | |
1153 xrel = joystick->hwdata->balls[i].axis[0]; | |
1154 yrel = joystick->hwdata->balls[i].axis[1]; | |
1155 if ( xrel || yrel ) { | |
1156 joystick->hwdata->balls[i].axis[0] = 0; | |
1157 joystick->hwdata->balls[i].axis[1] = 0; | |
1158 SDL_PrivateJoystickBall(joystick, (Uint8)i, xrel, yrel); | |
1159 } | |
1160 } | |
1161 } | |
1162 | |
1163 /* Function to close a joystick after use */ | |
1164 void SDL_SYS_JoystickClose(SDL_Joystick *joystick) | |
1165 { | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1166 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1167 register int i; |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1168 if (SDL_joylist[joystick->index].fname == NULL) { |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1169 SDL_joylist_head(i, joystick->index); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1170 SDL_JoystickClose(SDL_joylist[i].joy); |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1171 } |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1172 #endif |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1173 |
0 | 1174 if ( joystick->hwdata ) { |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1175 #ifndef NO_LOGICAL_JOYSTICKS |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1176 if (SDL_joylist[joystick->index].fname != NULL) |
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1177 #endif |
0 | 1178 close(joystick->hwdata->fd); |
1179 if ( joystick->hwdata->hats ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1180 SDL_free(joystick->hwdata->hats); |
0 | 1181 } |
1182 if ( joystick->hwdata->balls ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1183 SDL_free(joystick->hwdata->balls); |
0 | 1184 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1185 SDL_free(joystick->hwdata); |
0 | 1186 joystick->hwdata = NULL; |
1187 } | |
1188 } | |
1189 | |
1190 /* Function to perform any system-specific joystick related cleanup */ | |
1191 void SDL_SYS_JoystickQuit(void) | |
1192 { | |
1193 int i; | |
1194 | |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1195 for ( i=0; SDL_joylist[i].fname; ++i ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1196 SDL_free(SDL_joylist[i].fname); |
0 | 1197 } |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
1198 SDL_joylist[0].fname = NULL; |
0 | 1199 } |
1200 | |
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1551
diff
changeset
|
1201 #endif /* SDL_JOYSTICK_LINUX */ |