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