/*---------------------------------------------------------------------------* Project: WPAD Demo Program File: mplus.c Copyright (C) 2008 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #include #include #include #include #define DEMO_USE_MEMLIB=1 // This turns on the DEMO library's MEM heaps. #include /*---------------------------------------------------------------------------* * Local Definitions *---------------------------------------------------------------------------*/ // screen size #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 // font size #define FONT_HEIGHT 12 #define FONT_SPACE 1 // draw screen #define COL_WIDTH 140 #define X0_START 0 #define X1_START 70 #define Y0_START 38 #define Y1_START 400 // sampling buffer #define SMPBUF_SIZE 100 // print buffer #define BUFFER_SIZE_BYTES 128 #define BUFFER_SIZE_LINES 6 #define CMD_MPLS_OFF WPAD_MPLS_OFF #define CMD_MPLS_STD WPAD_MPLS_STD #define CMD_MPLS_FS WPAD_MPLS_FS #define CMD_MPLS_CL WPAD_MPLS_CL #define CMD_MPLS_HW_RST WPAD_MPLS_ZRST #define CMD_MPLS_SW_RST (WPAD_MPLS_ZRST+1) // temporary defined /*---------------------------------------------------------------------------* * Local Data *---------------------------------------------------------------------------*/ // sampling buffers static WPADMPStatus mp_ringbuffer[WPAD_MAX_CONTROLLERS][SMPBUF_SIZE]; static WPADCLStatus cl_ringbuffer[WPAD_MAX_CONTROLLERS][SMPBUF_SIZE]; static WPADFSStatus fs_ringbuffer[WPAD_MAX_CONTROLLERS][SMPBUF_SIZE]; static WPADStatus co_ringbuffer[WPAD_MAX_CONTROLLERS][SMPBUF_SIZE]; // reset flag static u8 reset = 1; // print buffer static char __buffer[BUFFER_SIZE_LINES][BUFFER_SIZE_BYTES]; static u32 __curr_line = 0; // device strings static u8 str_dev_core [] = " CORE "; static u8 str_dev_extn [] = " FREE "; static u8 str_dev_cl [] = " CLAC "; static u8 str_dev_mp [] = " MPLS "; static u8 str_dev_mpfs [] = " MP+FS"; static u8 str_dev_mpcl [] = " MP+CL"; static u8 str_dev_mpft [] = " MP+FT"; static u8 str_dev_future [] = " FTRE "; static u8 str_dev_notsup [] = " NOSP "; static u8 str_dev_unknown[] = " UNKW "; // status strings static u8 str_status_ok [] = " NONE "; static u8 str_status_none[] = " NCNT "; static u8 str_status_busy[] = " BUSY "; static u8 str_status_xfer[] = " TRNS "; static u8 str_status_inv [] = " INVD "; static u8 str_status_crpt[] = " CRPT "; static u8 str_status_unk [] = " UNKW "; // dpd format strings static u8 dpd_fmt_off [] = "OFF "; static u8 dpd_fmt_std [] = "STD "; static u8 dpd_fmt_exp [] = "EXP "; static u8 dpd_fmt_full[] = "FULL"; // data format strings static u8 fmt_core1[] = "CO "; static u8 fmt_core2[] = "CO+A "; static u8 fmt_core3[] = "CO+AD "; static u8 fmt_nun1 [] = "FS "; static u8 fmt_nun2 [] = "FS+A "; static u8 fmt_nun3 [] = "FS+AD "; static u8 fmt_clas1[] = "CL "; static u8 fmt_clas2[] = "CL+A "; static u8 fmt_clas3[] = "CL+AD "; static u8 fmt_full [] = "CO+ADF"; static u8 fmt_mpls [] = "MPLS "; static const GXColor BLACK= { 20, 20, 20, 255 }; static u8 mpls[WPAD_MAX_CONTROLLERS] = {0,0,0,0}; static u8 hcnt[WPAD_MAX_CONTROLLERS] = {0,0,0,0}; /*---------------------------------------------------------------------------* * Function prototypes *---------------------------------------------------------------------------*/ static void *myAlloc ( u32 size ); static u8 myFree ( void *ptr ); static void myPrint ( int x, int y, int z, char *fmt, ... ); // callbacks void connectCallback ( s32 chan, s32 reason ); void extensionCallback ( s32 chan, s32 result ); void samplingCallback ( s32 chan ); void mplsCallback ( s32 chan, s32 result ); // Internal functions static void initialize ( void ); static void renderStatus ( void ); static void renderAimings ( void ); static void recalibrate ( s32 chan, u32 type ); static void printBuffer ( char *string, ... ); static u8 *getDevName ( u32 type ); static u8 *getErrName ( s32 status ); static u8 *getFmtString ( u8 fmt ); static u8 *getDpdFmt ( u8 type ); /*---------------------------------------------------------------------------* Name: Main Description: None. Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ void main( void ) { s32 i; u16 prev[4]; u16 curr[4]; initialize(); while(reset) { for(i=WPAD_CHAN0; i 100) { cmd = CMD_MPLS_SW_RST; hcnt[i] = 0; } } // Check the command if (cmd == 0xff) { continue; } // Display a message for each command switch(cmd) { case CMD_MPLS_OFF: printBuffer("Try to turn off motion plus."); break; case CMD_MPLS_STD: printBuffer("Try to turn on motion plus."); break; case CMD_MPLS_FS : printBuffer("Try to turn on nunchaku + motion plus."); break; case CMD_MPLS_CL : printBuffer("Try to turn on classic + motion plus."); break; case CMD_MPLS_HW_RST: printBuffer("Try to do the hardware re-calibration."); break; case CMD_MPLS_SW_RST: printBuffer("Try to do the software re-calibration."); break; } if (cmd != CMD_MPLS_SW_RST) { // Issue a command WPADControlMpls(i, cmd, mplsCallback); } else { recalibrate(i, type); } } DEMOBeforeRender(); renderStatus(); renderAimings(); DEMODoneRender(); } OSRestart(0); } // End main() /*---------------------------------------------------------------------------* Name: connectCallback Description: Function to be called when a controller is connected or disconnected. Arguments: chan: Specified channel to be connected/disconnected. reason: Reason of calling this. if WPAD_ERR_NONE, connected. if WPAD_ERR_NO_CONTROLLER, disconnected. Returns: None. *---------------------------------------------------------------------------*/ void connectCallback( s32 chan, s32 reason ) { // Wii Remote is connected. if (reason == WPAD_ERR_NONE) { WPADSetExtensionCallback(chan, extensionCallback); WPADSetSamplingCallback(chan, samplingCallback); WPADControlDpd(chan, WPAD_DPD_EXP, NULL); WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD); WPADSetAutoSamplingBuf(chan, (void *)(&co_ringbuffer[chan][0]), SMPBUF_SIZE); mpls[chan] = 0; } } /*---------------------------------------------------------------------------* Name: extensionCallback Description: Function to be called when an extension is attached or detached. Arguments: chan: specified channel to be attached/detached. result: new device type. / ----------------------------------------------------------------------- / the meaning of result is below. if WPAD_DEV_CORE, an extension is detached. if WPAD_DEV_FUTURE, an extension is undefined. if WPAD_DEV_NOT_SUPPORTED, an extension is not supported. if WPAD_DEV_FREESTYLE, Nunchuk extension is attached. if WPAD_DEV_CLASSIC, Classic Controller extension is attached. if WPAD_DEV_MPLS, MotionPlus extension is turned on in standard mode and extension is detached from the Wii MotionPlus. if WPAD_DEV_MPLS_FREESTYLE, MotionPlus extension is turned on in expansion mode and Nunchuk extension is installed into the Wii MotionPlus. if WPAD_DEV_MPLS_CLASSIC, MotionPlus extension is turned on in expansion mode and Classic Controller extension is installed into the Wii MotionPlus. if WPAD_DEV_MPLS_FUTURE, MotionPlus extension is turned on in expansion mode and other extension is installed into the Wii MotionPlus. if WPAD_DEV_UNKNOWN, an extension is attached but it is not known yet. An extension cannot be recognized shortly when it is attached and WPAD_DEV_UNKOWN is returned at first. After a while, the host recognizes the correct device type and the type is returned. Note: If WPAD_DEV_FUTURE or WPAD_DEV_NOT_SUPPORTED is returned, Wii Remote at least has to work. / ----------------------------------------------------------------------- / Returns: None. *---------------------------------------------------------------------------*/ void extensionCallback( s32 chan, s32 result ) { if ( result != WPAD_DEV_MPLS && result != WPAD_DEV_MPLS_FREESTYLE && result != WPAD_DEV_MPLS_CLASSIC && result != WPAD_DEV_MPLS_FUTURE) { mpls[chan] = 0; } switch(result) { case WPAD_DEV_UNKNOWN: printBuffer("Initializing extension on chan %1d...", chan); break; case WPAD_DEV_CORE: WPADControlDpd(chan, WPAD_DPD_EXP, NULL); WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD); WPADSetAutoSamplingBuf(chan, (void *)(&co_ringbuffer[chan][0]), SMPBUF_SIZE); printBuffer("Extension removed on chan %1d.", chan); break; case WPAD_DEV_FREESTYLE: WPADControlDpd(chan, WPAD_DPD_STD, NULL); WPADSetDataFormat(chan, WPAD_FMT_FREESTYLE_ACC_DPD); WPADSetAutoSamplingBuf(chan, (void *)(&fs_ringbuffer[chan][0]), SMPBUF_SIZE); printBuffer("Freestyle initialized on chan %1d.", chan); break; case WPAD_DEV_CLASSIC: WPADControlDpd(chan, WPAD_DPD_STD, NULL); WPADSetDataFormat(chan, WPAD_FMT_CLASSIC_ACC_DPD); WPADSetAutoSamplingBuf(chan, (void *)(&cl_ringbuffer[chan][0]), SMPBUF_SIZE); printBuffer("Classic initialized on chan %1d.", chan); break; case WPAD_DEV_MPLS: // Started the Wii MotionPlus if (mpls[chan] == 0) { mpls[chan] = 1; WPADControlDpd(chan, WPAD_DPD_STD, NULL); WPADSetDataFormat(chan, WPAD_FMT_MPLS); WPADSetAutoSamplingBuf(chan, (void *)(&mp_ringbuffer[chan][0]), SMPBUF_SIZE); printBuffer("MotionPlus initialized on chan %1d.", chan); } // An external extension controller was disconnected from the Wii MotionPlus else { printBuffer("Detached Extenion from MotionPlus on chan %1d.", chan); } break; case WPAD_DEV_MPLS_FREESTYLE: WPADControlDpd(chan, WPAD_DPD_STD, NULL); WPADSetDataFormat(chan, WPAD_FMT_MPLS); WPADSetAutoSamplingBuf(chan, (void *)(&mp_ringbuffer[chan][0]), SMPBUF_SIZE); printBuffer("Attached Freestyle into MotionPlus on chan %1d.", chan); break; case WPAD_DEV_MPLS_CLASSIC: WPADControlDpd(chan, WPAD_DPD_STD, NULL); WPADSetDataFormat(chan, WPAD_FMT_MPLS); WPADSetAutoSamplingBuf(chan, (void *)(&mp_ringbuffer[chan][0]), SMPBUF_SIZE); printBuffer("Attached Classic into MotionPlus on chan %1d.", chan); break; case WPAD_DEV_MPLS_FUTURE: WPADControlDpd(chan, WPAD_DPD_STD, NULL); WPADSetDataFormat(chan, WPAD_FMT_MPLS); WPADSetAutoSamplingBuf(chan, (void *)(&mp_ringbuffer[chan][0]), SMPBUF_SIZE); printBuffer("Attached Future device into MotionPlus on chan %1d.", chan); break; case WPAD_DEV_FUTURE: case WPAD_DEV_NOT_SUPPORTED: WPADControlDpd(chan, WPAD_DPD_EXP, NULL); WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD); WPADSetAutoSamplingBuf(chan, (void *)(&co_ringbuffer[chan][0]), SMPBUF_SIZE); printBuffer("Unknown device [%d] on chan %1d.", result, chan); break; default: break; } } /*---------------------------------------------------------------------------* Name: samplingCallback Description: Function to be called whenever controller data is received. Arguments: chan: specified channel. Returns: None. *---------------------------------------------------------------------------*/ void samplingCallback( s32 chan ) { (void)chan; } /*---------------------------------------------------------------------------* Name: mplsCallback Description: Function to be called whenever the result for WPADControlMpls is received. Arguments: chan: specified channel. result: result. Returns: None. *---------------------------------------------------------------------------*/ void mplsCallback( s32 chan, s32 result ) { printBuffer("Result = %d on chan %1d.", result, chan); } /*---------------------------------------------------------------------------* Name: myAlloc Description: Allocate memory from MEM2. Arguments: size: Memory size Returns: Point to the head address of the allocated memory. *---------------------------------------------------------------------------*/ static void *myAlloc( u32 size ) { return MEMAllocFromAllocator(&DemoAllocator2, size); } /*---------------------------------------------------------------------------* Name: myFree Description: Free memory. Arguments: ptr: Point to head of the memory address to be freed. Returns: Result, but unused now. *---------------------------------------------------------------------------*/ static u8 myFree( void *ptr ) { MEMFreeToAllocator(&DemoAllocator2, ptr); return(1); } static void myPrint( int x, int y, int z, char *fmt, ... ) { va_list vlist; char string[256]; va_start(vlist, fmt); vsprintf(string, fmt, vlist); va_end(vlist); if (SCGetLanguage() == SC_LANG_JAPANESE) { DEMORFPrintf((s16)x, (s16)y, (s16)z, "%s", string); } else { DEMOPrintf((s16)x, (s16)y, (s16)z, "%s", string); } } /*---------------------------------------------------------------------------* Name: printBuffer Description: Stored message to be drawn on screen. Arguments: string: message like printf(). Returns: None. *---------------------------------------------------------------------------*/ static void printBuffer( char *string, ... ) { va_list vlist; memset(&__buffer[__curr_line][0], 0, BUFFER_SIZE_BYTES); va_start(vlist, string); vsprintf((char *)(&__buffer[__curr_line][0]), string, vlist); va_end(vlist); __curr_line = (__curr_line + 1) % BUFFER_SIZE_LINES; } /*---------------------------------------------------------------------------* Name: getDevName Description: Got the device name string. Arguments: type: device type. Returns: Device name string. *---------------------------------------------------------------------------*/ static u8 *getDevName( u32 type ) { u8 *ptr; switch(type) { case WPAD_DEV_CORE: ptr = &str_dev_core[0]; break; case WPAD_DEV_FREESTYLE: ptr = &str_dev_extn[0]; break; case WPAD_DEV_CLASSIC: ptr = &str_dev_cl[0]; break; case WPAD_DEV_MPLS: ptr = &str_dev_mp[0]; break; case WPAD_DEV_MPLS_FREESTYLE: ptr = &str_dev_mpfs[0]; break; case WPAD_DEV_MPLS_CLASSIC: ptr = &str_dev_mpcl[0]; break; case WPAD_DEV_MPLS_FUTURE: ptr = &str_dev_mpft[0]; break; case WPAD_DEV_FUTURE: ptr = &str_dev_future[0]; break; case WPAD_DEV_NOT_SUPPORTED: ptr = &str_dev_notsup[0]; break; case WPAD_DEV_UNKNOWN: default: ptr = &str_dev_unknown[0]; break; } return(ptr); } /*---------------------------------------------------------------------------* Name: getErrName Description: Got the error name string. Arguments: status: error type. Returns: Error name string. *---------------------------------------------------------------------------*/ static u8 *getErrName( s32 status ) { u8 *ptr; switch(status) { case WPAD_ERR_NONE: ptr = &str_status_ok[0]; break; case WPAD_ERR_NO_CONTROLLER: ptr = &str_status_none[0]; break; case WPAD_ERR_BUSY: ptr = &str_status_busy[0]; break; case WPAD_ERR_TRANSFER: ptr = &str_status_xfer[0]; break; case WPAD_ERR_INVALID: ptr = &str_status_inv[0]; break; case WPAD_ERR_CORRUPTED: ptr = &str_status_crpt[0]; break; default: ptr = &str_status_unk[0]; break; } return(ptr); } /*---------------------------------------------------------------------------* Name: getDpdFmt Description: Got the DPD format name string. Arguments: fmt: dpd format type. Returns: DPD format name string. *---------------------------------------------------------------------------*/ static u8 *getDpdFmt(u8 fmt) { u8 *ptr; switch(fmt) { case WPAD_DPD_OFF: ptr = &dpd_fmt_off[0]; break; case WPAD_DPD_STD: ptr = &dpd_fmt_std[0]; break; case WPAD_DPD_EXP: ptr = &dpd_fmt_exp[0]; break; case WPAD_DPD_FULL: ptr = &dpd_fmt_full[0]; break; } return (ptr); } /*---------------------------------------------------------------------------* Name: getFmtString Description: Got the data format name string. Arguments: type: device type. Returns: Data format name string. *---------------------------------------------------------------------------*/ static u8 *getFmtString( u8 fmt ) { u8 *ptr; switch(fmt) { case WPAD_FMT_CORE: ptr = &fmt_core1[0]; break; case WPAD_FMT_CORE_ACC: ptr = &fmt_core2[0]; break; case WPAD_FMT_CORE_ACC_DPD: ptr = &fmt_core3[0]; break; case WPAD_FMT_FREESTYLE: ptr = &fmt_nun1[0]; break; case WPAD_FMT_FREESTYLE_ACC: ptr = &fmt_nun2[0]; break; case WPAD_FMT_FREESTYLE_ACC_DPD: ptr = &fmt_nun3[0]; break; case WPAD_FMT_CLASSIC: ptr = &fmt_clas1[0]; break; case WPAD_FMT_CLASSIC_ACC: ptr = &fmt_clas2[0]; break; case WPAD_FMT_CLASSIC_ACC_DPD: ptr = &fmt_clas3[0]; break; case WPAD_FMT_CORE_ACC_DPD_FULL: ptr = &fmt_full[0]; break; case WPAD_FMT_MPLS: ptr = &fmt_mpls[0]; break; default: ptr = &fmt_core1[0]; break; } return (ptr); } /*---------------------------------------------------------------------------* Name: renderStatus Description: Draw controller status. Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ static void renderStatus( void ) { s16 x = X0_START; s16 y = Y0_START; int i; myPrint(30, 20, 0, "WPAD Demo -- Mplus"); myPrint(x, y, 0, "------------------------------"); y+=FONT_HEIGHT; myPrint(x, y, 0, "Status :"); y+=FONT_HEIGHT; myPrint(x, y, 0, "Type :"); y+=FONT_HEIGHT; myPrint(x, y, 0, "Err :"); y+=FONT_HEIGHT; myPrint(x, y, 0, "Buttons:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "DPD0-xy:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "DPD1-xy:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "ACC-XYZ:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "---------"); y+=FONT_HEIGHT; myPrint(x, y, 0, "YAW :"); y+=FONT_HEIGHT; myPrint(x, y, 0, "ROLL :"); y+=FONT_HEIGHT; myPrint(x, y, 0, "PITCH :"); y+=FONT_HEIGHT; myPrint(x, y, 0, "STATUS :"); y+=FONT_HEIGHT; myPrint(x, y, 0, "---------"); y+=FONT_HEIGHT; myPrint(x, y, 0, "EXT :"); y+=FONT_HEIGHT; myPrint(x, y, 0, " :"); y+=FONT_HEIGHT; myPrint(x, y, 0, " :"); y+=FONT_HEIGHT; myPrint(x, y, 0, " :"); y+=FONT_HEIGHT; myPrint(x, y, 0, "---------"); y+=FONT_HEIGHT; myPrint(x, y, 0, "YAWCL H:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "ROLCL H:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "PITCL H:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "YAWCL L:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "ROLCL L:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "PITCL L:"); y+=FONT_HEIGHT; myPrint(x, y, 0, "DPS :"); y+=FONT_HEIGHT; myPrint(x, y, 0, "---------"); y+=FONT_HEIGHT; for(i=WPAD_CHAN0; ibutton & WPAD_BUTTON_LEFT ) buf1[ 0] = '<'; if( ptr->button & WPAD_BUTTON_UP ) buf1[ 1] = '^'; if( ptr->button & WPAD_BUTTON_DOWN ) buf1[ 2] = 'v'; if( ptr->button & WPAD_BUTTON_RIGHT ) buf1[ 3] = '>'; if( ptr->button & WPAD_BUTTON_A ) buf2[ 0] = 'A'; if( ptr->button & WPAD_BUTTON_B ) buf2[ 1] = 'B'; if( ptr->button & WPAD_BUTTON_1 ) buf2[ 2] = '1'; if( ptr->button & WPAD_BUTTON_2 ) buf2[ 3] = '2'; if( ptr->button & WPAD_BUTTON_MINUS ) buf3[ 0] = '-'; if( ptr->button & WPAD_BUTTON_HOME ) buf3[ 1] = 'H'; if( ptr->button & WPAD_BUTTON_PLUS ) buf3[ 2] = '+'; myPrint(x, y, 0, " %s%s%s", buf1,buf2,buf3); y+= FONT_HEIGHT; myPrint(x, y, 0, " %4d", (s16)(ptr->obj[0].x)); myPrint(x+35, y, 0, " %4d", (s16)(ptr->obj[0].y)); y+= FONT_HEIGHT; myPrint(x, y, 0, " %4d", (s16)(ptr->obj[1].x)); myPrint(x+35, y, 0, " %4d", (s16)(ptr->obj[1].y)); y+= FONT_HEIGHT; myPrint(x, y, 0, " %+3d", (s16)(ptr->accX)); myPrint(x+35, y, 0, " %+3d", (s16)(ptr->accY)); myPrint(x+70, y, 0, " %+3d", (s16)(ptr->accZ)); y+= FONT_HEIGHT; y+=FONT_HEIGHT; } if (type == WPAD_DEV_MPLS || type == WPAD_DEV_MPLS_FREESTYLE || type == WPAD_DEV_MPLS_CLASSIC || type == WPAD_DEV_MPLS_FUTURE) { WPADMPStatus *ptr = (WPADMPStatus*)(&tmp); WPADMpls high; WPADMpls low; f32 dps; WPADGetMplsCalibration(i, &high, &low); // Yaw if (ptr->stat & WPAD_MPLS_STAT_YAWSEL) { dps = (ptr->yaw - low.yaw_zero) / low.yaw_scale * low.degrees ; } else { dps = (ptr->yaw - high.yaw_zero) / high.yaw_scale * high.degrees; } // which src? raw data, dps myPrint(x, y, 0, "[%s] %5d%+8.2f", (ptr->stat & WPAD_MPLS_STAT_YAWSEL) ? "L" : "H", (s16)(ptr->yaw), dps); y+= FONT_HEIGHT; // Roll if (ptr->stat & WPAD_MPLS_STAT_ROLSEL) { dps = (ptr->roll - low.roll_zero) / low.roll_scale * low.degrees ; } else { dps = (ptr->roll - high.roll_zero) / high.roll_scale * high.degrees; } // which src? raw data, dps myPrint(x, y, 0, "[%s] %5d%+8.2f", (ptr->stat & WPAD_MPLS_STAT_ROLSEL) ? "L" : "H", (s16)(ptr->roll), dps); y+= FONT_HEIGHT; // Pitch if (ptr->stat & WPAD_MPLS_STAT_PITSEL) { dps = (ptr->pitch - low.pitch_zero) / low.pitch_scale * low.degrees ; } else { dps = (ptr->pitch - high.pitch_zero) / high.pitch_scale * high.degrees; } // which src? raw data, dps myPrint(x, y, 0, "[%s] %5d%+8.2f", (ptr->stat & WPAD_MPLS_STAT_PITSEL) ? "L" : "H", (s16)(ptr->pitch), dps); y+= FONT_HEIGHT; // MPLS Status myPrint(x, y, 0, " %s %s %s", (ptr->stat & WPAD_MPLS_STAT_ATTACH) ? "A" : "-", // Extra extension is attached or detached? (ptr->stat & WPAD_MPLS_STAT_PLSVLD) ? "M" : "-", // MotionPlus data is valid or corrupted? (ptr->stat & WPAD_MPLS_STAT_EXTVLD) ? "E" : "-"); // Extra extension data is valid or corrupted? y+= FONT_HEIGHT; y+= FONT_HEIGHT; if (ptr->stat & WPAD_MPLS_STAT_ATTACH && ptr->stat & WPAD_MPLS_STAT_EXTVLD) { if (type == WPAD_DEV_MPLS_FREESTYLE) { if ( ptr->button & WPAD_BUTTON_C ) buf4[ 0] = 'C'; if ( ptr->button & WPAD_BUTTON_Z ) buf4[ 1] = 'Z'; myPrint(x, y, 0, " %s", buf4); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->ext.fs.fsStickX)); myPrint(x+35, y, 0, " %d", (s16)(ptr->ext.fs.fsStickY)); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->ext.fs.fsAccX)); myPrint(x+35, y, 0, " %d", (s16)(ptr->ext.fs.fsAccY)); myPrint(x+70, y, 0, " %d", (s16)(ptr->ext.fs.fsAccZ)); y+= FONT_HEIGHT; y += FONT_HEIGHT; } if (type == WPAD_DEV_MPLS_CLASSIC) { if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_LEFT ) buf5[ 0] = '<'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_UP ) buf5[ 1] = '^'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_DOWN ) buf5[ 2] = 'v'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_RIGHT ) buf5[ 3] = '>'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_A ) buf6[ 0] = 'A'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_B ) buf6[ 1] = 'B'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_X ) buf6[ 2] = 'X'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_Y ) buf6[ 3] = 'Y'; if ( ptr->ext.cl.clButton & WPAD_CL_TRIGGER_L ) buf7[ 0] = 'L'; if ( ptr->ext.cl.clButton & WPAD_CL_TRIGGER_R ) buf7[ 1] = 'R'; if ( ptr->ext.cl.clButton & WPAD_CL_TRIGGER_ZL ) buf7[ 2] = 'z'; if ( ptr->ext.cl.clButton & WPAD_CL_TRIGGER_ZR ) buf7[ 3] = 'Z'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_MINUS ) buf8[ 0] = '-'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_HOME ) buf8[ 1] = 'H'; if ( ptr->ext.cl.clButton & WPAD_CL_BUTTON_PLUS ) buf8[ 2] = '+'; myPrint(x, y, 0, " %s%s%s%s", buf5,buf6,buf7,buf8); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->ext.cl.clLStickX)); myPrint(x+35, y, 0, " %d", (s16)(ptr->ext.cl.clLStickY)); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->ext.cl.clRStickX)); myPrint(x+35, y, 0, " %d", (s16)(ptr->ext.cl.clRStickY)); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->ext.cl.clTriggerL)); myPrint(x+35, y, 0, " %d", (s16)(ptr->ext.cl.clTriggerR)); y+= FONT_HEIGHT; } } y = (s16)(Y0_START + FONT_HEIGHT * 19); myPrint(x, y, 0, " %.1f %.1f", high.yaw_zero, high.yaw_scale); y+=FONT_HEIGHT; myPrint(x, y, 0, " %.1f %.1f", high.roll_zero, high.roll_scale); y+=FONT_HEIGHT; myPrint(x, y, 0, " %.1f %.1f", high.pitch_zero, high.pitch_scale); y+=FONT_HEIGHT; myPrint(x, y, 0, " %.1f %.1f", low.yaw_zero, low.yaw_scale); y+=FONT_HEIGHT; myPrint(x, y, 0, " %.1f %.1f", low.roll_zero, low.roll_scale); y+=FONT_HEIGHT; myPrint(x, y, 0, " %.1f %.1f", low.pitch_zero, low.pitch_scale); y+=FONT_HEIGHT; myPrint(x, y, 0, " %d %d", high.degrees, low.degrees); y+=FONT_HEIGHT; } else { y+= FONT_HEIGHT * 5; } if (WPAD_DEV_FREESTYLE == type) { WPADFSStatus *ptr = (WPADFSStatus*)(&tmp); if ( ptr->button & WPAD_BUTTON_C ) buf4[ 0] = 'C'; if ( ptr->button & WPAD_BUTTON_Z ) buf4[ 1] = 'Z'; myPrint(x, y, 0, " %s", buf4); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->fsStickX)); myPrint(x+35, y, 0, " %d", (s16)(ptr->fsStickY)); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->fsAccX)); myPrint(x+35, y, 0, " %d", (s16)(ptr->fsAccY)); myPrint(x+70, y, 0, " %d", (s16)(ptr->fsAccZ)); y+= FONT_HEIGHT; y += FONT_HEIGHT; } if (WPAD_DEV_CLASSIC == type) { WPADCLStatus *ptr = (WPADCLStatus*)(&tmp); if ( ptr->clButton & WPAD_CL_BUTTON_LEFT ) buf5[ 0] = '<'; if ( ptr->clButton & WPAD_CL_BUTTON_UP ) buf5[ 1] = '^'; if ( ptr->clButton & WPAD_CL_BUTTON_DOWN ) buf5[ 2] = 'v'; if ( ptr->clButton & WPAD_CL_BUTTON_RIGHT ) buf5[ 3] = '>'; if ( ptr->clButton & WPAD_CL_BUTTON_A ) buf6[ 0] = 'A'; if ( ptr->clButton & WPAD_CL_BUTTON_B ) buf6[ 1] = 'B'; if ( ptr->clButton & WPAD_CL_BUTTON_X ) buf6[ 2] = 'X'; if ( ptr->clButton & WPAD_CL_BUTTON_Y ) buf6[ 3] = 'Y'; if ( ptr->clButton & WPAD_CL_TRIGGER_L ) buf7[ 0] = 'L'; if ( ptr->clButton & WPAD_CL_TRIGGER_R ) buf7[ 1] = 'R'; if ( ptr->clButton & WPAD_CL_TRIGGER_ZL ) buf7[ 2] = 'z'; if ( ptr->clButton & WPAD_CL_TRIGGER_ZR ) buf7[ 3] = 'Z'; if ( ptr->clButton & WPAD_CL_BUTTON_MINUS ) buf8[ 0] = '-'; if ( ptr->clButton & WPAD_CL_BUTTON_HOME ) buf8[ 1] = 'H'; if ( ptr->clButton & WPAD_CL_BUTTON_PLUS ) buf8[ 2] = '+'; myPrint(x, y, 0, " %s%s%s%s", buf5,buf6,buf7,buf8); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->clLStickX)); myPrint(x+35, y, 0, " %d", (s16)(ptr->clLStickY)); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->clRStickX)); myPrint(x+35, y, 0, " %d", (s16)(ptr->clRStickY)); y+= FONT_HEIGHT; myPrint(x, y, 0, " %d", (s16)(ptr->clTriggerL)); myPrint(x+35, y, 0, " %d", (s16)(ptr->clTriggerR)); y+= FONT_HEIGHT; } } } // print stored messages on screen x = X0_START; y = Y1_START; { u32 line = __curr_line; int i; for (i=0; i> %s", &__buffer[line][0]); line = (line + 1) % BUFFER_SIZE_LINES; y+= FONT_HEIGHT; } } } /*---------------------------------------------------------------------------* Name: renderAimings Description: Draw dots using sampled controller data. Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ static void renderAimings( void ) { WPADStatus *ptr; int i,j; u32 latest = WPADGetLatestIndexInBuf(WPAD_CHAN0); u32 index = ((latest - 1) + SMPBUF_SIZE) % SMPBUF_SIZE; u32 type; for(j=0; jerr || WPAD_ERR_CORRUPTED == ptr->err) { s16 x=(s16)(SCREEN_WIDTH -(ptr->obj[0].x+ptr->obj[1].x)/2*SCREEN_WIDTH /WPAD_DPD_IMG_RESO_WX); s16 y=(s16)(SCREEN_HEIGHT-(ptr->obj[0].y+ptr->obj[1].y)/2*SCREEN_HEIGHT/WPAD_DPD_IMG_RESO_WY); myPrint(x, y, 0, "."); } index = ((index - 1) + SMPBUF_SIZE) % SMPBUF_SIZE; } } } /*---------------------------------------------------------------------------* Name: resetCallback Description: Function to be called when RESET button is pressed. Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ static void resetCallback( void ) { reset = 0; } /*---------------------------------------------------------------------------* Name: initialize Description: Initialized this application. Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ static void initialize( void ) { int i; s32 wpad_state; DEMOInit( &GXNtsc480IntDf ); DEMOPadInit(); DEMOInitROMFont(); DEMOSetROMFontSize(FONT_HEIGHT, FONT_SPACE); GXSetCopyClear( BLACK, GX_MAX_Z24 ); GXCopyDisp( DEMOGetCurrentBuffer(), GX_TRUE ); DEMOInitCaption( DM_FT_XLU, SCREEN_WIDTH, SCREEN_HEIGHT ); GXSetZMode( GX_ENABLE, GX_ALWAYS, GX_ENABLE ); // Set pixel processing mode GXSetBlendMode( GX_BM_BLEND, GX_BL_ONE, GX_BL_ONE, GX_LO_CLEAR ); // Translucent mode memset(__buffer, 0, BUFFER_SIZE_BYTES*BUFFER_SIZE_LINES); WPADRegisterAllocator(myAlloc, myFree); WPADInit(); for (i=0; i