changeset 4524:01a0cf736e0d

Fix the bugs the previous version should fix (and those introduced by the previous version ;) )
author albeu
date Mon, 04 Feb 2002 14:19:54 +0000
parents 433104e0ec0f
children 46c4e34b4e76
files input/input.c input/joystick.c input/joystick.h
diffstat 3 files changed, 11 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- 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 <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 @@
     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
--- 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);