annotate src/joystick/linux/SDL_sysjoystick.c @ 1379:c0a74f199ecf

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