Joystick problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Joystick problem

Huepper
Hi Guys,

I am developing a feeder for vJoy (virtual joystick) for my flight simulator.
I use of SDL2 only the joystick part in a worker thread. The whole works so far super
but I have a small problem as long as I have not moved the corresponding joystick axis.

Below the minimized code I use








Code:


SDL_Init(SDL_INIT_JOYSTICK)
Joystick = SDL_JoystickOpen(nJoystick);
while (!done)
{
   SDL_JoystickUpdate();
   nValue = SDL_JoystickGetAxis(Joystick, nThrottle1);
}




As long as I do not move the joystick axis (nThrottle1), SDL_JoystickGetAxis () always returns 0 (zero) -
and not the current position.

Once the axis is moved, SDL_JoystickGetAxis () works as expected.

What am I doing wrong here?

Thanks
-Uwe

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Joystick problem

Daniel Gibson
Hi Uwe,

Not sure if SDL even gets a value for the axis from the OS before
they're moved. Might also be different per platform; which OS are you using?

Cheers,
Daniel

On 21.11.2016 23:58, Huepper wrote:

> Hi Guys,
>
> I am developing a feeder for vJoy (virtual joystick) for my flight
> simulator.
> I use of SDL2 only the joystick part in a worker thread. The whole works
> so far super
> but I have a small problem as long as I have not moved the corresponding
> joystick axis.
>
> Below the minimized code I use
>
>
>
>
>
>
>
>
> Code:
>
>
> SDL_Init(SDL_INIT_JOYSTICK)
> Joystick = SDL_JoystickOpen(nJoystick);
> while (!done)
> {
>    SDL_JoystickUpdate();
>    nValue = SDL_JoystickGetAxis(Joystick, nThrottle1);
> }
>
>
>
>
> As long as I do not move the joystick axis (nThrottle1),
> SDL_JoystickGetAxis () always returns 0 (zero) -
> and not the current position.
>
> Once the axis is moved, SDL_JoystickGetAxis () works as expected.
>
> What am I doing wrong here?
>
> Thanks
> -Uwe
>
>
> _______________________________________________
> SDL mailing list
> [hidden email]
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Joystick problem

Huepper
In reply to this post by Huepper
Hi Daniel,

Oh, sorry, I forgot to mention: Win10 x64, VS2015 C ++ / MFC, SDL2.05, Target Win32 App

It also seems to happen only in debug sessions. I notice it at sometimes jerky throttle levers (in the Simulator) at the first moment and during the line-wise debugings (SDL_JoystickGetAxis () returns 0 as long as I do not move the joy axis).

In the release version, there is nothing negative to note.
If the code snippet I've published is OK, then I can live with it.

Thank you very much for your interest

Cheers,
-Uwe

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Joystick problem

Daniel Gibson
Hi Uwe,

the code snippet looks ok; however you /could/ do it differently to work
around the problem, by using a proper event-loop, with SDL_PollEvent().
Then you could save a "not initialized" flag per axis and only use the
axis once you received a SDL_JOYAXISMOTION event for it.
Those events will always have real values, and not an "I don't have a
value yet so you get 0".
(No idea why debug vs release builds behave differently here)

Cheers,
Daniel

On 28.11.2016 23:39, Huepper wrote:

> Hi Daniel,
>
> Oh, sorry, I forgot to mention: Win10 x64, VS2015 C ++ / MFC, SDL2.05,
> Target Win32 App
>
> It also seems to happen only in debug sessions. I notice it at sometimes
> jerky throttle levers (in the Simulator) at the first moment and during
> the line-wise debugings (SDL_JoystickGetAxis () returns 0 as long as I
> do not move the joy axis).
>
> In the release version, there is nothing negative to note.
> If the code snippet I've published is OK, then I can live with it.
>
> Thank you very much for your interest
>
> Cheers,
> -Uwe
>
>
> _______________________________________________
> SDL mailing list
> [hidden email]
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Joystick problem

Huepper
In reply to this post by Huepper
Hi Daniel,

I can not use the SDL_EventSystem because I have no SDL_Window. That with the poll is OK for me.
I may be doing something different during the debugging session and the problem is not within SDL.
With my request I only wanted to make sure that I did nothing wrong, since the published examples
always refer to the EventSystem.

Thanks again for your support

Cheers
-Uwe

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Loading...