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.
25 static const char rcs_id
[] = "Id: lnx_jstk.c,v 1.1 1995/12/20 14:06:09 lepied Exp";
27 #ifdef HAVE_XORG_CONFIG_H
28 #include <xorg-config.h>
31 #include <sys/types.h>
35 #define inline __inline__
36 #include <linux/joystick.h>
38 #include <sys/ioctl.h>
42 #if !defined(JSIOCGTIMELIMIT)
43 /* make 2.1.x joystick.h backward compatable */
44 #define JSIOCGTIMELIMIT JS_GET_TIMELIMIT
45 #define JSIOCSTIMELIMIT JS_SET_TIMELIMIT
46 #define js_status JS_DATA_TYPE
50 /***********************************************************************
54 * open the device and init timeout according to the device value.
56 ***********************************************************************
60 xf86JoystickOn(char *name
, int *timeout
, int *centerX
, int *centerY
)
66 ErrorF("xf86JoystickOn %s\n", name
);
69 if ((fd
= open(name
, O_RDWR
| O_NDELAY
, 0)) < 0)
71 xf86Msg(X_WARNING
, "Cannot open joystick '%s' (%s)\n", name
,
77 if (ioctl (fd
, JSIOCGTIMELIMIT
, timeout
) == -1) {
78 Error("joystick JSIOCGTIMELIMIT ioctl");
81 xf86Msg(X_CONFIG
, "Joystick: timeout value = %d\n", *timeout
);
85 if (ioctl(fd
, JSIOCSTIMELIMIT
, timeout
) == -1) {
86 Error("joystick JSIOCSTIMELIMIT ioctl");
90 /* Assume the joystick is centred when this is called */
91 read(fd
, &js
, JS_RETURN
);
94 xf86Msg(X_CONFIG
, "Joystick: CenterX set to %d\n", *centerX
);
98 xf86Msg(X_CONFIG
, "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
.buttons
;
171 * Entry point for XFree86 Loader
174 linux_jstkModuleInit(pointer
*data
, INT32
*magic
)
180 /* end of lnx_jstk.c */