Welcome! Log In Create A New Profile

Advanced

How do i get infrared data from a 2nd wiimote (devkitppc)

Posted by xzachtmx 
How do i get infrared data from a 2nd wiimote (devkitppc)
August 09, 2009 12:21AM
Ok i need to get the x and y coordinates of the wiimote's infrared communication to the sensor bar. So i did this:

// Wiimote IR

ir_t ir;
ir_t ir2;

So i setup 2 variables to hold the infrared for both remotes.

Then i updated it in the game loop:

// IR Movement

WPAD_IR(0, &ir);
WPAD_IR(1, &ir2);

And then i displayed a picture ( the cursor) at each wiimote's coordinates:

display_jpeg(about, ir.x, ir.y);
display_jpeg(about, ir2.x, ir2.y);

now... for some reason only the first wiimote is working... and the second one's picture is stuck in the top left corner no matter how i aim it at the screen.

Any suggestions? Ty for any help!
Re: How do i get infrared data from a 2nd wiimote (devkitppc)
August 09, 2009 01:00AM
show the rest of your code
Re: How do i get infrared data from a 2nd wiimote (devkitppc)
August 09, 2009 01:22AM
Sorry... had a feeling it might come in handy. Hope it helps and thanks so much :

#include

#include

#include

#include

#include

#include

#include
#include



static u32 *xfb;

static GXRModeObj *rmode;



// Wiimote IR

ir_t ir;
ir_t ir2;

extern char picdata[];
extern int piclength;




void Initialise() {



VIDEO_Init();

WPAD_Init();

WPAD_SetVRes(0, 640, 480);

WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);



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();

}



void DrawBox (int x1, int y1, int x2, int y2, int color) {

DrawHLine (x1, x2, y1, color);

DrawHLine (x1, x2, y2, color);

DrawVLine (x1, y1, y2, color);

DrawVLine (x2, y1, y2, color);

}


void display_jpeg(JPEGIMG jpeg, int x, int y) {
unsigned int *jpegout = (unsigned int *) jpeg.outbuffer;
int i,j;
int height = jpeg.height;
int width = jpeg.width/2;
for(i=0;i<=width;i++)
for(j=0;j<=height-2;j++)
xfb[(i+x)+320*(j+16+y)]=jpegout[i+width*j];
free(jpeg.outbuffer);
}




int main() {

JPEGIMG about;



memset(&about, 0, sizeof(JPEGIMG));



about.inbuffer = picdata;

about.inbufferlength = piclength;



JPEG_Decompress(&about);



Initialise();



while(1) {



WPAD_ScanPads();

u32 pressed = WPAD_ButtonsDown(0);



// IR Movement

WPAD_IR(0, &ir);
WPAD_IR(1, &ir2);



if (pressed & WPAD_BUTTON_HOME) {

exit(0);

}



VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_GREEN);

display_jpeg(about, ir.x, ir.y);
display_jpeg(about, ir2.x, ir2.y);


VIDEO_WaitVSync();

}



return 0;

}
Re: How do i get infrared data from a 2nd wiimote (devkitppc)
August 09, 2009 06:09AM
Just guessing here (because I do not know Wiiuse), but shouldn't there be a call to
WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
for every WiiMote?
Re: How do i get infrared data from a 2nd wiimote (devkitppc)
August 09, 2009 05:51PM
Zamadatix?

Add this to your code to make it work:
WPAD_SetVRes(1, 640, 480);

WPAD_SetDataFormat(WPAD_CHAN_1, WPAD_FMT_BTNS_ACC_IR);
Sorry, only registered users may post in this forum.

Click here to login