Welcome! Log In Create A New Profile

Advanced

Guitar Hero Controller strum Help

Posted by g_man 
Guitar Hero Controller strum Help
March 07, 2009 08:10AM
I'm just beggining proggramming for the wii, but i do have some background C experience.
I was wondering, i can get the guitar hero controller to recognize when green is pressed, but not when i have strummed.
I have coppied the code for it straight from the header file and it doesn't give me an error.

Here is the code:
		WPAD_ScanPads();

		u32 buttonsDown = WPAD_ButtonsDown(0);
		u32 buttonsHeld = WPAD_ButtonsHeld(0);
		
		
		if( buttonsDown & WPAD_GUITAR_HERO_3_BUTTON_GREEN ) {
			printf("Green pressed.\n");
		}
		
		if( buttonsDown & (WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN || WPAD_GUITAR_HERO_3_BUTTON_STRUM_UP ) )
			{
				printf("You Have Strummed");
			}
Thanks
Re: Guitar Hero Controller strum Help
March 08, 2009 04:14AM
Correct me if I'm wrong, but wouldn't this expression always be 1, since both values are non zero and you're comparing them with a logical or?
(WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN || WPAD_GUITAR_HERO_3_BUTTON_STRUM_UP )
Obviously this would result in unwanted results in your second if statement, since you end up doing a binary and operation with buttonsDown and 1, instead of buttonsDown and WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN and WPAD_GUITAR_HERO_3_BUTTON_STRUM_UP respectively.

I suggest trying it that way, and see if if it works.
if ( ( buttonsDown & WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN ) || ( buttonsDown & WPAD_GUITAR_HERO_BUTTON_STRUM_UP ) )
{
	printf( "You have strummed." );
}
Re: Guitar Hero Controller strum Help
March 08, 2009 04:52AM
You could also just change the logical or to a binary or, since those are each just a bit in a certain position. Binary or is one pipe, |, i.e.
(WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN | WPAD_GUITAR_HERO_3_BUTTON_STRUM_UP )
Re: Guitar Hero Controller strum Help
March 08, 2009 05:30AM
Quote
Botskiz
Correct me if I'm wrong, but wouldn't this expression always be 1, since both values are non zero and you're comparing them with a logical or?
(WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN || WPAD_GUITAR_HERO_3_BUTTON_STRUM_UP )
Obviously this would result in unwanted results in your second if statement, since you end up doing a binary and operation with buttonsDown and 1, instead of buttonsDown and WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN and WPAD_GUITAR_HERO_3_BUTTON_STRUM_UP respectively.

I suggest trying it that way, and see if if it works.
if ( ( buttonsDown & WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN ) || ( buttonsDown & WPAD_GUITAR_HERO_BUTTON_STRUM_UP ) )
{
	printf( "You have strummed." );
}
Thanks, but now i have one other problem, when i strum up the screen also say's that i have pushed 2.
Here's the code for 2 and i just copied your part into my code
		if( buttonsDown & WPAD_BUTTON_2 ) {
			printf("Button 2 pressed.\n");
		}
Do they happen to share the same bit's? this doesn't happen when i just hit the 2 button though
thanks

edit: when i hit Z on the controller the same thing happens too, it say i have strummed and that i have hit Z
code for Z
		if( buttonsDown & WPAD_NUNCHUK_BUTTON_Z ) {
			printf("Button Z pressed.\n");
		}



Edited 1 time(s). Last edit at 03/08/2009 05:33AM by g_man.
Re: Guitar Hero Controller strum Help
March 08, 2009 02:57PM
Yes, some buttons share the same input values despite being on different controllers. You need to use a switch statement to keep everything seperated.
Re: Guitar Hero Controller strum Help
March 08, 2009 04:24PM
There are multiple ways of figuring out the type of controller connected to the Wii remote. Depending on what you want to do one way might be more useful than another. Please note that all the code below is untested and written from the top of my head, so you might want to do some additional error checking. But I hope it's correct enough to help you figuring out the rest by yourself :)

This code uses WPAD_Probe to get the expansion type of the first controller.
u32 expType = 0; // Stores only the controller/expansion type.

// Use WPAD_Probe to get the expansion type.
WPAD_Probe( WPAD_CHAN_0, &expType );

if ( ( buttonsDown & WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN ) && ( expType == WPAD_EXP_GUITARHERO3 ) )
{
	printf( "You have strummed down." );
}

Another way would be to use WPAD_Expansion() to get a pointer to all the data of the connected expansion, and read the type from there.
expansion_t *ext; // Pointer to the expansion data.

// Use WPAD_Expansion() to the the expansion data.
WPAD_Expansion( WPAD_CHAN_0, ext );

if ( ( buttonsDown & WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN ) && ( exp->type == WPAD_EXP_GUITARHERO3 ) )
{
	printf( "You have strummed down." );
}

And then of course you could also just read any data the wii remote has to offer by using WPAD_Data();
WPADData *padData; // Pointer to the wii remote data.

// Use WPAD_Data() to get any Wii remote data.
padData = WPAD_Data( WPAD_CHAN_0 );

if ( ( buttonsDown & WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN ) && ( padData->exp.type == WPAD_EXP_GUITARHERO3 ) )
{
	printf( "You have strummed down." );
}
Re: Guitar Hero Controller strum Help
July 01, 2009 05:59AM
I'm having trouble with this as well. I guess my question is ... Is the guitar from World Tour recognized as a GH3 controller? I am doing all my testing with a WT guitar and I cannot make my program respond to it. If I knew the anwser to this, it would help me track down what is going wrong.
Re: Guitar Hero Controller strum Help
July 01, 2009 10:03AM
No, it isn't. Guitar Fun has a seperate version made for use with GH:WT guitar, the regular version just does GH3. That's probably why it isn't working for you.
Re: Guitar Hero Controller strum Help
July 01, 2009 12:43PM
But who is responsible for the memory that the returned pointers point at? The caller? If so, how should it be deallocated?
Re: Guitar Hero Controller strum Help
July 08, 2009 01:12AM
You don't need to free the data returned by the Expansion function. libwiiuse keeps ownership.

GHWT guitars are pretty much equal to the GH3 guitars, but the slight difference makes the current libwiiuse fail to use it at all. The change for that is simple, and I've added a patch for WT guitars here: [sourceforge.net]
Re: Guitar Hero Controller strum Help
July 08, 2009 02:10PM
But how does it know when to free the memory? How long is the pointer valid?
Re: Guitar Hero Controller strum Help
July 19, 2009 07:41PM
Late answer, but the pointer is valid as long as you don't unload the wii motes, so forever really. libwiiuse keeps updating the structure whenever you call the update function.
Sorry, only registered users may post in this forum.

Click here to login