Welcome! Log In Create A New Profile

Advanced

Whats Wrong With This?

Posted by khjui 
Whats Wrong With This?
January 20, 2010 01:35PM
Hi

When I try and compile this:

#include 
#include 
#include 
#include 
#include 

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	// Initialise the video system
	VIDEO_Init();
	
	//Initialise Wii Light
	WIILIGHT_Init();

	
	// This function initialises the attached controllers
	WPAD_Init();
	
	// Obtain the preferred video mode from the system
	// This will correspond to the settings in the Wii menu
	rmode = VIDEO_GetPreferredMode(NULL);

	// Allocate memory for the display in the uncached region
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	
	// Initialise the console, required for printf
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	
	//Initialise the Wii Mote
	WPAD_Init();
	WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
	
	for(;;)
	{
		WPAD_ScanPads();
		
		u16 btnsdown = WPAD_ButtonsDown(0);
		u16 btnsheld = WPAD_ButtonsHeld(0);

		// Infrared calculation
		ir_t ir; // The struct for infrared
		WPAD_IR(WPAD_CHAN_0, &ir); // Let's get our infrared data
		
		if(btnsdown & WPAD_BUTTON_HOME)
		exit(0); 
			// Factory function
	
	
	// Set up the video registers with the chosen mode
	VIDEO_Configure(rmode);
	
	// Tell the video hardware where our display memory is
	VIDEO_SetNextFramebuffer(xfb);
	
	// Make the display visible
	VIDEO_SetBlack(FALSE);

	// Flush the video register changes to the hardware
	VIDEO_Flush();

	// Wait for Video setup to complete
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();


	// The console understands VT terminal escape codes
	// This positions the cursor on row 2, column 0
	// we can use variables for this with format codes too
	// e.g. printf ("\x1b[%d;%dH", row, column );
	printf("\x1b[2;0H");
	
	WIILIGHT_SetLevel(255);
	WIILIGHT_TurnOn();	

	
	Printf("Press (A) To Switch On And Off The Wii Disk Drive Light");

	while(1) {

		// Call WPAD_ScanPads each loop, this reads the latest controller states
		WPAD_ScanPads();

		// WPAD_ButtonsDown tells us which buttons were pressed in this loop
		// this is a "one shot" state which will not fire again until the button has been released
		u32 pressed = WPAD_ButtonsDown(0);

		// We return to the launcher application via exit
		if ( pressed & WPAD_BUTTON_HOME ) exit(0);
		
		//Toggles The Wii Disk Drive Light
		if ( pressed & WPAD_BUTTON_A ) WIILIGHT-Toggle();

		// Wait for the next frame
		VIDEO_WaitVSync();
	}

	return 0;
}

I Get This:

> "make" 
template.c
c:/devkitPro/examples/wii/template/source/template.c: In function 'main':
c:/devkitPro/examples/wii/template/source/template.c:43: warning: unused variable 'btnsheld'
c:/devkitPro/examples/wii/template/source/template.c:95: error: expected declaration or statement at end of input
make[1]: *** [template.o] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:01

[/code

What have I done wrong? 

-Tom
Re: Whats Wrong With This?
January 20, 2010 02:43PM
The error says the problem is on line 95, if you look carefully you have this:
WIILIGHT-Toggle()
There is a minus sign, so it's a subtraction. It does not make sense!!!
Re: Whats Wrong With This?
January 20, 2010 07:08PM
I guess my last post solved the problem since you released this "app": [wiibrew.org]

If I were you, I would have kept it for me. Because it's really the template.c code + two lines of code found on the lib page. I don't think people will learn a lot from your code.

By the way, in the Homebrew Browser this is an app called wiilight in the demo section. I think it does almost the same thing, it might even be better :)
Re: Whats Wrong With This?
January 20, 2010 11:56PM
huh? you have a for loop that i don't think you used right. also, you have more { than you do }. those things come in pairs.
and you have the video init stuff inside a loop.
// Set up the video registers with the chosen mode
VIDEO_Configure(rmode);

// Tell the video hardware where our display memory is
VIDEO_SetNextFramebuffer(xfb);

// Make the display visible
VIDEO_SetBlack(FALSE);

// Flush the video register changes to the hardware
VIDEO_Flush();

// Wait for Video setup to complete
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();



that should probably not be before the for loop. but it is also probably handled by your first videoinit(). if so, it is not needed at all in this main();.


so i would say delete this whole section
for(;;)
	{
		WPAD_ScanPads();
		
		u16 btnsdown = WPAD_ButtonsDown(0);
		u16 btnsheld = WPAD_ButtonsHeld(0);

		// Infrared calculation
		ir_t ir; // The struct for infrared
		WPAD_IR(WPAD_CHAN_0, &ir); // Let's get our infrared data
		
		if(btnsdown & WPAD_BUTTON_HOME)
		exit(0); 
			// Factory function
	
	
	// Set up the video registers with the chosen mode
	VIDEO_Configure(rmode);
	
	// Tell the video hardware where our display memory is
	VIDEO_SetNextFramebuffer(xfb);
	
	// Make the display visible
	VIDEO_SetBlack(FALSE);

	// Flush the video register changes to the hardware
	VIDEO_Flush();

	// Wait for Video setup to complete
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();


	// The console understands VT terminal escape codes
	// This positions the cursor on row 2, column 0
	// we can use variables for this with format codes too
	// e.g. printf ("\x1b[%d;%dH", row, column );
	printf("\x1b[2;0H");

and it probably will compile.


also, you have WPAD_init twice.



Edited 2 time(s). Last edit at 01/21/2010 12:00AM by giantpune.
Sorry, only registered users may post in this forum.

Click here to login