1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     hid_AnalogStickClamper.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev:$
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/config.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         STICK_CLAMP_MODE_CIRCLE = 0,
54         STICK_CLAMP_MODE_CROSS,
55         STICK_CLAMP_MODE_MINIMUM
56     };
57 
58 public:
59     AnalogStickClamper();
~AnalogStickClamper()60     ~AnalogStickClamper(){};
61 
62     void SetStickClamp(s16 min, s16 max);
63     void SetStickClampFree(s16 min, s16 max);
64     void GetStickClamp(s16* pMin, s16* pMax) const;
65     ClampMode GetStickClampMode( ) const;
66     void SetStickClampMode(ClampMode mode);
67     f32 NormalizeStick(s16 x);
68     void NormalizeStickWithScale( f32* normalized_x, f32* normalized_y, s16 x, s16 y );
69     void SetNormalizeStickScaleSettings( f32 scale, s16 threshold  );
70     void GetNormalizeStickScaleSettings( f32* scale, s16* threshold  ) const;
71 
72     void ClampValueOfClamp();
73     void ClampCore(s16* pOutX, s16* pOutY,s32 x,s32 y);
74 
75 private:
76     s16                 m_MinOfStickClampCircle;
77     s16                 m_MinOfStickClampCross;
78     s16                 m_MinOfStickClampMinimum;
79     s16                 m_MaxOfStickClampCircle;
80     s16                 m_MaxOfStickClampCross;
81     s16                 m_MaxOfStickClampMinimum;
82     nn::util::SizedEnum1<ClampMode>      m_StickClampMode;
83     NN_PADDING1;
84     s16                 m_Threshold;
85     f32                 m_Scale;
86     f32                 m_Stroke;
87     f32                 m_StrokeVelocity;
88     f32                 m_LastLength;
89     f32                 m_LastDiff;
90 
91 };
92 
93 // inline definition
GetStickClamp(s16 * pMin,s16 * pMax)94 inline void AnalogStickClamper::GetStickClamp(s16* pMin, s16* pMax) const
95 {
96     if (m_StickClampMode == STICK_CLAMP_MODE_CIRCLE)
97     {
98        *pMin = m_MinOfStickClampCircle;
99        *pMax = m_MaxOfStickClampCircle;
100     }
101     else if (m_StickClampMode == STICK_CLAMP_MODE_CROSS)
102     {
103        *pMin = m_MinOfStickClampCross;
104        *pMax = m_MaxOfStickClampCross;
105     }
106     else
107     {
108         *pMin = m_MinOfStickClampMinimum;
109         *pMax = m_MaxOfStickClampMinimum;
110     }
111 }
112 
GetStickClampMode()113 inline AnalogStickClamper::ClampMode AnalogStickClamper::GetStickClampMode( ) const
114 {
115     return m_StickClampMode;
116 }
117 
SetStickClampMode(ClampMode mode)118 inline void AnalogStickClamper::SetStickClampMode(ClampMode mode)
119 {
120     m_StickClampMode = mode;
121 }
122 
123 
124 
125 
126 }}}
127 
128 #endif /* NN_HID_CTR_HID_ANALOG_STICK_CLAMPER_H_ */
129