1 /*---------------------------------------------------------------------------* 2 Project: KPAD library version 2 3 File: KPADinside.h 4 Programmers: Keizo Ohta 5 HIRATSU Daisuke 6 7 Copyright 2005-2008 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 //----- Definitions for the different calculations 34 #define KPAD_CMOS_FOV WPAD_DPD_ANGLE // CMOS lens angle of view (Field Of View, in degrees) 35 #define KPAD_CMOS_HFOV_TAN 0.383864f // Tangent of half angle 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 �}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 that adjust how the controller responds 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 value 86 f32 dist_org ; // Distance during calibration 87 Vec2 accXY_nrm_hori ; // Direction of XY acceleration 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 �}1 91 92 //----- Variables used for internal control 93 KPADObject kobj_sample[ WPAD_DPD_MAX_OBJECTS ] ; // All captured marks will be covered 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 KPADUnifiedWpadStatus *uniRingBufEx ; // Pointer to additional ring buffer 102 u32 uniRingBufExLen ; // Length of additional ring buffer 103 104 f32 sec_length ; // Distance between left and right marks 105 Vec2 sec_nrm ; // Direction from the left to right mark 106 f32 sec_dist ; // Raw distance from the TV (meter) 107 f32 trust_sec_length ; // Trusted interval distance stored here 108 109 Vec hard_acc ; // Raw acceleration 110 111 Vec2 obj_horizon ; // Tilt calculated with the object 112 Vec2 acc_horizon ; // Tilt calculated with the acceleration (either side) 113 114 Vec2 ah_circle_pos ; // Point chasing the acc_horizon 115 u16 ah_circle_ct ; // Countdown if in a certain range (stopped if zero) 116 117 u8 dpd_valid2_ct ; // Number of successful consecutive two point recognitions 118 u8 readLocked ; // The KPADRead function is in progress 119 120 //----- Button control 121 u16 btn_repeat_time ; // Time to be counted 122 u16 btn_repeat_next ; // Time of setting next flag 123 u16 btn_repeat_delay ; // Repeat start time 124 u16 btn_repeat_pulse ; // Repeat interval time 125 //----- For Classic Controller unit 126 u16 btn_cl_repeat_time ; // Time to be counted 127 u16 btn_cl_repeat_next ; // Time of setting next flag 128 129 KPADControlDpdCallback dpd_ctrl_callback ; // User callback when DPD setting change becomes necessary 130 131 f32 acc_scale_x ; 132 f32 acc_scale_y ; 133 f32 acc_scale_z ; 134 f32 fs_acc_scale_x ; 135 f32 fs_acc_scale_y ; 136 f32 fs_acc_scale_z ; 137 138 Vec2 kobj_frame_min; // Range where the center of mass coordinate is valid 139 Vec2 kobj_frame_max; // 140 f32 err_dist_speed_1 ; // Reciprocal 141 f32 err_dist_speedM_1 ; // Reciprocal of negative value 142 f32 ah_circle_radius2 ; // Second power 143 f32 dist_vv1 ; // Constants 144 f32 err_dist_min ; // Automatic calculation of minimum operational distance (in meters) 145 146 WPADSamplingCallback appSamplingCallback ; // For application 147 WPADConnectCallback appConnectCallback ; // For application 148 149 u8 resetReq ; 150 u8 exResetReq ; 151 u8 dpdNextState ; 152 u8 dpdCurrState ; 153 154 u8 dpdIssued ; 155 u8 dpdCmd ; 156 u8 dpdPreCallbackDone ; 157 u8 dpdPostCallbackDone ; 158 159 u8 aimReq ; 160 u8 aimEnabled ; 161 162 u8 fsAccRevise ; 163 u8 btnProcMode ; 164 165 KPADPlayMode pos_play_mode ; 166 KPADPlayMode hori_play_mode ; 167 KPADPlayMode dist_play_mode ; 168 KPADPlayMode acc_play_mode ; 169 170 } KPADInsideStatus; 171 172 173 /******************************************************************************* 174 EXTERNAL WORK 175 *******************************************************************************/ 176 //----- Various adjustments 177 extern f32 kp_obj_interval ; // Separation between marks at each extreme (in meters) 178 extern f32 kp_acc_horizon_pw ; // Calculating twist from acceleration 179 extern f32 kp_ah_circle_radius ; // Static determination radius 180 extern f32 kp_ah_circle_pw ; // Static determination tracking level 181 extern u16 kp_ah_circle_ct ; // Static determination count 182 extern BOOL kp_stick_clamp_cross ; // Perform cross-clamping 183 184 185 //----- Numerical values regarded as errors 186 extern f32 kp_err_outside_frame ; // Width of surrounding area where center of mass coordinate is invalid (not all surrounding lights are necessarily shown) 187 extern f32 kp_err_dist_min ; // Minimum operational distance (in meters) 188 extern f32 kp_err_dist_max ; // Maximum operational distance (in meters) 189 extern f32 kp_err_dist_speed ; // Acceptable range of change in distance (in meters) 190 extern f32 kp_err_first_inpr ; // Dot product of acceleration tilt and object tilt when selecting two points for the first time 191 extern f32 kp_err_next_inpr ; // Acceptable range of change in tilt (internal product value) 192 extern f32 kp_err_acc_inpr ; // Acceptable range for internal product with static acceleration tilt 193 extern f32 kp_err_up_inpr ; // Acceptable range for internal product with controller pointed upwards 194 extern f32 kp_err_near_pos ; // Distance from the previous point when selecting one point as a continuation 195 196 //----- KPAD 197 extern KPADInsideStatus inside_kpads[] ; 198 199 200 /******************************************************************************* 201 EXTERNAL FUNCTIONS 202 *******************************************************************************/ 203 204 205 #ifdef __cplusplus 206 } 207 #endif 208 209 #endif // KPAD_INSIDE_H__ 210