1 /*---------------------------------------------------------------------------* 2 Project: KPAD library 3 File: KPADinside.h 4 Programmers: Keizo Ohta 5 HIRATSU Daisuke 6 7 Copyright 2005 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 KPAD_INSIDE_H__ 17 #error KPADinside.h of KPADOld cannot be used with that of KPAD version 2 18 #endif 19 20 #ifndef KPADOLD_INSIDE_H__ 21 #define KPADOLD_INSIDE_H__ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #include <revolution/wpad.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 /******************************************************************************* 54 TYPEDEF 55 *******************************************************************************/ 56 typedef struct { 57 Vec2 center ; // Center of mass coordinate (coordinate system where the horizontal range of CMOS will be + or - 1) 58 59 s8 error_fg ; // -1: not displayed, 0: OK, 1: too far out, 2: same coordinate 60 s8 state_fg ; // -1: expected value, 0: normal 61 s8 _fg_1 ; // Extra 62 s8 _fg_2 ; // Extra 63 } KPADObject ; 64 65 66 typedef struct { 67 KPADStatus status ; 68 69 //----- Variables adjusting the controller response 70 f32 pos_play_radius ; // Tolerance radius (size at pos coordinate system) 71 f32 pos_sensitivity ; // Tracking sensitivity (0: slow -> 1: sensitive) 72 73 f32 hori_play_radius ; // Adjust response of 'horizon' 74 f32 hori_sensitivity ; // 75 76 f32 dist_play_radius ; // Adjust response of 'dist' 77 f32 dist_sensitivity ; // 78 79 f32 acc_play_radius ; // Adjust the response of 'acc' 80 f32 acc_sensitivity ; // 81 82 //----- DPD calibration values 83 f32 dist_org ; // Distance at calibration 84 Vec2 accXY_nrm_hori ; // XY acceleration direction when the controller is placed horizontally 85 Vec2 sec_nrm_hori ; // Direction from left mark to right mark when the controller is placed horizontally 86 Vec2 center_org ; // Coordinate during calibration 87 f32 dpd2pos_scale ; // Scale value where the left and right pointing edge in the shooting range will be + or - 1 88 89 //----- Variables used for internal control 90 KPADObject kobj_sample[ WPAD_DPD_MAX_OBJECTS ] ; // All captured marks will be placed 91 KPADObject kobj_regular[ KPAD_USE_OBJECTS ] ; // Left to right order (top to bottom order for straight vertical) 92 93 s16 valid_objs ; // Valid object count 94 u16 work_ct ; // Number of DPD processes in a single game frame 95 96 s16 wpad_chan_no ; // IO channel number 97 s16 wpad_ring_idx ; // Processed ring buffer 98 WPADCLStatus wpad_ring_bf[ KPAD_RING_BUFS ] ;// Buffer storing the SDK variable 99 100 f32 sec_length ; // Distance between left and right mark 101 Vec2 sec_nrm ; // Direction from the left to right mark 102 f32 sec_dist ; // Raw distance from the TV (meter) 103 f32 trust_sec_length ; // Trusted interval distance stored here 104 105 Vec hard_acc ; // Raw acceleration 106 107 Vec2 obj_horizon ; // Tilt calculated by the object 108 Vec2 acc_horizon ; // Tilt calculated by the acceleration (either side) 109 110 Vec2 ah_circle_pos ; // Point chasing the acc_horizon 111 u16 ah_circle_ct ; // Countdown if in a certain range (stopped if zero) 112 113 u8 dpd_valid2_ct ; // Number of successful consecutive two point recognitions 114 s8 _fg_4 ; // Extra 115 116 //----- Button controls 117 u16 btn_repeat_time ; // Time for counting 118 u16 btn_repeat_next ; // Time of setting next flag 119 u16 btn_repeat_delay ; // Repeat start time 120 u16 btn_repeat_pulse ; // Repeat interval time 121 //----- For Classic Controller unit 122 u16 btn_cl_repeat_time ; // Time for counting 123 u16 btn_cl_repeat_next ; // Time of setting next flag 124 u16 btn_cl_repeat_delay ; // Repeat start time 125 u16 btn_cl_repeat_pulse ; // Repeat interval time 126 127 BOOL dpd_set_enabled; // Whether DPD module should be turned on or off (TRUE indicates ON) 128 BOOL dpd_request_flag ; // Flag indicating whether the DPD module settings change has been issued 129 BOOL dpd_ctrl_busy; // Flag indicating whether DPD module is busy 130 KPADControlDpdCallback dpd_ctrl_callback; // User callback when DPD setting change becomes necessary 131 132 BOOL dpd_ctrl_retry_flag; // DPD type and data format configuration retry request flag 133 134 } KPADInsideStatus ; 135 136 137 /******************************************************************************* 138 EXTERNAL WORK 139 *******************************************************************************/ 140 //----- Various adjustments 141 extern f32 kp_obj_interval ; // Separation between marks at each extremes (in meters) 142 extern f32 kp_acc_horizon_pw ; // Calculating twist from acceleration 143 extern f32 kp_ah_circle_radius ; // Stationary state determination radius 144 extern f32 kp_ah_circle_pw ; // Stationary state determination tracking level 145 extern u16 kp_ah_circle_ct ; // Stationary state determination count 146 147 //----- Values determined to be an error. 148 extern f32 kp_err_outside_frame ; // Surrounding area width where center of mass coordinate will be invalid (not all surrounding lights are necessarily shown) 149 extern f32 kp_err_dist_min ; // Minimum operational distance (in meters) 150 extern f32 kp_err_dist_max ; // Maximum operational distance (in meters) 151 extern f32 kp_err_dist_speed ; // Accepted range of distance change (in meters) 152 extern f32 kp_err_first_inpr ; // Internal product of acceleration tilt and object tilt when selecting two points for the first time 153 extern f32 kp_err_next_inpr ; // Accepted range of tilt change (internal product value) 154 extern f32 kp_err_acc_inpr ; // Accepted range of acceleration tilt and internal product value at stationary state 155 extern f32 kp_err_up_inpr ; // Accepted internal product range with controller pointed upwards 156 extern f32 kp_err_near_pos ; // Distance from the previous point when selecting one point as a continuation 157 158 //----- KPAD 159 extern KPADInsideStatus inside_kpads[] ; 160 161 162 /******************************************************************************* 163 EXTERNAL FUNCTION 164 *******************************************************************************/ 165 166 167 #ifdef __cplusplus 168 } 169 #endif 170 171 #endif // KPADOLD_INSIDE_H__ 172