1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     hid_AccelerometerReader.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: 46940 $
14  *---------------------------------------------------------------------------*/
15 
16 /* Please see man pages for details
17 
18 
19 */
20 #ifndef NN_HID_CTR_HID_ACCELEROMETERREADER_H_
21 #define NN_HID_CTR_HID_ACCELEROMETERREADER_H_
22 
23 #include <nn/Handle.h>
24 #include <nn/Result.h>
25 #include <nn/types.h>
26 #include <nn/hid/CTR/hid_Result.h>
27 #include <nn/hid/CTR/hid_Api.h>
28 #include <nn/hid/CTR/hid_Accelerometer.h>
29 #include <nn/hid/CTR/hid_DeviceStatus.h>
30 #include <nn/util/util_SizedEnum.h>
31 #include <nn/util/util_NonCopyable.h>
32 #include <nn/math.h>
33 
34 namespace nn {
35 namespace hid {
36 namespace CTR {
37 /* Please see man pages for details
38 
39 
40 */
41 const s16   MAX_OF_ACCELEROMETER_VALUE                      = 930;
42 
43 /* Please see man pages for details
44 
45 
46 */
47 const s16   ACCELEROMETER_VALUE_PER_1G                      = 512;
48 const f32   ACCELERATION_SCALE_PER_1G                       = 1.f / ACCELEROMETER_VALUE_PER_1G;
49 
50 /* Please see man pages for details
51 
52 
53 */
54 const s16   MAX_OF_ACCELEROMETER_PLAY                       = MAX_OF_ACCELEROMETER_VALUE * 2;
55 
56 const s16   ACCELEROMETER_SENSITIVITY_SCALE_SHIFT           = 7;
57 
58 /* Please see man pages for details
59 
60 
61 */
62 const s16   MAX_OF_ACCELEROMETER_SENSITIVITY                = 128; // 1 << ACCELEROMETER_SENSITIVITY_SCALE_SHIFT
63 
64 
65 /* Please see man pages for details
66 
67 
68 
69 */
70 class AccelerometerReader : private nn::util::NonCopyable<AccelerometerReader>
71 {
72 public:
73 
74     /* Please see man pages for details
75 
76 
77      */
78 
79     /* Please see man pages for details
80 
81 
82 
83 
84 
85 
86     */
87     AccelerometerReader(Accelerometer& accelerometer = GetAccelerometer( ));
88 
89     /* Please see man pages for details
90 
91 
92     */
93     ~AccelerometerReader( );
94 
95     /*
96 
97 */
98 
99     /* Please see man pages for details
100 
101 
102      */
103 
104     /* Please see man pages for details
105 
106 
107 
108 
109 
110 
111 
112     */
113     void Read(AccelerometerStatus* pBufs, s32* pReadLen, s32 bufLen);
114 
115     /* Please see man pages for details
116 
117 
118 
119 
120 
121 
122 
123 
124 
125     */
126     bool ReadLatest(AccelerometerStatus* pBuf);
127 
128     /*
129 
130 */
131 
132     /* Please see man pages for details
133 
134 
135      */
136 
137     /* Please see man pages for details
138 
139 
140 
141 
142 
143     */
144     void GetSensitivity(s16* pPlay, s16* pSensitivity) const;
145 
146     /* Please see man pages for details
147 
148 
149 
150 
151 
152 
153 
154 
155     */
156     void SetSensitivity(s16 play, s16 sensitivity);
157 
158     /*
159 
160 */
161 
162     /* Please see man pages for details
163 
164 
165      */
166 
167     /* Please see man pages for details
168 
169 
170 
171 
172 
173 
174 
175      */
176     void EnableAxisRotation();
177 
178 
179     /* Please see man pages for details
180 
181      */
182     void DisableAxisRotation();
183 
184 
185     /* Please see man pages for details
186 
187 
188 
189     */
190     bool IsEnableAxisRotation() const;
191 
192 
193     /* Please see man pages for details
194 
195 
196      */
197     void SetAxisRotationMatrix(const nn::math::MTX34& mtx);
198 
199     /* Please see man pages for details
200 
201 
202 
203 
204 
205 
206 
207      */
208     nn::math::MTX34 GetAxisRotationMatrix() const;
209 
210     /* Please see man pages for details
211 
212 
213 
214 
215 
216 
217      */
218     void GetAxisRotationMatrix(nn::math::MTX34* pMtx) const;
219 
220 
221     /* Please see man pages for details
222 
223 
224 
225 
226 
227      */
228     void ResetAxisRotationMatrix();
229 
230     /*
231 
232 */
233 
234     /* Please see man pages for details
235 
236 
237      */
238 
239     /* Please see man pages for details
240 
241 
242 
243 
244 
245 
246 
247      */
248 
249     void EnableOffset();
250 
251     /* Please see man pages for details
252 
253 
254 
255      */
256     void DisableOffset();
257 
258     /* Please see man pages for details
259 
260 
261 
262      */
263     bool IsEnableOffset() const;
264 
265 
266     /* Please see man pages for details
267 
268 
269 
270 
271 
272 
273 
274 
275 
276      */
277     void SetOffset(s16 x, s16 y,s16 z);
278 
279 
280     /* Please see man pages for details
281 
282 
283 
284 
285 
286      */
287 
288     void SetOffsetFromBaseStatus(AccelerometerStatus baseAccelerometerStatus);
289 
290     /* Please see man pages for details
291 
292 
293 
294 
295 
296      */
297     void GetOffset(s16* pX, s16* pY, s16*pZ) const;
298 
299     /* Please see man pages for details
300 
301 
302 
303      */
304     void ResetOffset();
305 
306     /*
307 
308 */
309 
310 
311     /* Please see man pages for details
312 
313 
314      */
315     /* Please see man pages for details
316 
317 
318 
319 
320 
321 
322 
323 
324 
325     */
326     void ConvertToAcceleration(AccelerationFloat* pAcceleration, s32 bufLen, const AccelerometerStatus* pSamplingData, s32 samplingLen = -1);
327 
328     /*
329 
330 */
331 
332 
333     /* Please see man pages for details
334 
335     */
336     static const s8 MAX_READ_NUM = 7;
337 
338 private:
339     void Transform(AccelerometerStatus* pAccStatus);
340 
341 protected:
342     Accelerometer&                              m_Accelerometer;
343     s16                                         m_Play;
344     s16                                         m_Sensitivity;
345 
346     AccelerometerStatus                         m_LatestCalculatedStatus;
347     AccelerometerStatus                         m_OffsetAccStatus;
348     NN_PADDING4;
349 
350     nn::math::MTX34                             m_RotateMtx;
351     bool                                        m_EnableOffset;
352     bool                                        m_EnableRotate;
353     NN_PADDING2;
354     s32                                         m_IndexOfRead;
355     s64                                         m_TickOfRead;
356 };
357 
358 
359 
360 // inline implementation
SetSensitivity(s16 play,s16 sensitivity)361 inline void AccelerometerReader::SetSensitivity(s16 play, s16 sensitivity)
362 {
363     NN_TASSERT_(0 <= play && MAX_OF_ACCELEROMETER_PLAY >= play && 0 <= sensitivity && MAX_OF_ACCELEROMETER_SENSITIVITY >= sensitivity);
364     m_Play = play;
365     m_Sensitivity = sensitivity;
366 }
367 
GetSensitivity(s16 * pPlay,s16 * pSensitivity)368 inline void AccelerometerReader::GetSensitivity(s16* pPlay, s16* pSensitivity) const
369 {
370     *pPlay = m_Play;
371     *pSensitivity = m_Sensitivity;
372 }
373 
374 } // namespace CTR {
375 } // namespace hid {
376 } // namespace nn {
377 
378 #endif  // #ifndef NN_HID_CTR_HID_ACCELEROMETERREADER_H_
379