/*---------------------------------------------------------------------------* Project: KPAD library version 2 File: KPADinside.h Programmers: Keizo Ohta HIRATSU Daisuke Copyright 2005-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. *---------------------------------------------------------------------------*/ #ifdef KPADOLD_INSIDE_H__ #error KPADinside.h of KPAD version 2 cannot be used with that of KPADOld #endif #ifndef KPAD_INSIDE_H__ #define KPAD_INSIDE_H__ #ifdef __cplusplus extern "C" { #endif #include /******************************************************************************* DEFINE *******************************************************************************/ //----- Definitions for calculation #define KPAD_CMOS_FOV WPAD_DPD_ANGLE // CMOS lens angle of view (Field Of View) #define KPAD_CMOS_HFOV_TAN 0.383864f // Tangent of half angle of CMOS_FOV #define KPAD_CMOS_RESO_WX 128 // CMOS resolution #define KPAD_CMOS_RESO_WY 96 #define KPAD_CMOS_RESO_CX (KPAD_CMOS_RESO_WX / 2) #define KPAD_CMOS_RESO_CY (KPAD_CMOS_RESO_WY / 2) #define KPAD_DPD_RESO_WX WPAD_DPD_IMG_RESO_WX // DPD resolution #define KPAD_DPD_RESO_WY WPAD_DPD_IMG_RESO_WY #define KPAD_DPD_RESO_CX (KPAD_DPD_RESO_WX / 2) #define KPAD_DPD_RESO_CY (KPAD_DPD_RESO_WY / 2) #define KPAD_USE_OBJECTS 2 // Number of marks used for determining position #define KPAD_BTN_RPT_TIME_MAX 20000 // btn_repeat_time range (will not be this value) #define KPAD_BTN_NO_RPT_DELAY 40000 // Delay setting when not repeating /******************************************************************************* TYPEDEF *******************************************************************************/ typedef struct { Vec2 center ; // Center of mass coordinate (coordinate system where the horizontal range of CMOS will be + or - 1) s8 error_fg ; // -1: not displayed, 0: OK, 1: too far out, 2: same coordinate s8 state_fg ; // -1: expected value, 0: normal s8 _fg_1 ; // Extra s8 _fg_2 ; // Extra } KPADObject ; typedef union { KPADStatus k; KPADUnifiedWpadStatus w; } KPADTmpStatus; typedef struct { KPADStatus status ; //----- Variables that adjust how the controller responds f32 pos_play_radius ; // Tolerance radius (size at pos coordinate system) f32 pos_sensitivity ; // Tracking sensitivity (0: slow -> 1: sensitive) f32 hori_play_radius ; // Adjust response of the 'horizon' f32 hori_sensitivity ; // f32 dist_play_radius ; // Adjust response of the 'dist' f32 dist_sensitivity ; // f32 acc_play_radius ; // Adjust the response of 'acc' f32 acc_sensitivity ; // //----- DPD calibration value f32 dist_org ; // Distance after calibration Vec2 accXY_nrm_hori ; // XY acceleration direction when the controller is placed horizontally Vec2 sec_nrm_hori ; // Direction from left mark to right mark when the controller is placed horizontally Vec2 center_org ; // Coordinates during calibration f32 dpd2pos_scale ; // Scale value where the left and right pointing edge in the shooting range will be + or - 1 //----- Variable used for internal control KPADObject kobj_sample[ WPAD_DPD_MAX_OBJECTS ] ; // All captured marks will be covered KPADObject kobj_regular[ KPAD_USE_OBJECTS ] ; // Left to right order (top to bottom order for straight vertical) s16 valid_objs ; // Valid object count u8 bufIdx ; u8 bufCount ; KPADUnifiedWpadStatus uniRingBuf[ KPAD_RING_BUFS ] ; KPADUnifiedWpadStatus *uniRingBufEx ; // Pointer to additional ring buffer u32 uniRingBufExLen ; // Length of additional ring buffer f32 sec_length ; // Distance between left and right marks Vec2 sec_nrm ; // Direction from the left to right mark f32 sec_dist ; // Raw distance from the TV (meter) f32 trust_sec_length ; // Trusted interval distance stored here Vec hard_acc ; // Raw acceleration Vec2 obj_horizon ; // Tilt calculated by the object Vec2 acc_horizon ; // Tilt calculated by the acceleration (either side) Vec2 ah_circle_pos ; // Point chasing the acc_horizon u16 ah_circle_ct ; // Countdown if in a certain range (stopped if zero) u8 dpd_valid2_ct ; // Number of successful consecutive two point recognition u8 readLocked ; // KPADRead() is in progress //----- Button control u16 btn_repeat_time ; // Time to be counted u16 btn_repeat_next ; // Time of setting next flag u16 btn_repeat_delay ; // Repeat start time u16 btn_repeat_pulse ; // Repeat interval time //----- For Classic Controller unit u16 btn_cl_repeat_time ; // Time to be counted u16 btn_cl_repeat_next ; // Time of setting next flag KPADControlDpdCallback dpd_ctrl_callback ; // User callback when DPD setting change becomes necessary f32 acc_scale_x ; f32 acc_scale_y ; f32 acc_scale_z ; f32 fs_acc_scale_x ; f32 fs_acc_scale_y ; f32 fs_acc_scale_z ; Vec2 kobj_frame_min; // Range where the center of mass coordinate is valid Vec2 kobj_frame_max; // f32 err_dist_speed_1 ; // Reciprocal f32 err_dist_speedM_1 ; // Reciprocal of negative value f32 ah_circle_radius2 ; // Second power f32 dist_vv1 ; // Constant f32 err_dist_min ; // Automatic calculation of minimum operational distance (in meters) WPADSamplingCallback appSamplingCallback ; // For application WPADConnectCallback appConnectCallback ; // For application u8 resetReq ; u8 exResetReq ; u8 dpdNextState ; u8 dpdCurrState ; u8 dpdIssued ; u8 dpdCmd ; u8 dpdPreCallbackDone ; u8 dpdPostCallbackDone ; u8 aimReq ; u8 aimEnabled ; u8 fsAccRevise ; u8 btnProcMode ; KPADPlayMode pos_play_mode ; KPADPlayMode hori_play_mode ; KPADPlayMode dist_play_mode ; KPADPlayMode acc_play_mode ; u8 wbcIssued ; u8 wbcEnabled ; u8 wbcSetup ; u8 wbcZeroPointWaitCount ; u8 wbcSetZeroPoint1Done ; u8 wbcSetZeroPoint2Done ; u8 wbcSetZeroPoint3Done ; u8 wbcGetWeightAveDone ; u16 wbcZeroPointSampleCount ; u16 wbcWeightAveSampleCount ; u32 paddings ; double wbcZeroPoint[ WPAD_PRESS_UNITS ] ; double wbcWeightAve[ WPAD_PRESS_UNITS ] ; } KPADInsideStatus; /******************************************************************************* EXTERNAL WORK *******************************************************************************/ //----- Various adjustments extern f32 kp_obj_interval ; // Separation between marks at each extremes (in meters) extern f32 kp_acc_horizon_pw ; // Calculating twist from acceleration extern f32 kp_ah_circle_radius ; // Stationary state determination radius extern f32 kp_ah_circle_pw ; // Stationary state determination tracking level extern u16 kp_ah_circle_ct ; // Stationary state determination count extern BOOL kp_stick_clamp_cross ; // Perform cross clamping //----- Values determined to be an error. extern f32 kp_err_outside_frame ; // Surrounding area width where center of mass coordinate will be invalid (not all surrounding lights are necessarily shown) extern f32 kp_err_dist_min ; // Minimum operational distance (in meters) extern f32 kp_err_dist_max ; // Maximum operational distance (in meters) extern f32 kp_err_dist_speed ; // Accepted range of distance change (in meters) extern f32 kp_err_first_inpr ; // Internal product of acceleration tilt and object tilt when selecting two points for the first time extern f32 kp_err_next_inpr ; // Accepted range of tilt change (internal product value) extern f32 kp_err_acc_inpr ; // Accepted range of acceleration tilt and internal product value at stationary state extern f32 kp_err_up_inpr ; // Accepted internal product range with controller pointed upwards extern f32 kp_err_near_pos ; // Distance from the previous point when selecting one point as a continuation //----- KPAD extern KPADInsideStatus inside_kpads[] ; /******************************************************************************* EXTERNAL FUNCTION *******************************************************************************/ #ifdef __cplusplus } #endif #endif // KPAD_INSIDE_H__