author | Sam Lantinga <slouken@libsdl.org> |
Fri, 26 Aug 2016 12:18:08 -0700 | |
changeset 10281 | cb13d22b7f09 |
parent 10280 | 3134026517cb |
permissions | -rw-r--r-- |
0 | 1 |
/* |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
2 |
Simple DirectMedia Layer |
9998
f67cf37e9cd4
Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents:
9630
diff
changeset
|
3 |
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
0 | 4 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
7 |
arising from the use of this software. |
0 | 8 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
11 |
freely, subject to the following restrictions: |
0 | 12 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
16 |
appreciated but is not required. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
18 |
misrepresented as being the original software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5317
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
0 | 20 |
*/ |
8093
b43765095a6f
Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents:
8053
diff
changeset
|
21 |
#include "../../SDL_internal.h" |
0 | 22 |
|
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1551
diff
changeset
|
23 |
#ifdef SDL_JOYSTICK_LINUX |
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1551
diff
changeset
|
24 |
|
6729
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
25 |
#ifndef SDL_INPUT_LINUXEV |
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
26 |
#error SDL now requires a Linux 2.4+ kernel with /dev/input/event support. |
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
27 |
#endif |
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
28 |
|
8138
0fbc97d82043
Fixed comments in joystick implementation files claiming to be headers.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
8093
diff
changeset
|
29 |
/* This is the Linux implementation of the SDL joystick API */ |
0 | 30 |
|
31 |
#include <sys/stat.h> |
|
32 |
#include <unistd.h> |
|
33 |
#include <fcntl.h> |
|
34 |
#include <sys/ioctl.h> |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
35 |
#include <limits.h> /* For the definition of PATH_MAX */ |
0 | 36 |
#include <linux/joystick.h> |
37 |
||
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
38 |
#include "SDL_assert.h" |
0 | 39 |
#include "SDL_joystick.h" |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
40 |
#include "SDL_endian.h" |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
41 |
#include "../SDL_sysjoystick.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
42 |
#include "../SDL_joystick_c.h" |
2713
0906692aa6a4
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2285
diff
changeset
|
43 |
#include "SDL_sysjoystick_c.h" |
0 | 44 |
|
6910
a3d4fd1ba315
Fixed compiling on older Linux systems without libudev
Sam Lantinga <slouken@libsdl.org>
parents:
6885
diff
changeset
|
45 |
/* This isn't defined in older Linux kernel headers */ |
a3d4fd1ba315
Fixed compiling on older Linux systems without libudev
Sam Lantinga <slouken@libsdl.org>
parents:
6885
diff
changeset
|
46 |
#ifndef SYN_DROPPED |
a3d4fd1ba315
Fixed compiling on older Linux systems without libudev
Sam Lantinga <slouken@libsdl.org>
parents:
6885
diff
changeset
|
47 |
#define SYN_DROPPED 3 |
a3d4fd1ba315
Fixed compiling on older Linux systems without libudev
Sam Lantinga <slouken@libsdl.org>
parents:
6885
diff
changeset
|
48 |
#endif |
a3d4fd1ba315
Fixed compiling on older Linux systems without libudev
Sam Lantinga <slouken@libsdl.org>
parents:
6885
diff
changeset
|
49 |
|
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
50 |
#include "../../core/linux/SDL_udev.h" |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
51 |
|
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
52 |
static int MaybeAddDevice(const char *path); |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
53 |
#if SDL_USE_LIBUDEV |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
54 |
static int MaybeRemoveDevice(const char *path); |
7788
25355ecf10aa
Fixed bug where a Logitech wireless keyboard with built-in mouse touchpad didn't get recongized as both devices.
Sam Lantinga <slouken@libsdl.org>
parents:
7772
diff
changeset
|
55 |
void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath); |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
56 |
#endif /* SDL_USE_LIBUDEV */ |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
57 |
|
0 | 58 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
59 |
/* A linked list of available joysticks */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
60 |
typedef struct SDL_joylist_item |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
61 |
{ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
62 |
int device_instance; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
63 |
char *path; /* "/dev/input/event2" or whatever */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
64 |
char *name; /* "SideWinder 3D Pro" or whatever */ |
6743
1835c3299b2a
Fixed compiling Linux code
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
65 |
SDL_JoystickGUID guid; |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
66 |
dev_t devnum; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
67 |
struct joystick_hwdata *hwdata; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
68 |
struct SDL_joylist_item *next; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
69 |
} SDL_joylist_item; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
70 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
71 |
static SDL_joylist_item *SDL_joylist = NULL; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
72 |
static SDL_joylist_item *SDL_joylist_tail = NULL; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
73 |
static int numjoysticks = 0; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
74 |
static int instance_counter = 0; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
75 |
|
0 | 76 |
#define test_bit(nr, addr) \ |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
77 |
(((1UL << ((nr) % (sizeof(long) * 8))) & ((addr)[(nr) / (sizeof(long) * 8)])) != 0) |
3404 | 78 |
#define NBITS(x) ((((x)-1)/(sizeof(long) * 8))+1) |
0 | 79 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
80 |
static int |
6743
1835c3299b2a
Fixed compiling Linux code
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
81 |
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid) |
0 | 82 |
{ |
7909
4434ab25abf3
Fixes Bug 1944 - Linux events, joysticks having only hat are not read
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7860
diff
changeset
|
83 |
struct input_id inpid; |
4434ab25abf3
Fixes Bug 1944 - Linux events, joysticks having only hat are not read
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7860
diff
changeset
|
84 |
Uint16 *guid16 = (Uint16 *) ((char *) &guid->data); |
4434ab25abf3
Fixes Bug 1944 - Linux events, joysticks having only hat are not read
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7860
diff
changeset
|
85 |
|
4434ab25abf3
Fixes Bug 1944 - Linux events, joysticks having only hat are not read
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7860
diff
changeset
|
86 |
#if !SDL_USE_LIBUDEV |
4434ab25abf3
Fixes Bug 1944 - Linux events, joysticks having only hat are not read
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7860
diff
changeset
|
87 |
/* When udev is enabled we only get joystick devices here, so there's no need to test them */ |
3404 | 88 |
unsigned long evbit[NBITS(EV_MAX)] = { 0 }; |
89 |
unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; |
|
90 |
unsigned long absbit[NBITS(ABS_MAX)] = { 0 }; |
|
0 | 91 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
92 |
if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) || |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
93 |
(ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) || |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
94 |
(ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
95 |
return (0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
96 |
} |
3079
cfc8b35ad6b1
Fixed haptic subsystem on linux 2.6.28 by lowering the EV_IsJoystick check (seems like some stuff was changed). Shouldn't break anything with earlier versions. Might need to be more robust if false positives show up.
Edgar Simo <bobbens@gmail.com>
parents:
3022
diff
changeset
|
97 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
98 |
if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) && |
3079
cfc8b35ad6b1
Fixed haptic subsystem on linux 2.6.28 by lowering the EV_IsJoystick check (seems like some stuff was changed). Shouldn't break anything with earlier versions. Might need to be more robust if false positives show up.
Edgar Simo <bobbens@gmail.com>
parents:
3022
diff
changeset
|
99 |
test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
100 |
return 0; |
3079
cfc8b35ad6b1
Fixed haptic subsystem on linux 2.6.28 by lowering the EV_IsJoystick check (seems like some stuff was changed). Shouldn't break anything with earlier versions. Might need to be more robust if false positives show up.
Edgar Simo <bobbens@gmail.com>
parents:
3022
diff
changeset
|
101 |
} |
7909
4434ab25abf3
Fixes Bug 1944 - Linux events, joysticks having only hat are not read
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7860
diff
changeset
|
102 |
#endif |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
103 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
104 |
if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
105 |
return 0; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
106 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
107 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
108 |
if (ioctl(fd, EVIOCGID, &inpid) < 0) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
109 |
return 0; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
110 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
111 |
|
6831
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
112 |
#ifdef DEBUG_JOYSTICK |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
113 |
printf("Joystick: %s, bustype = %d, vendor = 0x%x, product = 0x%x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version); |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
114 |
#endif |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
115 |
|
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
116 |
SDL_memset(guid->data, 0, sizeof(guid->data)); |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
117 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
118 |
/* We only need 16 bits for each of these; space them out to fill 128. */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
119 |
/* Byteswap so devices get same GUID on little/big endian platforms. */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
120 |
*(guid16++) = SDL_SwapLE16(inpid.bustype); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
121 |
*(guid16++) = 0; |
6831
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
122 |
|
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
123 |
if (inpid.vendor && inpid.product && inpid.version) { |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
124 |
*(guid16++) = SDL_SwapLE16(inpid.vendor); |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
125 |
*(guid16++) = 0; |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
126 |
*(guid16++) = SDL_SwapLE16(inpid.product); |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
127 |
*(guid16++) = 0; |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
128 |
*(guid16++) = SDL_SwapLE16(inpid.version); |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
129 |
*(guid16++) = 0; |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
130 |
} else { |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
131 |
SDL_strlcpy((char*)guid16, namebuf, sizeof(guid->data) - 4); |
935b871e1ffe
Fixed setting the GUID for Bluetooth joysticks
Sam Lantinga <slouken@libsdl.org>
parents:
6754
diff
changeset
|
132 |
} |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
133 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
134 |
return 1; |
0 | 135 |
} |
136 |
||
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
137 |
#if SDL_USE_LIBUDEV |
7788
25355ecf10aa
Fixed bug where a Logitech wireless keyboard with built-in mouse touchpad didn't get recongized as both devices.
Sam Lantinga <slouken@libsdl.org>
parents:
7772
diff
changeset
|
138 |
void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath) |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
139 |
{ |
9321
01966f6feadc
Fixed game controller hotplug support for some embedded Linux devices
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
140 |
if (devpath == NULL) { |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
141 |
return; |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
142 |
} |
9321
01966f6feadc
Fixed game controller hotplug support for some embedded Linux devices
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
143 |
|
01966f6feadc
Fixed game controller hotplug support for some embedded Linux devices
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
144 |
switch (udev_type) { |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
145 |
case SDL_UDEV_DEVICEADDED: |
9321
01966f6feadc
Fixed game controller hotplug support for some embedded Linux devices
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
146 |
if (!(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) { |
01966f6feadc
Fixed game controller hotplug support for some embedded Linux devices
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
147 |
return; |
01966f6feadc
Fixed game controller hotplug support for some embedded Linux devices
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
148 |
} |
7802
d239ba573818
Report joystick added/removed events even if we don't have udev.
Sam Lantinga <slouken@libsdl.org>
parents:
7788
diff
changeset
|
149 |
MaybeAddDevice(devpath); |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
150 |
break; |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
151 |
|
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
152 |
case SDL_UDEV_DEVICEREMOVED: |
7802
d239ba573818
Report joystick added/removed events even if we don't have udev.
Sam Lantinga <slouken@libsdl.org>
parents:
7788
diff
changeset
|
153 |
MaybeRemoveDevice(devpath); |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
154 |
break; |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
155 |
|
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
156 |
default: |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
157 |
break; |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
158 |
} |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
159 |
|
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
160 |
} |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
161 |
#endif /* SDL_USE_LIBUDEV */ |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
162 |
|
0 | 163 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
164 |
/* !!! FIXME: I would love to dump this code and use libudev instead. */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
165 |
static int |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
166 |
MaybeAddDevice(const char *path) |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
167 |
{ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
168 |
struct stat sb; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
169 |
int fd = -1; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
170 |
int isstick = 0; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
171 |
char namebuf[128]; |
6743
1835c3299b2a
Fixed compiling Linux code
Sam Lantinga <slouken@libsdl.org>
parents:
6738
diff
changeset
|
172 |
SDL_JoystickGUID guid; |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
173 |
SDL_joylist_item *item; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
174 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
175 |
if (path == NULL) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
176 |
return -1; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
177 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
178 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
179 |
if (stat(path, &sb) == -1) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
180 |
return -1; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
181 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
182 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
183 |
/* Check to make sure it's not already in list. */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
184 |
for (item = SDL_joylist; item != NULL; item = item->next) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
185 |
if (sb.st_rdev == item->devnum) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
186 |
return -1; /* already have this one */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
187 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
188 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
189 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
190 |
fd = open(path, O_RDONLY, 0); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
191 |
if (fd < 0) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
192 |
return -1; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
193 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
194 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
195 |
#ifdef DEBUG_INPUT_EVENTS |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
196 |
printf("Checking %s\n", path); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
197 |
#endif |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
198 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
199 |
isstick = IsJoystick(fd, namebuf, sizeof (namebuf), &guid); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
200 |
close(fd); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
201 |
if (!isstick) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
202 |
return -1; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
203 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
204 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
205 |
item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item)); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
206 |
if (item == NULL) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
207 |
return -1; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
208 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
209 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
210 |
SDL_zerop(item); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
211 |
item->devnum = sb.st_rdev; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
212 |
item->path = SDL_strdup(path); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
213 |
item->name = SDL_strdup(namebuf); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
214 |
item->guid = guid; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
215 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
216 |
if ( (item->path == NULL) || (item->name == NULL) ) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
217 |
SDL_free(item->path); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
218 |
SDL_free(item->name); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
219 |
SDL_free(item); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
220 |
return -1; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
221 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
222 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
223 |
item->device_instance = instance_counter++; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
224 |
if (SDL_joylist_tail == NULL) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
225 |
SDL_joylist = SDL_joylist_tail = item; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
226 |
} else { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
227 |
SDL_joylist_tail->next = item; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
228 |
SDL_joylist_tail = item; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
229 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
230 |
|
7916
8f16728ce87b
Make sure the joystick count is correct when the added and removed events are dispatched, in case someone is watching for them with an event filter.
Sam Lantinga <slouken@libsdl.org>
parents:
7909
diff
changeset
|
231 |
/* Need to increment the joystick count before we post the event */ |
8f16728ce87b
Make sure the joystick count is correct when the added and removed events are dispatched, in case someone is watching for them with an event filter.
Sam Lantinga <slouken@libsdl.org>
parents:
7909
diff
changeset
|
232 |
++numjoysticks; |
8f16728ce87b
Make sure the joystick count is correct when the added and removed events are dispatched, in case someone is watching for them with an event filter.
Sam Lantinga <slouken@libsdl.org>
parents:
7909
diff
changeset
|
233 |
|
10281
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
10280
diff
changeset
|
234 |
SDL_PrivateJoystickAdded(numjoysticks - 1); |
7802
d239ba573818
Report joystick added/removed events even if we don't have udev.
Sam Lantinga <slouken@libsdl.org>
parents:
7788
diff
changeset
|
235 |
|
7916
8f16728ce87b
Make sure the joystick count is correct when the added and removed events are dispatched, in case someone is watching for them with an event filter.
Sam Lantinga <slouken@libsdl.org>
parents:
7909
diff
changeset
|
236 |
return numjoysticks; |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
237 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
238 |
|
6749
87254cb5734f
Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents:
6743
diff
changeset
|
239 |
#if SDL_USE_LIBUDEV |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
240 |
/* !!! FIXME: I would love to dump this code and use libudev instead. */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
241 |
static int |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
242 |
MaybeRemoveDevice(const char *path) |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
243 |
{ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
244 |
SDL_joylist_item *item; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
245 |
SDL_joylist_item *prev = NULL; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
246 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
247 |
if (path == NULL) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
248 |
return -1; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
249 |
} |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6389
diff
changeset
|
250 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
251 |
for (item = SDL_joylist; item != NULL; item = item->next) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
252 |
/* found it, remove it. */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
253 |
if (SDL_strcmp(path, item->path) == 0) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
254 |
const int retval = item->device_instance; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
255 |
if (item->hwdata) { |
6752
8de11011eb1f
Corrected Linux joystick things, fixes assertion failure from testjoystick.
Ryan C. Gordon <icculus@icculus.org>
parents:
6751
diff
changeset
|
256 |
item->hwdata->item = NULL; |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
257 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
258 |
if (prev != NULL) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
259 |
prev->next = item->next; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
260 |
} else { |
6865
670ebd20759d
Fix a corruption when you remove first joystick on Linux.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6852
diff
changeset
|
261 |
SDL_assert(SDL_joylist == item); |
670ebd20759d
Fix a corruption when you remove first joystick on Linux.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6852
diff
changeset
|
262 |
SDL_joylist = item->next; |
670ebd20759d
Fix a corruption when you remove first joystick on Linux.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6852
diff
changeset
|
263 |
} |
670ebd20759d
Fix a corruption when you remove first joystick on Linux.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6852
diff
changeset
|
264 |
if (item == SDL_joylist_tail) { |
670ebd20759d
Fix a corruption when you remove first joystick on Linux.
Jørgen P. Tjernø <jorgen@valvesoftware.com>
parents:
6852
diff
changeset
|
265 |
SDL_joylist_tail = prev; |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
266 |
} |
7802
d239ba573818
Report joystick added/removed events even if we don't have udev.
Sam Lantinga <slouken@libsdl.org>
parents:
7788
diff
changeset
|
267 |
|
7916
8f16728ce87b
Make sure the joystick count is correct when the added and removed events are dispatched, in case someone is watching for them with an event filter.
Sam Lantinga <slouken@libsdl.org>
parents:
7909
diff
changeset
|
268 |
/* Need to decrement the joystick count before we post the event */ |
8f16728ce87b
Make sure the joystick count is correct when the added and removed events are dispatched, in case someone is watching for them with an event filter.
Sam Lantinga <slouken@libsdl.org>
parents:
7909
diff
changeset
|
269 |
--numjoysticks; |
8f16728ce87b
Make sure the joystick count is correct when the added and removed events are dispatched, in case someone is watching for them with an event filter.
Sam Lantinga <slouken@libsdl.org>
parents:
7909
diff
changeset
|
270 |
|
10281
cb13d22b7f09
Added SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved()
Sam Lantinga <slouken@libsdl.org>
parents:
10280
diff
changeset
|
271 |
SDL_PrivateJoystickRemoved(item->device_instance); |
7802
d239ba573818
Report joystick added/removed events even if we don't have udev.
Sam Lantinga <slouken@libsdl.org>
parents:
7788
diff
changeset
|
272 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
273 |
SDL_free(item->path); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
274 |
SDL_free(item->name); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
275 |
SDL_free(item); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
276 |
return retval; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
277 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
278 |
prev = item; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
279 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
280 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
281 |
return -1; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
282 |
} |
6749
87254cb5734f
Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents:
6743
diff
changeset
|
283 |
#endif |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
284 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
285 |
static int |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
286 |
JoystickInitWithoutUdev(void) |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
287 |
{ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
288 |
int i; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
289 |
char path[PATH_MAX]; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
290 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
291 |
/* !!! FIXME: only finds sticks if they're called /dev/input/event[0..31] */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
292 |
/* !!! FIXME: we could at least readdir() through /dev/input...? */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
293 |
/* !!! FIXME: (or delete this and rely on libudev?) */ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
294 |
for (i = 0; i < 32; i++) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
295 |
SDL_snprintf(path, SDL_arraysize(path), "/dev/input/event%d", i); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
296 |
MaybeAddDevice(path); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
297 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
298 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
299 |
return numjoysticks; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
300 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
301 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
302 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
303 |
#if SDL_USE_LIBUDEV |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
304 |
static int |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
305 |
JoystickInitWithUdev(void) |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
306 |
{ |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
307 |
if (SDL_UDEV_Init() < 0) { |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
308 |
return SDL_SetError("Could not initialize UDEV"); |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
309 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
310 |
|
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
311 |
/* Set up the udev callback */ |
9321
01966f6feadc
Fixed game controller hotplug support for some embedded Linux devices
Sam Lantinga <slouken@libsdl.org>
parents:
8860
diff
changeset
|
312 |
if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) { |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
313 |
SDL_UDEV_Quit(); |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
314 |
return SDL_SetError("Could not set up joystick <-> udev callback"); |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
315 |
} |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
316 |
|
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
317 |
/* Force a scan to build the initial device list */ |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
318 |
SDL_UDEV_Scan(); |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
319 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
320 |
return numjoysticks; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
321 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
322 |
#endif |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
323 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
324 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
325 |
SDL_SYS_JoystickInit(void) |
0 | 326 |
{ |
5317
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
327 |
/* First see if the user specified one or more joysticks to use */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
328 |
if (SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL) { |
5317
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
329 |
char *envcopy, *envpath, *delim; |
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
330 |
envcopy = SDL_strdup(SDL_getenv("SDL_JOYSTICK_DEVICE")); |
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
331 |
envpath = envcopy; |
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
332 |
while (envpath != NULL) { |
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
333 |
delim = SDL_strchr(envpath, ':'); |
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
334 |
if (delim != NULL) { |
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
335 |
*delim++ = '\0'; |
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
336 |
} |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
337 |
MaybeAddDevice(envpath); |
5317
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
338 |
envpath = delim; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
339 |
} |
5317
901a9e9ff0b7
Fixed bug #1121 (More than one device through SDL_JOYSTICK_DEVICE)
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
340 |
SDL_free(envcopy); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
341 |
} |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
342 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
343 |
#if SDL_USE_LIBUDEV |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
344 |
return JoystickInitWithUdev(); |
0 | 345 |
#endif |
346 |
||
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
347 |
return JoystickInitWithoutUdev(); |
0 | 348 |
} |
349 |
||
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
350 |
int SDL_SYS_NumJoysticks() |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
351 |
{ |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
352 |
return numjoysticks; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
353 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
354 |
|
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
355 |
void SDL_SYS_JoystickDetect() |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
356 |
{ |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
357 |
#if SDL_USE_LIBUDEV |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
358 |
SDL_UDEV_Poll(); |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
359 |
#endif |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
360 |
|
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
361 |
} |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
362 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
363 |
static SDL_joylist_item * |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
364 |
JoystickByDevIndex(int device_index) |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
365 |
{ |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
366 |
SDL_joylist_item *item = SDL_joylist; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
367 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
368 |
if ((device_index < 0) || (device_index >= numjoysticks)) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
369 |
return NULL; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
370 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
371 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
372 |
while (device_index > 0) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
373 |
SDL_assert(item != NULL); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
374 |
device_index--; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
375 |
item = item->next; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
376 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
377 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
378 |
return item; |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
379 |
} |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
380 |
|
0 | 381 |
/* Function to get the device-dependent name of a joystick */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
382 |
const char * |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
383 |
SDL_SYS_JoystickNameForDeviceIndex(int device_index) |
0 | 384 |
{ |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
385 |
return JoystickByDevIndex(device_index)->name; |
0 | 386 |
} |
387 |
||
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
388 |
/* Function to perform the mapping from device index to the instance id for this index */ |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
389 |
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
390 |
{ |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
391 |
return JoystickByDevIndex(device_index)->device_instance; |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
392 |
} |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
393 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
394 |
static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
395 |
allocate_hatdata(SDL_Joystick * joystick) |
0 | 396 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
397 |
int i; |
0 | 398 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
399 |
joystick->hwdata->hats = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
400 |
(struct hwdata_hat *) SDL_malloc(joystick->nhats * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
401 |
sizeof(struct hwdata_hat)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
402 |
if (joystick->hwdata->hats == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
403 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
404 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
405 |
for (i = 0; i < joystick->nhats; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
406 |
joystick->hwdata->hats[i].axis[0] = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
407 |
joystick->hwdata->hats[i].axis[1] = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
408 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
409 |
return (0); |
0 | 410 |
} |
411 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
412 |
static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
413 |
allocate_balldata(SDL_Joystick * joystick) |
0 | 414 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
415 |
int i; |
0 | 416 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
417 |
joystick->hwdata->balls = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
418 |
(struct hwdata_ball *) SDL_malloc(joystick->nballs * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
419 |
sizeof(struct hwdata_ball)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
420 |
if (joystick->hwdata->balls == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
421 |
return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
422 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
423 |
for (i = 0; i < joystick->nballs; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
424 |
joystick->hwdata->balls[i].axis[0] = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
425 |
joystick->hwdata->balls[i].axis[1] = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
426 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
427 |
return (0); |
0 | 428 |
} |
429 |
||
6729
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
430 |
static void |
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
431 |
ConfigJoystick(SDL_Joystick * joystick, int fd) |
0 | 432 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
433 |
int i, t; |
3404 | 434 |
unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; |
435 |
unsigned long absbit[NBITS(ABS_MAX)] = { 0 }; |
|
436 |
unsigned long relbit[NBITS(REL_MAX)] = { 0 }; |
|
0 | 437 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
438 |
/* See if this device uses the new unified event API */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
439 |
if ((ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) >= 0) && |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
440 |
(ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) >= 0) && |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
441 |
(ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbit)), relbit) >= 0)) { |
0 | 442 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
443 |
/* Get the number of buttons, axes, and other thingamajigs */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
444 |
for (i = BTN_JOYSTICK; i < KEY_MAX; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
445 |
if (test_bit(i, keybit)) { |
0 | 446 |
#ifdef DEBUG_INPUT_EVENTS |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
447 |
printf("Joystick has button: 0x%x\n", i); |
0 | 448 |
#endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
449 |
joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
450 |
++joystick->nbuttons; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
451 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
452 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
453 |
for (i = BTN_MISC; i < BTN_JOYSTICK; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
454 |
if (test_bit(i, keybit)) { |
0 | 455 |
#ifdef DEBUG_INPUT_EVENTS |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
456 |
printf("Joystick has button: 0x%x\n", i); |
0 | 457 |
#endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
458 |
joystick->hwdata->key_map[i - BTN_MISC] = joystick->nbuttons; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
459 |
++joystick->nbuttons; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
460 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
461 |
} |
9630
6c86d3216f6a
Linux joystick: Look at entire axis namespace for controls (thanks, "spaz16"!).
Ryan C. Gordon <icculus@icculus.org>
parents:
9619
diff
changeset
|
462 |
for (i = 0; i < ABS_MAX; ++i) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
463 |
/* Skip hats */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
464 |
if (i == ABS_HAT0X) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
465 |
i = ABS_HAT3Y; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
466 |
continue; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
467 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
468 |
if (test_bit(i, absbit)) { |
5084 | 469 |
struct input_absinfo absinfo; |
0 | 470 |
|
8053
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
471 |
if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
472 |
continue; |
8053
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
473 |
} |
0 | 474 |
#ifdef DEBUG_INPUT_EVENTS |
8053
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
475 |
printf("Joystick has absolute axis: 0x%.2x\n", i); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
476 |
printf("Values = { %d, %d, %d, %d, %d }\n", |
5084 | 477 |
absinfo.value, absinfo.minimum, absinfo.maximum, |
478 |
absinfo.fuzz, absinfo.flat); |
|
0 | 479 |
#endif /* DEBUG_INPUT_EVENTS */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
480 |
joystick->hwdata->abs_map[i] = joystick->naxes; |
5084 | 481 |
if (absinfo.minimum == absinfo.maximum) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
482 |
joystick->hwdata->abs_correct[i].used = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
483 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
484 |
joystick->hwdata->abs_correct[i].used = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
485 |
joystick->hwdata->abs_correct[i].coef[0] = |
6845
e14535915e3e
Patch - Joystick coef[] doesn't support dial with low number of positions.
Sam Lantinga <slouken@libsdl.org>
parents:
6844
diff
changeset
|
486 |
(absinfo.maximum + absinfo.minimum) - 2 * absinfo.flat; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
487 |
joystick->hwdata->abs_correct[i].coef[1] = |
6845
e14535915e3e
Patch - Joystick coef[] doesn't support dial with low number of positions.
Sam Lantinga <slouken@libsdl.org>
parents:
6844
diff
changeset
|
488 |
(absinfo.maximum + absinfo.minimum) + 2 * absinfo.flat; |
e14535915e3e
Patch - Joystick coef[] doesn't support dial with low number of positions.
Sam Lantinga <slouken@libsdl.org>
parents:
6844
diff
changeset
|
489 |
t = ((absinfo.maximum - absinfo.minimum) - 4 * absinfo.flat); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
490 |
if (t != 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
491 |
joystick->hwdata->abs_correct[i].coef[2] = |
6845
e14535915e3e
Patch - Joystick coef[] doesn't support dial with low number of positions.
Sam Lantinga <slouken@libsdl.org>
parents:
6844
diff
changeset
|
492 |
(1 << 28) / t; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
493 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
494 |
joystick->hwdata->abs_correct[i].coef[2] = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
495 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
496 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
497 |
++joystick->naxes; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
498 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
499 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
500 |
for (i = ABS_HAT0X; i <= ABS_HAT3Y; i += 2) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
501 |
if (test_bit(i, absbit) || test_bit(i + 1, absbit)) { |
8053
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
502 |
struct input_absinfo absinfo; |
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
503 |
|
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
504 |
if (ioctl(fd, EVIOCGABS(i), &absinfo) < 0) { |
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
505 |
continue; |
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
506 |
} |
0 | 507 |
#ifdef DEBUG_INPUT_EVENTS |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
508 |
printf("Joystick has hat %d\n", (i - ABS_HAT0X) / 2); |
8053
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
509 |
printf("Values = { %d, %d, %d, %d, %d }\n", |
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
510 |
absinfo.value, absinfo.minimum, absinfo.maximum, |
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
511 |
absinfo.fuzz, absinfo.flat); |
495f4a047be1
Fixed detecting the wired XBox 360 controller on Linux
Sam Lantinga <slouken@libsdl.org>
parents:
7916
diff
changeset
|
512 |
#endif /* DEBUG_INPUT_EVENTS */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
513 |
++joystick->nhats; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
514 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
515 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
516 |
if (test_bit(REL_X, relbit) || test_bit(REL_Y, relbit)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
517 |
++joystick->nballs; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
518 |
} |
0 | 519 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
520 |
/* Allocate data to keep track of these thingamajigs */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
521 |
if (joystick->nhats > 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
522 |
if (allocate_hatdata(joystick) < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
523 |
joystick->nhats = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
524 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
525 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
526 |
if (joystick->nballs > 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
527 |
if (allocate_balldata(joystick) < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
528 |
joystick->nballs = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
529 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
530 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
531 |
} |
0 | 532 |
} |
533 |
||
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
534 |
|
0 | 535 |
/* Function to open a joystick for use. |
9380
07b7c1005a23
Updated internal documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9321
diff
changeset
|
536 |
The joystick to open is specified by the device index. |
0 | 537 |
This should fill the nbuttons and naxes fields of the joystick structure. |
538 |
It returns 0, or -1 if there is an error. |
|
539 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
540 |
int |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6389
diff
changeset
|
541 |
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) |
0 | 542 |
{ |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
543 |
SDL_joylist_item *item = JoystickByDevIndex(device_index); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
544 |
char *fname = NULL; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
545 |
int fd = -1; |
892
dc29e5907694
Date: Sun, 18 Apr 2004 16:09:53 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
872
diff
changeset
|
546 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
547 |
if (item == NULL) { |
7037
3fedf1f25b94
Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents:
6911
diff
changeset
|
548 |
return SDL_SetError("No such device"); |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
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 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
551 |
fname = item->path; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
552 |
fd = open(fname, O_RDONLY, 0); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
553 |
if (fd < 0) { |
7037
3fedf1f25b94
Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents:
6911
diff
changeset
|
554 |
return SDL_SetError("Unable to open %s", fname); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
555 |
} |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
556 |
|
6751
a1f87fd7ed72
Corrected device instance value for Linux joysticks.
Ryan C. Gordon <icculus@icculus.org>
parents:
6749
diff
changeset
|
557 |
joystick->instance_id = item->device_instance; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
558 |
joystick->hwdata = (struct joystick_hwdata *) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
559 |
SDL_malloc(sizeof(*joystick->hwdata)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
560 |
if (joystick->hwdata == NULL) { |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
561 |
close(fd); |
7037
3fedf1f25b94
Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents:
6911
diff
changeset
|
562 |
return SDL_OutOfMemory(); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
563 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
564 |
SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); |
6752
8de11011eb1f
Corrected Linux joystick things, fixes assertion failure from testjoystick.
Ryan C. Gordon <icculus@icculus.org>
parents:
6751
diff
changeset
|
565 |
joystick->hwdata->item = item; |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
566 |
joystick->hwdata->guid = item->guid; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
567 |
joystick->hwdata->fd = fd; |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
568 |
joystick->hwdata->fname = SDL_strdup(item->path); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
569 |
if (joystick->hwdata->fname == NULL) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
570 |
SDL_free(joystick->hwdata); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
571 |
joystick->hwdata = NULL; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
572 |
close(fd); |
7037
3fedf1f25b94
Make SDL_SetError and friends unconditionally return -1.
Ryan C. Gordon <icculus@icculus.org>
parents:
6911
diff
changeset
|
573 |
return SDL_OutOfMemory(); |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
574 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
575 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
576 |
SDL_assert(item->hwdata == NULL); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
577 |
item->hwdata = joystick->hwdata; |
0 | 578 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
579 |
/* Set the joystick to non-blocking read mode */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
580 |
fcntl(fd, F_SETFL, O_NONBLOCK); |
0 | 581 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
582 |
/* Get the number of buttons and axes on the joystick */ |
6729
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
583 |
ConfigJoystick(joystick, fd); |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
584 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7133
diff
changeset
|
585 |
/* mark joystick as fresh and ready */ |
6844
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
586 |
joystick->hwdata->fresh = 1; |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
587 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
588 |
return (0); |
0 | 589 |
} |
590 |
||
9561
d8ad01792399
Fixed typo in internal joystick documentation comments.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
9433
diff
changeset
|
591 |
/* Function to determine if this joystick is attached to the system right now */ |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
592 |
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
593 |
{ |
9433
bd062398b648
Cleanups in the joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
9380
diff
changeset
|
594 |
return joystick->hwdata->item != NULL; |
6707
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
595 |
} |
70eeb7e3ec2f
Organized joystick hotplug code a bit.
Sam Lantinga <slouken@libsdl.org>
parents:
6698
diff
changeset
|
596 |
|
7860
2b0bcdea3a79
Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents:
7802
diff
changeset
|
597 |
static SDL_INLINE void |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
598 |
HandleHat(SDL_Joystick * stick, Uint8 hat, int axis, int value) |
0 | 599 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
600 |
struct hwdata_hat *the_hat; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
601 |
const Uint8 position_map[3][3] = { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
602 |
{SDL_HAT_LEFTUP, SDL_HAT_UP, SDL_HAT_RIGHTUP}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
603 |
{SDL_HAT_LEFT, SDL_HAT_CENTERED, SDL_HAT_RIGHT}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
604 |
{SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
605 |
}; |
0 | 606 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
607 |
the_hat = &stick->hwdata->hats[hat]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
608 |
if (value < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
609 |
value = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
610 |
} else if (value == 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
611 |
value = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
612 |
} else if (value > 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
613 |
value = 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
614 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
615 |
if (value != the_hat->axis[axis]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
616 |
the_hat->axis[axis] = value; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
617 |
SDL_PrivateJoystickHat(stick, hat, |
3013
8cc00819c8d6
Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents:
3011
diff
changeset
|
618 |
position_map[the_hat-> |
8cc00819c8d6
Reverted Bob's indent checkin
Sam Lantinga <slouken@libsdl.org>
parents:
3011
diff
changeset
|
619 |
axis[1]][the_hat->axis[0]]); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
620 |
} |
0 | 621 |
} |
622 |
||
7860
2b0bcdea3a79
Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents:
7802
diff
changeset
|
623 |
static SDL_INLINE void |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
624 |
HandleBall(SDL_Joystick * stick, Uint8 ball, int axis, int value) |
0 | 625 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
626 |
stick->hwdata->balls[ball].axis[axis] += value; |
0 | 627 |
} |
628 |
||
629 |
||
7860
2b0bcdea3a79
Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents:
7802
diff
changeset
|
630 |
static SDL_INLINE int |
6729
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
631 |
AxisCorrect(SDL_Joystick * joystick, int which, int value) |
0 | 632 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
633 |
struct axis_correct *correct; |
0 | 634 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
635 |
correct = &joystick->hwdata->abs_correct[which]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
636 |
if (correct->used) { |
6845
e14535915e3e
Patch - Joystick coef[] doesn't support dial with low number of positions.
Sam Lantinga <slouken@libsdl.org>
parents:
6844
diff
changeset
|
637 |
value *= 2; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
638 |
if (value > correct->coef[0]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
639 |
if (value < correct->coef[1]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
640 |
return 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
641 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
642 |
value -= correct->coef[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
643 |
} else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
644 |
value -= correct->coef[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
645 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
646 |
value *= correct->coef[2]; |
6845
e14535915e3e
Patch - Joystick coef[] doesn't support dial with low number of positions.
Sam Lantinga <slouken@libsdl.org>
parents:
6844
diff
changeset
|
647 |
value >>= 13; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
648 |
} |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
649 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
650 |
/* Clamp and return */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
651 |
if (value < -32768) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
652 |
return -32768; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
653 |
if (value > 32767) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
654 |
return 32767; |
554
38b1a98aeb11
Linux joystick cleanups from Alan Swanson
Sam Lantinga <slouken@libsdl.org>
parents:
408
diff
changeset
|
655 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
656 |
return value; |
0 | 657 |
} |
658 |
||
7860
2b0bcdea3a79
Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents:
7802
diff
changeset
|
659 |
static SDL_INLINE void |
6844
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
660 |
PollAllValues(SDL_Joystick * joystick) |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
661 |
{ |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
662 |
struct input_absinfo absinfo; |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
663 |
int a, b = 0; |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
664 |
|
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7133
diff
changeset
|
665 |
/* Poll all axis */ |
6844
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
666 |
for (a = ABS_X; b < ABS_MAX; a++) { |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
667 |
switch (a) { |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
668 |
case ABS_HAT0X: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
669 |
case ABS_HAT0Y: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
670 |
case ABS_HAT1X: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
671 |
case ABS_HAT1Y: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
672 |
case ABS_HAT2X: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
673 |
case ABS_HAT2Y: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
674 |
case ABS_HAT3X: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
675 |
case ABS_HAT3Y: |
7191
75360622e65f
File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents:
7133
diff
changeset
|
676 |
/* ingore hats */ |
6844
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
677 |
break; |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
678 |
default: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
679 |
if (joystick->hwdata->abs_correct[b].used) { |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
680 |
if (ioctl(joystick->hwdata->fd, EVIOCGABS(a), &absinfo) >= 0) { |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
681 |
absinfo.value = AxisCorrect(joystick, b, absinfo.value); |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
682 |
|
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
683 |
#ifdef DEBUG_INPUT_EVENTS |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
684 |
printf("Joystick : Re-read Axis %d (%d) val= %d\n", |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
685 |
joystick->hwdata->abs_map[b], a, absinfo.value); |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
686 |
#endif |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
687 |
SDL_PrivateJoystickAxis(joystick, |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
688 |
joystick->hwdata->abs_map[b], |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
689 |
absinfo.value); |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
690 |
} |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
691 |
} |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
692 |
b++; |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
693 |
} |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
694 |
} |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
695 |
} |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
696 |
|
7860
2b0bcdea3a79
Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings
Sam Lantinga <slouken@libsdl.org>
parents:
7802
diff
changeset
|
697 |
static SDL_INLINE void |
6729
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
698 |
HandleInputEvents(SDL_Joystick * joystick) |
0 | 699 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
700 |
struct input_event events[32]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
701 |
int i, len; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
702 |
int code; |
0 | 703 |
|
6844
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
704 |
if (joystick->hwdata->fresh) { |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
705 |
PollAllValues(joystick); |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
706 |
joystick->hwdata->fresh = 0; |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
707 |
} |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
708 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
709 |
while ((len = read(joystick->hwdata->fd, events, (sizeof events))) > 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
710 |
len /= sizeof(events[0]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
711 |
for (i = 0; i < len; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
712 |
code = events[i].code; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
713 |
switch (events[i].type) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
714 |
case EV_KEY: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
715 |
if (code >= BTN_MISC) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
716 |
code -= BTN_MISC; |
6728
0f8336c1f6d9
Removed the "logical" Linux joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
6707
diff
changeset
|
717 |
SDL_PrivateJoystickButton(joystick, |
0f8336c1f6d9
Removed the "logical" Linux joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
6707
diff
changeset
|
718 |
joystick->hwdata->key_map[code], |
0f8336c1f6d9
Removed the "logical" Linux joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
6707
diff
changeset
|
719 |
events[i].value); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
720 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
721 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
722 |
case EV_ABS: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
723 |
switch (code) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
724 |
case ABS_HAT0X: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
725 |
case ABS_HAT0Y: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
726 |
case ABS_HAT1X: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
727 |
case ABS_HAT1Y: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
728 |
case ABS_HAT2X: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
729 |
case ABS_HAT2Y: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
730 |
case ABS_HAT3X: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
731 |
case ABS_HAT3Y: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
732 |
code -= ABS_HAT0X; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
733 |
HandleHat(joystick, code / 2, code % 2, events[i].value); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
734 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
735 |
default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
736 |
events[i].value = |
6729
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
737 |
AxisCorrect(joystick, code, events[i].value); |
6728
0f8336c1f6d9
Removed the "logical" Linux joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
6707
diff
changeset
|
738 |
SDL_PrivateJoystickAxis(joystick, |
0f8336c1f6d9
Removed the "logical" Linux joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
6707
diff
changeset
|
739 |
joystick->hwdata->abs_map[code], |
0f8336c1f6d9
Removed the "logical" Linux joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
6707
diff
changeset
|
740 |
events[i].value); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
741 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
742 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
743 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
744 |
case EV_REL: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
745 |
switch (code) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
746 |
case REL_X: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
747 |
case REL_Y: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
748 |
code -= REL_X; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
749 |
HandleBall(joystick, code / 2, code % 2, events[i].value); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
750 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
751 |
default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
752 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
753 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
754 |
break; |
6844
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
755 |
case EV_SYN: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
756 |
switch (code) { |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
757 |
case SYN_DROPPED : |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
758 |
#ifdef DEBUG_INPUT_EVENTS |
7133
87d4cb9bb66c
Corrected spelling in C source files.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents:
7037
diff
changeset
|
759 |
printf("Event SYN_DROPPED detected\n"); |
6844
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
760 |
#endif |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
761 |
PollAllValues(joystick); |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
762 |
break; |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
763 |
default: |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
764 |
break; |
e09997fb33cc
Fix for dropped joystick events contributed by Simon <simon@mungewell.org>
Sam Lantinga <slouken@libsdl.org>
parents:
6831
diff
changeset
|
765 |
} |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
766 |
default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
767 |
break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
768 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
769 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
770 |
} |
0 | 771 |
} |
772 |
||
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
773 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
774 |
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
0 | 775 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
776 |
int i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
777 |
|
6729
fdaeea9e7567
Removed old Linux joystick API (/dev/js*).
Ryan C. Gordon <icculus@icculus.org>
parents:
6728
diff
changeset
|
778 |
HandleInputEvents(joystick); |
0 | 779 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
780 |
/* Deliver ball motion updates */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
781 |
for (i = 0; i < joystick->nballs; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
782 |
int xrel, yrel; |
0 | 783 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
784 |
xrel = joystick->hwdata->balls[i].axis[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
785 |
yrel = joystick->hwdata->balls[i].axis[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
786 |
if (xrel || yrel) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
787 |
joystick->hwdata->balls[i].axis[0] = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
788 |
joystick->hwdata->balls[i].axis[1] = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
789 |
SDL_PrivateJoystickBall(joystick, (Uint8) i, xrel, yrel); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
790 |
} |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
791 |
} |
0 | 792 |
} |
793 |
||
794 |
/* Function to close a joystick after use */ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
795 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
796 |
SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
0 | 797 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
798 |
if (joystick->hwdata) { |
6728
0f8336c1f6d9
Removed the "logical" Linux joystick code.
Ryan C. Gordon <icculus@icculus.org>
parents:
6707
diff
changeset
|
799 |
close(joystick->hwdata->fd); |
6752
8de11011eb1f
Corrected Linux joystick things, fixes assertion failure from testjoystick.
Ryan C. Gordon <icculus@icculus.org>
parents:
6751
diff
changeset
|
800 |
if (joystick->hwdata->item) { |
8de11011eb1f
Corrected Linux joystick things, fixes assertion failure from testjoystick.
Ryan C. Gordon <icculus@icculus.org>
parents:
6751
diff
changeset
|
801 |
joystick->hwdata->item->hwdata = NULL; |
8de11011eb1f
Corrected Linux joystick things, fixes assertion failure from testjoystick.
Ryan C. Gordon <icculus@icculus.org>
parents:
6751
diff
changeset
|
802 |
} |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
803 |
SDL_free(joystick->hwdata->hats); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
804 |
SDL_free(joystick->hwdata->balls); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
805 |
SDL_free(joystick->hwdata->fname); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
806 |
SDL_free(joystick->hwdata); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
807 |
} |
0 | 808 |
} |
809 |
||
810 |
/* Function to perform any system-specific joystick related cleanup */ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
811 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
812 |
SDL_SYS_JoystickQuit(void) |
0 | 813 |
{ |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
814 |
SDL_joylist_item *item = NULL; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
815 |
SDL_joylist_item *next = NULL; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
816 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
817 |
for (item = SDL_joylist; item; item = next) { |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
818 |
next = item->next; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
819 |
SDL_free(item->path); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
820 |
SDL_free(item->name); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
821 |
SDL_free(item); |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
822 |
} |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
823 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
824 |
SDL_joylist = SDL_joylist_tail = NULL; |
0 | 825 |
|
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
826 |
numjoysticks = 0; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
827 |
instance_counter = 0; |
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
828 |
|
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
829 |
#if SDL_USE_LIBUDEV |
7772
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
830 |
SDL_UDEV_DelCallback(joystick_udev_callback); |
6b3cc8b7c589
Uses SDL_UDEV for Linux joystick hotplugging
Gabriel Jacobo <gabomdq@gmail.com>
parents:
7191
diff
changeset
|
831 |
SDL_UDEV_Quit(); |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
832 |
#endif |
0 | 833 |
} |
834 |
||
6738 | 835 |
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6389
diff
changeset
|
836 |
{ |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
837 |
return JoystickByDevIndex(device_index)->guid; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6389
diff
changeset
|
838 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6389
diff
changeset
|
839 |
|
6738 | 840 |
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6389
diff
changeset
|
841 |
{ |
6734
7fdaee2be782
Updated Linux joystick code to support hotplug, GUIDs, etc.
Ryan C. Gordon <icculus@icculus.org>
parents:
6729
diff
changeset
|
842 |
return joystick->hwdata->guid; |
6690
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6389
diff
changeset
|
843 |
} |
9548c8a58103
Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds
Sam Lantinga <slouken@libsdl.org>
parents:
6389
diff
changeset
|
844 |
|
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1551
diff
changeset
|
845 |
#endif /* SDL_JOYSTICK_LINUX */ |
6693
3c98e4ec2180
Fixed iOS joystick support for new API
Sam Lantinga <slouken@libsdl.org>
parents:
6691
diff
changeset
|
846 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1821
diff
changeset
|
847 |
/* vi: set ts=4 sw=4 expandtab: */ |