[MPlayer-dev-eng] joystick double events & keydown/keyup for axis'
Mark Pustjens
pustjens at dds.nl
Fri Jan 14 00:05:22 CET 2005
Hi everyone,
I recently bought a new gamepad, which has very sensitive axes.
This caused some problems with mplayer, in the way that it fired key-down
events much too soon. Just lightly touching the stick would couse an
event.
That is why i changed the default sensitivity using a hysteresis.
The hysteresis upper and lower bound should be configurable using a
commandline option, but i haven't taken the effort of finding out how i
should add this.
Also, the joystick input routines sends events for keyup and keydown
events of joystick axes. This causes problems if you want to use an axis
as a button. Bindings for axes are executed twice, once for keydown, and
once for keyup.
Take for example a binding an axis with the `pause' command. First it pauses,
and as soon as you return the stick to the center, the playback is
unpaused.
If have fixed this behavior. Bindings are now only executed for keydown
events. This fix does not break the autorepeat functionality.
I have tested the patch using an usb joypad and a gameport gamepad. Both
worked for me.
If you can, please test this patch and give some comments on the code
changes.
I have attached the patch to this message.
--
What was it they said about gods? They wouldn't exist if there weren't people
to believe in them? And that applied to everything. Reality was what went on
inside people's heads.
(Moving Pictures)
-------------- next part --------------
diff -c input.old/input.c input/input.c
*** input.old/input.c Thu Jan 13 23:24:29 2005
--- input/input.c Thu Jan 13 23:20:07 2005
***************
*** 236,241 ****
--- 236,243 ----
{ JOY_BTN7, "JOY_BTN7" },
{ JOY_BTN8, "JOY_BTN8" },
{ JOY_BTN9, "JOY_BTN9" },
+ { JOY_BTN10, "JOY_BTN10" },
+ { JOY_BTN11, "JOY_BTN11" },
{ KEY_XF86_PAUSE, "XF86_PAUSE" },
{ KEY_XF86_STOP, "XF86_STOP" },
***************
*** 1002,1010 ****
num_key_down++;
last_key_down = 1;
}
! // We ignore key from last combination
! ret = last_key_down ? mp_input_get_cmd_from_keys(num_key_down,key_down,paused) : NULL;
! // Remove the key
if(j+1 < num_key_down)
memmove(&key_down[j],&key_down[j+1],(num_key_down-(j+1))*sizeof(int));
num_key_down--;
--- 1004,1020 ----
num_key_down++;
last_key_down = 1;
}
!
! #ifdef HAVE_JOYSTICK
! if (!use_joystick || !(code >= JOY_AXIS0_PLUS && code <= JOY_AXIS9_MINUS)){
! #endif
! // We ignore key from last combination
! ret = last_key_down ? mp_input_get_cmd_from_keys(num_key_down,key_down,paused) : NULL;
! // Remove the key
! #ifdef HAVE_JOYSTICK
! }
! #endif
!
if(j+1 < num_key_down)
memmove(&key_down[j],&key_down[j+1],(num_key_down-(j+1))*sizeof(int));
num_key_down--;
diff -c input.old/joystick.c input/joystick.c
*** input.old/joystick.c Thu Jan 13 23:24:29 2005
--- input/joystick.c Thu Jan 13 22:26:56 2005
***************
*** 15,22 ****
#include <fcntl.h>
#include <errno.h>
! #ifndef JOY_AXIS_DELTA
! #define JOY_AXIS_DELTA 500
#endif
#ifndef JS_DEV
--- 15,26 ----
#include <fcntl.h>
#include <errno.h>
! #ifndef JOY_AXIS_KEYDOWN
! #define JOY_AXIS_KEYDOWN 30000
! #endif
!
! #ifndef JOY_AXIS_KEYUP
! #define JOY_AXIS_KEYUP 30000
#endif
#ifndef JS_DEV
***************
*** 101,121 ****
return MP_INPUT_NOTHING;
}
! if(ev.type & JS_EVENT_INIT) {
printf("Joystick : warning init event, we have lost sync with driver\n");
ev.type &= ~JS_EVENT_INIT;
! if(ev.type == JS_EVENT_BUTTON) {
int s = (btns >> ev.number) & 1;
if(s == ev.value) // State is the same : ignore
return MP_INPUT_NOTHING;
! }
! if(ev.type == JS_EVENT_AXIS) {
! if( ( axis[ev.number] == 1 && ev.value > JOY_AXIS_DELTA) ||
! (axis[ev.number] == -1 && ev.value < -JOY_AXIS_DELTA) ||
! (axis[ev.number] == 0 && ev.value >= -JOY_AXIS_DELTA && ev.value <= JOY_AXIS_DELTA)
) // State is the same : ignore
return MP_INPUT_NOTHING;
! }
}
if(ev.type & JS_EVENT_BUTTON) {
--- 105,126 ----
return MP_INPUT_NOTHING;
}
! if (ev.type & JS_EVENT_INIT) {
printf("Joystick : warning init event, we have lost sync with driver\n");
ev.type &= ~JS_EVENT_INIT;
! if (ev.type == JS_EVENT_BUTTON) {
int s = (btns >> ev.number) & 1;
if(s == ev.value) // State is the same : ignore
return MP_INPUT_NOTHING;
! } else if (ev.type == JS_EVENT_AXIS) {
! if( ( axis[ev.number] == 1 && ev.value > JOY_AXIS_KEYUP) ||
! (axis[ev.number] == -1 && ev.value < -JOY_AXIS_KEYUP) ||
! (axis[ev.number] == 0 && ev.value >= -JOY_AXIS_KEYDOWN && ev.value <= JOY_AXIS_KEYDOWN)
) // State is the same : ignore
return MP_INPUT_NOTHING;
! } else {
! printf("Joystick warning unknown event type %d\n",ev.type);
! }
}
if(ev.type & JS_EVENT_BUTTON) {
***************
*** 126,138 ****
else
return (JOY_BTN0+ev.number);
} else if(ev.type & JS_EVENT_AXIS) {
! if(ev.value < -JOY_AXIS_DELTA && axis[ev.number] != -1) {
axis[ev.number] = -1;
return (JOY_AXIS0_MINUS+(2*ev.number)) | MP_KEY_DOWN;
! } else if(ev.value > JOY_AXIS_DELTA && axis[ev.number] != 1) {
axis[ev.number] = 1;
return (JOY_AXIS0_PLUS+(2*ev.number)) | MP_KEY_DOWN;
! } else if(ev.value <= JOY_AXIS_DELTA && ev.value >= -JOY_AXIS_DELTA && axis[ev.number] != 0) {
int r = axis[ev.number] == 1 ? JOY_AXIS0_PLUS+(2*ev.number) : JOY_AXIS0_MINUS+(2*ev.number);
axis[ev.number] = 0;
return r;
--- 131,143 ----
else
return (JOY_BTN0+ev.number);
} else if(ev.type & JS_EVENT_AXIS) {
! if(ev.value < -JOY_AXIS_KEYDOWN && axis[ev.number] != -1) {
axis[ev.number] = -1;
return (JOY_AXIS0_MINUS+(2*ev.number)) | MP_KEY_DOWN;
! } else if(ev.value > JOY_AXIS_KEYDOWN && axis[ev.number] != 1) {
axis[ev.number] = 1;
return (JOY_AXIS0_PLUS+(2*ev.number)) | MP_KEY_DOWN;
! } else if(ev.value <= JOY_AXIS_KEYUP && ev.value >= -JOY_AXIS_KEYUP && axis[ev.number] != 0) {
int r = axis[ev.number] == 1 ? JOY_AXIS0_PLUS+(2*ev.number) : JOY_AXIS0_MINUS+(2*ev.number);
axis[ev.number] = 0;
return r;
diff -c input.old/joystick.h input/joystick.h
*** input.old/joystick.h Thu Jan 13 23:24:29 2005
--- input/joystick.h Thu Jan 13 23:21:11 2005
***************
*** 32,37 ****
--- 32,39 ----
#define JOY_BTN7 (JOY_BTN_BASE+7)
#define JOY_BTN8 (JOY_BTN_BASE+8)
#define JOY_BTN9 (JOY_BTN_BASE+9)
+ #define JOY_BTN10 (JOY_BTN_BASE+10)
+ #define JOY_BTN11 (JOY_BTN_BASE+11)
int mp_input_joystick_init(char* dev);
More information about the MPlayer-dev-eng
mailing list