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