annotate src/joystick/bsd/SDL_sysjoystick.c @ 715:de0351c47596

Date: Mon, 01 Sep 2003 15:37:52 +0900 From: SUGIMOTO Sadahiro Subject: [SDL] [PATCH] bsd joystick Hi, on FreeBSD systems, I had troubles using a USB joystick with SDL. There are two problems in src/joystick/bsd/SDL_sysjoystick.c . 1. The macro __FreeBSD_version is compared to inappropriate numbers. According to http://www.jp.freebsd.org/cgi/cvsweb.cgi/src/lib/libusbhid/usbhid.h http://www.jp.freebsd.org/cgi/cvsweb.cgi/src/lib/libusbhid/Attic/libusb.h http://www.jp.freebsd.org/cgi/cvsweb.cgi/src/lib/libusbhid/Attic/libusbhid.h the APIs of USB HID are common in each following groups of OS versions, a. 4.1-4.5 b. 4.6-4.8, and 5.0 c. 5.1 2. open() error $ uname -sr FreeBSD 5.1-RELEASE $ ls -l /dev/uhid0 crw-r--r-- 1 root operator 122, 0 8 3 14:06 /dev/uhid0 Then, open("/dev/uhid0", O_RDWR) fails. It seems that this device file does not need to be writable, so O_RDONLY may be suitable.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 05 Sep 2003 15:20:47 +0000
parents 85e104fe14c2
children b8d311d90021
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
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
35 #include <sys/param.h>
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
36
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include <stdio.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include <stdlib.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include <unistd.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include <fcntl.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #include <string.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #include <errno.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43
403
8d431937739d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 402
diff changeset
44 #if defined(HAVE_USB_H)
8d431937739d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 402
diff changeset
45 #include <usb.h>
8d431937739d *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 402
diff changeset
46 #endif
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 #include <dev/usb/usb.h>
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 #include <dev/usb/usbhid.h>
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
611
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
58 #ifdef __FreeBSD__
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
59 #include <osreldate.h>
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
60 #endif
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
61
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 #include "SDL_error.h"
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 #include "SDL_joystick.h"
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 #include "SDL_sysjoystick.h"
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 #include "SDL_joystick_c.h"
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 #define MAX_UHID_JOYS 4
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 #define MAX_JOY_JOYS 2
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 #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
70
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 struct report {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 struct usb_ctl_report *buf; /* Buffer */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 size_t size; /* Buffer size */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 int rid; /* Report ID */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 enum {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 SREPORT_UNINIT,
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 SREPORT_CLEAN,
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 SREPORT_DIRTY
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 } status;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 };
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 static struct {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 int uhid_report;
402
7efee6e36f00 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 381
diff changeset
84 hid_kind_t kind;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 const char *name;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 } const repinfo[] = {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 { UHID_INPUT_REPORT, hid_input, "input" },
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 { UHID_OUTPUT_REPORT, hid_output, "output" },
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 { UHID_FEATURE_REPORT, hid_feature, "feature" }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 };
307
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 REPORT_INPUT = 0,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
94 REPORT_OUTPUT = 1,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
95 REPORT_FEATURE = 2
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
96 };
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
97
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
98 enum {
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
99 JOYAXE_X,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
100 JOYAXE_Y,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
101 JOYAXE_Z,
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
102 JOYAXE_SLIDER,
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
103 JOYAXE_WHEEL,
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
104 JOYAXE_RX,
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
105 JOYAXE_RY,
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
106 JOYAXE_RZ,
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
107 JOYAXE_count
307
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
108 };
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 struct joystick_hwdata {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 int fd;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 char *path;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 enum {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 BSDJOY_UHID, /* uhid(4) */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 BSDJOY_JOY /* joy(4) */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 } type;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 struct report_desc *repdesc;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 struct report inreport;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
119 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
120 };
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 static char *joynames[MAX_JOYS];
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 static char *joydevnames[MAX_JOYS];
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 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
126 static void report_free(struct report *);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127
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
128 #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
129 #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
130 #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
131 #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
132 #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
133
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 int
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 SDL_SYS_JoystickInit(void)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 {
503
2ee72e47ca08 Fixed memory overwrite in BSD joystick driver (thanks SUGIMOTO Sadahiro!)
Sam Lantinga <slouken@libsdl.org>
parents: 461
diff changeset
137 char s[16];
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 int i, fd;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 SDL_numjoysticks = 0;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 memset(joynames, NULL, sizeof(joynames));
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 memset(joydevnames, NULL, sizeof(joydevnames));
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 for (i = 0; i < MAX_UHID_JOYS; i++) {
544
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
146 SDL_Joystick nj;
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
147
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 sprintf(s, "/dev/uhid%d", i);
544
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
149
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
150 nj.index = SDL_numjoysticks;
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
151 joynames[nj.index] = strdup(s);
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
152
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
153 if (SDL_SYS_JoystickOpen(&nj) == 0) {
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
154 SDL_SYS_JoystickClose(&nj);
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
155 SDL_numjoysticks++;
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
156 } else {
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
157 free(joynames[nj.index]);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 }
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 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
161 sprintf(s, "/dev/joy%d", i);
544
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
162 fd = open(s, O_RDONLY);
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
163 if (fd != -1) {
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 joynames[SDL_numjoysticks++] = strdup(s);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 close(fd);
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 }
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 /* Read the default USB HID usage table. */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 hid_init(NULL);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 return (SDL_numjoysticks);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 const char *
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 SDL_SYS_JoystickName(int index)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 if (joydevnames[index] != NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 return (joydevnames[index]);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 return (joynames[index]);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
184 static int
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
185 usage_to_joyaxe(unsigned usage)
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
186 {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
187 int joyaxe;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
188 switch (usage) {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
189 case HUG_X:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
190 joyaxe = JOYAXE_X; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
191 case HUG_Y:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
192 joyaxe = JOYAXE_Y; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
193 case HUG_Z:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
194 joyaxe = JOYAXE_Z; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
195 case HUG_SLIDER:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
196 joyaxe = JOYAXE_SLIDER; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
197 case HUG_WHEEL:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
198 joyaxe = JOYAXE_WHEEL; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
199 case HUG_RX:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
200 joyaxe = JOYAXE_RX; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
201 case HUG_RY:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
202 joyaxe = JOYAXE_RY; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
203 case HUG_RZ:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
204 joyaxe = JOYAXE_RZ; break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
205 default:
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
206 joyaxe = -1;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
207 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
208 return joyaxe;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
209 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
210
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
211 static unsigned
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
212 hatval_to_sdl(Sint32 hatval)
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
213 {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
214 static const unsigned hat_dir_map[8] = {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
215 SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN,
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
216 SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
217 };
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
218 unsigned result;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
219 if ((hatval & 7) == hatval)
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
220 result = hat_dir_map[hatval];
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
221 else
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
222 result = SDL_HAT_CENTERED;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
223 return result;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
224 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
225
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
226
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 int
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 SDL_SYS_JoystickOpen(SDL_Joystick *joy)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 char *path = joynames[joy->index];
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 struct joystick_hwdata *hw;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 struct hid_item hitem;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 struct hid_data *hdata;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 struct report *rep;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 int fd;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236
715
de0351c47596 Date: Mon, 01 Sep 2003 15:37:52 +0900
Sam Lantinga <slouken@libsdl.org>
parents: 632
diff changeset
237 fd = open(path, O_RDONLY);
544
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
238 if (fd == -1) {
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 SDL_SetError("%s: %s", path, strerror(errno));
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 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
244 if (hw == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 SDL_OutOfMemory();
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 close(fd);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 joy->hwdata = hw;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 hw->fd = fd;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 hw->path = strdup(path);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 hw->type = BSDJOY_UHID;
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
253 {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
254 int ax;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
255 for (ax = 0; ax < JOYAXE_count; ax++)
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
256 hw->axis_map[ax] = -1;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
257 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 hw->repdesc = hid_get_report_desc(fd);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 if (hw->repdesc == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 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
261 strerror(errno));
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 goto usberr;
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
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 rep = &hw->inreport;
611
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
266 rep->rid = 0;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 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
268 goto usberr;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 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
271 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
272 hw->path);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 goto usberr;
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
611
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
276 #if defined(USBHID_NEW) || (defined(__FreeBSD__) && __FreeBSD_version >= 500111)
407
173909e17b7f API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents: 405
diff changeset
277 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
278 #else
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 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
280 #endif
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 if (hdata == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 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
283 goto usberr;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 joy->naxes = 0;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 joy->nbuttons = 0;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 joy->nhats = 0;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 joy->nballs = 0;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 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
291 char *sp;
1f148809d972 Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 307
diff changeset
292 const char *s;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 switch (hitem.kind) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 case hid_collection:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 switch (HID_PAGE(hitem.usage)) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 case HUP_GENERIC_DESKTOP:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 switch (HID_USAGE(hitem.usage)) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 case HUG_JOYSTICK:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 case HUG_GAME_PAD:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 s = hid_usage_in_page(hitem.usage);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 sp = malloc(strlen(s) + 5);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 sprintf(sp, "%s (%d)", s,
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 joy->index);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 joydevnames[joy->index] = sp;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 case hid_input:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 switch (HID_PAGE(hitem.usage)) {
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
311 case HUP_GENERIC_DESKTOP: {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
312 unsigned usage = HID_USAGE(hitem.usage);
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
313 int joyaxe = usage_to_joyaxe(usage);
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
314 if (joyaxe >= 0) {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
315 hw->axis_map[joyaxe] = joy->naxes;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
316 joy->naxes++;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
317 } else if (usage == HUG_HAT_SWITCH) {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
318 joy->nhats++;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
319 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
320 break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
321 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 case HUP_BUTTON:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 joy->nbuttons++;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 break;
405
b5de7389a0a5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 404
diff changeset
325 default:
b5de7389a0a5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 404
diff changeset
326 break;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 default:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 hid_end_parse(hdata);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 /* The poll blocks the event thread. */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 fcntl(fd, F_SETFL, O_NONBLOCK);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 return (0);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 usberr:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 close(hw->fd);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 free(hw->path);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 free(hw);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 void
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 SDL_SYS_JoystickUpdate(SDL_Joystick *joy)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 {
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
349 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
350 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
351 struct report *rep;
358
1f148809d972 Wilbern Cobb fixed joystick code on FreeBSD
Sam Lantinga <slouken@libsdl.org>
parents: 307
diff changeset
352 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
353 Sint32 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 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
356
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 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
358 return;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 }
611
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
360 #if defined(USBHID_NEW) || (defined(__FreeBSD__) && __FreeBSD_version >= 500111)
407
173909e17b7f API changes on OpenBSD and FreeBSD...
Sam Lantinga <slouken@libsdl.org>
parents: 405
diff changeset
361 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
362 #else
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 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
364 #endif
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 if (hdata == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 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
367 joy->hwdata->path);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 return;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370
307
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
371 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
372 switch (hitem.kind) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 case hid_input:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 switch (HID_PAGE(hitem.usage)) {
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
375 case HUP_GENERIC_DESKTOP: {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
376 unsigned usage = HID_USAGE(hitem.usage);
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
377 int joyaxe = usage_to_joyaxe(usage);
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
378 if (joyaxe >= 0) {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
379 naxe = joy->hwdata->axis_map[joyaxe];
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
380 /* 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
381 v = (Sint32)hid_get_data(REP_BUF_DATA(rep),
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
382 &hitem);
461
1d36f593078a Date: Thu, 18 Jul 2002 23:51:40 +0200 (MEST)
Sam Lantinga <slouken@libsdl.org>
parents: 426
diff changeset
383 v -= (hitem.logical_maximum + hitem.logical_minimum + 1)/2;
1d36f593078a Date: Thu, 18 Jul 2002 23:51:40 +0200 (MEST)
Sam Lantinga <slouken@libsdl.org>
parents: 426
diff changeset
384 v *= 32768/((hitem.logical_maximum - hitem.logical_minimum + 1)/2);
307
0185452e9f83 This properly scales axes, and adds support for sliders/wheels
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
385 if (v != joy->axes[naxe]) {
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
386 SDL_PrivateJoystickAxis(joy, naxe, v);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 }
632
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
388 } else if (usage == HUG_HAT_SWITCH) {
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
389 v = (Sint32)hid_get_data(REP_BUF_DATA(rep),
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
390 &hitem);
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
391 SDL_PrivateJoystickHat(joy, 0, hatval_to_sdl(v));
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
392 }
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
393 break;
85e104fe14c2 Date: Sun, 1 Jun 2003 15:38:45 -0700 (PDT)
Sam Lantinga <slouken@libsdl.org>
parents: 611
diff changeset
394 }
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 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
396 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
397 &hitem);
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 if (joy->buttons[nbutton] != v) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 SDL_PrivateJoystickButton(joy,
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 nbutton, v);
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 nbutton++;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 break;
405
b5de7389a0a5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 404
diff changeset
404 default:
b5de7389a0a5 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 404
diff changeset
405 continue;
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 default:
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 break;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 hid_end_parse(hdata);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 return;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 /* Function to close a joystick after use */
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 void
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 SDL_SYS_JoystickClose(SDL_Joystick *joy)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 report_free(&joy->hwdata->inreport);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 hid_dispose_report_desc(joy->hwdata->repdesc);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 close(joy->hwdata->fd);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 free(joy->hwdata->path);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 free(joy->hwdata);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 return;
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
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 void
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 SDL_SYS_JoystickQuit(void)
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 int i;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 for (i = 0; i < MAX_JOYS; i++) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 if (joynames[i] != NULL)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 free(joynames[i]);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 if (joydevnames[i] != NULL)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 free(joydevnames[i]);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 return;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 }
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 static int
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 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
447 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 int len;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
450 #ifdef __FreeBSD__
715
de0351c47596 Date: Mon, 01 Sep 2003 15:37:52 +0900
Sam Lantinga <slouken@libsdl.org>
parents: 632
diff changeset
451 # 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
452 # if (__FreeBSD_version <= 500111)
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
453 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
454 # else
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
455 len = hid_report_size(rd, repinfo[repind].kind, r->rid);
0a2ef9e8ca41 Date: Wed, 9 Apr 2003 01:03:25 -0400 (EDT)
Sam Lantinga <slouken@libsdl.org>
parents: 552
diff changeset
456 # endif
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
457 # else
544
2d7373ffd131 Fixed bsd joystick detection ... again (thanks Wilbern)
Sam Lantinga <slouken@libsdl.org>
parents: 503
diff changeset
458 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
459 #endif
552
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
460 #else
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
461 # ifdef USBHID_NEW
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
462 len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
463 # else
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
464 len = hid_report_size(rd, repinfo[repind].kind, r->rid);
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
465 # endif
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
466 #endif
639d58d32471 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 544
diff changeset
467
278
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 if (len < 0) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 SDL_SetError("Negative HID report size");
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 r->size = len;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 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
475 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
476 r->size);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 if (r->buf == NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478 SDL_OutOfMemory();
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 return (-1);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 } else {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 r->buf = NULL;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 r->status = SREPORT_CLEAN;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 return (0);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 static void
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 report_free(struct report *r)
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 if (r->buf != NULL) {
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 free(r->buf);
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 r->status = SREPORT_UNINIT;
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 }
dcd9f7b50a1c Added support for joysticks on *BSD (thanks Wilbern!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497