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