Mercurial > sdl-ios-xcode
annotate src/joystick/bsd/SDL_sysjoystick.c @ 407:173909e17b7f
API changes on OpenBSD and FreeBSD...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 12 Jun 2002 03:32:01 +0000 |
parents | b5de7389a0a5 |
children | 33712e5d1ec8 |
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 |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
278
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
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 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
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 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Library General Public License for more details. |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
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 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@devolution.com |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 /* |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 * Joystick driver for the uhid(4) interface found in OpenBSD, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 * NetBSD and FreeBSD. |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 * |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 * Maintainer: <vedge at csoft.org> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #ifdef SAVE_RCSID |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 static char rcsid = |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
32 "@(#) $Id$"; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 #endif |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 #include <stdio.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 #include <stdlib.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 #include <unistd.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 #include <fcntl.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 #include <string.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 #include <errno.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 |
403
8d431937739d
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
402
diff
changeset
|
42 #if defined(HAVE_USB_H) |
8d431937739d
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
402
diff
changeset
|
43 #include <usb.h> |
8d431937739d
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
402
diff
changeset
|
44 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 #include <dev/usb/usb.h> |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 #include <dev/usb/usbhid.h> |
358
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
47 |
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
|
48 #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
|
49 #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
|
50 #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
|
51 #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
|
52 #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
|
53 #include <libusbhid.h> |
358
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
54 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 #include "SDL_error.h" |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 #include "SDL_joystick.h" |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 #include "SDL_sysjoystick.h" |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 #include "SDL_joystick_c.h" |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 #define MAX_UHID_JOYS 4 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 #define MAX_JOY_JOYS 2 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 #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
|
64 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 struct report { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 struct usb_ctl_report *buf; /* Buffer */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 size_t size; /* Buffer size */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 int rid; /* Report ID */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 enum { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 SREPORT_UNINIT, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 SREPORT_CLEAN, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 SREPORT_DIRTY |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 } status; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 }; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 static struct { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 int uhid_report; |
402
7efee6e36f00
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
381
diff
changeset
|
78 hid_kind_t kind; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 const char *name; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 } const repinfo[] = { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 { UHID_INPUT_REPORT, hid_input, "input" }, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 { UHID_OUTPUT_REPORT, hid_output, "output" }, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 { UHID_FEATURE_REPORT, hid_feature, "feature" } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 }; |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
85 |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
86 enum { |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
87 REPORT_INPUT = 0, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
88 REPORT_OUTPUT = 1, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
89 REPORT_FEATURE = 2 |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
90 }; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
91 |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
92 enum { |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
93 JOYAXE_X, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
94 JOYAXE_Y, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
95 JOYAXE_Z, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
96 JOYAXE_SLIDER, |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
97 JOYAXE_WHEEL |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
98 }; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 struct joystick_hwdata { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 int fd; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 char *path; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 enum { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 BSDJOY_UHID, /* uhid(4) */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 BSDJOY_JOY /* joy(4) */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 } type; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 struct report_desc *repdesc; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 struct report inreport; |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
109 #if 0 |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
110 int axismin[]; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
111 int axismax[]; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
112 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 }; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 static char *joynames[MAX_JOYS]; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 static char *joydevnames[MAX_JOYS]; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 static int report_alloc(struct report *, struct report_desc *, int); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 static void report_free(struct report *); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 |
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
|
121 #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
|
122 #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
|
123 #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
|
124 #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
|
125 #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
|
126 |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 int |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 SDL_SYS_JoystickInit(void) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 char s[10]; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 int i, fd; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 SDL_numjoysticks = 0; |
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 memset(joynames, NULL, sizeof(joynames)); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 memset(joydevnames, NULL, sizeof(joydevnames)); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 for (i = 0; i < MAX_UHID_JOYS; i++) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 sprintf(s, "/dev/uhid%d", i); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 fd = open(s, O_RDWR); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 if (fd > 0) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 joynames[SDL_numjoysticks++] = strdup(s); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 close(fd); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 for (i = 0; i < MAX_JOY_JOYS; i++) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 sprintf(s, "/dev/joy%d", i); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 fd = open(s, O_RDWR); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 if (fd > 0) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 joynames[SDL_numjoysticks++] = strdup(s); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 close(fd); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 /* Read the default USB HID usage table. */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 hid_init(NULL); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 return (SDL_numjoysticks); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 const char * |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 SDL_SYS_JoystickName(int index) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 if (joydevnames[index] != NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 return (joydevnames[index]); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 return (joynames[index]); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 int |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 SDL_SYS_JoystickOpen(SDL_Joystick *joy) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 char *path = joynames[joy->index]; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 struct joystick_hwdata *hw; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 struct hid_item hitem; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 struct hid_data *hdata; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 struct report *rep; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 int fd; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 fd = open(path, O_RDWR); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 if (fd < 0) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 SDL_SetError("%s: %s", path, strerror(errno)); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 hw = (struct joystick_hwdata *)malloc(sizeof(struct joystick_hwdata)); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 if (hw == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 SDL_OutOfMemory(); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 close(fd); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 joy->hwdata = hw; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 hw->fd = fd; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 hw->path = strdup(path); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 hw->type = BSDJOY_UHID; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 hw->repdesc = hid_get_report_desc(fd); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 if (hw->repdesc == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 SDL_SetError("%s: USB_GET_REPORT_DESC: %s", hw->path, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 strerror(errno)); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 goto usberr; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 rep = &hw->inreport; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 if (report_alloc(rep, hw->repdesc, REPORT_INPUT) < 0) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 goto usberr; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 if (rep->size <= 0) { |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
208 SDL_SetError("%s: Input report descriptor has invalid length", |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
209 hw->path); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 goto usberr; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
213 #ifdef USBHID_NEW |
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
214 hdata = hid_start_parse(hw->repdesc, 1 << hid_input, rep->rid); |
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
215 #else |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 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
|
217 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 if (hdata == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 SDL_SetError("%s: Cannot start HID parser", hw->path); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 goto usberr; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 joy->naxes = 0; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 joy->nbuttons = 0; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 joy->nhats = 0; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 joy->nballs = 0; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 while (hid_get_item(hdata, &hitem) > 0) { |
358
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
228 char *sp; |
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
229 const char *s; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 switch (hitem.kind) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 case hid_collection: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 switch (HID_PAGE(hitem.usage)) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 case HUP_GENERIC_DESKTOP: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 switch (HID_USAGE(hitem.usage)) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 case HUG_JOYSTICK: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 case HUG_GAME_PAD: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 s = hid_usage_in_page(hitem.usage); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 sp = malloc(strlen(s) + 5); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 sprintf(sp, "%s (%d)", s, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 joy->index); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 joydevnames[joy->index] = sp; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 case hid_input: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 switch (HID_PAGE(hitem.usage)) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 case HUP_GENERIC_DESKTOP: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 switch (HID_USAGE(hitem.usage)) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 case HUG_X: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 case HUG_Y: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 case HUG_Z: |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
253 case HUG_SLIDER: |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
254 case HUG_WHEEL: |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
255 #if 0 |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 hw->axismin[joy->naxes] = |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 hitem.logical_minimum; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 hw->axismax[joy->naxes] = |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 hitem.logical_maximum; |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
260 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 joy->naxes++; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 case HUP_BUTTON: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 joy->nbuttons++; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 break; |
405
b5de7389a0a5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
404
diff
changeset
|
268 default: |
b5de7389a0a5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
404
diff
changeset
|
269 break; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 default: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 hid_end_parse(hdata); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 /* The poll blocks the event thread. */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 fcntl(fd, F_SETFL, O_NONBLOCK); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 return (0); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 usberr: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 close(hw->fd); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 free(hw->path); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 free(hw); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 void |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 SDL_SYS_JoystickUpdate(SDL_Joystick *joy) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 { |
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
|
292 struct hid_item hitem; |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
293 struct hid_data *hdata; |
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
294 struct report *rep; |
358
1f148809d972
Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents:
307
diff
changeset
|
295 int nbutton, naxe = -1; |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
296 Sint32 v; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 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
|
299 |
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
|
300 if (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) != rep->size) { |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 } |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
303 #ifdef USBHID_NEW |
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
304 hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input, rep->rid); |
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
305 #else |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 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
|
307 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 if (hdata == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 fprintf(stderr, "%s: Cannot start HID parser\n", |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 joy->hwdata->path); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
314 for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) { |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 switch (hitem.kind) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 case hid_input: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 switch (HID_PAGE(hitem.usage)) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 case HUP_GENERIC_DESKTOP: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 switch (HID_USAGE(hitem.usage)) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 case HUG_X: |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
321 naxe = JOYAXE_X; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
322 goto scaleaxe; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 case HUG_Y: |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
324 naxe = JOYAXE_Y; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
325 goto scaleaxe; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 case HUG_Z: |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
327 naxe = JOYAXE_Z; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
328 goto scaleaxe; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
329 case HUG_SLIDER: |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
330 naxe = JOYAXE_SLIDER; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
331 goto scaleaxe; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
332 case HUG_WHEEL: |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
333 naxe = JOYAXE_WHEEL; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
334 goto scaleaxe; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
335 } |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
336 scaleaxe: |
381
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
337 v = (Sint32)hid_get_data(REP_BUF_DATA(rep), |
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
|
338 &hitem); |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
339 if (v != 127) { |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
340 if (v < 127) { |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
341 v = -(256 - v); |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
342 v <<= 7; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
343 v++; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
344 } else { |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
345 v++; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
346 v <<= 7; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
347 v--; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 } |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
349 } else { |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
350 v = 0; |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
351 } |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
352 if (v != joy->axes[naxe]) { |
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
353 SDL_PrivateJoystickAxis(joy, naxe, v); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 case HUP_BUTTON: |
381
bc1401311390
Wilbern Cobb submitted a fix for building BSD joystick support that should work on all BSD flavors.
Sam Lantinga <slouken@libsdl.org>
parents:
358
diff
changeset
|
357 v = (Sint32)hid_get_data(REP_BUF_DATA(rep), |
307
0185452e9f83
This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
358 &hitem); |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 if (joy->buttons[nbutton] != v) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 SDL_PrivateJoystickButton(joy, |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 nbutton, v); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 nbutton++; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 break; |
405
b5de7389a0a5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
404
diff
changeset
|
365 default: |
b5de7389a0a5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
404
diff
changeset
|
366 continue; |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 default: |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 break; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 hid_end_parse(hdata); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 /* Function to close a joystick after use */ |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 void |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 SDL_SYS_JoystickClose(SDL_Joystick *joy) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 report_free(&joy->hwdata->inreport); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 hid_dispose_report_desc(joy->hwdata->repdesc); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 close(joy->hwdata->fd); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 free(joy->hwdata->path); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 free(joy->hwdata); |
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 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 void |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 SDL_SYS_JoystickQuit(void) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
394 int i; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
395 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 for (i = 0; i < MAX_JOYS; i++) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 if (joynames[i] != NULL) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 free(joynames[i]); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 if (joydevnames[i] != NULL) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 free(joydevnames[i]); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
402 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 return; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 static int |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 report_alloc(struct report *r, struct report_desc *rd, int repind) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 int len; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
411 #ifdef USBHID_NEW |
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
412 len = hid_report_size(rd, repinfo[repind].kind, r->rid); |
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
413 #else |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 len = hid_report_size(rd, repinfo[repind].kind, &r->rid); |
407
173909e17b7f
API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents:
405
diff
changeset
|
415 #endif |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 if (len < 0) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 SDL_SetError("Negative HID report size"); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 r->size = len; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 if (r->size > 0) { |
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
|
423 r->buf = malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) + |
278
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
424 r->size); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 if (r->buf == NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 SDL_OutOfMemory(); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 return (-1); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 } else { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 r->buf = NULL; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
432 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 r->status = SREPORT_CLEAN; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
434 return (0); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
435 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
436 |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
437 static void |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
438 report_free(struct report *r) |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
439 { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
440 if (r->buf != NULL) { |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 free(r->buf); |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
442 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 r->status = SREPORT_UNINIT; |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 } |
dcd9f7b50a1c
Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 |