Float printing bug in devkitPPC
Posted: Thu Jul 03, 2008 2:36 am
I'm trying to display Wiimote IR values, Accelometer, Orient, and GForce values, but all I get is a f where the displayed number should be. I tried %1.3f instead of %f, but still nothing. I tried displaying my own float var, but the exact same result. And when I use sprintf, and then print the string used on screen, I get numbers, but they're all zeroes. Strangely, when printing floats with %.2f to a text file, it seems to work fine...
Code: Select all
void HandleRemote(s32 chan)
{
u32 ext;//Extension type
u32 ret=0;
int i=0;
ret=WPAD_Probe(chan,&ext);
//WPAD_ScanPads();
u32 pressed = WPAD_ButtonsHeld(chan);
WPADData *Data = WPAD_Data((int)chan);
WPADData data = *Data;
WPAD_Orientation(chan, &data.orient);
WPAD_GForce(chan, &data.gforce);
WPAD_Accel(chan, &data.accel);
WPAD_Expansion(chan, &data.exp);
if(ret!=remoteErrors[chan] && remoteErrors[chan]==WPAD_ERR_NO_CONTROLLER)
{
//Wiimote/WPAD won't do re-enable these on reconnect.
WPAD_SetDataFormat(chan, WPAD_DATA_BUTTONS | WPAD_DATA_ACCEL | WPAD_DATA_EXPANSION | WPAD_DATA_IR);
}
remoteErrors[chan] = ret;
remoteExtensions[chan] = ext;
int offset = 5 + ((int)chan*37);
iprintf("\x1b[%d;6HRemote #%d", offset+0,(int)chan);
for(i=1; i<=37; i++)
iprintf("\x1b[%d;1H ", offset+i);
/*if(ret==WPAD_ERR_NONE && ext==WPAD_EXP_NUNCHUK)
{
if(pressed & WPAD_NUNCHUK_BUTTON_Z)iprintf("\x1b[5;%dHButton Z pressed on Nunchuk! ", offset+1);
if(pressed & WPAD_NUNCHUK_BUTTON_C)iprintf("\x1b[5;%dHButton C pressed on Nunchuk! ", offset+2);
}
if (pressed & WPAD_BUTTON_A)iprintf("\x1b[%d;6HButton A pressed! ", offset+3);
if ( pressed & WPAD_BUTTON_B)
{
iprintf("\x1b[%d;6HButton B pressed! ", offset+4);
ScanWiimotes();
}
if ( pressed & WPAD_BUTTON_1)iprintf("\x1b[%d;6HButton 1 pressed! ", offset+5);
if ( pressed & WPAD_BUTTON_2)iprintf("\x1b[%d;6HButton 2 pressed! ", offset+6);
if ( pressed & WPAD_BUTTON_MINUS)iprintf("\x1b[%d;6HButton - (Minus) pressed! ", offset+7);
if ( pressed & WPAD_BUTTON_PLUS)iprintf("\x1b[%d;6HButton + (Plus) pressed! ", offset+8);
if ( pressed & WPAD_BUTTON_UP)iprintf("\x1b[%d;6HButton Up pressed! ", offset+9);
if ( pressed & WPAD_BUTTON_DOWN)iprintf("\x1b[%d;6HButton Down pressed! ", offset+10);
if ( pressed & WPAD_BUTTON_RIGHT)iprintf("\x1b[%d;6HButton Right pressed! ", offset+12);
if ( pressed & WPAD_BUTTON_LEFT)iprintf("\x1b[%d;6HButton Left pressed! ", offset+13);*/
offset-=13;
//if(data.ir.raw_valid)
//{
iprintf("\x1b[6;6HIR RAW X %1.3f ", data.ir.ax);
iprintf("\x1b[7;6HIR RAW Y %1.3f ", data.ir.ay);
iprintf("\x1b[8;6HIR SMOOTH X %1.3f ", data.ir.sx);
iprintf("\x1b[9;6HIR SMOOTH Y %1.3f ", data.ir.sy);
//if(data.ir.valid)
//{
iprintf("\x1b[10;6HIR X %1.3f ", data.ir.x);
iprintf("\x1b[11;6HIR Y %1.3f ", data.ir.y);
//}
iprintf("\x1b[12;6HIR ANGLE %1.3f ", data.ir.angle);
//}
//\x1b[12;6H
iprintf("ACCEL X %d \n", (int)Data->accel.x);
iprintf("ACCEL Y %d \n", (int)Data->accel.y);
iprintf("ACCEL Z %d \n", (int)Data->accel.z);
char buf[256];
memset(buf,0,256);
sprintf(buf, "HORIENT ROLL %1.3f PITCH %1.3f YAW %1.3f", (float)Data->orient.roll, (float)Data->orient.pitch, (float)Data->orient.yaw);
iprintf("%s \n", buf);
//iprintf("\x1b[15;6HORIENT ROLL %1.3f ", (float)Data->orient.roll);
//iprintf("\x1b[16;6HORIENT PITCH %1.3f ", (float)Data->orient.pitch);
//iprintf("\x1b[17;6HORIENT YAW %1.3f ", (float)Data->orient.yaw);
iprintf("GFORCE X %1.3f \n", (float)data.gforce.x);
iprintf("GFORCE Y %1.3f \n", (float)data.gforce.y);
iprintf("GFORCE Z %1.3f \n", (float)data.gforce.z);
if(ret==WPAD_ERR_NONE && ext==WPAD_EXP_NUNCHUK)
{
iprintf("\x1b[21;6HNCUHCK MIN X %d Y %d ", (int)data.exp.nunchuk.js.min.x, (int)data.exp.nunchuk.js.min.y);
iprintf("\x1b[22;6HNCUHCK MAX X %d Y %d ", (int)data.exp.nunchuk.js.max.x, (int)data.exp.nunchuk.js.max.y);
iprintf("\x1b[23;6HNCUHCK CENTER X %d Y %d ", (int)data.exp.nunchuk.js.center.x, (int)data.exp.nunchuk.js.center.y);
iprintf("\x1b[24;6HNCUHCK POS X %d Y %d ", (int)data.exp.nunchuk.js.pos.x, (int)data.exp.nunchuk.js.pos.y);
iprintf("\x1b[25;6HNCUHCK ANG %1.3f MAG %1.3f ", (float)data.exp.nunchuk.js.ang, (float)data.exp.nunchuk.js.mag);
}
float myvar = 1.5f;
iprintf("HMYVAR %1.3f ", (float)myvar);
}