Page 1 of 1

libpad with 2 controllers

Posted: Wed May 18, 2005 9:32 pm
by cheriff
Ok. I making an arcade-y type thing, with 1up, 2up or 2 player, depending on who's pressed start. And i'm up to the bit where i set up the pads (ie at the beginning!). So.
Based on the libpad sample, i noticed that when calling initializePad when none inserted hangs. Then i found code in the turnips source that must have been pulled out that chekcs for pad's existence: (cheers to pukko!)

Code: Select all

 while((ret=padGetState(port, slot)) != PAD_STATE_STABLE) {
        if(ret==0) {
            // No pad connected!
            printf("Pad(%d, %d) is disconnected\n", port, slot);
            return 0;
        }
	printf("looping\n");       
     }
So i stuck that at the start and now initializePad returns quietly when none is pulgged in. So far so good.
The problem is that this only seems to work with dualshock (1 and 2) If i have a old digi pad or (more importantly) my remote IR-dongle the above loop goes for ever.(both have 0 modes and identify as a vanilla digital pad) However to find the type i have to do other stuff, which dies when no pad is inserted.
So now i just have to know at compile time what type of pad, rather than if there is one or not.
There has to be a way to achieve this, but i'm yet to find any source to assist.
All ideas are welcome!
thanks - cheriff

Posted: Thu May 19, 2005 2:51 am
by Drakonite
Keep in mind the pad example contains a lot of crap it doesn't need to have...

You should be able to detect what type of pad is connected easily, I thought the pad example showed how.

If you don't have it figured out by the time I can play around with my PS2 again, I'll dig through my code and see if I can get an example for you.

Posted: Thu May 19, 2005 3:34 am
by cheriff
I can detect between dualshock / digital (as thats all I have) but this method fails when nothing is in.,
I can detect between dualshock / nothing using another method, but that fails when a digi pad is in.
All i really need is "Is there a pad (of any type) in slot x? (Y/N)"

I'm sleeping now (soon) so I'l play some more tomorrow and maybe post some code.
Cheers, - cheriff

Posted: Thu May 19, 2005 3:49 am
by Drakonite
padGetState will return a different value if there is no pad connected, not sure what the defines for it are (or if anyone bothered to put a define in libpad for it for that matter)

Posted: Fri May 20, 2005 11:46 am
by cheriff
Yep, you're right.
The pad sample had something like waitPadready() that looped untill padGetState eventually returned 6 or 2 (seems to be 6=dualshock2, 2=not?).
So I just changed it to stop when state is 0 (no pad) and return the fact, so as not to go thru the rest of the init routine on a non-pad.
So thanks for the pointer.. why do i always find the 'easy' answer after ages of testing every combination of padman/xpadman digi/analog pad and port/slot numbers... beh.