/*---------------------------------------------------------------------------* Project: Clamp demo File: clamp2.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: clamp2.c,v $ Revision 1.3 2006/10/24 12:36:12 yasuh-to Added error handling. Revision 1.2 2006/09/06 16:10:53 yasuh-to Fixed the following bug. "This program supports controller hot-swap only for the controller ports where a controller was connected to when booted." Revision 1.1 2006/09/06 14:33:05 yasuh-to Clamp2 demo. Clamp2 uses new paramaters these are more widly than GC's. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include PADStatus Pads[PAD_MAX_CONTROLLERS]; static void PrintPads(void) { int chan; OSReport("Port AB XY S ZLR +Pad Left Right Trigger\n"); // 1[-2] AB XY S ZLR <>^v (1234, 1234) (1234, 1234) (123, 123) for (chan = 0; chan < PAD_MAX_CONTROLLERS; ++chan) { OSReport("%d[%-2d] %c%c %c%c %c %c%c%c %c%c%c%c (%4d, %4d) (%4d, %4d) (%3d, %3d)\n", chan, Pads[chan].err, (Pads[chan].button & PAD_BUTTON_A) ? 'O' : '_', (Pads[chan].button & PAD_BUTTON_B) ? 'O' : '_', (Pads[chan].button & PAD_BUTTON_X) ? 'O' : '_', (Pads[chan].button & PAD_BUTTON_Y) ? 'O' : '_', (Pads[chan].button & PAD_BUTTON_START) ? 'O' : '_', (Pads[chan].button & PAD_TRIGGER_Z) ? 'O' : '_', (Pads[chan].button & PAD_TRIGGER_L) ? 'O' : '_', (Pads[chan].button & PAD_TRIGGER_R) ? 'O' : '_', (Pads[chan].button & PAD_BUTTON_LEFT) ? '<' : '_', (Pads[chan].button & PAD_BUTTON_RIGHT) ? '>' : '_', (Pads[chan].button & PAD_BUTTON_UP) ? '^' : '_', (Pads[chan].button & PAD_BUTTON_DOWN) ? 'v' : '_', Pads[chan].stickX, Pads[chan].stickY, Pads[chan].substickX, Pads[chan].substickY, Pads[chan].triggerLeft, Pads[chan].triggerRight); } } void main(void) { u32 padBit; u32 resetBits; u32 connectedBits; int chan; static BOOL s_clampTypeSwitch=FALSE; VIInit(); PADInit(); OSReport("\033c"); // Resets the terminal connectedBits = 0x0; for (;;) { PADRead(Pads); resetBits = 0x0; for (chan = 0; chan < PAD_MAX_CONTROLLERS; ++chan) { padBit = PAD_CHAN0_BIT >> chan; switch (Pads[chan].err) { case PAD_ERR_NONE: if ( Pads[chan].button & PAD_BUTTON_START) { s_clampTypeSwitch = !s_clampTypeSwitch; } case PAD_ERR_TRANSFER: connectedBits |= padBit; break; case PAD_ERR_NO_CONTROLLER: connectedBits &= ~padBit; resetBits |= padBit; break; case PAD_ERR_NOT_READY: default: break; } } if (connectedBits) { resetBits &= ~connectedBits; } if (resetBits) { PADReset(resetBits); } OSReport("\033[H"); // Home if (connectedBits) { PADStatus org[PAD_MAX_CONTROLLERS]; OSReport("Attached Controllers: 0x%1x.\n", connectedBits); PrintPads(); memcpy(org, Pads, sizeof org); if (!s_clampTypeSwitch) { PADClamp2(Pads, PAD_STICK_CLAMP_OCTA_WITH_MARGIN); PADClampTrigger(Pads, PAD_TRIGGER_FIXED_BASE); OSReport("\nClamped WITH_MARGIN \n"); } else { PADClamp2(Pads, PAD_STICK_CLAMP_OCTA_WITHOUT_MARGIN); PADClampTrigger(Pads, PAD_TRIGGER_INDIVIDUAL_BASE); OSReport("\nClamped WITHOUT_MARGIN\n"); } PrintPads(); memcpy(Pads, org, sizeof org); if (!s_clampTypeSwitch) { PADClampCircle2(Pads, PAD_STICK_CLAMP_CIRCLE_WITH_MARGIN); PADClampTrigger(Pads, PAD_TRIGGER_FIXED_BASE); OSReport("\nClamped (circle) WITH_MARGIN \n"); } else { PADClampCircle2(Pads, PAD_STICK_CLAMP_CIRCLE_WITHOUT_MARGIN); PADClampTrigger(Pads, PAD_TRIGGER_INDIVIDUAL_BASE); OSReport("\nClamped (circle) WITHOUT_MARGIN\n"); } PrintPads(); } else { OSReport("Please connect controllers\n"); } VIWaitForRetrace(); } }