Detect NO Button Press
April 19, 2011 03:11AM
So, im writing an event subsystem for my wii engine that propagates key-press and stick-move events to registered callback classes. I dont need to create an event if no buttons are pressed, but how do you check if no buttons have been pressed? I dont want to check every button combination, rather, a function that tells me. Does PAD_ButtonsDown() return NULL if no buttons are pressed? How would you go about this? Also, is there a function that tells you if a certain controller is plugged in?

BTW, im using gamecube controllers.

Thanks,
mv2112
Re: Detect NO Button Press
April 19, 2011 09:53AM
Hi, there!

A quick look into libogc's source and 2 lines of code added to a program tell me PAD_ButtonsDown() returns 0 if you do not press any button. Those sources of information also tell me you should be careful because if the controller is not connected you will get a 0 too.

The other question was trickier. I looked around and the only possible way I found out was using PAD_Read() but I failed. I didn't bother trying further because it seems like calling that function again (PAD_ScanPads calls it) interferes with the input-reading (different results depending on which one you call first), you can take a look at pad.c in libogc's source if you want to give it a try.

I would add this function to pad.c (or something similar). I don't know if there is any other way to find if a controller is connected, but if I were you I'll keep looking for it because otherwise everyone wishing to use your code will have to recompile libogc.
bool isPlugged(int pad)
{
	if(pad<PAD_CHAN0 || pad>PAD_CHAN3 || __pad_keys[pad].chan==-1) return FALSE; //Pad_ScanPads sets the channel to -1 if PAD_Read writes PAD_ERR_NO_CONTROLLER somewhere
	return TRUE;
}
You should have sought that yourself! Now I'll keep all the knowledge this would have given you and I won't share it :(

Have a good day!



Edited 1 time(s). Last edit at 04/19/2011 09:56AM by Aruskano.
Re: Detect NO Button Press
April 19, 2011 11:44AM
I believe

#include ogc/si.h
int i;
for (i=0;<4;i++)
    if ( SI_GetType(i) & SI_GC_STANDARD )
        printf("GC port %d has a GC controller plugged in.\n",%d);

will work, though I haven't tested it.
Re: Detect NO Button Press
April 19, 2011 01:25PM
PAD_ButtonsDown( ) returns in each bits the status of each buttons of the specified Gamecube controller (0: not pressed, 1: pressed) so it indeed returns zero if no buttons are pressed.

PAD_ScanPads( ) returns in low bits the status of each 4 Gamecube port, like this 0000dcba, with:

a = port 1 status (0: not connected, 1: connected)
b = port 2 status " "
c = port 3 status " "
d = port 4 status " "



Edited 2 time(s). Last edit at 04/19/2011 01:34PM by ekeeke.
Re: Detect NO Button Press
April 19, 2011 02:54PM
well I don't know about call backs but I would use a global varaible;

no_button_pressed=true;

if(PAD_ButtonsDown( ) ) no_button_pressed=false;
Re: Detect NO Button Press
April 19, 2011 09:09PM
chris: it works.

I completely overlooked that connected variable yesterday! thanks for pointing it out, ekeeke.

According to the info ekeeke gave us you could use this function or something similar.
bool isPlugged(u32 scan, int chan){

u8 chanbit = 1 << chan;
scan &= chanbit;

if (scan == 0) return 0;
return 1;
}
Re: Detect NO Button Press
April 20, 2011 05:50AM
w00t! It Works!
Thanks for the replies!

mv2112
Sorry, only registered users may post in this forum.

Click here to login