1 /*---------------------------------------------------------------------------* 2 Project: KPAD library version 2 3 File: KPADinside.h 4 Programmers: Keizo Ohta 5 HIRATSU Daisuke 6 7 Copyright 2005-2006 Nintendo. All rights reserved. 8 9 These coded instructions, statements, and computer programs contain 10 proprietary information of Nintendo of America Inc. and/or Nintendo 11 Company Ltd., and are protected by Federal copyright law. They may 12 not be disclosed to third parties or copied or duplicated in any form, 13 in whole or in part, without the prior written consent of Nintendo. 14 *---------------------------------------------------------------------------*/ 15 16 #ifdef KPADOLD_INSIDE_H__ 17 #error KPADinside.h of KPAD version 2 cannot be used with that of KPADOld 18 #endif 19 20 #ifndef KPAD_INSIDE_H__ 21 #define KPAD_INSIDE_H__ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #include <revolution/kpad.h> 28 29 30 /******************************************************************************* 31 DEFINE 32 *******************************************************************************/ 33 //----- Various calculation constants 34 #define KPAD_CMOS_FOV WPAD_DPD_ANGLE // CMOS lens angle of view (in degrees) (Field Of View) 35 #define KPAD_CMOS_HFOV_TAN 0.383864f // Tangent of half angle (Half) of CMOS_FOV 36 37 #define KPAD_CMOS_RESO_WX 128 // CMOS resolution 38 #define KPAD_CMOS_RESO_WY 96 39 #define KPAD_CMOS_RESO_CX (KPAD_CMOS_RESO_WX / 2) 40 #define KPAD_CMOS_RESO_CY (KPAD_CMOS_RESO_WY / 2) 41 42 #define KPAD_DPD_RESO_WX WPAD_DPD_IMG_RESO_WX // DPD resolution 43 #define KPAD_DPD_RESO_WY WPAD_DPD_IMG_RESO_WY 44 #define KPAD_DPD_RESO_CX (KPAD_DPD_RESO_WX / 2) 45 #define KPAD_DPD_RESO_CY (KPAD_DPD_RESO_WY / 2) 46 47 #define KPAD_USE_OBJECTS 2 // Number of marks used for determining position 48 49 #define KPAD_BTN_RPT_TIME_MAX 20000 // btn_repeat_time range (will not be this value) 50 #define KPAD_BTN_NO_RPT_DELAY 40000 // Delay setting when not repeating 51 52 /******************************************************************************* 53 TYPEDEF 54 *******************************************************************************/ 55 typedef struct { 56 Vec2 center ; // Center of mass coordinate (coordinate system where the horizontal range of CMOS will be + or - 1) 57 58 s8 error_fg ; // -1: not displayed, 0: OK, 1: too far out, 2: same coordinate 59 s8 state_fg ; // -1: expected value, 0: normal 60 s8 _fg_1 ; // Extra 61 s8 _fg_2 ; // Extra 62 } KPADObject ; 63 64 typedef union { 65 KPADStatus k; 66 KPADUnifiedWpadStatus w; 67 } KPADTmpStatus; 68 69 typedef struct { 70 KPADStatus status ; 71 72 //----- Variables adjusting the controller response 73 f32 pos_play_radius ; // Tolerance radius (size at pos coordinate system) 74 f32 pos_sensitivity ; // Tracking sensitivity (0: slow -> 1: sensitive) 75 76 f32 hori_play_radius ; // Adjust response of 'horizon' 77 f32 hori_sensitivity ; // 78 79 f32 dist_play_radius ; // Adjust response of 'dist' 80 f32 dist_sensitivity ; // 81 82 f32 acc_play_radius ; // Adjust the response of 'acc' 83 f32 acc_sensitivity ; // 84 85 //----- DPD calibration values 86 f32 dist_org ; // Distance at calibration 87 Vec2 accXY_nrm_hori ; // XY acceleration direction when the controller is placed horizontally 88 Vec2 sec_nrm_hori ; // Direction from left mark to right mark when the controller is placed horizontally 89 Vec2 center_org ; // Coordinate during calibration 90 f32 dpd2pos_scale ; // Scale value where the left and right pointing edge in the shooting range will be + or - 1 91 92 //----- Variables used for internal control 93 KPADObject kobj_sample[ WPAD_DPD_MAX_OBJECTS ] ; // All captured marks will be placed 94 KPADObject kobj_regular[ KPAD_USE_OBJECTS ] ; // Left to right order (top to bottom order for straight vertical) 95 96 s16 valid_objs ; // Valid object count 97 u8 bufIdx ; 98 u8 bufCount ; 99 100 KPADUnifiedWpadStatus uniRingBuf[KPAD_RING_BUFS] ; 101 102 f32 sec_length ; // Distance between left and right mark 103 Vec2 sec_nrm ; // Direction from the left to right mark 104 f32 sec_dist ; // Raw distance from the TV (meter) 105 f32 trust_sec_length ; // Trusted interval distance stored here 106 107 Vec hard_acc ; // Raw acceleration 108 109 Vec2 obj_horizon ; // Tilt calculated by the object 110 Vec2 acc_horizon ; // Tilt calculated by the acceleration (either side) 111 112 Vec2 ah_circle_pos ; // Point chasing the acc_horizon 113 u16 ah_circle_ct ; // Countdown if in a certain range (stopped if zero) 114 115 u8 dpd_valid2_ct ; // Number of successful consecutive two point recognitions 116 s8 _fg_4 ; // Extra 117 118 //----- Button controls 119 u16 btn_repeat_time ; // Time for counting 120 u16 btn_repeat_next ; // Time of setting next flag 121 u16 btn_repeat_delay ; // Repeat start time 122 u16 btn_repeat_pulse ; // Repeat interval time 123 //----- For Classic Controller unit 124 u16 btn_cl_repeat_time ; // Time for counting 125 u16 btn_cl_repeat_next ; // Time of setting next flag 126 127 KPADControlDpdCallback dpd_ctrl_callback ; // User callback when DPD setting change becomes necessary 128 129 f32 acc_scale_x ; 130 f32 acc_scale_y ; 131 f32 acc_scale_z ; 132 f32 fs_acc_scale_x ; 133 f32 fs_acc_scale_y ; 134 f32 fs_acc_scale_z ; 135 136 Vec2 kobj_frame_min; // Range where the center of mass coordinate is valid 137 Vec2 kobj_frame_max; // 138 f32 err_dist_speed_1 ; // Inverse 139 f32 err_dist_speedM_1 ; // Inverse of negative value 140 f32 ah_circle_radius2 ; // Second power 141 f32 dist_vv1 ; // Constant 142 f32 err_dist_min ; // Minimum operational distance automatic calculation (in meters) 143 144 WPADSamplingCallback appSamplingCallback ; // For application 145 146 u8 readLocked ; // KPADRead() is in progress 147 u8 resetReq ; 148 u8 exResetReq ; 149 u8 dpdIssued ; 150 151 u8 dpdEnabled ; 152 u8 dpdCmd ; 153 u8 dpdPreCallbackDone ; 154 u8 dpdPostCallbackDone ; 155 156 u8 aimReq ; 157 u8 aimEnabled ; 158 159 u8 fsAccRevise ; 160 u8 padding ; 161 162 KPADPlayMode pos_play_mode ; 163 KPADPlayMode hori_play_mode ; 164 KPADPlayMode dist_play_mode ; 165 KPADPlayMode acc_play_mode ; 166 167 } KPADInsideStatus; 168 169 170 /******************************************************************************* 171 EXTERNAL WORK 172 *******************************************************************************/ 173 //----- Various adjustments 174 extern f32 kp_obj_interval ; // Separation between marks at each extremes (in meters) 175 extern f32 kp_acc_horizon_pw ; // Calculating twist from acceleration 176 extern f32 kp_ah_circle_radius ; // Stationary state determination radius 177 extern f32 kp_ah_circle_pw ; // Stationary state determination tracking level 178 extern u16 kp_ah_circle_ct ; // Stationary state determination count 179 extern BOOL kp_stick_clamp_cross ; // Perform cross clamping 180 181 182 //----- Values determined to be an error. 183 extern f32 kp_err_outside_frame ; // Surrounding area width where center of mass coordinate will be invalid (not all surrounding lights are necessarily shown) 184 extern f32 kp_err_dist_min ; // Minimum operational distance (in meters) 185 extern f32 kp_err_dist_max ; // Maximum operational distance (in meters) 186 extern f32 kp_err_dist_speed ; // Accepted range of distance change (in meters) 187 extern f32 kp_err_first_inpr ; // Internal product of acceleration tilt and object tilt when selecting two points for the first time 188 extern f32 kp_err_next_inpr ; // Accepted range of tilt change (internal product value) 189 extern f32 kp_err_acc_inpr ; // Accepted range of acceleration tilt and internal product value at stationary state 190 extern f32 kp_err_up_inpr ; // Accepted internal product range with controller pointed upwards 191 extern f32 kp_err_near_pos ; // Distance from the previous point when selecting one point as a continuation 192 193 //----- KPAD 194 extern KPADInsideStatus inside_kpads[] ; 195 196 197 /******************************************************************************* 198 EXTERNAL FUNCTION 199 *******************************************************************************/ 200 201 202 #ifdef __cplusplus 203 } 204 #endif 205 206 #endif // KPAD_INSIDE_H__ 207