19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.hardware;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
2074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <p>
2174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * This class represents a {@link android.hardware.Sensor Sensor} event and
2274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * holds informations such as the sensor's type, the time-stamp, accuracy and of
2374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * course the sensor's {@link SensorEvent#values data}.
2474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * </p>
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
2674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <p>
2774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <u>Definition of the coordinate system used by the SensorEvent API.</u>
2874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * </p>
2974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian *
3074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <p>
310f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * The coordinate-system is defined relative to the screen of the phone in its
3274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * default orientation. The axes are not swapped when the device's screen
3374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * orientation changes.
3474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * </p>
3574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian *
3674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <p>
370f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * The X axis is horizontal and points to the right, the Y axis is vertical and
380f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * points up and the Z axis points towards the outside of the front face of the
390f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * screen. In this system, coordinates behind the screen have negative Z values.
400f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * </p>
410f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian *
420f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * <p>
430f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * <center><img src="../../../images/axis_device.png"
440f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * alt="Sensors coordinate-system diagram." border="0" /></center>
4574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * </p>
4674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian *
4774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <p>
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <b>Note:</b> This coordinate system is different from the one used in the
4974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * Android 2D APIs where the origin is in the top-left corner.
5074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * </p>
519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
520f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * @see SensorManager
530f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * @see SensorEvent
540f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * @see Sensor
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class SensorEvent {
599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
610f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * The length and contents of the {@link #values values} array depends on
620f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * which {@link android.hardware.Sensor sensor} type is being monitored (see
630f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * also {@link SensorEvent} for a definition of the coordinate system used).
6474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </p>
6574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     *
660f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_ACCELEROMETER
670f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * Sensor.TYPE_ACCELEROMETER}:</h4> All values are in SI units (m/s^2)
680f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
6974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <ul>
7074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
710f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * values[0]: Acceleration minus Gx on the x-axis
720f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
7374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
740f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * values[1]: Acceleration minus Gy on the y-axis
750f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
7674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
770f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * values[2]: Acceleration minus Gz on the z-axis
780f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
7974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </ul>
800f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
8174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
820f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * A sensor of this type measures the acceleration applied to the device
830f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * (<b>Ad</b>). Conceptually, it does so by measuring forces applied to the
840f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * sensor itself (<b>Fs</b>) using the relation:
850f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
860f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
87612ff27425cf2976396d992f32b58ab900c7d708Brad Fitzpatrick     * <b><center>Ad = - &#8721;Fs / mass</center></b>
880f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
8974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
900f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * In particular, the force of gravity is always influencing the measured
910f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * acceleration:
920f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
930f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
94612ff27425cf2976396d992f32b58ab900c7d708Brad Fitzpatrick     * <b><center>Ad = -g - &#8721;F / mass</center></b>
950f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
9674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
970f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * For this reason, when the device is sitting on a table (and obviously not
980f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * accelerating), the accelerometer reads a magnitude of <b>g</b> = 9.81
990f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * m/s^2
1000f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
1010f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
10274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
1030f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * Similarly, when the device is in free-fall and therefore dangerously
1040f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * accelerating towards to ground at 9.81 m/s^2, its accelerometer reads a
1050f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * magnitude of 0 m/s^2.
1060f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
1070f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
10874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
1090f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * It should be apparent that in order to measure the real acceleration of
1100f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * the device, the contribution of the force of gravity must be eliminated.
1110f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * This can be achieved by applying a <i>high-pass</i> filter. Conversely, a
1120f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <i>low-pass</i> filter can be used to isolate the force of gravity.
1130f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
114fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
115fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <pre class="prettyprint">
116fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
117fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     public void onSensorChanged(SensorEvent event)
118fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     {
119fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          // alpha is calculated as t / (t + dT)
120fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          // with t, the low-pass filter's time-constant
121fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          // and dT, the event delivery rate
122fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
123fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          final float alpha = 0.8;
124fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
125fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          gravity[0] = alpha * gravity[0] + (1 - alpha) * event.data[0];
126fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          gravity[1] = alpha * gravity[1] + (1 - alpha) * event.data[1];
127fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          gravity[2] = alpha * gravity[2] + (1 - alpha) * event.data[2];
128fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
129fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          linear_acceleration[0] = event.data[0] - gravity[0];
130fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          linear_acceleration[1] = event.data[1] - gravity[1];
131fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          linear_acceleration[2] = event.data[2] - gravity[2];
132fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     }
133fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </pre>
134fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
13574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
13674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <u>Examples</u>:
13774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <ul>
13874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <li>When the device lies flat on a table and is pushed on its left side
13974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * toward the right, the x acceleration value is positive.</li>
1400f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
14174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <li>When the device lies flat on a table, the acceleration value is
14274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * +9.81, which correspond to the acceleration of the device (0 m/s^2) minus
14374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * the force of gravity (-9.81 m/s^2).</li>
1440f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
14574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <li>When the device lies flat on a table and is pushed toward the sky
14674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * with an acceleration of A m/s^2, the acceleration value is equal to
14774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * A+9.81 which correspond to the acceleration of the device (+A m/s^2)
14874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * minus the force of gravity (-9.81 m/s^2).</li>
14974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </ul>
1500f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
1510f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
1520f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD
1530f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * Sensor.TYPE_MAGNETIC_FIELD}:</h4>
15474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * All values are in micro-Tesla (uT) and measure the ambient magnetic field
15574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * in the X, Y and Z axis.
1560f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
1577a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     * <h4>{@link android.hardware.Sensor#TYPE_GYROSCOPE Sensor.TYPE_GYROSCOPE}:</h4>
1587a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  All values are in radians/second and measure the rate of rotation
1597a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  around the X, Y and Z axis. The coordinate system is the same as is
1607a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  used for the acceleration sensor.  Rotation is positive in the counter-clockwise
1617a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  direction.  That is, an observer looking from some positive location on the x, y.
1627a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  or z axis at a device positioned on the origin would report positive rotation
1637a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  if the device appeared to be rotating counter clockwise.  Note that this is the
1647a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  standard mathematical definition of positive rotation and does not agree with the
1657a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  definition of roll given earlier.
1667a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *
167fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <ul>
168fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <p>
169fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * values[0]: Angular speed around the x-axis
170fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </p>
171fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <p>
172fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * values[1]: Angular speed around the y-axis
173fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </p>
174fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <p>
175fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * values[2]: Angular speed around the z-axis
176fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </p>
177fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </ul>
178fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <p>
179fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * Typically the output of the gyroscope is integrated over time to calculate
180fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * an angle, for example:
181fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </p>
182fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <pre class="prettyprint">
183fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     private static final float NS2S = 1.0f / 1000000000.0f;
184fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     private float timestamp;
185fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     public void onSensorChanged(SensorEvent event)
186fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     {
187fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          if (timestamp != 0) {
188fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *              final float dT = (event.timestamp - timestamp) * NS2S;
189fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *              angle[0] += event.data[0] * dT;
190fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *              angle[1] += event.data[1] * dT;
191fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *              angle[2] += event.data[2] * dT;
192fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          }
193fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          timestamp = event.timestamp;
194fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     }
195fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </pre>
196fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
197fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <p>In practice, the gyroscope noise and offset will introduce some errors which need
198fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * to be compensated for. This is usually done using the information from other
199fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * sensors, but is beyond the scope of this document.</p>
200fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
2010f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_LIGHT Sensor.TYPE_LIGHT}:</h4>
20274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <ul>
20374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
20474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * values[0]: Ambient light level in SI lux units
20574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </ul>
2060f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
2070f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_PROXIMITY Sensor.TYPE_PROXIMITY}:
2080f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </h4>
2090f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
21074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <ul>
21174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
21274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * values[0]: Proximity sensor distance measured in centimeters
21374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </ul>
2140f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
21574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
2160f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <b>Note:</b> Some proximity sensors only support a binary <i>near</i> or
2170f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <i>far</i> measurement. In this case, the sensor should report its
2180f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * {@link android.hardware.Sensor#getMaximumRange() maximum range} value in
2190f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * the <i>far</i> state and a lesser value in the <i>near</i> state.
2200f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
2210f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
2227a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  <h4>{@link android.hardware.Sensor#TYPE_GRAVITY Sensor.TYPE_GRAVITY}:</h4>
2237badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>A three dimensional vector indicating the direction and magnitude of gravity.  Units
2247badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  are m/s^2. The coordinate system is the same as is used by the acceleration sensor.</p>
2257badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p><b>Note:</b> When the device is at rest, the output of the gravity sensor should be identical
2267badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  to that of the accelerometer.</p>
2277a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *
2287a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  <h4>{@link android.hardware.Sensor#TYPE_LINEAR_ACCELERATION Sensor.TYPE_LINEAR_ACCELERATION}:</h4>
2297a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  A three dimensional vector indicating acceleration along each device axis, not including
2307a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  gravity.  All values have units of m/s^2.  The coordinate system is the same as is used by the
2317badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  acceleration sensor.
2327badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>The output of the accelerometer, gravity and  linear-acceleration sensors must obey the
2337badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  following relation:</p>
2347badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *   <p><ul>acceleration = gravity + linear-acceleration</ul></p>
2357a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *
2367a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  <h4>{@link android.hardware.Sensor#TYPE_ROTATION_VECTOR Sensor.TYPE_ROTATION_VECTOR}:</h4>
2377badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>The rotation vector represents the orientation of the device as a combination of an <i>angle</i>
2387badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  and an <i>axis</i>, in which the device has rotated through an angle &#952 around an axis
2397badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  &lt;x, y, z>.</p>
2407badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>The three elements of the rotation vector are
2417badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  &lt;x*sin(&#952/2), y*sin(&#952/2), z*sin(&#952/2)>, such that the magnitude of the rotation
2427badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  vector is equal to sin(&#952/2), and the direction of the rotation vector is equal to the
2437badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  direction of the axis of rotation.</p>
2447badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  </p>The three elements of the rotation vector are equal to
2457badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  the last three components of a <b>unit</b> quaternion
2467badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  &lt;cos(&#952/2), x*sin(&#952/2), y*sin(&#952/2), z*sin(&#952/2)>.</p>
2477badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>Elements of the rotation vector are unitless.
2487badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  The x,y, and z axis are defined in the same way as the acceleration
2497badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  sensor.</p>
2507badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * <ul>
2517badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * <p>
2527badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * values[0]: x*sin(&#952/2)
2537badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * </p>
2547badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * <p>
2557badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * values[1]: y*sin(&#952/2)
2567badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * </p>
2577badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * <p>
2587badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * values[2]: z*sin(&#952/2)
2597badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * </p>
2607badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * <p>
2617badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * values[3]: cos(&#952/2) <i>(optional: only if value.length = 4)</i>
2627badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * </p>
2637badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * </ul>
2647a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *
2650f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_ORIENTATION
2660f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * Sensor.TYPE_ORIENTATION}:</h4> All values are angles in degrees.
2670f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
2680f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <ul>
2690f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <p>
2700f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * values[0]: Azimuth, angle between the magnetic north direction and the
2710f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * y-axis, around the z-axis (0 to 359). 0=North, 90=East, 180=South,
2720f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * 270=West
2730f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
2740f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
2750f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <p>
2760f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * values[1]: Pitch, rotation around x-axis (-180 to 180), with positive
2770f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * values when the z-axis moves <b>toward</b> the y-axis.
2780f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
2790f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
2800f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <p>
2810f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * values[2]: Roll, rotation around y-axis (-90 to 90), with positive values
2820f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * when the x-axis moves <b>toward</b> the z-axis.
2830f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
2840f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </ul>
2850f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
2860f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <p>
2870f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <b>Note:</b> This definition is different from <b>yaw, pitch and roll</b>
2880f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * used in aviation where the X axis is along the long side of the plane
2890f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * (tail to nose).
2900f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
2910f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
2920f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <p>
2930f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <b>Note:</b> This sensor type exists for legacy reasons, please use
2940f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * {@link android.hardware.SensorManager#getRotationMatrix
2950f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * getRotationMatrix()} in conjunction with
2960f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * {@link android.hardware.SensorManager#remapCoordinateSystem
2970f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * remapCoordinateSystem()} and
2980f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * {@link android.hardware.SensorManager#getOrientation getOrientation()} to
2990f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * compute these values instead.
3000f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
3010f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
3020f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <p>
3030f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <b>Important note:</b> For historical reasons the roll angle is positive
3040f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * in the clockwise direction (mathematically speaking, it should be
3050f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * positive in the counter-clockwise direction).
3060f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
3070f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
3080f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * @see SensorEvent
3090f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * @see GeomagneticField
3104115c518753052add46b017bb3044da6f6169a7bMike Lockwood     */
3117a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell
3129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final float[] values;
3139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
31574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * The sensor that generated this event. See
31674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * {@link android.hardware.SensorManager SensorManager} for details.
3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
31874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian   public Sensor sensor;
31974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian
3209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
32174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * The accuracy of this event. See {@link android.hardware.SensorManager
32274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * SensorManager} for details.
3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int accuracy;
32574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian
32674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian
3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The time in nanosecond at which the event happened
3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public long timestamp;
3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
33274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian
3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    SensorEvent(int size) {
3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        values = new float[size];
3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
3369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
337