1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: hid_AccelerometerReader.h
4 Copyright (C)2009 Nintendo Co., Ltd. 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: 37190 $
11 *---------------------------------------------------------------------------
12
13
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 void ConvertToAcceleration(AccelerationFloat* pAcceleration, s32 bufLen, const AccelerometerStatus* pSamplingData);
325
326 /*
327
328 */
329
330
331
332 private:
333 void Transform(AccelerometerStatus* pAccStatus);
334
335 protected:
336 Accelerometer& m_Accelerometer;
337 s16 m_Play;
338 s16 m_Sensitivity;
339
340 AccelerometerStatus m_LatestCalculatedStatus;
341 AccelerometerStatus m_OffsetAccStatus;
342 NN_PADDING4;
343
344 nn::math::MTX34 m_RotateMtx;
345 bool m_EnableOffset;
346 bool m_EnableRotate;
347 NN_PADDING2;
348 s32 m_IndexOfRead;
349 s64 m_TickOfRead;
350 };
351
352
353
354 // inline implementation
SetSensitivity(s16 play,s16 sensitivity)355 inline void AccelerometerReader::SetSensitivity(s16 play, s16 sensitivity)
356 {
357 NN_TASSERT_(0 <= play && MAX_OF_ACCELEROMETER_PLAY >= play && 0 <= sensitivity && MAX_OF_ACCELEROMETER_SENSITIVITY >= sensitivity);
358 m_Play = play;
359 m_Sensitivity = sensitivity;
360 }
361
GetSensitivity(s16 * pPlay,s16 * pSensitivity)362 inline void AccelerometerReader::GetSensitivity(s16* pPlay, s16* pSensitivity) const
363 {
364 *pPlay = m_Play;
365 *pSensitivity = m_Sensitivity;
366 }
367
368 } // namespace CTR {
369 } // namespace hid {
370 } // namespace nn {
371
372 #endif // #ifndef NN_HID_CTR_HID_ACCELEROMETERREADER_H_
373