annotate src/joystick/bsd/SDL_sysjoystick.c @ 4306:aa6aac8a5243 SDL-1.2

Whoops, FreeBSD 6.2 doesn't define __FreeBSD_kernel_version
author Sam Lantinga <slouken@libsdl.org>
date Sat, 10 Oct 2009 09:43:08 +0000
parents ecb22f65f0aa
children f4ee83767bfd
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
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 4022
diff changeset
3 Copyright (C) 1997-2009 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 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1565
diff changeset
24 #ifdef SDL_JOYSTICK_USBHID
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1565
diff changeset
25
278
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 * 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
28 * NetBSD and FreeBSD.
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 *
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 * Maintainer: <vedge at csoft.org>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
33 #include <sys/param.h>
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
34
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include <unistd.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include <fcntl.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include <errno.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38
4306
aa6aac8a5243 Whoops, FreeBSD 6.2 doesn't define __FreeBSD_kernel_version
Sam Lantinga <slouken@libsdl.org>
parents: 4305
diff changeset
39 #include <sys/param.h>
aa6aac8a5243 Whoops, FreeBSD 6.2 doesn't define __FreeBSD_kernel_version
Sam Lantinga <slouken@libsdl.org>
parents: 4305
diff changeset
40 #ifndef __FreeBSD_kernel_version
aa6aac8a5243 Whoops, FreeBSD 6.2 doesn't define __FreeBSD_kernel_version
Sam Lantinga <slouken@libsdl.org>
parents: 4305
diff changeset
41 #define __FreeBSD_kernel_version __FreeBSD_version
aa6aac8a5243 Whoops, FreeBSD 6.2 doesn't define __FreeBSD_kernel_version
Sam Lantinga <slouken@libsdl.org>
parents: 4305
diff changeset
42 #endif
aa6aac8a5243 Whoops, FreeBSD 6.2 doesn't define __FreeBSD_kernel_version
Sam Lantinga <slouken@libsdl.org>
parents: 4305
diff changeset
43
403
8d431937739d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 402
diff changeset
44 #if defined(HAVE_USB_H)
8d431937739d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 402
diff changeset
45 #include <usb.h>
8d431937739d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 402
diff changeset
46 #endif
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
47 #ifdef __DragonFly__
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
48 #include <bus/usb/usb.h>
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
49 #include <bus/usb/usbhid.h>
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
50 #else
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 #include <dev/usb/usb.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 #include <dev/usb/usbhid.h>
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
53 #endif
358
1f148809d972 Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 307
diff changeset
54
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
55 #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
56 #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
57 #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
58 #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
59 #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
60 #include <libusbhid.h>
358
1f148809d972 Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 307
diff changeset
61 #endif
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
63 #ifdef __FREEBSD__
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
64 #ifndef __DragonFly__
611
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
65 #include <osreldate.h>
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
66 #endif
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
67 #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
68 #endif
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
69
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
70 #if SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
71 #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
72 #endif
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
73
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 #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
75 #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
76 #include "../SDL_joystick_c.h"
278
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 #define MAX_UHID_JOYS 4
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 #define MAX_JOY_JOYS 2
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 #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
81
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 struct report {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 struct usb_ctl_report *buf; /* Buffer */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 size_t size; /* Buffer size */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 int rid; /* Report ID */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 enum {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 SREPORT_UNINIT,
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 SREPORT_CLEAN,
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 SREPORT_DIRTY
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 } status;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 };
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 static struct {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 int uhid_report;
402
7efee6e36f00 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 381
diff changeset
95 hid_kind_t kind;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 const char *name;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 } const repinfo[] = {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 { UHID_INPUT_REPORT, hid_input, "input" },
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 { UHID_OUTPUT_REPORT, hid_output, "output" },
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 { UHID_FEATURE_REPORT, hid_feature, "feature" }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 };
307
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
102
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
103 enum {
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
104 REPORT_INPUT = 0,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
105 REPORT_OUTPUT = 1,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
106 REPORT_FEATURE = 2
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
107 };
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
108
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
109 enum {
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
110 JOYAXE_X,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
111 JOYAXE_Y,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
112 JOYAXE_Z,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
113 JOYAXE_SLIDER,
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
114 JOYAXE_WHEEL,
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
115 JOYAXE_RX,
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
116 JOYAXE_RY,
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
117 JOYAXE_RZ,
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
118 JOYAXE_count
307
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
119 };
278
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 struct joystick_hwdata {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 int fd;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 char *path;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 enum {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 BSDJOY_UHID, /* uhid(4) */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 BSDJOY_JOY /* joy(4) */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 } type;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 struct report_desc *repdesc;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 struct report inreport;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
130 int axis_map[JOYAXE_count]; /* map present JOYAXE_* to 0,1,..*/
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
131 int x;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
132 int y;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
133 int xmin;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
134 int ymin;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
135 int xmax;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
136 int ymax;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 };
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 static char *joynames[MAX_JOYS];
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 static char *joydevnames[MAX_JOYS];
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 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
143 static void report_free(struct report *);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144
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
145 #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
146 #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
147 #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
148 #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
149 #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
150
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 int
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 SDL_SYS_JoystickInit(void)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 {
503
2ee72e47ca08 Fixed memory overwrite in BSD joystick driver (thanks SUGIMOTO Sadahiro!)
Sam Lantinga <slouken@libsdl.org>
parents: 461
diff changeset
154 char s[16];
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 int i, fd;
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 SDL_numjoysticks = 0;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
159 SDL_memset(joynames, 0, sizeof(joynames));
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
160 SDL_memset(joydevnames, 0, sizeof(joydevnames));
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 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
163 SDL_Joystick nj;
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
164
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
165 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
166
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
167 nj.index = SDL_numjoysticks;
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
168 joynames[nj.index] = strdup(s);
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
169
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
170 if (SDL_SYS_JoystickOpen(&nj) == 0) {
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
171 SDL_SYS_JoystickClose(&nj);
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
172 SDL_numjoysticks++;
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
173 } else {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
174 SDL_free(joynames[nj.index]);
965
b68e551205e9 Fix from Alfred Perlstein
Sam Lantinga <slouken@libsdl.org>
parents: 776
diff changeset
175 joynames[nj.index] = NULL;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 }
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 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
179 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
180 fd = open(s, O_RDONLY);
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
181 if (fd != -1) {
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 joynames[SDL_numjoysticks++] = strdup(s);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 close(fd);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 /* Read the default USB HID usage table. */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 hid_init(NULL);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 return (SDL_numjoysticks);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 const char *
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 SDL_SYS_JoystickName(int index)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 if (joydevnames[index] != NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 return (joydevnames[index]);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 return (joynames[index]);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
202 static int
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
203 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
204 {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
205 int joyaxe;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
206 switch (usage) {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
207 case HUG_X:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
208 joyaxe = JOYAXE_X; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
209 case HUG_Y:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
210 joyaxe = JOYAXE_Y; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
211 case HUG_Z:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
212 joyaxe = JOYAXE_Z; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
213 case HUG_SLIDER:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
214 joyaxe = JOYAXE_SLIDER; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
215 case HUG_WHEEL:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
216 joyaxe = JOYAXE_WHEEL; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
217 case HUG_RX:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
218 joyaxe = JOYAXE_RX; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
219 case HUG_RY:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
220 joyaxe = JOYAXE_RY; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
221 case HUG_RZ:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
222 joyaxe = JOYAXE_RZ; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
223 default:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
224 joyaxe = -1;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
225 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
226 return joyaxe;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
227 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
228
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
229 static unsigned
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
230 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
231 {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
232 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
233 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
234 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
235 };
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
236 unsigned result;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
237 if ((hatval & 7) == hatval)
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
238 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
239 else
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
240 result = SDL_HAT_CENTERED;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
241 return result;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
242 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
243
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
244
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 int
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 SDL_SYS_JoystickOpen(SDL_Joystick *joy)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 char *path = joynames[joy->index];
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 struct joystick_hwdata *hw;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 struct hid_item hitem;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 struct hid_data *hdata;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 struct report *rep;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 int fd;
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
254 int i;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255
715
de0351c47596 Date: Mon, 01 Sep 2003 15:37:52 +0900
Sam Lantinga <slouken@libsdl.org>
parents: 632
diff changeset
256 fd = open(path, O_RDONLY);
544
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
257 if (fd == -1) {
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 SDL_SetError("%s: %s", path, strerror(errno));
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
262 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
263 if (hw == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 SDL_OutOfMemory();
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 close(fd);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 joy->hwdata = hw;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 hw->fd = fd;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 hw->path = strdup(path);
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
271 hw->x = 0;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
272 hw->y = 0;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
273 hw->xmin = 0xffff;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
274 hw->ymin = 0xffff;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
275 hw->xmax = 0;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
276 hw->ymax = 0;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
277 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
278 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
279 joy->naxes = 2;
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
280 joy->nbuttons = 2;
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
281 joy->nhats = 0;
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
282 joy->nballs = 0;
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
283 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
284 goto usbend;
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
285 } else {
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
286 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
287 }
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
288
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
289 {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
290 int ax;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
291 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
292 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
293 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 hw->repdesc = hid_get_report_desc(fd);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 if (hw->repdesc == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 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
297 strerror(errno));
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 goto usberr;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 rep = &hw->inreport;
1559
e7f61857028a ------- Comment #8 From Sergey Svishchev 2006-03-19 12:35 [reply] -------
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
302 if (ioctl(fd, USB_GET_REPORT_ID, &rep->rid) < 0) {
e7f61857028a ------- Comment #8 From Sergey Svishchev 2006-03-19 12:35 [reply] -------
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
303 rep->rid = -1; /* XXX */
e7f61857028a ------- Comment #8 From Sergey Svishchev 2006-03-19 12:35 [reply] -------
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
304 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 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
306 goto usberr;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 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
309 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
310 hw->path);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 goto usberr;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313
4305
ecb22f65f0aa Adapted from 215_kfreebsd_gnu.diff
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
314 #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_kernel_version >= 500111)
407
173909e17b7f API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents: 405
diff changeset
315 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
316 #else
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 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
318 #endif
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 if (hdata == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 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
321 goto usberr;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 joy->naxes = 0;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 joy->nbuttons = 0;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 joy->nhats = 0;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 joy->nballs = 0;
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
327 for (i=0; i<JOYAXE_count; i++)
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
328 hw->axis_map[i] = -1;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 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
331 char *sp;
1f148809d972 Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 307
diff changeset
332 const char *s;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 switch (hitem.kind) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 case hid_collection:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 switch (HID_PAGE(hitem.usage)) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 case HUP_GENERIC_DESKTOP:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 switch (HID_USAGE(hitem.usage)) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 case HUG_JOYSTICK:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 case HUG_GAME_PAD:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 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
342 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
343 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
344 joy->index);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 joydevnames[joy->index] = sp;
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 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 case hid_input:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 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
351 case HUP_GENERIC_DESKTOP: {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
352 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
353 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
354 if (joyaxe >= 0) {
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
355 hw->axis_map[joyaxe] = 1;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
356 } 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
357 joy->nhats++;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
358 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
359 break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
360 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 case HUP_BUTTON:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 joy->nbuttons++;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 break;
405
b5de7389a0a5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 404
diff changeset
364 default:
b5de7389a0a5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 404
diff changeset
365 break;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 default:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 hid_end_parse(hdata);
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
373 for (i=0; i<JOYAXE_count; i++)
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
374 if (hw->axis_map[i] > 0)
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
375 hw->axis_map[i] = joy->naxes++;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
377 usbend:
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 /* The poll blocks the event thread. */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 fcntl(fd, F_SETFL, O_NONBLOCK);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 return (0);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 usberr:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 close(hw->fd);
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
384 SDL_free(hw->path);
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
385 SDL_free(hw);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 void
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 SDL_SYS_JoystickUpdate(SDL_Joystick *joy)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 {
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
392 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
393 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
394 struct report *rep;
358
1f148809d972 Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 307
diff changeset
395 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
396 Sint32 v;
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
397
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
398 #if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
399 struct joystick gameport;
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
400
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
401 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
402 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
403 return;
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
404 if (abs(joy->hwdata->x - gameport.x) > 8) {
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
405 joy->hwdata->x = gameport.x;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
406 if (joy->hwdata->x < joy->hwdata->xmin) {
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
407 joy->hwdata->xmin = joy->hwdata->x;
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
408 }
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
409 if (joy->hwdata->x > joy->hwdata->xmax) {
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
410 joy->hwdata->xmax = joy->hwdata->x;
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
411 }
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
412 if (joy->hwdata->xmin == joy->hwdata->xmax) {
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
413 joy->hwdata->xmin--;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
414 joy->hwdata->xmax++;
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
415 }
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
416 v = (Sint32)joy->hwdata->x;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
417 v -= (joy->hwdata->xmax + joy->hwdata->xmin + 1)/2;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
418 v *= 32768/((joy->hwdata->xmax - joy->hwdata->xmin + 1)/2);
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
419 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
420 }
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
421 if (abs(joy->hwdata->y - gameport.y) > 8) {
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
422 joy->hwdata->y = gameport.y;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
423 if (joy->hwdata->y < joy->hwdata->ymin) {
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
424 joy->hwdata->ymin = joy->hwdata->y;
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
425 }
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
426 if (joy->hwdata->y > joy->hwdata->ymax) {
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
427 joy->hwdata->ymax = joy->hwdata->y;
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
428 }
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
429 if (joy->hwdata->ymin == joy->hwdata->ymax) {
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
430 joy->hwdata->ymin--;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
431 joy->hwdata->ymax++;
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
432 }
4022
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
433 v = (Sint32)joy->hwdata->y;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
434 v -= (joy->hwdata->ymax + joy->hwdata->ymin + 1)/2;
c5a6dcdaef04 Merged FreeBSD joystick patch
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
435 v *= 32768/((joy->hwdata->ymax - joy->hwdata->ymin + 1)/2);
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
436 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
437 }
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
438 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
439 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
440 }
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
441 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
442 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
443 }
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
444 return;
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
445 }
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
446 #endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 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
449
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
450 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
451 return;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 }
4305
ecb22f65f0aa Adapted from 215_kfreebsd_gnu.diff
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
453 #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_kernel_version >= 500111)
407
173909e17b7f API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents: 405
diff changeset
454 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
455 #else
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 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
457 #endif
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 if (hdata == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 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
460 joy->hwdata->path);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 return;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463
307
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
464 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
465 switch (hitem.kind) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 case hid_input:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467 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
468 case HUP_GENERIC_DESKTOP: {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
469 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
470 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
471 if (joyaxe >= 0) {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
472 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
473 /* 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
474 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
475 &hitem);
461
1d36f593078a Date: Thu, 18 Jul 2002 23:51:40 +0200 (MEST)
Sam Lantinga <slouken@libsdl.org>
parents: 426
diff changeset
476 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
477 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
478 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
479 SDL_PrivateJoystickAxis(joy, naxe, v);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 }
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
481 } 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
482 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
483 &hitem);
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
484 SDL_PrivateJoystickHat(joy, 0,
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
485 hatval_to_sdl(v)-hitem.logical_minimum);
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
486 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
487 break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
488 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 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
490 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
491 &hitem);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 if (joy->buttons[nbutton] != v) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 SDL_PrivateJoystickButton(joy,
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 nbutton, v);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 nbutton++;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497 break;
405
b5de7389a0a5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 404
diff changeset
498 default:
b5de7389a0a5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 404
diff changeset
499 continue;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 default:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 }
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 hid_end_parse(hdata);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 return;
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
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 /* Function to close a joystick after use */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 void
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 SDL_SYS_JoystickClose(SDL_Joystick *joy)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
515 if (SDL_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
516 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
517 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
518 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 close(joy->hwdata->fd);
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
520 SDL_free(joy->hwdata->path);
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
521 SDL_free(joy->hwdata);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 return;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 void
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 SDL_SYS_JoystickQuit(void)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 int i;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 for (i = 0; i < MAX_JOYS; i++) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 if (joynames[i] != NULL)
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
533 SDL_free(joynames[i]);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534 if (joydevnames[i] != NULL)
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
535 SDL_free(joydevnames[i]);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 return;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 static int
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 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
543 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 int len;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
546 #ifdef __DragonFly__
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
547 len = hid_report_size(rd, r->rid, repinfo[repind].kind);
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
548 #elif __FREEBSD__
4305
ecb22f65f0aa Adapted from 215_kfreebsd_gnu.diff
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
549 # if (__FreeBSD_kernel_version >= 460000) || defined(__FreeBSD_kernel__)
ecb22f65f0aa Adapted from 215_kfreebsd_gnu.diff
Sam Lantinga <slouken@libsdl.org>
parents: 4159
diff changeset
550 # if (__FreeBSD_kernel_version <= 500111)
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
551 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
552 # else
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
553 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
554 # endif
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
555 # else
544
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
556 len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
557 # endif
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
558 #else
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
559 # ifdef USBHID_NEW
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
560 len = hid_report_size(rd, repinfo[repind].kind, r->rid);
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
561 # else
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
562 len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
563 # endif
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
564 #endif
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
565
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 if (len < 0) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 SDL_SetError("Negative HID report size");
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 r->size = len;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 if (r->size > 0) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
573 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
574 r->size);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 if (r->buf == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 SDL_OutOfMemory();
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 } else {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 r->buf = NULL;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583 r->status = SREPORT_CLEAN;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 return (0);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 static void
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 report_free(struct report *r)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 if (r->buf != NULL) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
591 SDL_free(r->buf);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 r->status = SREPORT_UNINIT;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1565
diff changeset
596 #endif /* SDL_JOYSTICK_USBHID */