Search
lxdream.org :: lxdream/src/drivers/joy_linux.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/joy_linux.c
changeset 1010:a506a2f66180
prev984:a01567058a47
next1296:30ecee61f811
author nkeynes
date Sun Apr 12 02:04:27 2009 +0000 (15 years ago)
permissions -rw-r--r--
last change Fix analogue joystick input
file annotate diff log raw
1.1 --- a/src/drivers/joy_linux.c Sun Feb 15 21:47:39 2009 +0000
1.2 +++ b/src/drivers/joy_linux.c Sun Apr 12 02:04:27 2009 +0000
1.3 @@ -52,6 +52,11 @@
1.4
1.5 } *linux_joystick_t;
1.6
1.7 +/* Linux joysticks return data in the range -32767 to 32767 - rescale this to
1.8 + * -127 .. 127
1.9 + */
1.10 +#define SCALE_PRESSURE(x) ((x)>>8)
1.11 +
1.12 static gboolean linux_joystick_callback( GIOChannel *source, GIOCondition condition,
1.13 gpointer data );
1.14 static int linux_joystick_scan();
1.15 @@ -146,21 +151,21 @@
1.16 if( event.type == JS_EVENT_BUTTON ) {
1.17 int keycode = event.number+1;
1.18 if( event.value == 0 ) {
1.19 - input_event_keyup( (input_driver_t)joy, keycode, 0 );
1.20 + input_event_keyup( (input_driver_t)joy, keycode );
1.21 } else {
1.22 - input_event_keydown( (input_driver_t)joy, keycode, event.value );
1.23 + input_event_keydown( (input_driver_t)joy, keycode, MAX_PRESSURE );
1.24 }
1.25 } else if( event.type == JS_EVENT_AXIS ) {
1.26 int keycode = (event.number*2) + joy->button_count + 1;
1.27 if( event.value == 0 ) {
1.28 - input_event_keyup( (input_driver_t)joy, keycode, 0 );
1.29 - input_event_keyup( (input_driver_t)joy, keycode+1, 0 );
1.30 + input_event_keyup( (input_driver_t)joy, keycode );
1.31 + input_event_keyup( (input_driver_t)joy, keycode+1 );
1.32 } else if( event.value < 0 ) {
1.33 - input_event_keydown( (input_driver_t)joy, keycode+1, -event.value );
1.34 - input_event_keyup( (input_driver_t)joy, keycode, 0 );
1.35 + input_event_keyup( (input_driver_t)joy, keycode );
1.36 + input_event_keydown( (input_driver_t)joy, keycode+1, SCALE_PRESSURE(-event.value) );
1.37 } else {
1.38 - input_event_keydown( (input_driver_t)joy, keycode, event.value );
1.39 - input_event_keyup( (input_driver_t)joy, keycode+1, 0 );
1.40 + input_event_keyup( (input_driver_t)joy, keycode+1 );
1.41 + input_event_keydown( (input_driver_t)joy, keycode, SCALE_PRESSURE(event.value) );
1.42 }
1.43 }
1.44 }
.