Mercurial > sdl-ios-xcode
annotate src/joystick/linux/SDL_sysjoystick.c @ 871:9cc9e2462d9a
Avoid FPE with Linux 2.6
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 05 Mar 2004 15:09:18 +0000 |
parents | b8d311d90021 |
children | e7be95d758e8 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
589
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
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 | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
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 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* This is the system specific header for the SDL joystick API */ | |
29 | |
30 #include <stdio.h> /* For the definition of NULL */ | |
31 #include <stdlib.h> /* For getenv() prototype */ | |
32 #include <string.h> | |
33 #include <sys/stat.h> | |
34 #include <unistd.h> | |
35 #include <fcntl.h> | |
36 #include <sys/ioctl.h> | |
37 #include <limits.h> /* For the definition of PATH_MAX */ | |
377
f6987c9f04e4
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
38 #ifdef __arm__ |
f6987c9f04e4
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
39 #include <linux/limits.h> /* Arm cross-compiler needs this */ |
f6987c9f04e4
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
40 #endif |
0 | 41 #include <linux/joystick.h> |
42 #ifdef USE_INPUT_EVENTS | |
43 #include <linux/input.h> | |
44 #endif | |
45 | |
46 #include "SDL_error.h" | |
47 #include "SDL_joystick.h" | |
48 #include "SDL_sysjoystick.h" | |
49 #include "SDL_joystick_c.h" | |
50 | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
51 /* Special joystick configurations */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
52 static struct { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
53 const char *name; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
54 int naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
55 int nhats; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
56 int nballs; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
57 } special_joysticks[] = { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
58 { "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
|
59 { "SideWinder Precision Pro", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
60 { "SideWinder 3D Pro", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
61 { "Microsoft SideWinder 3D Pro", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
62 { "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
|
63 { "WingMan Interceptor", 3, 3, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
64 { "WingMan Extreme Digital 3D", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
65 { "Microsoft SideWinder Precision 2 Joystick", 4, 1, 0 }, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
66 { "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
|
67 { "Saitek Saitek X45", 6, 1, 0 } |
0 | 68 }; |
69 | |
70 /* The maximum number of joysticks we'll detect */ | |
71 #define MAX_JOYSTICKS 32 | |
72 | |
73 /* A list of available joysticks */ | |
74 static char *SDL_joylist[MAX_JOYSTICKS]; | |
75 | |
76 /* The private structure used to keep track of a joystick */ | |
77 struct joystick_hwdata { | |
78 int fd; | |
79 /* The current linux joystick driver maps hats to two axes */ | |
80 struct hwdata_hat { | |
81 int axis[2]; | |
82 } *hats; | |
83 /* The current linux joystick driver maps balls to two axes */ | |
84 struct hwdata_ball { | |
85 int axis[2]; | |
86 } *balls; | |
87 | |
88 /* Support for the Linux 2.4 unified input interface */ | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
89 #ifdef USE_INPUT_EVENTS |
0 | 90 SDL_bool is_hid; |
91 Uint8 key_map[KEY_MAX-BTN_MISC]; | |
92 Uint8 abs_map[ABS_MAX]; | |
93 struct axis_correct { | |
94 int used; | |
95 int coef[3]; | |
96 } abs_correct[ABS_MAX]; | |
97 #endif | |
98 }; | |
99 | |
100 static char *mystrdup(const char *string) | |
101 { | |
102 char *newstring; | |
103 | |
104 newstring = (char *)malloc(strlen(string)+1); | |
105 if ( newstring ) { | |
106 strcpy(newstring, string); | |
107 } | |
108 return(newstring); | |
109 } | |
110 | |
111 #ifdef USE_INPUT_EVENTS | |
112 #define test_bit(nr, addr) \ | |
113 (((1UL << ((nr) & 31)) & (((const unsigned int *) addr)[(nr) >> 5])) != 0) | |
114 | |
115 static int EV_IsJoystick(int fd) | |
116 { | |
117 unsigned long evbit[40]; | |
118 unsigned long keybit[40]; | |
119 unsigned long absbit[40]; | |
120 | |
121 if ( (ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) || | |
122 (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) || | |
123 (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0) ) { | |
124 return(0); | |
125 } | |
126 if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) && | |
127 test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit) && | |
128 (test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_A, keybit) || test_bit(BTN_1, keybit)))) return 0; | |
129 return(1); | |
130 } | |
131 | |
132 #endif /* USE_INPUT_EVENTS */ | |
133 | |
134 /* Function to scan the system for joysticks */ | |
135 int SDL_SYS_JoystickInit(void) | |
136 { | |
137 /* The base path of the joystick devices */ | |
245
ab781a7dd82f
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
221
diff
changeset
|
138 const char *joydev_pattern[] = { |
0 | 139 #ifdef USE_INPUT_EVENTS |
245
ab781a7dd82f
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
221
diff
changeset
|
140 "/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
|
141 #endif |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
142 "/dev/input/js%d", |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
143 "/dev/js%d" |
0 | 144 }; |
145 int numjoysticks; | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
146 int i, j; |
0 | 147 int fd; |
148 char path[PATH_MAX]; | |
149 dev_t dev_nums[MAX_JOYSTICKS]; /* major/minor device numbers */ | |
150 struct stat sb; | |
151 int n, duplicate; | |
152 | |
153 numjoysticks = 0; | |
154 | |
155 /* First see if the user specified a joystick to use */ | |
156 if ( getenv("SDL_JOYSTICK_DEVICE") != NULL ) { | |
157 strncpy(path, getenv("SDL_JOYSTICK_DEVICE"), sizeof(path)); | |
158 path[sizeof(path)-1] = '\0'; | |
159 if ( stat(path, &sb) == 0 ) { | |
160 fd = open(path, O_RDONLY, 0); | |
161 if ( fd >= 0 ) { | |
162 /* Assume the user knows what they're doing. */ | |
163 SDL_joylist[numjoysticks] = mystrdup(path); | |
164 if ( SDL_joylist[numjoysticks] ) { | |
165 dev_nums[numjoysticks] = sb.st_rdev; | |
166 ++numjoysticks; | |
167 } | |
168 close(fd); | |
169 } | |
170 } | |
171 } | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
172 |
0 | 173 for ( i=0; i<SDL_TABLESIZE(joydev_pattern); ++i ) { |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
174 for ( j=0; j < MAX_JOYSTICKS; ++j ) { |
0 | 175 sprintf(path, joydev_pattern[i], j); |
176 | |
177 /* rcg06302000 replaced access(F_OK) call with stat(). | |
178 * stat() will fail if the file doesn't exist, so it's | |
179 * equivalent behaviour. | |
180 */ | |
181 if ( stat(path, &sb) == 0 ) { | |
182 /* Check to make sure it's not already in list. | |
183 * This happens when we see a stick via symlink. | |
184 */ | |
185 duplicate = 0; | |
186 for (n=0; (n<numjoysticks) && !duplicate; ++n) { | |
187 if ( sb.st_rdev == dev_nums[n] ) { | |
188 duplicate = 1; | |
189 } | |
190 } | |
191 if (duplicate) { | |
192 continue; | |
193 } | |
194 | |
195 fd = open(path, O_RDONLY, 0); | |
196 if ( fd < 0 ) { | |
197 continue; | |
198 } | |
199 #ifdef USE_INPUT_EVENTS | |
200 #ifdef DEBUG_INPUT_EVENTS | |
201 printf("Checking %s\n", path); | |
202 #endif | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
203 if ( (i == 0) && ! EV_IsJoystick(fd) ) { |
0 | 204 close(fd); |
205 continue; | |
206 } | |
207 #endif | |
208 close(fd); | |
209 | |
210 /* We're fine, add this joystick */ | |
211 SDL_joylist[numjoysticks] = mystrdup(path); | |
212 if ( SDL_joylist[numjoysticks] ) { | |
213 dev_nums[numjoysticks] = sb.st_rdev; | |
214 ++numjoysticks; | |
215 } | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
216 } else |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
217 break; |
0 | 218 } |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
219 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
220 #ifdef USE_INPUT_EVENTS |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
221 /* This is a special case... |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
228 if ( (i == 0) && (numjoysticks > 0) ) |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
229 break; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
230 #endif |
0 | 231 } |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
232 |
0 | 233 return(numjoysticks); |
234 } | |
235 | |
236 /* Function to get the device-dependent name of a joystick */ | |
237 const char *SDL_SYS_JoystickName(int index) | |
238 { | |
239 int fd; | |
240 static char namebuf[128]; | |
241 char *name; | |
242 | |
243 name = NULL; | |
244 fd = open(SDL_joylist[index], O_RDONLY, 0); | |
245 if ( fd >= 0 ) { | |
246 if ( | |
247 #ifdef USE_INPUT_EVENTS | |
248 (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) && | |
249 #endif | |
250 (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0) ) { | |
251 name = SDL_joylist[index]; | |
252 } else { | |
253 name = namebuf; | |
254 } | |
255 close(fd); | |
256 } | |
257 return name; | |
258 } | |
259 | |
260 static int allocate_hatdata(SDL_Joystick *joystick) | |
261 { | |
262 int i; | |
263 | |
264 joystick->hwdata->hats = (struct hwdata_hat *)malloc( | |
265 joystick->nhats * sizeof(struct hwdata_hat)); | |
266 if ( joystick->hwdata->hats == NULL ) { | |
267 return(-1); | |
268 } | |
269 for ( i=0; i<joystick->nhats; ++i ) { | |
270 joystick->hwdata->hats[i].axis[0] = 1; | |
271 joystick->hwdata->hats[i].axis[1] = 1; | |
272 } | |
273 return(0); | |
274 } | |
275 | |
276 static int allocate_balldata(SDL_Joystick *joystick) | |
277 { | |
278 int i; | |
279 | |
280 joystick->hwdata->balls = (struct hwdata_ball *)malloc( | |
281 joystick->nballs * sizeof(struct hwdata_ball)); | |
282 if ( joystick->hwdata->balls == NULL ) { | |
283 return(-1); | |
284 } | |
285 for ( i=0; i<joystick->nballs; ++i ) { | |
286 joystick->hwdata->balls[i].axis[0] = 0; | |
287 joystick->hwdata->balls[i].axis[1] = 0; | |
288 } | |
289 return(0); | |
290 } | |
291 | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
292 static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick, int fd) |
0 | 293 { |
294 SDL_bool handled; | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
295 unsigned char n; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
296 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
|
297 const char *name; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
298 char *env, env_name[128]; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
299 int i; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
300 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
301 handled = SDL_FALSE; |
0 | 302 |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
303 /* Default joystick device settings */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
304 if ( ioctl(fd, JSIOCGAXES, &n) < 0 ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
305 joystick->naxes = 2; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
306 } else { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
307 joystick->naxes = n; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
308 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
309 if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
310 joystick->nbuttons = 2; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
311 } else { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
312 joystick->nbuttons = n; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
313 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
314 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
315 name = SDL_SYS_JoystickName(joystick->index); |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
316 old_axes = joystick->naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
317 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
318 /* Generic analog joystick support */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
319 if ( strstr(name, "Analog") == name && strstr(name, "-hat") ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
320 if ( sscanf(name,"Analog %d-axis %*d-button %d-hat", |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
321 &tmp_naxes, &tmp_nhats) == 2 ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
322 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
323 joystick->naxes = tmp_naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
324 joystick->nhats = tmp_nhats; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
325 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
326 handled = SDL_TRUE; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
327 } |
0 | 328 } |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
329 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
330 /* Special joystick support */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
331 for ( i=0; i < SDL_TABLESIZE(special_joysticks); ++i ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
332 if ( strcmp(name, special_joysticks[i].name) == 0 ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
333 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
334 joystick->naxes = special_joysticks[i].naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
335 joystick->nhats = special_joysticks[i].nhats; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
336 joystick->nballs = special_joysticks[i].nballs; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
337 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
338 handled = SDL_TRUE; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
339 break; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
340 } |
0 | 341 } |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
342 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
343 /* User environment joystick support */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
344 if ( (env = getenv("SDL_LINUX_JOYSTICK")) ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
345 strcpy(env_name, ""); |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
346 if ( *env == '\'' && sscanf(env, "'%[^']s'", env_name) == 1 ) |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
347 env += strlen(env_name)+2; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
348 else if ( sscanf(env, "%s", env_name) == 1 ) |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
349 env += strlen(env_name); |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
350 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
351 if ( strcmp(name, env_name) == 0 ) { |
0 | 352 |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
353 if ( sscanf(env, "%d %d %d", &tmp_naxes, &tmp_nhats, |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
354 &tmp_nballs) == 3 ) { |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
355 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
356 joystick->naxes = tmp_naxes; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
357 joystick->nhats = tmp_nhats; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
358 joystick->nballs = tmp_nballs; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
359 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
360 handled = SDL_TRUE; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
361 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
362 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
363 } |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
364 |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
365 /* Remap hats and balls */ |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
366 if (handled) { |
0 | 367 if ( joystick->nhats > 0 ) { |
589
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
368 if ( allocate_hatdata(joystick) < 0 ) { |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
369 joystick->nhats = 0; |
0 | 370 } |
371 } | |
372 if ( joystick->nballs > 0 ) { | |
373 if ( allocate_balldata(joystick) < 0 ) { | |
374 joystick->nballs = 0; | |
375 } | |
376 } | |
377 } | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
378 |
0 | 379 return(handled); |
380 } | |
381 | |
382 #ifdef USE_INPUT_EVENTS | |
383 | |
384 static SDL_bool EV_ConfigJoystick(SDL_Joystick *joystick, int fd) | |
385 { | |
871 | 386 int i, t; |
0 | 387 unsigned long keybit[40]; |
388 unsigned long absbit[40]; | |
389 unsigned long relbit[40]; | |
390 | |
391 /* See if this device uses the new unified event API */ | |
392 if ( (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) && | |
393 (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) && | |
394 (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0) ) { | |
395 joystick->hwdata->is_hid = SDL_TRUE; | |
396 | |
397 /* Get the number of buttons, axes, and other thingamajigs */ | |
398 for ( i=BTN_JOYSTICK; i < KEY_MAX; ++i ) { | |
399 if ( test_bit(i, keybit) ) { | |
400 #ifdef DEBUG_INPUT_EVENTS | |
401 printf("Joystick has button: 0x%x\n", i); | |
402 #endif | |
403 joystick->hwdata->key_map[i-BTN_MISC] = | |
404 joystick->nbuttons; | |
405 ++joystick->nbuttons; | |
406 } | |
407 } | |
408 for ( i=BTN_MISC; i < BTN_JOYSTICK; ++i ) { | |
409 if ( test_bit(i, keybit) ) { | |
410 #ifdef DEBUG_INPUT_EVENTS | |
411 printf("Joystick has button: 0x%x\n", i); | |
412 #endif | |
413 joystick->hwdata->key_map[i-BTN_MISC] = | |
414 joystick->nbuttons; | |
415 ++joystick->nbuttons; | |
416 } | |
417 } | |
418 for ( i=0; i<ABS_MAX; ++i ) { | |
419 /* Skip hats */ | |
420 if ( i == ABS_HAT0X ) { | |
421 i = ABS_HAT3Y; | |
422 continue; | |
423 } | |
424 if ( test_bit(i, absbit) ) { | |
425 int values[5]; | |
426 | |
427 ioctl(fd, EVIOCGABS(i), values); | |
428 #ifdef DEBUG_INPUT_EVENTS | |
429 printf("Joystick has absolute axis: %x\n", i); | |
430 printf("Values = { %d, %d, %d, %d, %d }\n", | |
431 values[0], values[1], | |
432 values[2], values[3], values[4]); | |
433 #endif /* DEBUG_INPUT_EVENTS */ | |
434 joystick->hwdata->abs_map[i] = joystick->naxes; | |
435 if ( values[1] == values[2] ) { | |
436 joystick->hwdata->abs_correct[i].used = 0; | |
437 } else { | |
438 joystick->hwdata->abs_correct[i].used = 1; | |
871 | 439 t = (2 - values[4]); |
440 if ( t != 0 ) { | |
441 joystick->hwdata->abs_correct[i].coef[0] = (values[2] + values[1]) / t; | |
442 } | |
443 t = (2 + values[4]); | |
444 if ( t != 0 ) { | |
445 joystick->hwdata->abs_correct[i].coef[1] = (values[2] + values[1]) / t; | |
446 } | |
447 t = ((values[2] - values[1]) / 2 - 2 * values[4]); | |
448 if ( t != 0 ) { | |
449 joystick->hwdata->abs_correct[i].coef[2] = (1 << 29) / t; | |
450 } | |
0 | 451 } |
452 ++joystick->naxes; | |
453 } | |
454 } | |
455 for ( i=ABS_HAT0X; i <= ABS_HAT3Y; i += 2 ) { | |
456 if ( test_bit(i, absbit) || test_bit(i+1, absbit) ) { | |
457 #ifdef DEBUG_INPUT_EVENTS | |
458 printf("Joystick has hat %d\n",(i-ABS_HAT0X)/2); | |
459 #endif | |
460 ++joystick->nhats; | |
461 } | |
462 } | |
463 if ( test_bit(REL_X, relbit) || test_bit(REL_Y, relbit) ) { | |
464 ++joystick->nballs; | |
465 } | |
466 | |
467 /* Allocate data to keep track of these thingamajigs */ | |
468 if ( joystick->nhats > 0 ) { | |
469 if ( allocate_hatdata(joystick) < 0 ) { | |
470 joystick->nhats = 0; | |
471 } | |
472 } | |
473 if ( joystick->nballs > 0 ) { | |
474 if ( allocate_balldata(joystick) < 0 ) { | |
475 joystick->nballs = 0; | |
476 } | |
477 } | |
478 } | |
479 return(joystick->hwdata->is_hid); | |
480 } | |
481 | |
482 #endif /* USE_INPUT_EVENTS */ | |
483 | |
484 /* Function to open a joystick for use. | |
485 The joystick to open is specified by the index field of the joystick. | |
486 This should fill the nbuttons and naxes fields of the joystick structure. | |
487 It returns 0, or -1 if there is an error. | |
488 */ | |
489 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) | |
490 { | |
491 int fd; | |
492 | |
493 /* Open the joystick and set the joystick file descriptor */ | |
494 fd = open(SDL_joylist[joystick->index], O_RDONLY, 0); | |
495 if ( fd < 0 ) { | |
496 SDL_SetError("Unable to open %s\n", | |
497 SDL_joylist[joystick->index]); | |
498 return(-1); | |
499 } | |
500 joystick->hwdata = (struct joystick_hwdata *) | |
501 malloc(sizeof(*joystick->hwdata)); | |
502 if ( joystick->hwdata == NULL ) { | |
503 SDL_OutOfMemory(); | |
504 close(fd); | |
505 return(-1); | |
506 } | |
507 memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); | |
508 joystick->hwdata->fd = fd; | |
509 | |
510 /* Set the joystick to non-blocking read mode */ | |
511 fcntl(fd, F_SETFL, O_NONBLOCK); | |
512 | |
513 /* Get the number of buttons and axes on the joystick */ | |
514 #ifdef USE_INPUT_EVENTS | |
515 if ( ! EV_ConfigJoystick(joystick, fd) ) | |
516 #endif | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
517 JS_ConfigJoystick(joystick, fd); |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
518 |
0 | 519 return(0); |
520 } | |
521 | |
522 static __inline__ | |
523 void HandleHat(SDL_Joystick *stick, Uint8 hat, int axis, int value) | |
524 { | |
525 struct hwdata_hat *the_hat; | |
526 const Uint8 position_map[3][3] = { | |
527 { SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP }, | |
528 { SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT }, | |
529 { SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN } | |
530 }; | |
531 | |
532 the_hat = &stick->hwdata->hats[hat]; | |
533 if ( value < 0 ) { | |
534 value = 0; | |
535 } else | |
536 if ( value == 0 ) { | |
537 value = 1; | |
538 } else | |
539 if ( value > 0 ) { | |
540 value = 2; | |
541 } | |
542 if ( value != the_hat->axis[axis] ) { | |
543 the_hat->axis[axis] = value; | |
544 SDL_PrivateJoystickHat(stick, hat, | |
545 position_map[the_hat->axis[1]][the_hat->axis[0]]); | |
546 } | |
547 } | |
548 | |
549 static __inline__ | |
550 void HandleBall(SDL_Joystick *stick, Uint8 ball, int axis, int value) | |
551 { | |
552 stick->hwdata->balls[ball].axis[axis] += value; | |
553 } | |
554 | |
555 /* Function to update the state of a joystick - called as a device poll. | |
556 * This function shouldn't update the joystick structure directly, | |
557 * but instead should call SDL_PrivateJoystick*() to deliver events | |
558 * and update joystick device state. | |
559 */ | |
560 static __inline__ void JS_HandleEvents(SDL_Joystick *joystick) | |
561 { | |
562 struct js_event events[32]; | |
563 int i, len; | |
564 Uint8 other_axis; | |
565 | |
566 while ((len=read(joystick->hwdata->fd, events, (sizeof events))) > 0) { | |
567 len /= sizeof(events[0]); | |
568 for ( i=0; i<len; ++i ) { | |
569 switch (events[i].type & ~JS_EVENT_INIT) { | |
570 case JS_EVENT_AXIS: | |
571 if ( events[i].number < joystick->naxes ) { | |
572 SDL_PrivateJoystickAxis(joystick, | |
573 events[i].number, events[i].value); | |
574 break; | |
575 } | |
576 events[i].number -= joystick->naxes; | |
589
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
577 other_axis = (events[i].number / 2); |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
578 if ( other_axis < joystick->nhats ) { |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
579 HandleHat(joystick, other_axis, |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
580 events[i].number%2, |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
581 events[i].value); |
2e58ece48b61
Removed obsolete Linux joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
554
diff
changeset
|
582 break; |
0 | 583 } |
584 events[i].number -= joystick->nhats*2; | |
585 other_axis = (events[i].number / 2); | |
586 if ( other_axis < joystick->nballs ) { | |
587 HandleBall(joystick, other_axis, | |
588 events[i].number%2, | |
589 events[i].value); | |
590 break; | |
591 } | |
592 break; | |
593 case JS_EVENT_BUTTON: | |
594 SDL_PrivateJoystickButton(joystick, | |
595 events[i].number, events[i].value); | |
596 break; | |
597 default: | |
598 /* ?? */ | |
599 break; | |
600 } | |
601 } | |
602 } | |
603 } | |
604 #ifdef USE_INPUT_EVENTS | |
605 static __inline__ int EV_AxisCorrect(SDL_Joystick *joystick, int which, int value) | |
606 { | |
607 struct axis_correct *correct; | |
608 | |
609 correct = &joystick->hwdata->abs_correct[which]; | |
610 if ( correct->used ) { | |
611 if ( value > correct->coef[0] ) { | |
612 if ( value < correct->coef[1] ) { | |
613 return 0; | |
614 } | |
615 value -= correct->coef[1]; | |
616 } else { | |
617 value -= correct->coef[0]; | |
618 } | |
619 value *= correct->coef[2]; | |
620 value >>= 14; | |
621 } | |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
622 |
0 | 623 /* Clamp and return */ |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
624 if ( value < -32767 ) return -32767; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
625 if ( value > 32767 ) return 32767; |
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
626 |
0 | 627 return value; |
628 } | |
629 | |
630 static __inline__ void EV_HandleEvents(SDL_Joystick *joystick) | |
631 { | |
632 struct input_event events[32]; | |
633 int i, len; | |
634 int code; | |
635 | |
636 while ((len=read(joystick->hwdata->fd, events, (sizeof events))) > 0) { | |
637 len /= sizeof(events[0]); | |
638 for ( i=0; i<len; ++i ) { | |
639 code = events[i].code; | |
640 switch (events[i].type) { | |
641 case EV_KEY: | |
642 if ( code >= BTN_MISC ) { | |
643 code -= BTN_MISC; | |
644 SDL_PrivateJoystickButton(joystick, | |
645 joystick->hwdata->key_map[code], | |
646 events[i].value); | |
647 } | |
648 break; | |
649 case EV_ABS: | |
650 switch (code) { | |
651 case ABS_HAT0X: | |
652 case ABS_HAT0Y: | |
653 case ABS_HAT1X: | |
654 case ABS_HAT1Y: | |
655 case ABS_HAT2X: | |
656 case ABS_HAT2Y: | |
657 case ABS_HAT3X: | |
658 case ABS_HAT3Y: | |
659 code -= ABS_HAT0X; | |
660 HandleHat(joystick, code/2, code%2, | |
661 events[i].value); | |
662 break; | |
663 default: | |
664 events[i].value = EV_AxisCorrect(joystick, code, events[i].value); | |
665 SDL_PrivateJoystickAxis(joystick, | |
666 joystick->hwdata->abs_map[code], | |
667 events[i].value); | |
668 break; | |
669 } | |
670 break; | |
671 case EV_REL: | |
672 switch (code) { | |
673 case REL_X: | |
674 case REL_Y: | |
675 code -= REL_X; | |
676 HandleBall(joystick, code/2, code%2, | |
677 events[i].value); | |
678 break; | |
679 default: | |
680 break; | |
681 } | |
682 break; | |
683 default: | |
684 break; | |
685 } | |
686 } | |
687 } | |
688 } | |
689 #endif /* USE_INPUT_EVENTS */ | |
690 | |
691 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) | |
692 { | |
693 int i; | |
694 | |
695 #ifdef USE_INPUT_EVENTS | |
696 if ( joystick->hwdata->is_hid ) | |
697 EV_HandleEvents(joystick); | |
698 else | |
699 #endif | |
700 JS_HandleEvents(joystick); | |
701 | |
702 /* Deliver ball motion updates */ | |
703 for ( i=0; i<joystick->nballs; ++i ) { | |
704 int xrel, yrel; | |
705 | |
706 xrel = joystick->hwdata->balls[i].axis[0]; | |
707 yrel = joystick->hwdata->balls[i].axis[1]; | |
708 if ( xrel || yrel ) { | |
709 joystick->hwdata->balls[i].axis[0] = 0; | |
710 joystick->hwdata->balls[i].axis[1] = 0; | |
711 SDL_PrivateJoystickBall(joystick, (Uint8)i, xrel, yrel); | |
712 } | |
713 } | |
714 } | |
715 | |
716 /* Function to close a joystick after use */ | |
717 void SDL_SYS_JoystickClose(SDL_Joystick *joystick) | |
718 { | |
719 if ( joystick->hwdata ) { | |
720 close(joystick->hwdata->fd); | |
721 if ( joystick->hwdata->hats ) { | |
722 free(joystick->hwdata->hats); | |
723 } | |
724 if ( joystick->hwdata->balls ) { | |
725 free(joystick->hwdata->balls); | |
726 } | |
727 free(joystick->hwdata); | |
728 joystick->hwdata = NULL; | |
729 } | |
730 } | |
731 | |
732 /* Function to perform any system-specific joystick related cleanup */ | |
733 void SDL_SYS_JoystickQuit(void) | |
734 { | |
735 int i; | |
736 | |
737 for ( i=0; SDL_joylist[i]; ++i ) { | |
738 free(SDL_joylist[i]); | |
739 } | |
740 SDL_joylist[0] = NULL; | |
741 } | |
742 |