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 * This class represents a {@link android.hardware.Sensor Sensor} event and
2174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * holds informations such as the sensor's type, the time-stamp, accuracy and of
2274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * course the sensor's {@link SensorEvent#values data}.
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
2474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <p>
2574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <u>Definition of the coordinate system used by the SensorEvent API.</u>
2674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * </p>
2774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian *
2874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <p>
290f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * The coordinate-system is defined relative to the screen of the phone in its
3074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * default orientation. The axes are not swapped when the device's screen
3174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * orientation changes.
3274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * </p>
3374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian *
3474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <p>
350f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * The X axis is horizontal and points to the right, the Y axis is vertical and
360f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * points up and the Z axis points towards the outside of the front face of the
370f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * screen. In this system, coordinates behind the screen have negative Z values.
380f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * </p>
390f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian *
400f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * <p>
410f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * <center><img src="../../../images/axis_device.png"
420f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * alt="Sensors coordinate-system diagram." border="0" /></center>
4374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * </p>
4474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian *
4574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * <p>
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <b>Note:</b> This coordinate system is different from the one used in the
4774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * Android 2D APIs where the origin is in the top-left corner.
4874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian * </p>
499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
500f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * @see SensorManager
510f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * @see SensorEvent
520f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian * @see Sensor
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class SensorEvent {
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
590f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * The length and contents of the {@link #values values} array depends on
600f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * which {@link android.hardware.Sensor sensor} type is being monitored (see
610f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * also {@link SensorEvent} for a definition of the coordinate system used).
6274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </p>
6374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     *
640f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_ACCELEROMETER
650f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * Sensor.TYPE_ACCELEROMETER}:</h4> All values are in SI units (m/s^2)
665d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
6774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <ul>
689a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[0]: Acceleration minus Gx on the x-axis </li>
699a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[1]: Acceleration minus Gy on the y-axis </li>
709a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[2]: Acceleration minus Gz on the z-axis </li>
7174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </ul>
725d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
7374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
740f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * A sensor of this type measures the acceleration applied to the device
750f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * (<b>Ad</b>). Conceptually, it does so by measuring forces applied to the
760f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * sensor itself (<b>Fs</b>) using the relation:
770f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
785d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
79612ff27425cf2976396d992f32b58ab900c7d708Brad Fitzpatrick     * <b><center>Ad = - &#8721;Fs / mass</center></b>
805d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
8174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
820f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * In particular, the force of gravity is always influencing the measured
830f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * acceleration:
840f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
855d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
86612ff27425cf2976396d992f32b58ab900c7d708Brad Fitzpatrick     * <b><center>Ad = -g - &#8721;F / mass</center></b>
875d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
8874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
890f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * For this reason, when the device is sitting on a table (and obviously not
900f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * accelerating), the accelerometer reads a magnitude of <b>g</b> = 9.81
910f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * m/s^2
920f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
935d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
9474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
950f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * Similarly, when the device is in free-fall and therefore dangerously
960f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * accelerating towards to ground at 9.81 m/s^2, its accelerometer reads a
970f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * magnitude of 0 m/s^2.
980f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
995d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
10074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
1010f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * It should be apparent that in order to measure the real acceleration of
1020f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * the device, the contribution of the force of gravity must be eliminated.
1030f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * This can be achieved by applying a <i>high-pass</i> filter. Conversely, a
1040f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <i>low-pass</i> filter can be used to isolate the force of gravity.
1050f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
106fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
107fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <pre class="prettyprint">
108fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
109fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     public void onSensorChanged(SensorEvent event)
110fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     {
111fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          // alpha is calculated as t / (t + dT)
112fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          // with t, the low-pass filter's time-constant
113fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          // and dT, the event delivery rate
114fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
115fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          final float alpha = 0.8;
116fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
117d11ee90b6ed54421f0016ffb7de77e5c812bc17fScott Main     *          gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
118d11ee90b6ed54421f0016ffb7de77e5c812bc17fScott Main     *          gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
119d11ee90b6ed54421f0016ffb7de77e5c812bc17fScott Main     *          gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
120fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
121d11ee90b6ed54421f0016ffb7de77e5c812bc17fScott Main     *          linear_acceleration[0] = event.values[0] - gravity[0];
122d11ee90b6ed54421f0016ffb7de77e5c812bc17fScott Main     *          linear_acceleration[1] = event.values[1] - gravity[1];
123d11ee90b6ed54421f0016ffb7de77e5c812bc17fScott Main     *          linear_acceleration[2] = event.values[2] - gravity[2];
124fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     }
125fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </pre>
126fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *
12774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
12874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <u>Examples</u>:
12974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <ul>
13074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <li>When the device lies flat on a table and is pushed on its left side
13174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * toward the right, the x acceleration value is positive.</li>
1325d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
13374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <li>When the device lies flat on a table, the acceleration value is
13474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * +9.81, which correspond to the acceleration of the device (0 m/s^2) minus
13574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * the force of gravity (-9.81 m/s^2).</li>
1365d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
13774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <li>When the device lies flat on a table and is pushed toward the sky
13874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * with an acceleration of A m/s^2, the acceleration value is equal to
13974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * A+9.81 which correspond to the acceleration of the device (+A m/s^2)
14074cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * minus the force of gravity (-9.81 m/s^2).</li>
14174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </ul>
1425d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
1435d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
1440f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD
1450f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * Sensor.TYPE_MAGNETIC_FIELD}:</h4>
14674cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * All values are in micro-Tesla (uT) and measure the ambient magnetic field
14774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * in the X, Y and Z axis.
1485d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
149ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_GYROSCOPE Sensor.TYPE_GYROSCOPE}:
150ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * </h4> All values are in radians/second and measure the rate of rotation
151ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * around the device's local X, Y and Z axis. The coordinate system is the
152ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * same as is used for the acceleration sensor. Rotation is positive in the
153ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * counter-clockwise direction. That is, an observer looking from some
154ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * positive location on the x, y or z axis at a device positioned on the
155ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * origin would report positive rotation if the device appeared to be
156ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * rotating counter clockwise. Note that this is the standard mathematical
157ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * definition of positive rotation and does not agree with the definition of
158ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * roll given earlier.
159fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <ul>
1609a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[0]: Angular speed around the x-axis </li>
1619a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[1]: Angular speed around the y-axis </li>
1629a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[2]: Angular speed around the z-axis </li>
163fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </ul>
164fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <p>
165ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * Typically the output of the gyroscope is integrated over time to
166ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * calculate a rotation describing the change of angles over the timestep,
167ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * for example:
168fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </p>
169ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *
170fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * <pre class="prettyprint">
171fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     private static final float NS2S = 1.0f / 1000000000.0f;
172ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *     private final float[] deltaRotationVector = new float[4]();
173fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     private float timestamp;
174ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *
175ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *     public void onSensorChanged(SensorEvent event) {
176ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *          // This timestep's delta rotation to be multiplied by the current rotation
177ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *          // after computing it from the gyro sample data.
178fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          if (timestamp != 0) {
179fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *              final float dT = (event.timestamp - timestamp) * NS2S;
180ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              // Axis of the rotation sample, not normalized yet.
181ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              float axisX = event.values[0];
182ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              float axisY = event.values[1];
183ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              float axisZ = event.values[2];
184ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *
185ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              // Calculate the angular speed of the sample
186ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              float omegaMagnitude = sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
187ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *
188ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              // Normalize the rotation vector if it's big enough to get the axis
189ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              if (omegaMagnitude > EPSILON) {
190ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *                  axisX /= omegaMagnitude;
191ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *                  axisY /= omegaMagnitude;
192ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *                  axisZ /= omegaMagnitude;
193ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              }
194ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *
195ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              // Integrate around this axis with the angular speed by the timestep
196ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              // in order to get a delta rotation from this sample over the timestep
197ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              // We will convert this axis-angle representation of the delta rotation
198ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              // into a quaternion before turning it into the rotation matrix.
199ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              float thetaOverTwo = omegaMagnitude * dT / 2.0f;
200ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              float sinThetaOverTwo = sin(thetaOverTwo);
201ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              float cosThetaOverTwo = cos(thetaOverTwo);
202ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              deltaRotationVector[0] = sinThetaOverTwo * axisX;
203ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              deltaRotationVector[1] = sinThetaOverTwo * axisY;
204ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              deltaRotationVector[2] = sinThetaOverTwo * axisZ;
205ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *              deltaRotationVector[3] = cosThetaOverTwo;
206fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          }
207fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *          timestamp = event.timestamp;
208ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *          float[] deltaRotationMatrix = new float[9];
209ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *          SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector);
210ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *          // User code should concatenate the delta rotation we computed with the current rotation
211ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *          // in order to get the updated rotation.
212ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     *          // rotationCurrent = rotationCurrent * deltaRotationMatrix;
213fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     *     }
214fa33565714e4192dbab446ee1fbccb87dd414bedMathias Agopian     * </pre>
215ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * <p>
216ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * In practice, the gyroscope noise and offset will introduce some errors
217ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * which need to be compensated for. This is usually done using the
218ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * information from other sensors, but is beyond the scope of this document.
219ad7f33a29c6ce41f2b662d1de9af7e9cf92f4dc9Mathias Agopian     * </p>
2200f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_LIGHT Sensor.TYPE_LIGHT}:</h4>
22174cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <ul>
2229a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li>values[0]: Ambient light level in SI lux units </li>
22374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </ul>
2245d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
2251260a89b54436fdd6d80e7c98b7db3c55f85104cMathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_PRESSURE Sensor.TYPE_PRESSURE}:</h4>
2261260a89b54436fdd6d80e7c98b7db3c55f85104cMathias Agopian     * <ul>
2279a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li>values[0]: Atmospheric pressure in hPa (millibar) </li>
2281260a89b54436fdd6d80e7c98b7db3c55f85104cMathias Agopian     * </ul>
2291260a89b54436fdd6d80e7c98b7db3c55f85104cMathias Agopian     *
2300f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_PROXIMITY Sensor.TYPE_PROXIMITY}:
2310f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </h4>
2325d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
23374cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <ul>
2349a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li>values[0]: Proximity sensor distance measured in centimeters </li>
23574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * </ul>
2365d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
23774cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * <p>
2380f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <b>Note:</b> Some proximity sensors only support a binary <i>near</i> or
2390f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <i>far</i> measurement. In this case, the sensor should report its
2400f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * {@link android.hardware.Sensor#getMaximumRange() maximum range} value in
2410f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * the <i>far</i> state and a lesser value in the <i>near</i> state.
2420f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
2435d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
2447a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  <h4>{@link android.hardware.Sensor#TYPE_GRAVITY Sensor.TYPE_GRAVITY}:</h4>
2457badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>A three dimensional vector indicating the direction and magnitude of gravity.  Units
2467badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  are m/s^2. The coordinate system is the same as is used by the acceleration sensor.</p>
2477badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p><b>Note:</b> When the device is at rest, the output of the gravity sensor should be identical
2487badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  to that of the accelerometer.</p>
2497a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *
2507a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  <h4>{@link android.hardware.Sensor#TYPE_LINEAR_ACCELERATION Sensor.TYPE_LINEAR_ACCELERATION}:</h4>
2517a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  A three dimensional vector indicating acceleration along each device axis, not including
2527a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  gravity.  All values have units of m/s^2.  The coordinate system is the same as is used by the
2537badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  acceleration sensor.
2547badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>The output of the accelerometer, gravity and  linear-acceleration sensors must obey the
2557badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  following relation:</p>
2567badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *   <p><ul>acceleration = gravity + linear-acceleration</ul></p>
2577a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *
2587a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *  <h4>{@link android.hardware.Sensor#TYPE_ROTATION_VECTOR Sensor.TYPE_ROTATION_VECTOR}:</h4>
2597badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>The rotation vector represents the orientation of the device as a combination of an <i>angle</i>
2607badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  and an <i>axis</i>, in which the device has rotated through an angle &#952 around an axis
2617badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  &lt;x, y, z>.</p>
2627badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>The three elements of the rotation vector are
2637badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  &lt;x*sin(&#952/2), y*sin(&#952/2), z*sin(&#952/2)>, such that the magnitude of the rotation
2647badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  vector is equal to sin(&#952/2), and the direction of the rotation vector is equal to the
2657badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  direction of the axis of rotation.</p>
2667badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  </p>The three elements of the rotation vector are equal to
2677badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  the last three components of a <b>unit</b> quaternion
2687badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  &lt;cos(&#952/2), x*sin(&#952/2), y*sin(&#952/2), z*sin(&#952/2)>.</p>
2697badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  <p>Elements of the rotation vector are unitless.
2707badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  The x,y, and z axis are defined in the same way as the acceleration
2717badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     *  sensor.</p>
272d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     *  The reference coordinate system is defined as a direct orthonormal basis,
273d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     *  where:
274d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * </p>
275d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     *
276d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * <ul>
277d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * <li>X is defined as the vector product <b>Y.Z</b> (It is tangential to
278d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * the ground at the device's current location and roughly points East).</li>
279d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * <li>Y is tangential to the ground at the device's current location and
28052bfc243684b2f340da326aaa38e9021e4e3b2e6Scott Main     * points towards magnetic north.</li>
281d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * <li>Z points towards the sky and is perpendicular to the ground.</li>
282d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * </ul>
283d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     *
284d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * <p>
285d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * <center><img src="../../../images/axis_globe.png"
286d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * alt="World coordinate-system diagram." border="0" /></center>
287d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     * </p>
288d84d2b7b1ee5c37da878534f4d493d8d00a3f65fMathias Agopian     *
2897badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * <ul>
2909a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[0]: x*sin(&#952/2) </li>
2919a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[1]: y*sin(&#952/2) </li>
2929a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[2]: z*sin(&#952/2) </li>
2936d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <li> values[3]: cos(&#952/2) </li>
2946d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <li> values[4]: estimated heading Accuracy (in radians) (-1 if unavailable)</li>
2957badd2c402f9e8e9fd13f6915ad2e32301f9f305Mathias Agopian     * </ul>
2966d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <p> values[3], originally optional, will always be present from SDK Level 18 onwards.
2976d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * values[4] is a new value that has been added in SDK Level 18.
2986d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * </p>
2997a0541d6b803da02b8724b1d140d6ccaaec23a36Kevin Powell     *
3000f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_ORIENTATION
3010f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * Sensor.TYPE_ORIENTATION}:</h4> All values are angles in degrees.
3025d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
3030f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <ul>
3049a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[0]: Azimuth, angle between the magnetic north direction and the
3050f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * y-axis, around the z-axis (0 to 359). 0=North, 90=East, 180=South,
3065d555a7b984c214882826f46f0b0db6b067743eckmccormick     * 270=West
3075d555a7b984c214882826f46f0b0db6b067743eckmccormick     * </p>
3085d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
3095d555a7b984c214882826f46f0b0db6b067743eckmccormick     * <p>
3105d555a7b984c214882826f46f0b0db6b067743eckmccormick     * values[1]: Pitch, rotation around x-axis (-180 to 180), with positive
3115d555a7b984c214882826f46f0b0db6b067743eckmccormick     * values when the z-axis moves <b>toward</b> the y-axis.
3125d555a7b984c214882826f46f0b0db6b067743eckmccormick     * </p>
3135d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
3145d555a7b984c214882826f46f0b0db6b067743eckmccormick     * <p>
3155d555a7b984c214882826f46f0b0db6b067743eckmccormick     * values[2]: Roll, rotation around the x-axis (-90 to 90)
3165d555a7b984c214882826f46f0b0db6b067743eckmccormick     * increasing as the device moves clockwise.
3175d555a7b984c214882826f46f0b0db6b067743eckmccormick     * </p>
3180f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </ul>
3195d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
3200f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <p>
3210f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <b>Note:</b> This definition is different from <b>yaw, pitch and roll</b>
3220f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * used in aviation where the X axis is along the long side of the plane
3230f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * (tail to nose).
3240f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
3255d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
3260f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <p>
3270f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <b>Note:</b> This sensor type exists for legacy reasons, please use
3280f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * {@link android.hardware.SensorManager#getRotationMatrix
3290f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * getRotationMatrix()} in conjunction with
3300f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * {@link android.hardware.SensorManager#remapCoordinateSystem
3310f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * remapCoordinateSystem()} and
3320f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * {@link android.hardware.SensorManager#getOrientation getOrientation()} to
3330f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * compute these values instead.
3340f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
3355d555a7b984c214882826f46f0b0db6b067743eckmccormick     *
3360f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <p>
3370f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * <b>Important note:</b> For historical reasons the roll angle is positive
3380f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * in the clockwise direction (mathematically speaking, it should be
3390f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * positive in the counter-clockwise direction).
3400f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     * </p>
3415819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     *
3425819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <h4>{@link android.hardware.Sensor#TYPE_RELATIVE_HUMIDITY
3435819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * Sensor.TYPE_RELATIVE_HUMIDITY}:</h4>
3445819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <ul>
3459a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[0]: Relative ambient air humidity in percent </li>
3465819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </ul>
3475819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <p>
3485819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * When relative ambient air humidity and ambient temperature are
3495819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * measured, the dew point and absolute humidity can be calculated.
3505819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </p>
3515819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <u>Dew Point</u>
3525819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <p>
3535819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * The dew point is the temperature to which a given parcel of air must be
3545819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * cooled, at constant barometric pressure, for water vapor to condense
3555819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * into water.
3565819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </p>
3575819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <center><pre>
3585819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     *                    ln(RH/100%) + m&#183;t/(T<sub>n</sub>+t)
3595819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * t<sub>d</sub>(t,RH) = T<sub>n</sub> &#183; ------------------------------
3605819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     *                 m - [ln(RH/100%) + m&#183;t/(T<sub>n</sub>+t)]
3615819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </pre></center>
3625819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dl>
3635819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>t<sub>d</sub></dt> <dd>dew point temperature in &deg;C</dd>
3645819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>t</dt>             <dd>actual temperature in &deg;C</dd>
3655819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>RH</dt>            <dd>actual relative humidity in %</dd>
3665819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>m</dt>             <dd>17.62</dd>
3675819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>T<sub>n</sub></dt> <dd>243.12 &deg;C</dd>
3685819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </dl>
3695819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <p>for example:</p>
3705819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <pre class="prettyprint">
3715819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * h = Math.log(rh / 100.0) + (17.62 * t) / (243.12 + t);
3725819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * td = 243.12 * h / (17.62 - h);
3735819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </pre>
3745819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <u>Absolute Humidity</u>
3755819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <p>
3765819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * The absolute humidity is the mass of water vapor in a particular volume
3775819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * of dry air. The unit is g/m<sup>3</sup>.
3785819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </p>
3795819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <center><pre>
3805819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     *                    RH/100%&#183;A&#183;exp(m&#183;t/(T<sub>n</sub>+t))
3815819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * d<sub>v</sub>(t,RH) = 216.7 &#183; -------------------------
3825819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     *                           273.15 + t
3835819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </pre></center>
3845819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dl>
3855819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>d<sub>v</sub></dt> <dd>absolute humidity in g/m<sup>3</sup></dd>
3865819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>t</dt>             <dd>actual temperature in &deg;C</dd>
3875819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>RH</dt>            <dd>actual relative humidity in %</dd>
3885819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>m</dt>             <dd>17.62</dd>
3895819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>T<sub>n</sub></dt> <dd>243.12 &deg;C</dd>
3905819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <dt>A</dt>             <dd>6.112 hPa</dd>
3915819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </dl>
3925819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <p>for example:</p>
3935819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * <pre class="prettyprint">
3945819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * dv = 216.7 *
3955819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * (rh / 100.0 * 6.112 * Math.exp(17.62 * t / (243.12 + t)) / (273.15 + t));
3965819051eee071d622e5cb1f32c74112b1c7b1072Urs Fleisch     * </pre>
3970f791a799dc81d93935fd2597297cf7ac2c0a044Mathias Agopian     *
398462db220a2986f7d9fc3d7e3e6af6615570eaa0bMathias Agopian     * <h4>{@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE Sensor.TYPE_AMBIENT_TEMPERATURE}:
399462db220a2986f7d9fc3d7e3e6af6615570eaa0bMathias Agopian     * </h4>
400462db220a2986f7d9fc3d7e3e6af6615570eaa0bMathias Agopian     *
401462db220a2986f7d9fc3d7e3e6af6615570eaa0bMathias Agopian     * <ul>
4029a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[0]: ambient (room) temperature in degree Celsius.</li>
403462db220a2986f7d9fc3d7e3e6af6615570eaa0bMathias Agopian     * </ul>
404462db220a2986f7d9fc3d7e3e6af6615570eaa0bMathias Agopian     *
4059a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     *
40692053f8b28ce0d035d292fa73622200990682511Scott Main     * <h4>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD_UNCALIBRATED
40792053f8b28ce0d035d292fa73622200990682511Scott Main     * Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED}:</h4>
4086d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * Similar to {@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD},
4096d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * but the hard iron calibration is reported separately instead of being included
4106d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * in the measurement. Factory calibration and temperature compensation will still
4116d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * be applied to the "uncalibrated" measurement. Assumptions that the magnetic field
4126d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * is due to the Earth's poles is avoided.
4136d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <p>
4146d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * The values array is shown below:
4156d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <ul>
4166d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <li> values[0] = x_uncalib </li>
4176d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <li> values[1] = y_uncalib </li>
4186d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <li> values[2] = z_uncalib </li>
4196d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <li> values[3] = x_bias </li>
4206d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <li> values[4] = y_bias </li>
4216d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <li> values[5] = z_bias </li>
4226d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * </ul>
4236d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * </p>
4246d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <p>
4256d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * x_uncalib, y_uncalib, z_uncalib are the measured magnetic field in X, Y, Z axes.
4266d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * Soft iron and temperature calibrations are applied. But the hard iron
4276d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * calibration is not applied. The values are in micro-Tesla (uT).
4286d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * </p>
4296d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <p>
4306d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * x_bias, y_bias, z_bias give the iron bias estimated in X, Y, Z axes.
4316d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * Each field is a component of the estimated hard iron calibration.
4326d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * The values are in micro-Tesla (uT).
4336d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * </p>
4346d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * <p> Hard iron - These distortions arise due to the magnetized iron, steel or permanenet
4356d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * magnets on the device.
4366d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * Soft iron - These distortions arise due to the interaction with the earth's magentic
4376d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * field.
4386d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * </p>
43992053f8b28ce0d035d292fa73622200990682511Scott Main     * <h4> {@link android.hardware.Sensor#TYPE_GAME_ROTATION_VECTOR}:</h4>
4406d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * Identical to {@link android.hardware.Sensor#TYPE_ROTATION_VECTOR} except that it
4416d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * doesn't use the geomagnetic field. Therefore the Y axis doesn't
4426d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * point north, but instead to some other reference, that reference is
4436d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * allowed to drift by the same order of magnitude as the gyroscope
4446d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * drift around the Z axis.
4459a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <p>
4466d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * In the ideal case, a phone rotated and returning to the same real-world
4476d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * orientation will report the same game rotation vector
4486d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * (without using the earth's geomagnetic field). However, the orientation
4496d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * may drift somewhat over time. See {@link android.hardware.Sensor#TYPE_ROTATION_VECTOR}
4506d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * for a detailed description of the values. This sensor will not have
4516d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh     * the estimated heading accuracy value.
4529a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * </p>
4539a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     *
45492053f8b28ce0d035d292fa73622200990682511Scott Main     * <h4> {@link android.hardware.Sensor#TYPE_GYROSCOPE_UNCALIBRATED
45592053f8b28ce0d035d292fa73622200990682511Scott Main     * Sensor.TYPE_GYROSCOPE_UNCALIBRATED}:</h4>
4569a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * All values are in radians/second and measure the rate of rotation
4579a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * around the X, Y and Z axis. An estimation of the drift on each axis is
4589a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * reported as well.
4599a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <p>
4609a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * No gyro-drift compensation is performed. Factory calibration and temperature
4619a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * compensation is still applied to the rate of rotation (angular speeds).
4629a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * </p>
4639a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <p>
4649a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * The coordinate system is the same as is used for the
4659a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * {@link android.hardware.Sensor#TYPE_ACCELEROMETER}
4669a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * Rotation is positive in the counter-clockwise direction (right-hand rule).
4679a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * That is, an observer looking from some positive location on the x, y or z axis
4689a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * at a device positioned on the origin would report positive rotation if the device
4699a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * appeared to be rotating counter clockwise.
4709a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * The range would at least be 17.45 rad/s (ie: ~1000 deg/s).
4719a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <ul>
4729a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[0] : angular speed (w/o drift compensation) around the X axis in rad/s </li>
4739a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[1] : angular speed (w/o drift compensation) around the Y axis in rad/s </li>
4749a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[2] : angular speed (w/o drift compensation) around the Z axis in rad/s </li>
4759a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[3] : estimated drift around X axis in rad/s </li>
4769a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[4] : estimated drift around Y axis in rad/s </li>
4779a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * <li> values[5] : estimated drift around Z axis in rad/s </li>
4789a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * </ul>
4799a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh     * </p>
48092053f8b28ce0d035d292fa73622200990682511Scott Main     * <p><b>Pro Tip:</b> Always use the length of the values array while performing operations
48192053f8b28ce0d035d292fa73622200990682511Scott Main     * on it. In earlier versions, this used to be always 3 which has changed now. </p>
48292053f8b28ce0d035d292fa73622200990682511Scott Main     *
48392053f8b28ce0d035d292fa73622200990682511Scott Main     * @see GeomagneticField
4844115c518753052add46b017bb3044da6f6169a7bMike Lockwood     */
4859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public final float[] values;
4869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
48874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * The sensor that generated this event. See
48974cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * {@link android.hardware.SensorManager SensorManager} for details.
4909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4919a8df4dcf9f83c1cf0cd8dedeb51d1ff8a52a2b5Jaikumar Ganesh    public Sensor sensor;
49274cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian
4939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
49474cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * The accuracy of this event. See {@link android.hardware.SensorManager
49574cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian     * SensorManager} for details.
4969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int accuracy;
49874cde2cee9e53006a710f4e80700cd560c2d0e4dMathias Agopian
4999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The time in nanosecond at which the event happened
5019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public long timestamp;
5039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5046d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh    SensorEvent(int valueSize) {
5056d0c1d78f121d4f1b72973740e8b120c7def1dc0Jaikumar Ganesh        values = new float[valueSize];
5069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
508