Welcome! Log In Create A New Profile


Button/stick codes?

Posted by DigitalMan 
Button/stick codes?
October 09, 2008 04:46AM
Quick query, since my web search returned nothing. Determining whether GameCube pad buttons have been pushed is simple enough, with "if (PAD_ButtonsDown(0) & PAD_BUTTON_A)" and such. There's also one tutorial online covering the main control stick and the C-stick. However, with no real documentation, the rest is left to inferences (one would assume PAD_BUTTON_B, Z, Y, etc. work the same), and more importantly, there's no information on collecting the analog data from the L and R buttons. I would like a solid, complete reference on the GameCube button commands.

Also, while it's pretty simple to look at someone's Wii homebrew code and figure out how they read the Wii-mote buttons, a full reference on remote/nunchuck/classic controller buttons and sticks would be nice, for the sake of completeness.

Sorry if I sound demanding ;) I'm just shocked there's not a place to find this already (maybe we should form a team to fill in the gaping holes in the DevKitPro documentation?)
Re: Button/stick codes?
October 09, 2008 09:26AM
[www.wiiuse.net] (when it's back up) will give you documentation on using the Wiiuse library (The WPAD system is a kind of a cross-breed, using Cube pad syntax on the Wiimotes).
Re: Button/stick codes?
October 09, 2008 09:34AM
s8 PAD_StickX(int pad)
s8 PAD_StickY(int pad)

s8 PAD_SubStickX(int pad);
s8 PAD_SubStickY(int pad);

both return values ranging from -127 to 127

Also, you can figure alot of this out by simply looking at the headerfiles and applying some common sense. Though I agree, some better documentation wouldn't hurt.
Re: Button/stick codes?
October 09, 2008 10:58AM
Well, the GCN sticks I got, and are currently used in my controller test program (Fun fact: the values, at least on this generic controller, never exceed 100, even if rigged to be calibrated wrong).

Again, I can figure out most of it on my own, but no one should have to rely on that given the state of Wii homebrew. The two options of either examining someone else's source or asking for help on a forum take a considerable amount of time. Thus the purpose of this topic: several, probably most, people here actually have the information, and a complete answer will show up in the forum search for future reference by others. Hopefully it would eventually show up in Google searches as well.

The header search, however, did turn up interesting results. Contrary to what common sense may tell some people, Z is considered a trigger as opposed to a button. Also, two values - analogA and analogB - don't seem to have an easy function to find them, like the sticks or triggers.

And for those who would rather look at code, I'll be putting my finished controller test demo on the WiiBrew wiki, if such a simple program would be welcome.

Edited 1 time(s). Last edit at 10/09/2008 11:33AM by DigitalMan.
Re: Button/stick codes?
October 11, 2008 01:42PM
Whoa, major problem here. In my control tester, I basically have code like:

(send variable loc as the controller number)

if (PAD_ButtonsHeld(loc) & PAD_BUTTON_A){
strcat(pressed, "A, ");

(change controller number, do it again)

However, PAD_BUTTON_A is indiscriminate. It doesn't care what controller it's on. If controller 1 is holding A, and controller 2 is holding X - or anything else - controller 2 is automatically holding A as well, because it thinks of it as, "If controller (loc) has a button held, and the A button is being held (somewhere in the system)..." instead of "If controller (loc) has a button held, and that button is A..."

Looking at the header file supports this; the buttons all have a single set value, regardless of controller number. So, how exactly do I separate controls by player?

Edit: With a few lines added for debugging, I determined that the controller inputs do function properly, are based on binary, and will work with or without a real comparison in the IF statement. The real problem seems to be with button presses, recorded in a string, surviving after the string is not only completely manually replaced with '\0' characters, but also returned to system memory (as it is created in that function anew for each controller number).

Edited 2 time(s). Last edit at 10/11/2008 02:19PM by DigitalMan.
Re: Button/stick codes?
October 11, 2008 02:39PM

The "loc" variable here specifies pad number

From the PAD.H file
#define PAD_CHAN0     0
#define PAD_CHAN1     1
#define PAD_CHAN2     2
#define PAD_CHAN3     3

u16 PAD_ButtonsUp(int pad);
u16 PAD_ButtonsDown(int pad);
u16 PAD_ButtonsHeld(int pad);

PAD_ButtonsHeld(PAD_CHAN0) will get you the buttons from GC Pad 1, PAD_ButtonsHeld(PAD_CHAN1) from Pad 2 etc.

Edited 1 time(s). Last edit at 10/11/2008 02:40PM by whodares.
Re: Button/stick codes?
October 11, 2008 03:06PM
Yes, according to my debugging process the buttons are recording from the right controller. The real problem must be the string.

The main loop cycles through all four controllers, over and over again. It sets the controller number to 0, then sends that value to my button function, where it becomes the variable "loc". It goes through a whole stack of IF statements like the one above, each time adding the button press to the string "pressed". The string is then printed to the console, as a visual readout of what buttons have been pressed. That much works fine.

Then, it returns, and the main loop increments "loc" to 1, for the second controller. If no buttons are held on the second controller, it's fine - but, if any buttons are held, the string is completely overwritten with the first controller's data. If controller 1 has A and B, and controller 2 has X, Y, L, and R, the controller 2 readout will be "A, B, L, R, ". Further debugging has shown that it "working" when no buttons are pressed is due to wiping the first character with a '\0' at another point; removal of this makes the controller 1 button string repeat the same for all four controllers, even if they aren't even plugged in. Thus, the error is in the last lines of the function:

int i;
for(i=0; i<45; i++) pressed='\0';

Which, in theory, replaces every character with basically nothing. The exact same line elsewhere in the code does its job perfectly, but not here.

I'm glad I actually decided to test this with multiple controllers, I was about to release the program!

EDIT: There we go. I moved those two lines to the top of the function, immediately after pressed[] is declared, and before it's used. Why does it work at the beginning of the function, but not the end, if the string holds the same data? Beats the hell out of me.

Edited 1 time(s). Last edit at 10/11/2008 03:11PM by DigitalMan.
Re: Button/stick codes?
October 11, 2008 03:46PM
Can you post the code? Either use the code button in the Message toolbar or use something like [pastebin.com]
Re: Button/stick codes?
October 13, 2008 12:57PM
That... that would be a lot of code. Given that all the bugs seem to be worked out now, I'll give a link to the program its self... just as soon as I figure out how to make a page on the WiiBrew wiki.
Sorry, only registered users may post in this forum.

Click here to login