The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Resend (x2) Patch - Joystick ReSync on SYN_DROPPED
mungewell


Joined: 17 Nov 2011
Posts: 40
Apologies if I'm starting to sound like a broken record, but I got no
commentary on the patch offered below.

In my system SDL2 is dropping a chunk of joystick events, which result in
a 'stuck brake/accelerator' whilst playing a racing simulator. This
basically means SDL2 is unsuitable for use at this point...

The patch below detects this situation and forces a re-read of all
attached joystick axis - thus resync to the correct/current pedal
positions.

Please apply... pretty please :-)
Simon.


---------------------------- Original Message ----------------------------
Subject: Re: Evdev based joystick - issues
From:
Date: Thu, January 17, 2013 11:10 pm
To:
Cc:
--------------------------------------------------------------------------

If figured out a solution to this problem, patch attached.

When a 'SYN_DROPPED' event is detected, each of the active axis for the
joystick are polled and the result returned to the application. This
counteracts the stuck axis and my driving game now works as expected.

I also included a 'fresh' flag so a newly opened joystick is polled for
values, which would normally only be sent when moved. This helps get
controls in a 'normal' position at start of game (rather than being stuck
at 1/2 value).

The 'SYN_DROPPED' situation can be forced by '^Z'ing the testjoystick
application and moving the joystick so the buffer overflows. 'fg' will
restart the application and the axis will 'magically' return to the
correct position.

Cheers,
Simon.

Quote:
Quote:
2). I am seeing some events being missed, this is (most noticably)
manifesting as the brake being slight 'stuck on'. This can be clear by
pressing the pedal again, but is _very_ frustrating to have your car
suddenly slow down with the brakes dragging. Anyone else experiencing
this?


A bit of a thread bump and update on this, although I don't yet have a
solution. I used the 'testjoystick' from yesterday's SDL2 snapshot and
confirmed the problem still exists.

I would have to state that at present these behaviour makes SDL2
unsuitable for a driving simulator. This also occurs with SDL1 if you use
event based joysticks (rather than the default /dev/js0).


It seems that my wheel is sending events too quickly, or rather the system
is not consuming them fast enough and there is a buffer overflowing in the
kernel.

The kernel issues the 'SYN_DROPPED' signal when this happens.

There's some more commentary here:
http://www.mail-archive.com//msg01920.html


There is also a mention of the 'EVIOCGABS()' call which should (not tested
it) cause the wheel to return the current value for the axis.

To my mind this would be extremely useful, both when starting up the new
connection with an event based joystick to get first value correct and in
situations where the buffers overflow - allowing a re-sync to happen
automatically.

Any comments/thoughts?
Simon


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Resend (x2) Patch - Joystick ReSync on SYN_DROPPED
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
Applied!http://hg.libsdl.org/SDL/rev/e09997fb33cc


FYI, bugzilla.libsdl.org is a better place to make sure patches don't get lost.


Cheers!

On Tue, Feb 5, 2013 at 4:10 PM, wrote:
Quote:
Apologies if I'm starting to sound like a broken record, but I got no
commentary on the patch offered below.

In my system SDL2 is dropping a chunk of joystick events, which result in
a 'stuck brake/accelerator' whilst playing a racing simulator. This
basically means SDL2 is unsuitable for use at this point...

The patch below detects this situation and forces a re-read of all
attached joystick axis - thus resync to the correct/current pedal
positions.

Please apply... pretty please :-)
Simon.


---------------------------- Original Message ----------------------------
Subject: Re: Evdev based joystick - issues
From:    
Date:    Thu, January 17, 2013 11:10 pm
To:      
Cc:      
--------------------------------------------------------------------------

If figured out a solution to this problem, patch attached.

When a 'SYN_DROPPED' event is detected, each of the active axis for the
joystick are polled and the result returned to the application. This
counteracts the stuck axis and my driving game now works as expected.

I also included a 'fresh' flag so a newly opened joystick is polled for
values, which would normally only be sent when moved. This helps get
controls in a 'normal' position at start of game (rather than being stuck
at 1/2 value).

The 'SYN_DROPPED' situation can be forced by '^Z'ing the testjoystick
application and moving the joystick so the buffer overflows. 'fg' will
restart the application and the axis will 'magically' return to the
correct position.

Cheers,
Simon.

Quote:
Quote:
2). I am seeing some events being missed, this is (most noticably)
manifesting as the brake being slight 'stuck on'. This can be clear by
pressing the pedal again, but is _very_ frustrating to have your car
suddenly slow down with the brakes dragging. Anyone else experiencing
this?


A bit of a thread bump and update on this, although I don't yet have a
solution. I used the 'testjoystick' from yesterday's SDL2 snapshot and
confirmed the problem still exists.

I would have to state that at present these behaviour makes SDL2
unsuitable for a driving simulator. This also occurs with SDL1 if you use
event based joysticks (rather than the default /dev/js0).


It seems that my wheel is sending events too quickly, or rather the system
is not consuming them fast enough and there is a buffer overflowing in the
kernel.

The kernel issues the 'SYN_DROPPED' signal when this happens.

There's some more commentary here:
http://www.mail-archive.com//msg01920.html


There is also a mention of the 'EVIOCGABS()' call which should (not tested
it) cause the wheel to return the current value for the axis.

To my mind this would be extremely useful, both when starting up the new
connection with an event based joystick to get first value correct and in
situations where the buffers overflow - allowing a re-sync to happen
automatically.

Any comments/thoughts?
Simon


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Resend (x2) Patch - Joystick ReSync on SYN_DROPPED
Mark de Wever
Guest

On Mon, Feb 11, 2013 at 04:47:01PM -0800, Sam Lantinga wrote:

The patch breaks compilation for me, the attached patch fixes it.

Please CC me since I'm not subscribed.

--
Regards,
Mark de Wever

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Resend (x2) Patch - Joystick ReSync on SYN_DROPPED
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
This block at the top didn't take care of it for you?

/* This isn't defined in older Linux kernel headers */
#ifndef SYN_DROPPED
#define SYN_DROPPED 3
#endif

On Sun, Feb 17, 2013 at 5:27 AM, Mark de Wever wrote:
Quote:
On Mon, Feb 11, 2013 at 04:47:01PM -0800, Sam Lantinga wrote:

The patch breaks compilation for me, the attached patch fixes it.

Please CC me since I'm not subscribed.

--
Regards,
Mark de Wever

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

jeffgriffin


Joined: 05 Mar 2013
Posts: 2
Thanks for this patch! It really helped me with some issues I was having with gamepads in XBMC.
I did have to make a couple tweaks, though:
1. I placed the PollAllValues for a "fresh" device inside the read loop. This was because it would fire an axis value of zero for any gamepad which was disconnected. This would not be a problem but for the fact that zero is not the resting point for some axes, therefore disconnected controllers constantly appear to be in a modified state. This way, fresh devices will be polled once they have sent the first real event.
2. Added button states to PollAllValues. This fixes an issue in XBMC where dropped button up events cause the button to "stick". A key_map value 0 can only mean "unmapped" in this patch, as opposed to both "unmapped" and "key 0".

You can see these changes here. Patch is applied to SDL-1.2.15, to keep me from needing to move my XBMC build onto the dev cut of SDL.