annotate src/joystick/bsd/SDL_sysjoystick.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 92947e3a18db
children 4da1ee79c9af
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 */
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
403
8d431937739d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 402
diff changeset
39 #if defined(HAVE_USB_H)
8d431937739d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 402
diff changeset
40 #include <usb.h>
8d431937739d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 402
diff changeset
41 #endif
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
42 #ifdef __DragonFly__
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
43 #include <bus/usb/usb.h>
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
44 #include <bus/usb/usbhid.h>
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
45 #else
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #include <dev/usb/usb.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #include <dev/usb/usbhid.h>
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
48 #endif
358
1f148809d972 Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 307
diff changeset
49
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
50 #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
51 #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
52 #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
53 #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
54 #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
55 #include <libusbhid.h>
358
1f148809d972 Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 307
diff changeset
56 #endif
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
58 #ifdef __FREEBSD__
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
59 #ifndef __DragonFly__
611
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
60 #include <osreldate.h>
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
61 #endif
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
62 #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
63 #endif
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
64
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
65 #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
66 #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
67 #endif
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
68
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 #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
70 #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
71 #include "../SDL_joystick_c.h"
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 #define MAX_UHID_JOYS 4
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 #define MAX_JOY_JOYS 2
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 #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
76
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
77 struct report
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
78 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
79 struct usb_ctl_report *buf; /* Buffer */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
80 size_t size; /* Buffer size */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
81 int rid; /* Report ID */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
82 enum
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
83 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
84 SREPORT_UNINIT,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
85 SREPORT_CLEAN,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
86 SREPORT_DIRTY
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
87 } status;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 };
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
90 static struct
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
91 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
92 int uhid_report;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
93 hid_kind_t kind;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
94 const char *name;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 } const repinfo[] = {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
96 {UHID_INPUT_REPORT, hid_input, "input"},
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
97 {UHID_OUTPUT_REPORT, hid_output, "output"},
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
98 {UHID_FEATURE_REPORT, hid_feature, "feature"}
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 };
307
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
100
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
101 enum
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
102 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
103 REPORT_INPUT = 0,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
104 REPORT_OUTPUT = 1,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
105 REPORT_FEATURE = 2
307
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
106 };
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
107
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
108 enum
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
109 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
110 JOYAXE_X,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
111 JOYAXE_Y,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
112 JOYAXE_Z,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
113 JOYAXE_SLIDER,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
114 JOYAXE_WHEEL,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
115 JOYAXE_RX,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
116 JOYAXE_RY,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
117 JOYAXE_RZ,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
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
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
121 struct joystick_hwdata
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
122 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
123 int fd;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
124 char *path;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
125 enum
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
126 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
127 BSDJOY_UHID, /* uhid(4) */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
128 BSDJOY_JOY /* joy(4) */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
129 } type;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
130 struct report_desc *repdesc;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
131 struct report inreport;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
132 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
133 };
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 static char *joynames[MAX_JOYS];
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 static char *joydevnames[MAX_JOYS];
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
138 static int report_alloc (struct report *, struct report_desc *, int);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
139 static void report_free (struct report *);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140
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
141 #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
142 #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
143 #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
144 #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
145 #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
146
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 int
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
148 SDL_SYS_JoystickInit (void)
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
150 char s[16];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
151 int i, fd;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
153 SDL_numjoysticks = 0;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
155 SDL_memset (joynames, 0, sizeof (joynames));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
156 SDL_memset (joydevnames, 0, sizeof (joydevnames));
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
158 for (i = 0; i < MAX_UHID_JOYS; i++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
159 SDL_Joystick nj;
544
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
160
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
161 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
162
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
163 nj.index = SDL_numjoysticks;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
164 joynames[nj.index] = strdup (s);
544
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
165
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
166 if (SDL_SYS_JoystickOpen (&nj) == 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
167 SDL_SYS_JoystickClose (&nj);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
168 SDL_numjoysticks++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
169 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
170 SDL_free (joynames[nj.index]);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
171 joynames[nj.index] = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
172 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
173 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
174 for (i = 0; i < MAX_JOY_JOYS; i++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
175 SDL_snprintf (s, SDL_arraysize (s), "/dev/joy%d", i);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
176 fd = open (s, O_RDONLY);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
177 if (fd != -1) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
178 joynames[SDL_numjoysticks++] = strdup (s);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
179 close (fd);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
180 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
181 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
183 /* Read the default USB HID usage table. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
184 hid_init (NULL);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
186 return (SDL_numjoysticks);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 const char *
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
190 SDL_SYS_JoystickName (int index)
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
192 if (joydevnames[index] != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
193 return (joydevnames[index]);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
194 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
195 return (joynames[index]);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
198 static int
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
199 usage_to_joyaxe (unsigned usage)
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
200 {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
201 int joyaxe;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
202 switch (usage) {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
203 case HUG_X:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
204 joyaxe = JOYAXE_X;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
205 break;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
206 case HUG_Y:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
207 joyaxe = JOYAXE_Y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
208 break;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
209 case HUG_Z:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
210 joyaxe = JOYAXE_Z;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
211 break;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
212 case HUG_SLIDER:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
213 joyaxe = JOYAXE_SLIDER;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
214 break;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
215 case HUG_WHEEL:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
216 joyaxe = JOYAXE_WHEEL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
217 break;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
218 case HUG_RX:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
219 joyaxe = JOYAXE_RX;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
220 break;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
221 case HUG_RY:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
222 joyaxe = JOYAXE_RY;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
223 break;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
224 case HUG_RZ:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
225 joyaxe = JOYAXE_RZ;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
226 break;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
227 default:
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
228 joyaxe = -1;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
229 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
230 return joyaxe;
632
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
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
233 static unsigned
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
234 hatval_to_sdl (Sint32 hatval)
632
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 static const unsigned hat_dir_map[8] = {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
237 SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
238 SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
239 };
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
240 unsigned result;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
241 if ((hatval & 7) == hatval)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
242 result = hat_dir_map[hatval];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
243 else
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
244 result = SDL_HAT_CENTERED;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
245 return result;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
246 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
247
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
248
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 int
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
250 SDL_SYS_JoystickOpen (SDL_Joystick * joy)
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
252 char *path = joynames[joy->index];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
253 struct joystick_hwdata *hw;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
254 struct hid_item hitem;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
255 struct hid_data *hdata;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
256 struct report *rep;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
257 int fd;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
258 int i;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
260 fd = open (path, O_RDONLY);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
261 if (fd == -1) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
262 SDL_SetError ("%s: %s", path, strerror (errno));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
263 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
264 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
266 hw = (struct joystick_hwdata *)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
267 SDL_malloc (sizeof (struct joystick_hwdata));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
268 if (hw == NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
269 SDL_OutOfMemory ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
270 close (fd);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
271 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
272 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
273 joy->hwdata = hw;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
274 hw->fd = fd;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
275 hw->path = strdup (path);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
276 if (!SDL_strncmp (path, "/dev/joy", 8)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
277 hw->type = BSDJOY_JOY;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
278 joy->naxes = 2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
279 joy->nbuttons = 2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
280 joy->nhats = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
281 joy->nballs = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
282 joydevnames[joy->index] = strdup ("Gameport joystick");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
283 goto usbend;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
284 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
285 hw->type = BSDJOY_UHID;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
286 }
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
287
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
288 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
289 int ax;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
290 for (ax = 0; ax < JOYAXE_count; ax++)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
291 hw->axis_map[ax] = -1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
292 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
293 hw->repdesc = hid_get_report_desc (fd);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
294 if (hw->repdesc == NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
295 SDL_SetError ("%s: USB_GET_REPORT_DESC: %s", hw->path,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
296 strerror (errno));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
297 goto usberr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
298 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
300 rep = &hw->inreport;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
301 if (ioctl (fd, USB_GET_REPORT_ID, &rep->rid) < 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
302 rep->rid = -1; /* XXX */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
303 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
304 if (report_alloc (rep, hw->repdesc, REPORT_INPUT) < 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
305 goto usberr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
306 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
307 if (rep->size <= 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
308 SDL_SetError ("%s: Input report descriptor has invalid length",
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
309 hw->path);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
310 goto usberr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
311 }
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
312 #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_version >= 500111)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
313 hdata = hid_start_parse (hw->repdesc, 1 << hid_input, rep->rid);
407
173909e17b7f API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents: 405
diff changeset
314 #else
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
315 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
316 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
317 if (hdata == NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
318 SDL_SetError ("%s: Cannot start HID parser", hw->path);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
319 goto usberr;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
320 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
321 joy->naxes = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
322 joy->nbuttons = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
323 joy->nhats = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
324 joy->nballs = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
325 for (i = 0; i < JOYAXE_count; i++)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
326 hw->axis_map[i] = -1;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
328 while (hid_get_item (hdata, &hitem) > 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
329 char *sp;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
330 const char *s;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
332 switch (hitem.kind) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
333 case hid_collection:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
334 switch (HID_PAGE (hitem.usage)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
335 case HUP_GENERIC_DESKTOP:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
336 switch (HID_USAGE (hitem.usage)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
337 case HUG_JOYSTICK:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
338 case HUG_GAME_PAD:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
339 s = hid_usage_in_page (hitem.usage);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
340 sp = SDL_malloc (SDL_strlen (s) + 5);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
341 SDL_snprintf (sp, SDL_strlen (s) + 5, "%s (%d)",
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
342 s, joy->index);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
343 joydevnames[joy->index] = sp;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
344 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
345 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
346 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
347 case hid_input:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
348 switch (HID_PAGE (hitem.usage)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
349 case HUP_GENERIC_DESKTOP:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
350 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
351 unsigned usage = HID_USAGE (hitem.usage);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
352 int joyaxe = usage_to_joyaxe (usage);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
353 if (joyaxe >= 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
354 hw->axis_map[joyaxe] = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
355 } else if (usage == HUG_HAT_SWITCH) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
356 joy->nhats++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
357 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
358 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
359 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
360 case HUP_BUTTON:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
361 joy->nbuttons++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
362 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
363 default:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
364 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
365 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
366 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
367 default:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
368 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
369 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
370 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
371 hid_end_parse (hdata);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
372 for (i = 0; i < JOYAXE_count; i++)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
373 if (hw->axis_map[i] > 0)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
374 hw->axis_map[i] = joy->naxes++;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
376 usbend:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
377 /* The poll blocks the event thread. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
378 fcntl (fd, F_SETFL, O_NONBLOCK);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
380 return (0);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
381 usberr:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
382 close (hw->fd);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
383 SDL_free (hw->path);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
384 SDL_free (hw);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
385 return (-1);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 }
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 void
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
389 SDL_SYS_JoystickUpdate (SDL_Joystick * joy)
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
391 struct hid_item hitem;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
392 struct hid_data *hdata;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
393 struct report *rep;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
394 int nbutton, naxe = -1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
395 Sint32 v;
776
18922ae3ee07 Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
396
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
397 #if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
398 struct joystick gameport;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
399 static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
400
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
401 if (joy->hwdata->type == BSDJOY_JOY) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
402 if (read (joy->hwdata->fd, &gameport, sizeof gameport) !=
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
403 sizeof gameport)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
404 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
405 if (abs (x - gameport.x) > 8) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
406 x = gameport.x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
407 if (x < xmin) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
408 xmin = x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
409 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
410 if (x > xmax) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
411 xmax = x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
412 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
413 if (xmin == xmax) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
414 xmin--;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
415 xmax++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
416 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
417 v = (Sint32) x;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
418 v -= (xmax + xmin + 1) / 2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
419 v *= 32768 / ((xmax - xmin + 1) / 2);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
420 SDL_PrivateJoystickAxis (joy, 0, v);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
421 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
422 if (abs (y - gameport.y) > 8) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
423 y = gameport.y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
424 if (y < ymin) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
425 ymin = y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
426 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
427 if (y > ymax) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
428 ymax = y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
429 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
430 if (ymin == ymax) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
431 ymin--;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
432 ymax++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
433 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
434 v = (Sint32) y;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
435 v -= (ymax + ymin + 1) / 2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
436 v *= 32768 / ((ymax - ymin + 1) / 2);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
437 SDL_PrivateJoystickAxis (joy, 1, v);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
438 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
439 if (gameport.b1 != joy->buttons[0]) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
440 SDL_PrivateJoystickButton (joy, 0, gameport.b1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
441 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
442 if (gameport.b2 != joy->buttons[1]) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
443 SDL_PrivateJoystickButton (joy, 1, gameport.b2);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
444 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
445 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
446 }
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
447 #endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
448
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
449 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
450
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
451 if (read (joy->hwdata->fd, REP_BUF_DATA (rep), rep->size) != rep->size) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
452 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
453 }
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
454 #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_version >= 500111)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
455 hdata = hid_start_parse (joy->hwdata->repdesc, 1 << hid_input, rep->rid);
407
173909e17b7f API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents: 405
diff changeset
456 #else
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
457 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
458 #endif
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
459 if (hdata == NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
460 fprintf (stderr, "%s: Cannot start HID parser\n", joy->hwdata->path);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
461 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
462 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
464 for (nbutton = 0; hid_get_item (hdata, &hitem) > 0;) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
465 switch (hitem.kind) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
466 case hid_input:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
467 switch (HID_PAGE (hitem.usage)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
468 case HUP_GENERIC_DESKTOP:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
469 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
470 unsigned usage = HID_USAGE (hitem.usage);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
471 int joyaxe = usage_to_joyaxe (usage);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
472 if (joyaxe >= 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
473 naxe = joy->hwdata->axis_map[joyaxe];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
474 /* scaleaxe */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
475 v = (Sint32) hid_get_data (REP_BUF_DATA (rep),
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
476 &hitem);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
477 v -= (hitem.logical_maximum +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
478 hitem.logical_minimum + 1) / 2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
479 v *= 32768 /
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
480 ((hitem.logical_maximum -
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
481 hitem.logical_minimum + 1) / 2);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
482 if (v != joy->axes[naxe]) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
483 SDL_PrivateJoystickAxis (joy, naxe, v);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
484 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
485 } else if (usage == HUG_HAT_SWITCH) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
486 v = (Sint32) hid_get_data (REP_BUF_DATA (rep),
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
487 &hitem);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
488 SDL_PrivateJoystickHat (joy, 0,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
489 hatval_to_sdl (v) -
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
490 hitem.logical_minimum);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
491 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
492 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
493 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
494 case HUP_BUTTON:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
495 v = (Sint32) hid_get_data (REP_BUF_DATA (rep), &hitem);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
496 if (joy->buttons[nbutton] != v) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
497 SDL_PrivateJoystickButton (joy, nbutton, v);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
498 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
499 nbutton++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
500 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
501 default:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
502 continue;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
503 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
504 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
505 default:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
506 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
507 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
508 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
509 hid_end_parse (hdata);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
511 return;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 /* Function to close a joystick after use */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 void
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
516 SDL_SYS_JoystickClose (SDL_Joystick * joy)
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
518 if (SDL_strncmp (joy->hwdata->path, "/dev/joy", 8)) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
519 report_free (&joy->hwdata->inreport);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
520 hid_dispose_report_desc (joy->hwdata->repdesc);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
521 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
522 close (joy->hwdata->fd);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
523 SDL_free (joy->hwdata->path);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
524 SDL_free (joy->hwdata);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
526 return;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 }
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 void
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
530 SDL_SYS_JoystickQuit (void)
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
532 int i;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
534 for (i = 0; i < MAX_JOYS; i++) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
535 if (joynames[i] != NULL)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
536 SDL_free (joynames[i]);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
537 if (joydevnames[i] != NULL)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
538 SDL_free (joydevnames[i]);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
539 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
541 return;
278
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
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 static int
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
545 report_alloc (struct report *r, struct report_desc *rd, int repind)
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
547 int len;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
549 #ifdef __DragonFly__
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
550 len = hid_report_size (rd, r->rid, repinfo[repind].kind);
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
551 #elif __FREEBSD__
715
de0351c47596 Date: Mon, 01 Sep 2003 15:37:52 +0900
Sam Lantinga <slouken@libsdl.org>
parents: 632
diff changeset
552 # 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
553 # if (__FreeBSD_version <= 500111)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
554 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
555 # else
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
556 len = hid_report_size (rd, repinfo[repind].kind, r->rid);
611
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
557 # endif
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
558 # else
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
559 len = hid_report_size (rd, repinfo[repind].kind, &r->rid);
1565
57431b199aed Fixed bug #52
Sam Lantinga <slouken@libsdl.org>
parents: 1559
diff changeset
560 # endif
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
561 #else
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
562 # ifdef USBHID_NEW
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
563 len = hid_report_size (rd, repinfo[repind].kind, r->rid);
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
564 # else
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
565 len = hid_report_size (rd, repinfo[repind].kind, &r->rid);
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
566 # endif
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
567 #endif
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
568
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
569 if (len < 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
570 SDL_SetError ("Negative HID report size");
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
571 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
572 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
573 r->size = len;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
575 if (r->size > 0) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
576 r->buf = SDL_malloc (sizeof (*r->buf) - sizeof (REP_BUF_DATA (r)) +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
577 r->size);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
578 if (r->buf == NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
579 SDL_OutOfMemory ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
580 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
581 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
582 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
583 r->buf = NULL;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
584 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
586 r->status = SREPORT_CLEAN;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
587 return (0);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 }
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 static void
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
591 report_free (struct report *r)
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
593 if (r->buf != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
594 SDL_free (r->buf);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
595 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
596 r->status = SREPORT_UNINIT;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1565
diff changeset
599 #endif /* SDL_JOYSTICK_USBHID */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1635
diff changeset
600 /* vi: set ts=4 sw=4 expandtab: */