1 /*---------------------------------------------------------------------------* 2 Project: Dolphin/Revolution gx demo 3 File: smp-toy-stick.c 4 5 Copyright 1998-2006 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 *---------------------------------------------------------------------------*/ 13 14 #include <demo.h> 15 #include "toy-stick.h" 16 17 #define AX_ZERO 0.9F 18 #define AY_ZERO 0.9F 19 #define DIGX_INC 0.05F 20 #define DIGY_INC 0.05F 21 #define DEAD_X 0.03F 22 #define DEAD_Y 0.03F 23 24 /*---------------------------------------------------------------------------* 25 Global variables 26 *---------------------------------------------------------------------------*/ 27 static f32 AnalogX = 0.0F; 28 static f32 AnalogY = 0.0F; 29 30 /*---------------------------------------------------------------------------* 31 Name: GetAnalogX 32 33 Description: returns value of x tilt 34 35 Arguments: none 36 37 Returns: f32, x tilt value 38 *---------------------------------------------------------------------------*/ GetAnalogX(void)39f32 GetAnalogX( void ) 40 { 41 return(AnalogX); 42 } 43 44 /*---------------------------------------------------------------------------* 45 Name: GetAnalogY 46 47 Description: returns value of y tilt 48 49 Arguments: none 50 51 Returns: f32, y tilt value 52 *---------------------------------------------------------------------------*/ GetAnalogY(void)53f32 GetAnalogY( void ) 54 { 55 return(AnalogY); 56 } 57 58 /*---------------------------------------------------------------------------* 59 Name: StickTick 60 61 Description: computes analog tilt x, y 62 63 Arguments: none 64 65 Returns: none 66 *---------------------------------------------------------------------------*/ 67 StickTick(void)68void StickTick( void ) 69 { 70 static f32 digitalX = 0.0F; 71 static f32 digitalY = 0.0F; 72 73 DEMOPadRead(); 74 75 // 76 // tilt table 77 // 78 if (DEMOPadGetStickX(0) > 0) 79 digitalX = DIGX_INC; 80 else if (DEMOPadGetStickX(0) < 0) 81 digitalX = -DIGX_INC; 82 else 83 digitalX = 0.0F; 84 85 AnalogX += digitalX; 86 AnalogX *= AX_ZERO; 87 if (AnalogX < DEAD_X && AnalogX > -DEAD_X) 88 AnalogX = 0.0F; 89 90 if (DEMOPadGetStickY(0) > 0) 91 digitalY = DIGY_INC; 92 else if (DEMOPadGetStickY(0) < 0) 93 digitalY = -DIGY_INC; 94 else 95 digitalY = 0.0F; 96 97 AnalogY += digitalY; 98 AnalogY *= AY_ZERO; 99 if (AnalogY < DEAD_Y && AnalogY > -DEAD_Y) 100 AnalogY = 0.0F; 101 } 102 103 /*---------------------------------------------------------------------------* 104 Name: StickDone 105 106 Description: return true when START button pressed 107 108 Arguments: none 109 110 Returns: u16 111 *---------------------------------------------------------------------------*/ StickDone(void)112u16 StickDone(void) 113 { 114 return((u16)(DEMOPadGetButton(0) & PAD_BUTTON_MENU)); 115 } 116 117