Problem to handle joystick input

23 views
Skip to first unread message

sergio-br2

unread,
Nov 27, 2014, 6:37:35 PM11/27/14
to cabrio...@googlegroups.com
Hello,

Cabrio is having problem to handle joystick input, I'm using a PS3 joystick and SDL is sending many events such as 0 value in axis 0, 1, 2 and 3 (right and left analog) and -32768 in axis 12 (accelerometer?). Cabrio is very slow with these events and you have to wait some seconds to it handle an Up or Down.

I managed to workaround this, change IF to while in event_poll function and putting event_flush after the for statement. But the problem is that when the controller is connected, you have to tap many times Up or Down to move the wheel (event_flush erases all the events, so you lost both valid and invalid input signals).

It seems you have to use SDL_PollEvent inside a while, not in a IF statement, as I saw in many examples over the web, so it will handle many events in one frame, not one event for each frame.

https://github.com/SteveMaddison/cabrio/issues/20

I don't have many skills in SDL, could someone see this? As the main goal of cabrio is to be a arcade frontend, this input handle is very important.


sergio-br2


PS: Is it hard to port to SDL2 ?

Joseph K

unread,
Nov 27, 2014, 7:00:10 PM11/27/14
to cabrio...@googlegroups.com
Good to know. We are in the midst of a rewrite and are making note of these sorts of issues. When we get to the user input portion, I'll hammer it with my Xbox controllers and see what I see. Hopefully wet can make it more responsive and capable. I agree that this is something that needs attention. I plan on using n64, Saturn, Playstation 2 and snes controllers with mine. I'll be sure to test them out.

On a lighter note, I'll have my left hand back next week. Hopefully I can start typing again shortly afterward.

Thanks for the input Sergio.

-Joseph
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

sergio-br2

unread,
Nov 28, 2014, 12:40:11 AM11/28/14
to cabrio...@googlegroups.com, jcko...@cs.unm.edu
Great, I managed to create a filter (thanks caedes from sdl IRC) to handle this noise, it seems it works.

In event.c:

int event_filter(const SDL_Event* event_f) {
    if( event_f->type == 7 && ( event_f->jaxis.axis >= 12 || ( event_f->jaxis.axis < 4 && event_f->jaxis.value == 0 ) ) )
        return 0;
    return 1;
}

void event_set_filter( void ) {
    SDL_SetEventFilter(event_filter);
}

int event_poll( void ) {
    SDL_Event sdl_event;
    int i;

    while( SDL_PollEvent( &sdl_event ) ) {
        event = EVENT_NONE;
[...]

And I call event_set_filter() from main, before while( !quit ) loop.

But I'm getting 2 problems now, the first: sometimes the wheel run without you pressing the analog axis, it forget to stops. It seems the program continues to send the same event that happened before until you type any key in keyboard or do something in joystick (we need to stop it without the 0 value in axis, I filtered this in event_filter).

The second, the main loop forgets the SDL_SetEventFilter configuration you did before when you returns from a game selected (I'm using retroarch), so you are unable to do anything, even close, and you have to disconnect the controller to managed to quit cabrio. Where I have to look? sdl_swap ? I need to call event_set_filter once, after leaving the game and before returning to cabrio.

sergio-br2
Reply all
Reply to author
Forward
0 new messages