/*---------------------------------------------------------------------------* Project: Dolphin/Revolution gx demo File: smp-toy-stick.c Copyright 1998-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. *---------------------------------------------------------------------------*/ #include #include "toy-stick.h" #define AX_ZERO 0.9F #define AY_ZERO 0.9F #define DIGX_INC 0.05F #define DIGY_INC 0.05F #define DEAD_X 0.03F #define DEAD_Y 0.03F /*---------------------------------------------------------------------------* Global variables *---------------------------------------------------------------------------*/ static f32 AnalogX = 0.0F; static f32 AnalogY = 0.0F; /*---------------------------------------------------------------------------* Name: GetAnalogX Description: returns value of x tilt Arguments: none Returns: f32, x tilt value *---------------------------------------------------------------------------*/ f32 GetAnalogX( void ) { return(AnalogX); } /*---------------------------------------------------------------------------* Name: GetAnalogY Description: returns value of y tilt Arguments: none Returns: f32, y tilt value *---------------------------------------------------------------------------*/ f32 GetAnalogY( void ) { return(AnalogY); } /*---------------------------------------------------------------------------* Name: StickTick Description: computes analog tilt x, y Arguments: none Returns: none *---------------------------------------------------------------------------*/ void StickTick( void ) { static f32 digitalX = 0.0F; static f32 digitalY = 0.0F; DEMOPadRead(); // // tilt table // if (DEMOPadGetStickX(0) > 0) digitalX = DIGX_INC; else if (DEMOPadGetStickX(0) < 0) digitalX = -DIGX_INC; else digitalX = 0.0F; AnalogX += digitalX; AnalogX *= AX_ZERO; if (AnalogX < DEAD_X && AnalogX > -DEAD_X) AnalogX = 0.0F; if (DEMOPadGetStickY(0) > 0) digitalY = DIGY_INC; else if (DEMOPadGetStickY(0) < 0) digitalY = -DIGY_INC; else digitalY = 0.0F; AnalogY += digitalY; AnalogY *= AY_ZERO; if (AnalogY < DEAD_Y && AnalogY > -DEAD_Y) AnalogY = 0.0F; } /*---------------------------------------------------------------------------* Name: StickDone Description: return true when START button pressed Arguments: none Returns: u16 *---------------------------------------------------------------------------*/ u16 StickDone(void) { return((u16)(DEMOPadGetButton(0) & PAD_BUTTON_MENU)); }