annotate src/joystick/linux/SDL_sysjoystick.c @ 1338:604d73db6802

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