/*---------------------------------------------------------------------------* Project: Dimming & Stopping Motor of DVD drive DEMO File: dimming.c Copyright (C)2006 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. $Log: dimming.c,v $ Revision 1.10 2007/07/17 06:32:28 urata Added VIResetDimmingCount. Revision 1.9 2006/11/29 00:00:54 urata Removed VIResetDimmingCount Revision 1.8 2006/11/28 06:02:04 urata Added VIResetDimmingCount. Revision 1.7 2006/10/26 07:15:36 urata Removed VI[Set/Get]ScreenSaverMode. Revision 1.6 2006/10/26 02:06:30 urata Fixed. Revision 1.5 2006/10/26 01:57:52 urata Added VI[Set/Get]ScreenSaverMode. Revision 1.4 2006/10/26 00:15:26 urata Added WPAD. Revision 1.3 2006/10/25 05:48:12 urata Added VISetTimeToDimming and removed VIEnableDimming, WPAD. Revision 1.2 2006/09/14 06:10:03 urata Added WPAD. Revision 1.1 2006/09/06 14:08:43 urata Initial checkin. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #define DEMO_USE_MEMLIB=1 // This turns on the DEMO library's MEM heaps. #include #define WAIT_TO_ISSUE_VISetTimeToDimming 500 //500 field #define WAIT_TO_ISSUE_VIResetDimmingCount 500 //500 field /*---------------------------------------------------------------------------* * Name : myAlloc() * Description : Callback needed by WPAD to allocate mem from MEM2 heap * Arguments : size of block, in bytes. * Returns : pointer to allocated block. *---------------------------------------------------------------------------*/ static void *myAlloc(u32 size) { void *ptr; ptr = MEMAllocFromAllocator(&DemoAllocator2, size); ASSERTMSG(ptr, "Memory allocation failed\n"); return(ptr); } /*---------------------------------------------------------------------------* * Name : myFree() * Description : Callback needed by WPAD to free mem from MEM2 heap * Arguments : None. * Returns : Always 1. *---------------------------------------------------------------------------*/ static u8 myFree(void *ptr) { MEMFreeToAllocator(&DemoAllocator2, ptr); // we should ensure that memory is free'd properly, but oh well return(1); } /*---------------------------------------------------------------------------* Name: FontInit Description: Arguments: none Returns: none *---------------------------------------------------------------------------*/ static void FontInit( void ) { GXColor Blue = {0x0,0x0,0x80,0xff}; //R,G,B,A if (DEMOInitROMFont() == 0) { OSHalt("FONT ERROR\n"); // NOT REACHED HERE } // Clear EFB GXSetCopyClear(Blue, 0x00ffffff); GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE); } /*---------------------------------------------------------------------------* Name: main Description: Arguments: none Returns: none *---------------------------------------------------------------------------*/ void main ( void ) { GXRenderModeObj *rmp; s32 wait,wait_for_reset; s16 tx,ty,fh; VITimeToDIM old_time; VITimeToDIM new_time; WPADStatus wpad; u16 oldbtn; u32 type; s32 wpad_state; DEMOInit(NULL); FontInit(); rmp = DEMOGetRenderModeObj(); // we should clear the WPADStatus block returned by // WPADRead(), because if no channel is connected, nothing // is copied. So we would be staring at garbage data. memset( (void *)(&wpad), 0, sizeof(WPADStatus)); // - We must now register memory allocation/free functions // for MEM2. // - WPAD requires some memory in MEM2 for data transfers // between the controller and WPAD driver stack. // - Memory allocation only occurs once, at the initialization. // - Memory usage is on the order of 1KB. // - NOTE: We are using the MEM library allocators defined by // the DEMO library. // WPADRegisterAllocator(myAlloc, myFree); // Initialize WPAD! WPADInit(); // The WPAD initialization process is asynchronous. // So we should wait until it's completed. // The WPAD initialization process is asynchronous. // So we should wait until it's completed. do { wpad_state = WPADGetStatus(); } while (WPAD_STATE_SETUP != wpad_state); new_time = VI_DM_DEFAULT; wait = WAIT_TO_ISSUE_VISetTimeToDimming; wait_for_reset = WAIT_TO_ISSUE_VIResetDimmingCount; while(1) { tx = 50; ty = 50; DEMOBeforeRender(); fh = 25; DEMOSetROMFontSize(fh, -1); DEMOInitCaption(DM_FT_XLU, (s16)rmp->fbWidth, (s16) rmp->efbHeight); DEMORFPrintf(tx, ty+=fh, 0, "Dimming test"); fh = 18; DEMOSetROMFontSize(fh, -1); ty+=fh; DEMORFPrintf(tx, ty+=fh, 0, "Count to dimming = %8u",VIGetDimmingCount()); DEMORFPrintf(tx, ty+=fh, 0, "Limit time to dimming = %s",old_time == VI_DM_10M ? "10 minutes" : old_time == VI_DM_15M ? "15 minutes" : " 5 minutes"); DEMORFPrintf(tx, ty+=fh, 0, "Wait time to issue VISetTimeToDimming = %3d[field]", wait < 0 ? 0 : wait); DEMORFPrintf(tx, ty+=fh, 0, "Wait time to issue VIResetDimmingCount = %3d[field]", wait_for_reset < 0 ? 0 : wait_for_reset); ty+=fh; ty+=fh; ty+=fh; DEMORFPrintf(tx, ty+=fh, 0, "A button to change the limit time to 5 minutes."); DEMORFPrintf(tx, ty+=fh, 0, "- button to change the limit time to 10 minutes."); DEMORFPrintf(tx, ty+=fh, 0, "+ button to change the limit time to 15 minutes."); DEMORFPrintf(tx, ty+=fh, 0, "B button to set the wait time to issue VISetTimeToDimming."); DEMORFPrintf(tx, ty+=fh, 0, "1 button to issue VIResetDimmingCount after %d field.",WAIT_TO_ISSUE_VIResetDimmingCount); DEMODoneRender(); // We should probe the channel first // is a controller connected? if(WPAD_ERR_NONE == WPADProbe(WPAD_CHAN0, &type)) { // Read data/status from channel 0. WPADRead( WPAD_CHAN0, &wpad ); } // if no error... DEMOPadRead(); if (( DEMOPadGetButtonDown(0) & PAD_BUTTON_A ) || ( (wpad.button & WPAD_BUTTON_A) && !oldbtn )) { new_time = VI_DM_DEFAULT; } if (( DEMOPadGetButtonDown(0) & PAD_BUTTON_X ) || ( (wpad.button & WPAD_BUTTON_MINUS) && !oldbtn )) { new_time = VI_DM_10M; } if (( DEMOPadGetButtonDown(0) & PAD_BUTTON_Y ) || ( (wpad.button & WPAD_BUTTON_PLUS) && !oldbtn )) { new_time = VI_DM_15M; } if (( DEMOPadGetButtonDown(0) & PAD_BUTTON_B ) || ( (wpad.button & WPAD_BUTTON_B) && !oldbtn )) { wait = WAIT_TO_ISSUE_VISetTimeToDimming; } if (( DEMOPadGetButtonDown(0) & PAD_TRIGGER_R ) || ( (wpad.button & WPAD_BUTTON_1) && !oldbtn )) { wait_for_reset = WAIT_TO_ISSUE_VIResetDimmingCount; } if(--wait < 0) { old_time = VISetTimeToDimming( new_time ); // VISetTimeToDimming works here without calling VIFlush. } if(wait_for_reset > 0) { wait_for_reset--; if(wait_for_reset == 0) { VIResetDimmingCount(); // VIResetDimmingCount works here without calling VIFlush. } } oldbtn = wpad.button; } }