summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authoralbeu <albeu@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-02-04 14:19:54 +0000
committeralbeu <albeu@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-02-04 14:19:54 +0000
commitb1abc1a384081642b7eef756e2b398d58ee60fe4 (patch)
treedb0c59ce954db6b1341bcbec9ff65b198f9d8b84 /input
parentf6787a2265915c08bf691784bc85caa5a46c3914 (diff)
downloadmpv-b1abc1a384081642b7eef756e2b398d58ee60fe4.tar.bz2
mpv-b1abc1a384081642b7eef756e2b398d58ee60fe4.tar.xz
Fix the bugs the previous version should fix (and those introduced
by the previous version ;) ) git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4525 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'input')
-rw-r--r--input/input.c10
-rw-r--r--input/joystick.c73
-rw-r--r--input/joystick.h2
3 files changed, 11 insertions, 74 deletions
diff --git a/input/input.c b/input/input.c
index 648553c0fe..4db77d280e 100644
--- a/input/input.c
+++ b/input/input.c
@@ -76,10 +76,10 @@ static mp_cmd_bind_t key_names[] = {
{ KEY_DOWN, "DOWN" },
{ KEY_UP, "UP" },
#ifdef HAVE_JOYSTICK
- { JOY_AXIS1_PLUS, "JOY_UP" },
- { JOY_AXIS1_MINUS, "JOY_DOWN" },
- { JOY_AXIS0_PLUS, "JOY_LEFT" },
- { JOY_AXIS0_MINUS, "JOY_RIGHT" },
+ { JOY_AXIS1_MINUS, "JOY_UP" },
+ { JOY_AXIS1_PLUS, "JOY_DOWN" },
+ { JOY_AXIS0_MINUS, "JOY_LEFT" },
+ { JOY_AXIS0_PLUS, "JOY_RIGHT" },
{ JOY_AXIS0_PLUS, "JOY_AXIS0_PLUS" },
{ JOY_AXIS0_MINUS, "JOY_AXIS0_MINUS" },
@@ -817,7 +817,7 @@ mp_input_init(void) {
if(fd < 0)
printf("Can't init input joystick\n");
else
- mp_input_add_key_fd(fd,1,mp_input_joystick_read,mp_input_joystick_close);
+ mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close);
}
#endif
diff --git a/input/joystick.c b/input/joystick.c
index bf5eb74b2b..7f91a7a459 100644
--- a/input/joystick.c
+++ b/input/joystick.c
@@ -27,14 +27,10 @@
#include <linux/joystick.h>
-static int buttons = 0;
-static int* axis;
-
int mp_input_joystick_init(char* dev) {
int fd,l=0;
int inited = 0;
struct js_event ev;
- char n_axis;
printf("Opening joystick device %s\n",dev ? dev : JS_DEV);
@@ -43,15 +39,6 @@ int mp_input_joystick_init(char* dev) {
printf("Can't open joystick device %s : %s\n",dev ? dev : JS_DEV,strerror(errno));
return -1;
}
-
- if(ioctl(fd, JSIOCGAXES, &n_axis) < 0) {
- printf("Joystick : can't get number of axis, %s\n",strerror(errno));
- close(fd);
- return -1;
- }
-
- axis = (int*)malloc(n_axis*sizeof(int));
-
while(! inited) {
l = 0;
@@ -73,16 +60,8 @@ int mp_input_joystick_init(char* dev) {
if((unsigned int)l < sizeof(struct js_event)) {
if(l > 0)
printf("Joystick : we loose %d bytes of data\n",l);
- return fd;
+ break;
}
- if(ev.type & JS_EVENT_INIT) {
- ev.type &= ~JS_EVENT_INIT;
- if(ev.type & JS_EVENT_BUTTON)
- buttons |= (ev.value << ev.number);
- else if(ev.type & JS_EVENT_AXIS)
- axis[ev.number] = ev.value;
- } else
- printf("Joystick : Warning non-init event during init :-o\n");
}
return fd;
@@ -115,26 +94,17 @@ int mp_input_joystick_read(int fd) {
}
if(ev.type & JS_EVENT_INIT) {
- printf("Joystick : warning reinit (Can happend more than on time)\n");
- ev.type &= ~JS_EVENT_INIT;
- if(ev.type & JS_EVENT_BUTTON)
- buttons |= (ev.value << ev.number);
- else if(ev.type & JS_EVENT_AXIS)
- axis[ev.number] = ev.value;
- else
- printf("Joystick warning unknow event type %d\n",ev.type);
- return mp_input_joystick_read(fd);
+ printf("Joystick : warning init event, we have lost sync with driver\n");
+ return mp_input_joystick_read(fd);
}
-
- ev.type &= ~JS_EVENT_INIT;
if(ev.type & JS_EVENT_BUTTON) {
- if(ev.value != ( 1 & (buttons >> ev.number)))
+ if(ev.value == 1)
return JOY_BTN0+ev.number;
} else if(ev.type & JS_EVENT_AXIS) {
- if(ev.value - axis[ev.number] > JOY_AXIS_DELTA)
+ if(-ev.value > JOY_AXIS_DELTA)
return JOY_AXIS0_MINUS+(2*ev.number);
- else if(axis[ev.number] - ev.value > JOY_AXIS_DELTA)
+ else if(ev.value > JOY_AXIS_DELTA)
return JOY_AXIS0_PLUS+(2*ev.number);
} else {
printf("Joystick warning unknow event type %d\n",ev.type);
@@ -144,32 +114,6 @@ 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
@@ -183,11 +127,6 @@ int mp_input_joystick_read(int fd) {
return MP_INPUT_NOTHING;
}
-void
-mp_input_joystick_close(int fd) {
-
-}
-
#endif
#endif
diff --git a/input/joystick.h b/input/joystick.h
index 2d04fa5a8c..32a7a7685f 100644
--- a/input/joystick.h
+++ b/input/joystick.h
@@ -37,5 +37,3 @@ int mp_input_joystick_init(char* dev);
int mp_input_joystick_read(int fd);
-void
-mp_input_joystick_close(int fd);