# HG changeset patch # User albeu # Date 1012832394 0 # Node ID 01a0cf736e0dae7a47841d60820a14f034c71f3e # Parent 433104e0ec0f6574653cdb19fc9e7c8183172e74 Fix the bugs the previous version should fix (and those introduced by the previous version ;) ) diff -r 433104e0ec0f -r 01a0cf736e0d input/input.c --- a/input/input.c Sun Feb 03 23:13:56 2002 +0000 +++ b/input/input.c Mon Feb 04 14:19:54 2002 +0000 @@ -76,10 +76,10 @@ { 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 @@ 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 -r 433104e0ec0f -r 01a0cf736e0d input/joystick.c --- a/input/joystick.c Sun Feb 03 23:13:56 2002 +0000 +++ b/input/joystick.c Mon Feb 04 14:19:54 2002 +0000 @@ -27,14 +27,10 @@ #include -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 @@ 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 @@ 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 @@ } 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 @@ 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 @@ return MP_INPUT_NOTHING; } -void -mp_input_joystick_close(int fd) { - -} - #endif #endif diff -r 433104e0ec0f -r 01a0cf736e0d input/joystick.h --- a/input/joystick.h Sun Feb 03 23:13:56 2002 +0000 +++ b/input/joystick.h Mon Feb 04 14:19:54 2002 +0000 @@ -37,5 +37,3 @@ int mp_input_joystick_read(int fd); -void -mp_input_joystick_close(int fd);