[Mplayer-cvslog] CVS: main/input input.c,1.2,1.3 joystick.c,1.1,1.2 joystick.h,1.1,1.2
Alban Bedel CVS
albeu at mplayer.dev.hu
Sun Feb 3 20:13:03 CET 2002
Update of /cvsroot/mplayer/main/input
In directory mplayer:/var/tmp.root/cvs-serv9050/input
Modified Files:
input.c joystick.c joystick.h
Log Message:
Corrected the quit bug and added support for up to 10 axis
Index: input.c
===================================================================
RCS file: /cvsroot/mplayer/main/input/input.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- input.c 31 Jan 2002 09:39:11 -0000 1.2
+++ input.c 3 Feb 2002 19:13:00 -0000 1.3
@@ -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();
Index: joystick.c
===================================================================
RCS file: /cvsroot/mplayer/main/input/joystick.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- joystick.c 30 Jan 2002 12:46:03 -0000 1.1
+++ joystick.c 3 Feb 2002 19:13:00 -0000 1.2
@@ -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
@@ -156,6 +181,11 @@
int mp_input_joystick_read(int fd) {
return MP_INPUT_NOTHING;
+}
+
+void
+mp_input_joystick_close(int fd) {
+
}
#endif
Index: joystick.h
===================================================================
RCS file: /cvsroot/mplayer/main/input/joystick.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- joystick.h 30 Jan 2002 12:46:03 -0000 1.1
+++ joystick.h 3 Feb 2002 19:13:00 -0000 1.2
@@ -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);
More information about the MPlayer-cvslog
mailing list