1 /*---------------------------------------------------------------------------*
2   Project:  horizon
3   File:     hid_AnalogStickClamper.h
4   Copyright 2011 Nintendo. All rights reserved.
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law. They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10   $Rev: $
11  *---------------------------------------------------------------------------
12 
13 
14 */
15 
16 #ifndef NN_HID_CTR_HID_ANALOG_STICK_CLAMPER_H_
17 #define NN_HID_CTR_HID_ANALOG_STICK_CLAMPER_H_
18 
19 #include <nn/types.h>
20 #include <nn/hid.h>
21 #include <nn/Result.h>
22 #include <nn/util/util_SizedEnum.h>
23 
24 namespace nn {
25 namespace hid {
26 namespace CTR {
27 
28 const f32 DEFAULT_SCALE_OF_NORMALIZE_STICK     = 1.5f;
29 const s16 DEFAULT_THRESHOLD_OF_NORMALIZE_STICK = 141;
30 
31 /* Please see man pages for details
32 
33 */
34 const s16   MIN_OF_STICK_CLAMP_MODE_CIRCLE  = 40;
35 
36 /* Please see man pages for details
37 
38 */
39 const s16   MIN_OF_STICK_CLAMP_MODE_CROSS   = 36;
40 
41 /* Please see man pages for details
42 
43 */
44 const s16   LIMIT_OF_STICK_CLAMP_MAX              = 145;
45 
46 
47 
48 class AnalogStickClamper
49 {
50 public:
51     enum ClampMode
52     {
53         CLAMP_MODE_CIRCLE = 0,
54         CLAMP_MODE_CROSS,
55         CLAMP_MODE_MINIMUM
56     };
57 
58 public:
59     AnalogStickClamper();
~AnalogStickClamper()60     ~AnalogStickClamper(){};
61 
62     void SetStickClamp(s16 min, s16 max);
63     void GetStickClamp(s16* pMin, s16* pMax) const;
64     ClampMode GetStickClampMode( ) const;
65     void SetStickClampMode(ClampMode mode);
66     f32 NormalizeStick(s16 x);
67     void NormalizeStickWithScale( f32* normalized_x, f32* normalized_y, s16 x, s16 y );
68     void SetNormalizeStickScaleSettings( f32 scale, s16 threshold  );
69     void GetNormalizeStickScaleSettings( f32* scale, s16* threshold  ) const;
70 
71     void ClampValueOfClamp();
72     void ClampCore(s16* pOutX, s16* pOutY,s32 x,s32 y);
73 
74 private:
75     s16                 m_MinOfStickClampCircle;
76     s16                 m_MinOfStickClampCross;
77     s16                 m_MinOfStickClampMinimum;
78     s16                 m_MaxOfStickClampCircle;
79     s16                 m_MaxOfStickClampCross;
80     s16                 m_MaxOfStickClampMinimum;
81     nn::util::SizedEnum1<ClampMode>      m_StickClampMode;
82     NN_PADDING1;
83     s16                 m_Threshold;
84     f32                 m_Scale;
85     f32                 m_Stroke;
86     f32                 m_StrokeVelocity;
87     f32                 m_LastLength;
88     f32                 m_LastDiff;
89 
90 };
91 
92 
93 
94 
95 }}}
96 
97 #endif /* HID_ANALOGSTICKCLAMPER_H_ */
98