changeset 4518:83128eed25f1

Corrected the quit bug and added support for up to 10 axis
author albeu
date Sun, 03 Feb 2002 19:13:00 +0000
parents 7d24c9bd2ae5
children c8bf6fd27d68
files input/input.c input/joystick.c input/joystick.h
diffstat 3 files changed, 109 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/input/input.c	Sun Feb 03 16:49:41 2002 +0000
+++ b/input/input.c	Sun Feb 03 19:13:00 2002 +0000
@@ -76,10 +76,32 @@
   { KEY_DOWN, "DOWN" },
   { KEY_UP, "UP" },
 #ifdef HAVE_JOYSTICK
-  { JOY_UP, "JOY_UP" },
-  { JOY_DOWN, "JOY_DOWN" },
-  { JOY_LEFT, "JOY_LEFT" },
-  { JOY_RIGHT, "JOY_RIGHT" },
+  { JOY_AXIS1_PLUS, "JOY_UP" },
+  { JOY_AXIS1_MINUS, "JOY_DOWN" },
+  { JOY_AXIS0_PLUS, "JOY_LEFT" },
+  { JOY_AXIS0_MINUS, "JOY_RIGHT" },
+
+  { JOY_AXIS0_PLUS, "JOY_AXIS0_PLUS" },
+  { JOY_AXIS0_MINUS, "JOY_AXIS0_MINUS" },
+  { JOY_AXIS1_PLUS, " JOY_AXIS1_PLUS" },
+  { JOY_AXIS1_MINUS, "JOY_AXIS1_MINUS" },
+  { JOY_AXIS2_PLUS, "JOY_AXIS2_PLUS" },
+  { JOY_AXIS2_MINUS, "JOY_AXIS2_MINUS" },
+  { JOY_AXIS3_PLUS, " JOY_AXIS3_PLUS" },
+  { JOY_AXIS3_MINUS, "JOY_AXIS3_MINUS" },
+  { JOY_AXIS4_PLUS, "JOY_AXIS4_PLUS" },
+  { JOY_AXIS4_MINUS, "JOY_AXIS4_MINUS" },
+  { JOY_AXIS5_PLUS, " JOY_AXIS5_PLUS" },
+  { JOY_AXIS5_MINUS, "JOY_AXIS5_MINUS" },
+  { JOY_AXIS6_PLUS, "JOY_AXIS6_PLUS" },
+  { JOY_AXIS6_MINUS, "JOY_AXIS6_MINUS" },
+  { JOY_AXIS7_PLUS, " JOY_AXIS7_PLUS" },
+  { JOY_AXIS7_MINUS, "JOY_AXIS7_MINUS" },
+  { JOY_AXIS8_PLUS, "JOY_AXIS8_PLUS" },
+  { JOY_AXIS8_MINUS, "JOY_AXIS8_MINUS" },
+  { JOY_AXIS9_PLUS, " JOY_AXIS9_PLUS" },
+  { JOY_AXIS9_MINUS, "JOY_AXIS9_MINUS" },
+
   { JOY_BTN0, "JOY_BTN0" },
   { JOY_BTN1, "JOY_BTN1" },
   { JOY_BTN2, "JOY_BTN2" },
@@ -498,8 +520,10 @@
       if(cmd_binds[j].input == code)
 	break;
     }
-    if(cmd_binds[j].cmd == NULL)
+    if(cmd_binds[j].cmd == NULL) {
+      printf("No bind found for key %d\n",code);
       continue;
+    }
     last_loop = i;
     return mp_input_parse_cmd(cmd_binds[j].cmd);
   }
@@ -793,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_close_func_t)close);
+      mp_input_add_key_fd(fd,1,mp_input_joystick_read,mp_input_joystick_close);
   }
 #endif
 
