Mercurial > sdl-ios-xcode
annotate src/joystick/bsd/SDL_sysjoystick.c @ 1361:19418e4422cb
New configure-based build system. Still work in progress, but much improved
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 16 Feb 2006 10:11:48 +0000 |
parents | c71e05b4dc2e |
children | d910939febfa |
rev | line source |
---|---|
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1185
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1185
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1185
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1185
diff
changeset
|
13 Lesser General Public License for more details. |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1185
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1185
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1185
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1185
diff
changeset
|
20 slouken@libsdl.org |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 /* |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 * Joystick driver for the uhid(4) interface found in OpenBSD, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 * NetBSD and FreeBSD. |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 * |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 * Maintainer: <vedge at csoft.org> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
552
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
30 #include <sys/param.h> |
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
31 |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 #include <unistd.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 #include <fcntl.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 #include <errno.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
403
8d431937739d
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
402
diff
changeset
|
36 #if defined(HAVE_USB_H) |
8d431937739d
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
402
diff
changeset
|
37 #include <usb.h> |
8d431937739d
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
402
diff
changeset
|
38 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 #include <dev/usb/usb.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 #include <dev/usb/usbhid.h> |
358
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
41 |
381
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
42 #if defined(HAVE_USBHID_H) |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
43 #include <usbhid.h> |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
44 #elif defined(HAVE_LIBUSB_H) |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
45 #include <libusb.h> |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
46 #elif defined(HAVE_LIBUSBHID_H) |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
47 #include <libusbhid.h> |
358
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
48 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 |
611
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
50 #ifdef __FreeBSD__ |
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
51 #include <osreldate.h> |
776
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
52 #include <sys/joystick.h> |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
53 #endif |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
54 |
1185
58538e140e2d
Apparently some bits of the BSD joystick code are x86 only...joystick.h
Ryan C. Gordon <icculus@icculus.org>
parents:
965
diff
changeset
|
55 #if defined(__NetBSD__) || (defined(__OpenBSD__) && defined(__i386__)) |
776
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
56 #include <machine/joystick.h> |
611
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
57 #endif |
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
58 |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 #include "SDL_joystick.h" |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
60 #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
|
61 #include "../SDL_joystick_c.h" |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 #define MAX_UHID_JOYS 4 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 #define MAX_JOY_JOYS 2 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 #define MAX_JOYS (MAX_UHID_JOYS + MAX_JOY_JOYS) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 struct report { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 struct usb_ctl_report *buf; /* Buffer */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 size_t size; /* Buffer size */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 int rid; /* Report ID */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 enum { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 SREPORT_UNINIT, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 SREPORT_CLEAN, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 SREPORT_DIRTY |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 } status; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 }; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 static struct { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 int uhid_report; |
402
7efee6e36f00
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
381
diff
changeset
|
80 hid_kind_t kind; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 const char *name; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 } const repinfo[] = { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 { UHID_INPUT_REPORT, hid_input, "input" }, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 { UHID_OUTPUT_REPORT, hid_output, "output" }, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 { UHID_FEATURE_REPORT, hid_feature, "feature" } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 }; |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
87 |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
88 enum { |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
89 REPORT_INPUT = 0, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
90 REPORT_OUTPUT = 1, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
91 REPORT_FEATURE = 2 |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
92 }; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
93 |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
94 enum { |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
95 JOYAXE_X, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
96 JOYAXE_Y, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
97 JOYAXE_Z, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
98 JOYAXE_SLIDER, |
632
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
99 JOYAXE_WHEEL, |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
100 JOYAXE_RX, |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
101 JOYAXE_RY, |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
102 JOYAXE_RZ, |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
103 JOYAXE_count |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
104 }; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 struct joystick_hwdata { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 int fd; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 char *path; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 enum { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 BSDJOY_UHID, /* uhid(4) */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 BSDJOY_JOY /* joy(4) */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 } type; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 struct report_desc *repdesc; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 struct report inreport; |
632
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
115 int axis_map[JOYAXE_count]; /* map present JOYAXE_* to 0,1,..*/ |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 }; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 static char *joynames[MAX_JOYS]; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 static char *joydevnames[MAX_JOYS]; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 static int report_alloc(struct report *, struct report_desc *, int); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 static void report_free(struct report *); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 |
381
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
124 #ifdef USBHID_UCR_DATA |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
125 #define REP_BUF_DATA(rep) ((rep)->buf->ucr_data) |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
126 #else |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
127 #define REP_BUF_DATA(rep) ((rep)->buf->data) |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
128 #endif |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
129 |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 int |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 SDL_SYS_JoystickInit(void) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 { |
503
2ee72e47ca08
Fixed memory overwrite in BSD joystick driver (thanks SUGIMOTO Sadahiro!)
Sam Lantinga <slouken@libsdl.org>
parents:
461
diff
changeset
|
133 char s[16]; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 int i, fd; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 SDL_numjoysticks = 0; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
138 SDL_memset(joynames, 0, sizeof(joynames)); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
139 SDL_memset(joydevnames, 0, sizeof(joydevnames)); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 for (i = 0; i < MAX_UHID_JOYS; i++) { |
544
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
142 SDL_Joystick nj; |
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
143 |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
144 SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i); |
544
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
145 |
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
146 nj.index = SDL_numjoysticks; |
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
147 joynames[nj.index] = strdup(s); |
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
148 |
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
149 if (SDL_SYS_JoystickOpen(&nj) == 0) { |
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
150 SDL_SYS_JoystickClose(&nj); |
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
151 SDL_numjoysticks++; |
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
152 } else { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
153 SDL_free(joynames[nj.index]); |
965
b68e551205e9
Fix from Alfred Perlstein
Sam Lantinga <slouken@libsdl.org>
parents:
776
diff
changeset
|
154 joynames[nj.index] = NULL; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 for (i = 0; i < MAX_JOY_JOYS; i++) { |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
158 SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i); |
544
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
159 fd = open(s, O_RDONLY); |
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
160 if (fd != -1) { |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 joynames[SDL_numjoysticks++] = strdup(s); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 close(fd); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 /* Read the default USB HID usage table. */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 hid_init(NULL); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 return (SDL_numjoysticks); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 const char * |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 SDL_SYS_JoystickName(int index) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 if (joydevnames[index] != NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 return (joydevnames[index]); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 return (joynames[index]); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 |
632
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
181 static int |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
182 usage_to_joyaxe(unsigned usage) |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
183 { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
184 int joyaxe; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
185 switch (usage) { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
186 case HUG_X: |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
187 joyaxe = JOYAXE_X; break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
188 case HUG_Y: |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
189 joyaxe = JOYAXE_Y; break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
190 case HUG_Z: |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
191 joyaxe = JOYAXE_Z; break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
192 case HUG_SLIDER: |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
193 joyaxe = JOYAXE_SLIDER; break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
194 case HUG_WHEEL: |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
195 joyaxe = JOYAXE_WHEEL; break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
196 case HUG_RX: |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
197 joyaxe = JOYAXE_RX; break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
198 case HUG_RY: |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
199 joyaxe = JOYAXE_RY; break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
200 case HUG_RZ: |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
201 joyaxe = JOYAXE_RZ; break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
202 default: |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
203 joyaxe = -1; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
204 } |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
205 return joyaxe; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
206 } |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
207 |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
208 static unsigned |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
209 hatval_to_sdl(Sint32 hatval) |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
210 { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
211 static const unsigned hat_dir_map[8] = { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
212 SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN, |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
213 SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
214 }; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
215 unsigned result; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
216 if ((hatval & 7) == hatval) |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
217 result = hat_dir_map[hatval]; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
218 else |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
219 result = SDL_HAT_CENTERED; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
220 return result; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
221 } |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
222 |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
223 |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 int |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 SDL_SYS_JoystickOpen(SDL_Joystick *joy) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 char *path = joynames[joy->index]; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 struct joystick_hwdata *hw; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 struct hid_item hitem; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 struct hid_data *hdata; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 struct report *rep; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 int fd; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 |
715
de0351c47596
Date: Mon, 01 Sep 2003 15:37:52 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
632
diff
changeset
|
234 fd = open(path, O_RDONLY); |
544
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
235 if (fd == -1) { |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 SDL_SetError("%s: %s", path, strerror(errno)); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
240 hw = (struct joystick_hwdata *)SDL_malloc(sizeof(struct joystick_hwdata)); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 if (hw == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 SDL_OutOfMemory(); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 close(fd); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 joy->hwdata = hw; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 hw->fd = fd; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 hw->path = strdup(path); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
249 if (! SDL_strncmp(path, "/dev/joy", 8)) { |
776
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
250 hw->type = BSDJOY_JOY; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
251 joy->naxes = 2; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
252 joy->nbuttons = 2; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
253 joy->nhats = 0; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
254 joy->nballs = 0; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
255 joydevnames[joy->index] = strdup("Gameport joystick"); |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
256 goto usbend; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
257 } else { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
258 hw->type = BSDJOY_UHID; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
259 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
260 |
632
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
261 { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
262 int ax; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
263 for (ax = 0; ax < JOYAXE_count; ax++) |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
264 hw->axis_map[ax] = -1; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
265 } |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 hw->repdesc = hid_get_report_desc(fd); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 if (hw->repdesc == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 SDL_SetError("%s: USB_GET_REPORT_DESC: %s", hw->path, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 strerror(errno)); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 goto usberr; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 rep = &hw->inreport; |
611
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
274 rep->rid = 0; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 if (report_alloc(rep, hw->repdesc, REPORT_INPUT) < 0) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 goto usberr; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 if (rep->size <= 0) { |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
279 SDL_SetError("%s: Input report descriptor has invalid length", |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
280 hw->path); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 goto usberr; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 |
611
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
284 #if defined(USBHID_NEW) || (defined(__FreeBSD__) && __FreeBSD_version >= 500111) |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
285 hdata = hid_start_parse(hw->repdesc, 1 << hid_input, rep->rid); |
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
286 #else |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 hdata = hid_start_parse(hw->repdesc, 1 << hid_input); |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
288 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 if (hdata == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 SDL_SetError("%s: Cannot start HID parser", hw->path); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 goto usberr; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 joy->naxes = 0; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 joy->nbuttons = 0; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 joy->nhats = 0; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 joy->nballs = 0; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 while (hid_get_item(hdata, &hitem) > 0) { |
358
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
299 char *sp; |
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
300 const char *s; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 switch (hitem.kind) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 case hid_collection: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 switch (HID_PAGE(hitem.usage)) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 case HUP_GENERIC_DESKTOP: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 switch (HID_USAGE(hitem.usage)) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 case HUG_JOYSTICK: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 case HUG_GAME_PAD: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 s = hid_usage_in_page(hitem.usage); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
310 sp = SDL_malloc(SDL_strlen(s) + 5); |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
311 SDL_snprintf(sp, SDL_strlen(s) + 5, "%s (%d)", s, |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 joy->index); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 joydevnames[joy->index] = sp; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 case hid_input: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 switch (HID_PAGE(hitem.usage)) { |
632
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
319 case HUP_GENERIC_DESKTOP: { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
320 unsigned usage = HID_USAGE(hitem.usage); |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
321 int joyaxe = usage_to_joyaxe(usage); |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
322 if (joyaxe >= 0) { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
323 hw->axis_map[joyaxe] = joy->naxes; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
324 joy->naxes++; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
325 } else if (usage == HUG_HAT_SWITCH) { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
326 joy->nhats++; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
327 } |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
328 break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
329 } |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 case HUP_BUTTON: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 joy->nbuttons++; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 break; |
405
b5de7389a0a5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
404
diff
changeset
|
333 default: |
b5de7389a0a5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
404
diff
changeset
|
334 break; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 default: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 hid_end_parse(hdata); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 |
776
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
343 usbend: |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 /* The poll blocks the event thread. */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 fcntl(fd, F_SETFL, O_NONBLOCK); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 return (0); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 usberr: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 close(hw->fd); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
350 SDL_free(hw->path); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
351 SDL_free(hw); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 void |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 SDL_SYS_JoystickUpdate(SDL_Joystick *joy) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 { |
381
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
358 struct hid_item hitem; |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
359 struct hid_data *hdata; |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
360 struct report *rep; |
358
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
361 int nbutton, naxe = -1; |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
362 Sint32 v; |
776
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
363 |
1185
58538e140e2d
Apparently some bits of the BSD joystick code are x86 only...joystick.h
Ryan C. Gordon <icculus@icculus.org>
parents:
965
diff
changeset
|
364 #if defined(__FreeBSD__) || defined(__NetBSD__) || (defined(__OpenBSD__) && defined(__i386__)) |
776
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
365 struct joystick gameport; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
366 static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
367 |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
368 if (joy->hwdata->type == BSDJOY_JOY) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
369 if (read(joy->hwdata->fd, &gameport, sizeof gameport) != sizeof gameport) |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
370 return; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
371 if (abs(x - gameport.x) > 8) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
372 x = gameport.x; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
373 if (x < xmin) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
374 xmin = x; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
375 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
376 if (x > xmax) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
377 xmax = x; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
378 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
379 if (xmin == xmax) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
380 xmin--; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
381 xmax++; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
382 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
383 v = (Sint32)x; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
384 v -= (xmax + xmin + 1)/2; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
385 v *= 32768/((xmax - xmin + 1)/2); |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
386 SDL_PrivateJoystickAxis(joy, 0, v); |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
387 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
388 if (abs(y - gameport.y) > 8) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
389 y = gameport.y; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
390 if (y < ymin) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
391 ymin = y; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
392 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
393 if (y > ymax) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
394 ymax = y; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
395 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
396 if (ymin == ymax) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
397 ymin--; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
398 ymax++; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
399 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
400 v = (Sint32)y; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
401 v -= (ymax + ymin + 1)/2; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
402 v *= 32768/((ymax - ymin + 1)/2); |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
403 SDL_PrivateJoystickAxis(joy, 1, v); |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
404 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
405 if (gameport.b1 != joy->buttons[0]) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
406 SDL_PrivateJoystickButton(joy, 0, gameport.b1); |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
407 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
408 if (gameport.b2 != joy->buttons[1]) { |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
409 SDL_PrivateJoystickButton(joy, 1, gameport.b2); |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
410 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
411 return; |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
412 } |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
413 #endif /* defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) */ |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 rep = &joy->hwdata->inreport; |
381
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
416 |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
417 if (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) != rep->size) { |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 } |
611
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
420 #if defined(USBHID_NEW) || (defined(__FreeBSD__) && __FreeBSD_version >= 500111) |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
421 hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input, rep->rid); |
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
422 #else |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input); |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
424 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 if (hdata == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 fprintf(stderr, "%s: Cannot start HID parser\n", |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 joy->hwdata->path); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
431 for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) { |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
432 switch (hitem.kind) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 case hid_input: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
434 switch (HID_PAGE(hitem.usage)) { |
632
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
435 case HUP_GENERIC_DESKTOP: { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
436 unsigned usage = HID_USAGE(hitem.usage); |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
437 int joyaxe = usage_to_joyaxe(usage); |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
438 if (joyaxe >= 0) { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
439 naxe = joy->hwdata->axis_map[joyaxe]; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
440 /* scaleaxe */ |
381
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
441 v = (Sint32)hid_get_data(REP_BUF_DATA(rep), |
632
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
442 &hitem); |
461
1d36f593078a
Date: Thu, 18 Jul 2002 23:51:40 +0200 (MEST)
Sam Lantinga <slouken@libsdl.org>
parents:
426
diff
changeset
|
443 v -= (hitem.logical_maximum + hitem.logical_minimum + 1)/2; |
1d36f593078a
Date: Thu, 18 Jul 2002 23:51:40 +0200 (MEST)
Sam Lantinga <slouken@libsdl.org>
parents:
426
diff
changeset
|
444 v *= 32768/((hitem.logical_maximum - hitem.logical_minimum + 1)/2); |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
445 if (v != joy->axes[naxe]) { |
632
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
446 SDL_PrivateJoystickAxis(joy, naxe, v); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 } |
632
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
448 } else if (usage == HUG_HAT_SWITCH) { |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
449 v = (Sint32)hid_get_data(REP_BUF_DATA(rep), |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
450 &hitem); |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
451 SDL_PrivateJoystickHat(joy, 0, hatval_to_sdl(v)); |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
452 } |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
453 break; |
85e104fe14c2
Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents:
611
diff
changeset
|
454 } |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
455 case HUP_BUTTON: |
381
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
456 v = (Sint32)hid_get_data(REP_BUF_DATA(rep), |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
457 &hitem); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
458 if (joy->buttons[nbutton] != v) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
459 SDL_PrivateJoystickButton(joy, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
460 nbutton, v); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
461 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
462 nbutton++; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
463 break; |
405
b5de7389a0a5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
404
diff
changeset
|
464 default: |
b5de7389a0a5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
404
diff
changeset
|
465 continue; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
466 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
467 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
468 default: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
469 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
470 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
471 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
472 hid_end_parse(hdata); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
473 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
475 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
476 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
477 /* Function to close a joystick after use */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
478 void |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
479 SDL_SYS_JoystickClose(SDL_Joystick *joy) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
480 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
481 if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) { |
776
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
482 report_free(&joy->hwdata->inreport); |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
483 hid_dispose_report_desc(joy->hwdata->repdesc); |
18922ae3ee07
Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
484 } |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
485 close(joy->hwdata->fd); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
486 SDL_free(joy->hwdata->path); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
487 SDL_free(joy->hwdata); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
488 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
489 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
490 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
491 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
492 void |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
493 SDL_SYS_JoystickQuit(void) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
494 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
495 int i; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
496 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
497 for (i = 0; i < MAX_JOYS; i++) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 if (joynames[i] != NULL) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
499 SDL_free(joynames[i]); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
500 if (joydevnames[i] != NULL) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
501 SDL_free(joydevnames[i]); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
502 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
503 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
504 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
506 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
507 static int |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 report_alloc(struct report *r, struct report_desc *rd, int repind) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 int len; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 |
552
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
512 #ifdef __FreeBSD__ |
715
de0351c47596
Date: Mon, 01 Sep 2003 15:37:52 +0900
Sam Lantinga <slouken@libsdl.org>
parents:
632
diff
changeset
|
513 # if (__FreeBSD_version >= 460000) |
611
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
514 # if (__FreeBSD_version <= 500111) |
552
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
515 len = hid_report_size(rd, r->rid, repinfo[repind].kind); |
611
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
516 # else |
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
517 len = hid_report_size(rd, repinfo[repind].kind, r->rid); |
0a2ef9e8ca41
Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents:
552
diff
changeset
|
518 # endif |
552
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
519 # else |
544
2d7373ffd131
Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents:
503
diff
changeset
|
520 len = hid_report_size(rd, repinfo[repind].kind, &r->rid); |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
521 #endif |
552
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
522 #else |
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
523 # ifdef USBHID_NEW |
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
524 len = hid_report_size(rd, repinfo[repind].kind, &r->rid); |
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
525 # else |
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
526 len = hid_report_size(rd, repinfo[repind].kind, r->rid); |
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
527 # endif |
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
528 #endif |
639d58d32471
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
544
diff
changeset
|
529 |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
530 if (len < 0) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
531 SDL_SetError("Negative HID report size"); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
532 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
533 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
534 r->size = len; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
535 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
536 if (r->size > 0) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
537 r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) + |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
538 r->size); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
539 if (r->buf == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
540 SDL_OutOfMemory(); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
541 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
542 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
543 } else { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
544 r->buf = NULL; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
545 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
546 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
547 r->status = SREPORT_CLEAN; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
548 return (0); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
549 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
550 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
551 static void |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
552 report_free(struct report *r) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
553 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
554 if (r->buf != NULL) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
555 SDL_free(r->buf); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
556 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
557 r->status = SREPORT_UNINIT; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
558 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
559 |