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
Joystick problem
Huepper


Joined: 19 Nov 2016
Posts: 3
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
Joystick problem
Daniel Gibson
Guest

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:
Quote:
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

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


_______________________________________________
SDL mailing list

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


Joined: 19 Nov 2016
Posts: 3
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
Joystick problem
Daniel Gibson
Guest

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:
Quote:
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

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


_______________________________________________
SDL mailing list

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


Joined: 19 Nov 2016
Posts: 3
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