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