Welcome! Log In Create A New Profile

Advanced

ir help!!!

Posted by g_man 
ir help!!!
March 08, 2009 06:12AM
I have made a simple program that is supposed to track the ir position of the wiimote, but i only get y positions, the x positions i get are 0 or 1.401298e-45.
here is the code
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static u32 *xfb;
static GXRModeObj *rmode;


ir_t ir;


void Initialise() {

	VIDEO_Init();
	WPAD_Init();

	rmode = VIDEO_GetPreferredMode(NULL);

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
}

int main() {

	Initialise();

	while(1) {

		WPAD_ScanPads();
		WPAD_IR(0, &ir);
		WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
		WPAD_SetVRes(0, 640, 480);

		
		u32 buttonsDown = WPAD_ButtonsDown(0);

		if( buttonsDown & WPAD_BUTTON_B ) {
			//Prints wiimote position
			printf("X= %e Y= %e\n", ir.x, ir.y);
		}	
		
		//Exit
		if (buttonsDown & WPAD_BUTTON_HOME) {
			exit(0);
		}
	}

	return 0;
}

Re: ir help!!!
March 08, 2009 06:27AM
You should be printing a double/float.

printf("X= %f Y= %f\n", ir.x, ir.y);

Also you can move the below code under WPAD_Init();
WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetVRes(0, 640, 480);
Re: ir help!!!
March 08, 2009 06:32AM
yeah %e is for double values. ir.x/y is a float. Try a %f in the printf.
Re: ir help!!!
March 08, 2009 06:36AM
thanks but still when i put %f it gives me 0 ALLWAYS for the x value and i get a range of Y's, is this a hardware issue, i dont think so because it works normally and on other apps, like the homebrew browser.
Re: ir help!!!
March 08, 2009 08:56AM
Have you tried putting the PAD init stuff outside the loop. They really only need to be called once. See Below :-

int main() {

	Initialise();

	WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
	WPAD_SetVRes(0, 640, 480);

	while(1) {

		WPAD_ScanPads();
		WPAD_IR(0, &ir);
		
		u32 buttonsDown = WPAD_ButtonsDown(0);

		if( buttonsDown & WPAD_BUTTON_B ) {
			//Prints wiimote position
			printf("X= %f Y= %f\n", ir.x, ir.y);
		}	
		
		//Exit
		if (buttonsDown & WPAD_BUTTON_HOME) {
			exit(0);
		}
	}

	return 0;
}

Re: ir help!!!
March 08, 2009 09:56PM
ya it's outside now but i still get the same problem, also it gives me a screen with a code dump on it, how can i fix this?

is iit possible that sombody could make a program that works for the pointer(it can be as simple as printing x and y values) and test it to make sure it works and then post it?



Edited 2 time(s). Last edit at 03/10/2009 01:07AM by g_man.
Re: ir help!!!
March 10, 2009 10:47AM
make x and y into variables prior to the print f

int main() {

Initialise();

WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetVRes(0, 640, 480);

while(1) {

WPAD_ScanPads();
WPAD_IR(0, &ir);
int cursorx, cursory
cursorx =ir.x
cursory =ir.y


u32 buttonsDown = WPAD_ButtonsDown(0);

if( buttonsDown & WPAD_BUTTON_B ) {
//Prints wiimote position
printf("X= %i Y= %i\n", cursorx, cursory);
}

//Exit
if (buttonsDown & WPAD_BUTTON_HOME) {
exit(0);
}
}

return 0;
}




This is the code i used and it worked for me.
Re: ir help!!!
March 11, 2009 01:33AM
I still didn't get any X values, and there is opening brackets around my #include's

here is my source
#include stdio.h>
#include stdlib.h>
#include string.h>
#include malloc.h>
#include ogcsys.h>
#include gccore.h>
#include wiiuse/wpad.h>


static u32 *xfb;
static GXRModeObj *rmode;


ir_t ir;


void Initialise() {

	VIDEO_Init();
	WPAD_Init();

	rmode = VIDEO_GetPreferredMode(NULL);

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);

	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
}


int main() {

	Initialise();

	WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
	WPAD_SetVRes(0, 640, 480);

	while(1) {

		WPAD_ScanPads();
		WPAD_IR(0, &ir);
		
		u32 buttonsDown = WPAD_ButtonsDown(0);

		if( buttonsDown & WPAD_BUTTON_B ) {
			//Prints wiimote position
			printf("X= %f Y= %f\n", ir.x, ir.y);
		}	
		
		//Exit
		if (buttonsDown & WPAD_BUTTON_HOME) {
			exit(0);
		}
	}

	return 0;
}

Re: ir help!!!
March 11, 2009 07:37AM
I tried compiling your code and it works for me.
Try running my compilation [agoajm.googlepages.com] and see if it works.
If it does then your problem is with your devkit installation.
Re: ir help!!!
March 16, 2009 05:37AM
thx, i reinstalled it and it works
Sorry, only registered users may post in this forum.

Click here to login