@@ -809,6 +833,18 @@
 
 void
 mp_input_uninit(void) {
+  unsigned int i;
+
+  for(i=0; i < num_key_fd; i++) {
+    if(key_fds[i].close_func)
+      key_fds[i].close_func(key_fds[i].fd);
+  }
+
+  for(i=0; i < num_cmd_fd; i++) {
+    if(cmd_fds[i].close_func)
+      cmd_fds[i].close_func(cmd_fds[i].fd);
+  }
+  
 
 #ifdef HAVE_LIRC
   mp_input_lirc_uninit();
--- a/input/joystick.c	Sun Feb 03 16:49:41 2002 +0000
+++ b/input/joystick.c	Sun Feb 03 19:13:00 2002 +0000
@@ -129,14 +129,13 @@
   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 @@
   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 @@
   return MP_INPUT_NOTHING;
 }
 
+void
+mp_input_joystick_close(int fd) {
+
+}
+
 #endif
 
 #endif
--- a/input/joystick.h	Sun Feb 03 16:49:41 2002 +0000
+++ b/input/joystick.h	Sun Feb 03 19:13:00 2002 +0000
@@ -1,23 +1,41 @@
 
 #define JOY_BASE   (0x100+128)
-#define JOY_UP (JOY_BASE+0)
-#define JOY_DOWN (JOY_BASE+1)
-#define JOY_LEFT (JOY_BASE+2)
-#define JOY_RIGHT (JOY_BASE+3)
+#define JOY_AXIS0_PLUS (JOY_BASE+0)
+#define JOY_AXIS0_MINUS (JOY_BASE+1)
+#define JOY_AXIS1_PLUS (JOY_BASE+2)
+#define JOY_AXIS1_MINUS (JOY_BASE+3)
+#define JOY_AXIS2_PLUS (JOY_BASE+4)
+#define JOY_AXIS2_MINUS (JOY_BASE+5)
+#define JOY_AXIS3_PLUS (JOY_BASE+6)
+#define JOY_AXIS3_MINUS (JOY_BASE+7)
+#define JOY_AXIS4_PLUS (JOY_BASE+8)
+#define JOY_AXIS4_MINUS (JOY_BASE+9)
+#define JOY_AXIS5_PLUS (JOY_BASE+10)
+#define JOY_AXIS5_MINUS (JOY_BASE+11)
+#define JOY_AXIS6_PLUS (JOY_BASE+12)
+#define JOY_AXIS6_MINUS (JOY_BASE+13)
+#define JOY_AXIS7_PLUS (JOY_BASE+14)
+#define JOY_AXIS7_MINUS (JOY_BASE+15)
+#define JOY_AXIS8_PLUS (JOY_BASE+16)
+#define JOY_AXIS8_MINUS (JOY_BASE+17)
+#define JOY_AXIS9_PLUS (JOY_BASE+18)
+#define JOY_AXIS9_MINUS (JOY_BASE+19)
 
-#define JOY_BTN0 (JOY_BASE+4)
-#define JOY_BTN1 (JOY_BASE+5)
-#define JOY_BTN2 (JOY_BASE+6)
-#define JOY_BTN3 (JOY_BASE+7)
-#define JOY_BTN4 (JOY_BASE+8)
-#define JOY_BTN5 (JOY_BASE+9)
-#define JOY_BTN6 (JOY_BASE+10)
-#define JOY_BTN7 (JOY_BASE+11)
-#define JOY_BTN8 (JOY_BASE+12)
-#define JOY_BTN9 (JOY_BASE+13)
+#define JOY_BTN_BASE (0x100+148)
+#define JOY_BTN0 (JOY_BTN_BASE+0)
+#define JOY_BTN1 (JOY_BTN_BASE+1)
+#define JOY_BTN2 (JOY_BTN_BASE+2)
+#define JOY_BTN3 (JOY_BTN_BASE+3)
+#define JOY_BTN4 (JOY_BTN_BASE+4)
+#define JOY_BTN5 (JOY_BTN_BASE+5)
+#define JOY_BTN6 (JOY_BTN_BASE+6)
+#define JOY_BTN7 (JOY_BTN_BASE+7)
+#define JOY_BTN8 (JOY_BTN_BASE+8)
+#define JOY_BTN9 (JOY_BTN_BASE+9)
 
 int mp_input_joystick_init(char* dev);
 
 int mp_input_joystick_read(int fd);
 
-
+void
+mp_input_joystick_close(int fd);