annotate src/joystick/linux/SDL_sysjoystick.c @ 1336:3692456e7b0f

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