2 * Copyright 1995 by Frederic Lepied, France. <fred@sugix.frmug.fr.net>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Frederic Lepied not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Frederic Lepied makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
24 /* Modified for FreeBSD by David Dawes <dawes@XFree86.org> */
27 #ifdef HAVE_XORG_CONFIG_H
28 #include <xorg-config.h>
31 #include <sys/types.h>
35 #include <machine/joystick.h>
41 #define JS_RETURN sizeof(struct joystick)
43 /***********************************************************************
47 * open the device and init timeout according to the device value.
49 ***********************************************************************
53 xf86JoystickOn(char * name
, int *timeout
, int *centerX
, int *centerY
)
61 ErrorF("xf86JoystickOn: %s\n", name
);
64 if ((status
= open(name
, O_RDWR
| O_NDELAY
, 0)) < 0)
66 xf86Msg(X_WARNING
, "xf86JoystickOn: Cannot open joystick '%s' (%s)\n",
67 name
, strerror(errno
));
72 /* Use the current setting */
73 ioctl(status
, JOY_GETTIMEOUT
, (char *)&timeinmicros
);
74 *timeout
= timeinmicros
/ 1000;
79 /* Maximum allowed timeout in the FreeBSD driver is 10ms */
86 xf86Msg(X_PROBED
, "Joystick: timeout value = %d\n", *timeout
);
88 timeinmicros
= *timeout
* 1000;
90 /* Assume the joystick is centred when this is called */
91 read(status
, &js
, JS_RETURN
);
94 xf86Msg(X_PROBED
, "Joystick: CenterX set to %d\n", *centerX
);
98 xf86Msg(X_PROBED
, "Joystick: CenterY set to %d\n", *centerY
);
104 /***********************************************************************
106 * xf86JoystickInit --
108 * called when X device is initialized.
110 ***********************************************************************
119 /***********************************************************************
125 ***********************************************************************
129 xf86JoystickOff(int *fd
, int doclose
)
133 if (((oldfd
= *fd
) >= 0) && doclose
) {
140 /***********************************************************************
142 * xf86JoystickGetState --
144 * return the state of buttons and the position of the joystick.
146 ***********************************************************************
150 xf86JoystickGetState(int fd
, int *x
, int *y
, int *buttons
)
155 status
= read(fd
, &js
, JS_RETURN
);
157 if (status
!= JS_RETURN
)
159 Error("Joystick read");
165 *buttons
= js
.b1
| (js
.b2
<< 1);
167 ErrorF("xf86JoystickGetState: x = %d, y = %d, buttons = %d\n", *x
, *y
,
175 * Entry point for XFree86 Loader
178 bsd_jstkModuleInit(pointer
*data
, INT32
*magic
)
183 /* end of bsd_jstk.c */