1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 15:22:09 +00:00

Corrected the quit bug and added support for up to 10 axis

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4519 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
albeu 2002-02-03 19:13:00 +00:00
parent 416e711c71
commit e4be4973e2
3 changed files with 109 additions and 25 deletions

View File

@ -76,10 +76,32 @@ static mp_cmd_bind_t key_names[] = {
{ 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 @@ mp_input_read_keys(int time,int paused) {
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 @@ 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_close_func_t)close);
mp_input_add_key_fd(fd,1,mp_input_joystick_read,mp_input_joystick_close);
}
#endif
@ -809,6 +833,18 @@ mp_input_init(void) {
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();

View File

@ -129,14 +129,13 @@ int mp_input_joystick_read(int fd) {
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 @@ 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
@ -158,6 +183,11 @@ int mp_input_joystick_read(int fd) {
return MP_INPUT_NOTHING;
}
void
mp_input_joystick_close(int fd) {
}
#endif
#endif

View File

@ -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);