Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unable to get any joypad input  (Read 6775 times)

0 Members and 1 Guest are viewing this topic.

jindocai

  • Newbie
  • *
  • Posts: 3
    • View Profile
Unable to get any joypad input
« on: January 26, 2008, 07:13:57 am »
I'm using v1.1  (v1.2 doesn't work for me).
OS: Vista 32bit
Compiler: VS2005SP1

Joypad: Logitech Dual Action, microsoft driver.
I get no joystick events (buttons & motion). Mouse & Keyboard work fine.

Anyone have this problem or know of a solution?
Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unable to get any joypad input
« Reply #1 on: January 26, 2008, 12:11:00 pm »
I have no way of testing joystick input since the last modification of the code, but so far nobody reported me such errors.

It will be hard for me to help you more on this problem, sorry.
Laurent Gomila - SFML developer

TTK-Bandit

  • Newbie
  • *
  • Posts: 21
    • View Profile
Unable to get any joypad input
« Reply #2 on: March 14, 2008, 03:04:03 pm »
I just tested my joystick, and it doesnt work either..

there are two things I had to change to make it work, the first one was more a hack, which probably isnt good if you have 2 joysticks, but I dunno how the whole joystick concept is supposed to work, but hopefully laurent will be able to fix it correctly:
in Joystick::Initialize, myIndex gets too big, since the loop checks for all joysticks, so for joystick index 0 the myIndex for my joystick was set to 1.
you need to break out of the loop at the end of the check for (Error == JOYERR_NOERROR)

the second fix is no hack anymore, there was a check in Joystick::UpdateState:
if ( joyGetDevCaps(myIndex, &Caps, sizeof(Caps)) )
which should be:
if ( joyGetDevCaps(myIndex, &Caps, sizeof(Caps)) == JOYERR_NOERROR )

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unable to get any joypad input
« Reply #3 on: March 14, 2008, 03:42:18 pm »
Thank you very much for your feedback :) I can't test it myself, and I don't get much feedback usually.

I fixed the second thing, nice catch.

However I'm not sure I understand what's wrong with the first problem. Could you give more details ?
Laurent Gomila - SFML developer

TTK-Bandit

  • Newbie
  • *
  • Posts: 21
    • View Profile
Unable to get any joypad input
« Reply #4 on: March 14, 2008, 04:07:27 pm »
this is what happens:
Joystick::Initialize gets called for the first joystick ( 0 )
it checks the while loop, the loop returns true, so it steps inside,
it checks if there was no error, if so set the properties
then it increases myIndex and checks the loop again.. it fails and the function is done..
but myIndex is now 1, not 0.

so I guess there are 2 fixes for this:
either make the while loop look like this:
Code: [Select]

    for( ; ((myIndex - JOYSTICKID1 <= Index) && (Error = joyGetPosEx(myIndex, &JoyInfo)) != JOYERR_PARMS; myIndex++ )
    {
        // Check if the current joystick is connected
        if (Error == JOYERR_NOERROR)
        {
           ....
        }
    }

or decrease myIndex by one at the end of the function

but in the end, I guess this still wont work with multiple joysticks, it probably has to look like this:
Code: [Select]
void Joystick::Initialize(unsigned int Index)
{
    // Reset state
    myIndex     = JOYSTICKID1;
    myNbAxes    = 0;
    myNbButtons = 0;

    // Get the Index-th connected joystick
    MMRESULT Error;
    JOYINFOEX JoyInfo;
    for( int joysticksFound = 0; (Error = joyGetPosEx(myIndex, &JoyInfo)) != JOYERR_PARMS; myIndex++ )
    {
        // Check if the current joystick is connected
        if (Error == JOYERR_NOERROR) {
if ( joysticksFound == Index ) {
            // Store its caps
JOYCAPS Caps;
joyGetDevCaps(myIndex, &Caps, sizeof(Caps));
myNbAxes    = Caps.wNumAxes;
myNbButtons = Caps.wNumButtons;
return;
}
joysticksFound++;
        }
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unable to get any joypad input
« Reply #5 on: March 14, 2008, 04:19:50 pm »
Ok, I get it :)

I've updated the code, if you try it let me know if it works.

Thanks for your help.
Laurent Gomila - SFML developer

TTK-Bandit

  • Newbie
  • *
  • Posts: 21
    • View Profile
Unable to get any joypad input
« Reply #6 on: March 15, 2008, 01:01:09 pm »
works
no problem

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Unable to get any joypad input
« Reply #7 on: March 15, 2008, 01:58:01 pm »
Cool :)

Did you test joystick events ? Real-time input ? Is everything really working fine ?
Laurent Gomila - SFML developer

TTK-Bandit

  • Newbie
  • *
  • Posts: 21
    • View Profile
Unable to get any joypad input
« Reply #8 on: March 15, 2008, 08:54:37 pm »
I did not actually test if the input is correct, but I receive button and axis events from my joystick.

 

anything