summaryrefslogtreecommitdiffstats
path: root/input/joystick.c
diff options
context:
space:
mode:
authoralbeu <albeu@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-02-03 19:13:00 +0000
committeralbeu <albeu@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-02-03 19:13:00 +0000
commite4be4973e2914e42727e5c9b8d0a66ee6de01448 (patch)
treea1d21c3ab8ea6c22b8d39a880e42ad1cb3d1ca32 /input/joystick.c
parent416e711c711d976001b29b05e2f1f0c5d5152c0f (diff)
downloadmpv-e4be4973e2914e42727e5c9b8d0a66ee6de01448.tar.bz2
mpv-e4be4973e2914e42727e5c9b8d0a66ee6de01448.tar.xz
Corrected the quit bug and added support for up to 10 axis
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4519 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'input/joystick.c')
-rw-r--r--input/joystick.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/input/joystick.c b/input/joystick.c
index 7bb7f0d86b..bf5eb74b2b 100644
--- a/input/joystick.c
+++ b/input/joystick.c
@@ -129,14 +129,13 @@ int mp_input_joystick_read(int fd) {
ev.type &= ~JS_EVENT_INIT;
if(ev.type & JS_EVENT_BUTTON) {
- int b = buttons | (ev.value << ev.number);
- if(b != buttons)
+ if(ev.value != ( 1 & (buttons >> ev.number)))
return JOY_BTN0+ev.number;
} else if(ev.type & JS_EVENT_AXIS) {
if(ev.value - axis[ev.number] > JOY_AXIS_DELTA)
- return ev.number == 0 ? JOY_UP : JOY_LEFT;
+ return JOY_AXIS0_MINUS+(2*ev.number);
else if(axis[ev.number] - ev.value > JOY_AXIS_DELTA)
- return ev.number == 0 ? JOY_DOWN : JOY_RIGHT;
+ return JOY_AXIS0_PLUS+(2*ev.number);
} else {
printf("Joystick warning unknow event type %d\n",ev.type);
return MP_INPUT_ERROR;
@@ -145,6 +144,32 @@ int mp_input_joystick_read(int fd) {
return MP_INPUT_NOTHING;
}
+void
+mp_input_joystick_close(int fd) {
+ struct js_event ev;
+ int l=0;
+ fd_set fds;
+ struct timeval tv;
+
+ // Wait to see if there is any stale relaease event in the queue (when we quit we the joystick)
+ FD_SET(fd,&fds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 2000000;
+ if(select(fd+1,&fds,NULL,NULL,&tv) > 0) {
+ while((unsigned int)l < sizeof(struct js_event)) {
+ int r = read(fd,&ev+l,sizeof(struct js_event)-l);
+ if(r <= 0) {
+ if(errno == EINTR)
+ continue;
+ else
+ break;
+ }
+ l += r;
+ }
+ }
+ close(fd);
+}
+
#else
// dummy function
@@ -158,6 +183,11 @@ int mp_input_joystick_read(int fd) {
return MP_INPUT_NOTHING;
}
+void
+mp_input_joystick_close(int fd) {
+
+}
+
#endif
#endif