annotate src/joystick/linux/SDL_sysjoystick.c @ 927:c5689bd09eaa

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