summaryrefslogtreecommitdiffstats
path: root/input/joystick.c
diff options
context:
space:
mode:
Diffstat (limited to 'input/joystick.c')
-rw-r--r--input/joystick.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/input/joystick.c b/input/joystick.c
index 7bb7f0d86b..bf5eb74b2b 100644
--- a/input/joystick.c
+++ b/input/joystick.c
@@ -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