1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
3  <head>
4    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5    <meta http-equiv="Content-Style-Type" content="text/css" />
6    <link rel="stylesheet" href="../../../../css/manpage.css" type="text/css" />
7    <style type="text/css"><!--
8      span.static_style
9      {
10        font-size			: 8pt;
11        color				: white;
12        font-weight			: bold;
13        background			: #44f;
14        border-left			: solid 1px #aaf;
15        border-top			: solid 1px #aaf;
16        border-right		: solid 1px #00c;
17        border-bottom		: solid 1px #00c;
18        padding-left		: 2px;
19        padding-right		: 2px;
20      }
21      span.virtual_style
22      {
23        font-size			 : 8pt;
24        color				 : white;
25        font-weight			: bold;
26        background			: #0a0;
27        border-left			: solid 1px #0f0;
28        border-top			: solid 1px #0f0;
29        border-right		: solid 1px #060;
30        border-bottom		: solid 1px #060;
31        padding-left		: 2px;
32        padding-right		: 2px;
33      }
34      span.protected_style
35      {
36        font-size			 : 8pt;
37        color				 : white;
38        font-weight			: bold;
39        background			: #444;
40        border-left			: solid 1px #ccc;
41        border-top			: solid 1px #ccc;
42        border-right		: solid 1px #222;
43        border-bottom		: solid 1px #222;
44        padding-left		: 2px;
45        padding-right		: 2px;
46      }
47        --></style>
48<title>nn::hid::CTR::AccelerometerReader</title>
49  </head>
50  <body>
51<h1><CODE><a href="../../../../nn/Overview.html">nn</a>::<a href="../../../../nn/hid/Overview.html">hid</a>::<a href="../../../../nn/hid/CTR/Overview.html">CTR</a>::AccelerometerReader</CODE> Class</h1>
52<h2>Syntax</h2>
53    <div class="section">
54      <pre class="definition">class AccelerometerReader : private <a href="../../../../nn/util/NonCopyable/Overview.html">nn::util::NonCopyable< AccelerometerReader ></a></pre>
55    </div>
56<h2>Description</h2>
57    <div class="section">
58<p>Class for loading sampling data from the accelerometer.</p><h3>Sampling Rate</h3><p>
59The accelerometer starts sampling when the first instance is generated, sampling data at intervals of roughly 10 milliseconds. Sampling stops when no instances exist.<BR />If you want to monitor the exact timing of sampling, you can use the <CODE><a href="../../../../nn/hid/CTR/Accelerometer/Overview.html">Accelerometer</a></CODE> class to know precisely when sampling occurs.<BR /><BR />No sampling is done right after generating a class instance or right after recovering from sleep, so there are times when the <a href="../../../../nn/hid/CTR/AccelerometerReader/Read.html"><CODE>Read</CODE></a> and <a href="../../../../nn/hid/CTR/AccelerometerReader/ReadLatest.html"><CODE>ReadLatest</CODE></a> functions do not get valid results. Waiting until results have been sampled at least once avoids this situation, so Nintendo recommends calling the <CODE><a href="../../../../nn/hid/CTR/HidBase/WaitSampling.html">nn::hid::CTR::HidBase::WaitSampling</a></CODE> function of the <CODE><a href="../../../../nn/hid/CTR/Accelerometer/Overview.html">nn::hid::CTR::Accelerometer</a></CODE> class right after generating a class instance or when recovering from sleep. This wait time is the same as the sampling frequency, up to a maximum of approximately 10 milliseconds.
60</p><h3>Generating/Destroying Instances and Sampling Processes</h3><p>
61As mentioned, the generation/destruction of instances is linked to the switching of sampling processes. Because the switching of sampling processes puts a load on the system, you should try to use the same instance while using the accelerometer and otherwise refrain from frequent generation and destruction of instances.<BR />Below is an example of <U>what you should avoid</U>.
62        </p><pre><code>
63   void GetAccelerometerValue(f32* x,f32* y,f32* z)
64   {
65      AccelerometerReader reader;	// Generate instance: Start of sampling
66      AccelerometerStatus status;
67
68      reader.ReadLatest( &status );     // Get value
69      *x = status.speed.x;
70      *y = status.speed.y;
71      *z = status.speed.z;
72
73      return;                   // Destroy reader: Sampling stops
74   }
75
76   void MainLoop() // Loop called once per frame
77   {
78       ... some sort of processing .....
79       GetAccelerometerValue( &x, &y, &z );  // Value obtained once in every frame
80
81       ... some sort of processing .....
82   }
83   </code></pre><p>
84In the example above, an instance of <CODE>AccelerometerReader</CODE> is created and destroyed on the stack in every frame. Because the process does not wait the minimal time for sampling by the accelerometer, in some cases appropriate values are not obtained. This is a bad design. The design should be revised, for example, by creating the instance in the heap, so that the instance continues to exist throughout the interval during which the application needs to get the acceleration.
85		</p><h3>Output Value Processing Features</h3><p>
86This class includes the following features to process output values.<table><tr><th>Acceleration Variation Tolerance</th><td>You can apply a correction to control any major variation in acceleration during continuous sampling.</td></tr><tr><th>Offset Correction</th><td>Outputs after subtracting the specified value from sampling results.</td></tr><tr><th>Axial Rotation</th><td>Outputs sampling results multiplied by an optional rotation matrix. Enables the output of values as if the accelerometer is on an incline.</td></tr></table><BR />All processing features are disabled by default. Configure and enable them as needed. For details, see the various function references.
87</p><h3>Axis Orientation</h3><p>
88The default accelerometer sensors are as follows.<table><tr><th>X+</th><td>The direction indicated by Left on the +Control Pad</td></tr><tr><th>Y+</th><td>The direction normal to and outward from the Touch Screen</td></tr><tr><th>Z+</th><td>The direction indicated by Up on the +Control Pad</td></tr></table></p><h3>Recalibration from the HOME Menu</h3><p>
89Effective from the first network update, the HOME Menu has a feature enabling users to recalibrate the accelerometer whenever they like.<br /><br />Thus, in some cases, correction of the accelerometer in accordance with the user's environment may take place while the system is transitioning from the application to the HOME Menu upon pressing the HOME Button.<br />After this operation, the values obtained by the <a href="../../../../nn/hid/CTR/AccelerometerReader/Read.html"><CODE>Read</CODE></a> and <a href="../../../../nn/hid/CTR/AccelerometerReader/ReadLatest.html"><CODE>ReadLatest</CODE></a> functions are the corrected values. In most cases, the corrected values accurately reflect the user's environment.<br /><br />The applications, however, need not take any special measures to deal with this.
90        </p></div>
91    <a name="constant" id="constant">
92<h2>Member Constants</h2>
93      <div class="section">
94        <table class="members">
95          <tr>
96            <td width="100">
97<span class="static_style" title="static">S</span>
98            </td>
99            <th>
100<span class="argument"><a href="../../../../nn/hid/CTR/AccelerometerReader/MAX_READ_NUM.html">MAX_READ_NUM</a></span>
101            </th>
102<td width="100">const <a href="../../../../nn_types/s8.html">s8</a></td>
103<td>The maximum number of data samples that can be read.</td>
104          </tr> </table>
105      </div>
106    </a> <a name="function" id="function">
107<h2>Member Functions</h2>
108      <div class="section">
109        <table class="members">
110          <tr>
111<th class="category" colspan="3">Constructors and Destructors</th>
112          </tr>
113          <tr>
114            <td width="100">  </td>
115            <th>
116<a href="../../../../nn/hid/CTR/AccelerometerReader/AccelerometerReader.html"><CODE>AccelerometerReader</CODE></a>
117            </th>
118<td>Constructor.</td>
119          </tr>
120          <tr>
121            <td width="100">  </td>
122            <th>
123<a href="../../../../nn/hid/CTR/AccelerometerReader/~AccelerometerReader.html"><CODE>~AccelerometerReader</CODE></a>
124            </th>
125<td>Destructor.</td>
126          </tr>
127          <tr>
128<th class="category" colspan="3">Reading Sampling Data</th>
129          </tr>
130          <tr>
131            <td width="100">  </td>
132            <th>
133<a href="../../../../nn/hid/CTR/AccelerometerReader/Read.html"><CODE>Read</CODE></a>
134            </th>
135<td>Loads sampling data from the accelerometer starting with the newest samples. Does not load any data that has been previously loaded.</td>
136          </tr>
137          <tr>
138            <td width="100">  </td>
139            <th>
140<a href="../../../../nn/hid/CTR/AccelerometerReader/ReadLatest.html"><CODE>ReadLatest</CODE></a>
141            </th>
142<td>Loads the newest sampling data from the accelerometer. Unlike the <CODE><a href="../../../../nn/hid/CTR/AccelerometerReader/Read.html">nn::hid::CTR::AccelerometerReader::Read</a></CODE> function, this function can load the same sampling data more than once.</td>
143          </tr>
144          <tr>
145<th class="category" colspan="3">Control Functions for Acceleration Variation Tolerance</th>
146          </tr>
147          <tr>
148            <td width="100">  </td>
149            <th>
150<a href="../../../../nn/hid/CTR/AccelerometerReader/GetSensitivity.html"><CODE>GetSensitivity</CODE></a>
151            </th>
152<td>Gets the settings for sensitivity and play tolerance for the change in acceleration between samples.</td>
153          </tr>
154          <tr>
155            <td width="100">  </td>
156            <th>
157<a href="../../../../nn/hid/CTR/AccelerometerReader/SetSensitivity.html"><CODE>SetSensitivity</CODE></a>
158            </th>
159<td>Sets the sensitivity and play tolerance for the change in acceleration between samples.</td>
160          </tr>
161          <tr>
162<th class="category" colspan="3">Axial Rotation</th>
163          </tr>
164          <tr>
165            <td width="100">  </td>
166            <th>
167<a href="../../../../nn/hid/CTR/AccelerometerReader/EnableAxisRotation.html"><CODE>EnableAxisRotation</CODE></a>
168            </th>
169<td>Enables axial rotation of the accelerometer.</td>
170          </tr>
171          <tr>
172            <td width="100">  </td>
173            <th>
174<a href="../../../../nn/hid/CTR/AccelerometerReader/DisableAxisRotation.html"><CODE>DisableAxisRotation</CODE></a>
175            </th>
176<td>Disables axial rotation of the accelerometer.</td>
177          </tr>
178          <tr>
179            <td width="100">  </td>
180            <th>
181<a href="../../../../nn/hid/CTR/AccelerometerReader/IsEnableAxisRotation.html"><CODE>IsEnableAxisRotation</CODE></a>
182            </th>
183<td>Checks whether axial rotation is enabled or disabled for the accelerometer.</td>
184          </tr>
185          <tr>
186            <td width="100">  </td>
187            <th>
188<a href="../../../../nn/hid/CTR/AccelerometerReader/SetAxisRotationMatrix.html"><CODE>SetAxisRotationMatrix</CODE></a>
189            </th>
190<td>Specifies the rotation matrix used for axial rotation of the accelerometer's sampling data.</td>
191          </tr>
192          <tr>
193            <td width="100">  </td>
194            <th>
195<a href="../../../../nn/hid/CTR/AccelerometerReader/GetAxisRotationMatrix.html"><CODE>GetAxisRotationMatrix</CODE></a>
196            </th>
197<td>Gets the rotation matrix currently specified to use for axial rotation of the accelerometer's sampling data.</td>
198          </tr>
199          <tr>
200            <td width="100">  </td>
201            <th>
202<a href="../../../../nn/hid/CTR/AccelerometerReader/ResetAxisRotationMatrix.html"><CODE>ResetAxisRotationMatrix</CODE></a>
203            </th>
204<td>Initializes the rotation matrix to use for transforming the accelerometer's sampling data.</td>
205          </tr>
206          <tr>
207<th class="category" colspan="3">Offset</th>
208          </tr>
209          <tr>
210            <td width="100">  </td>
211            <th>
212<a href="../../../../nn/hid/CTR/AccelerometerReader/EnableOffset.html"><CODE>EnableOffset</CODE></a>
213            </th>
214<td>Enables the accelerometer offset.</td>
215          </tr>
216          <tr>
217            <td width="100">  </td>
218            <th>
219<a href="../../../../nn/hid/CTR/AccelerometerReader/DisableOffset.html"><CODE>DisableOffset</CODE></a>
220            </th>
221<td>Disables the accelerometer offset.</td>
222          </tr>
223          <tr>
224            <td width="100">  </td>
225            <th>
226<a href="../../../../nn/hid/CTR/AccelerometerReader/IsEnableOffset.html"><CODE>IsEnableOffset</CODE></a>
227            </th>
228<td>Checks whether the accelerometer offset is enabled or disabled.</td>
229          </tr>
230          <tr>
231            <td width="100">  </td>
232            <th>
233<a href="../../../../nn/hid/CTR/AccelerometerReader/SetOffset.html"><CODE>SetOffset</CODE></a>
234            </th>
235<td>Sets the accelerometer offset value.</td>
236          </tr>
237          <tr>
238            <td width="100">  </td>
239            <th>
240<a href="../../../../nn/hid/CTR/AccelerometerReader/SetOffsetFromBaseStatus.html"><CODE>SetOffsetFromBaseStatus</CODE></a>
241            </th>
242<td>Sets the accelerometer offset value.</td>
243          </tr>
244          <tr>
245            <td width="100">  </td>
246            <th>
247<a href="../../../../nn/hid/CTR/AccelerometerReader/GetOffset.html"><CODE>GetOffset</CODE></a>
248            </th>
249<td>Gets the accelerometer offset value.</td>
250          </tr>
251          <tr>
252            <td width="100">  </td>
253            <th>
254<a href="../../../../nn/hid/CTR/AccelerometerReader/ResetOffset.html"><CODE>ResetOffset</CODE></a>
255            </th>
256<td>Resets the accelerometer offset value to the default.</td>
257          </tr>
258          <tr>
259<th class="category" colspan="3">Other</th>
260          </tr>
261          <tr>
262            <td width="100">  </td>
263            <th>
264<a href="../../../../nn/hid/CTR/AccelerometerReader/ConvertToAcceleration.html"><CODE>ConvertToAcceleration</CODE></a>
265            </th>
266<td>Converts the raw sampling data from the accelerometer into acceleration values (in g's).</td>
267          </tr> </table>
268      </div>
269    </a>
270<h2>Class Hierarchy</h2>
271    <div class="section">
272<p class="hierarchy"><CODE><a href="../../../../nn/util/NonCopyable/Overview.html">nn::util::NonCopyable</a></CODE><br />&nbsp;&nbsp;<b><CODE>nn::hid::CTR::AccelerometerReader</CODE></b>
273      </p>
274    </div>
275<h2>Revision History</h2>
276    <div class="section">
277      <dl class="history">
278        <dt>2012/01/12</dt>
279<dd>Corrected the indication that frequent generation/destruction of instances was prohibited.<br />Updated the text about recalibration from the HOME Menu.<br />Restructured the description about the timing of the start of sampling.<br />
280        </dd>
281        <dt>2011/10/06</dt>
282<dd>Noted you may not be able to get values using the example of what <I>not</I> to do.<br />
283        </dd>
284        <dt>2011/08/30</dt>
285<dd>Added text about creation and destruction of instances.<br />
286        </dd>
287        <dt>2011/03/15</dt>
288<dd>Added note about the possibility of recalibration from the HOME menu.<br />
289        </dd>
290        <dt>2010/12/06</dt>
291<dd>Added explanation of conditions under which sampling stops.<br />
292        </dd>
293        <dt>2010/01/07</dt>
294<dd>Initial version.<br />
295        </dd>
296      </dl>
297    </div>
298  <hr><p>CONFIDENTIAL</p></body>
299</html>
300