blob: 9906331be4978acc99cf0774c95e192b9cc33d12 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.hardware;
18
Artur Satayev26958002019-12-10 17:47:52 +000019import android.compat.annotation.UnsupportedAppUsage;
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010020
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021/**
Mathias Agopian74cde2c2010-06-16 18:55:46 -070022 * This class represents a {@link android.hardware.Sensor Sensor} event and
Peng Xufb1c9412016-03-29 21:50:43 -070023 * holds information such as the sensor's type, the time-stamp, accuracy and of
Mathias Agopian74cde2c2010-06-16 18:55:46 -070024 * course the sensor's {@link SensorEvent#values data}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025 *
Mathias Agopian74cde2c2010-06-16 18:55:46 -070026 * <p>
27 * <u>Definition of the coordinate system used by the SensorEvent API.</u>
28 * </p>
29 *
30 * <p>
Mathias Agopian0f791a72010-06-22 21:55:01 -070031 * The coordinate-system is defined relative to the screen of the phone in its
Mathias Agopian74cde2c2010-06-16 18:55:46 -070032 * default orientation. The axes are not swapped when the device's screen
33 * orientation changes.
34 * </p>
35 *
36 * <p>
Mathias Agopian0f791a72010-06-22 21:55:01 -070037 * The X axis is horizontal and points to the right, the Y axis is vertical and
38 * points up and the Z axis points towards the outside of the front face of the
39 * screen. In this system, coordinates behind the screen have negative Z values.
40 * </p>
41 *
42 * <p>
43 * <center><img src="../../../images/axis_device.png"
44 * alt="Sensors coordinate-system diagram." border="0" /></center>
Mathias Agopian74cde2c2010-06-16 18:55:46 -070045 * </p>
46 *
47 * <p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 * <b>Note:</b> This coordinate system is different from the one used in the
Mathias Agopian74cde2c2010-06-16 18:55:46 -070049 * Android 2D APIs where the origin is in the top-left corner.
50 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 *
Mathias Agopian0f791a72010-06-22 21:55:01 -070052 * @see SensorManager
53 * @see SensorEvent
54 * @see Sensor
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 */
57
58public class SensorEvent {
59 /**
Mathias Agopian74cde2c2010-06-16 18:55:46 -070060 * <p>
Mathias Agopian0f791a72010-06-22 21:55:01 -070061 * The length and contents of the {@link #values values} array depends on
62 * which {@link android.hardware.Sensor sensor} type is being monitored (see
63 * also {@link SensorEvent} for a definition of the coordinate system used).
Mathias Agopian74cde2c2010-06-16 18:55:46 -070064 * </p>
Mathias Agopian210fc912010-02-26 13:51:39 -080065 *
Mathias Agopian0f791a72010-06-22 21:55:01 -070066 * <h4>{@link android.hardware.Sensor#TYPE_ACCELEROMETER
67 * Sensor.TYPE_ACCELEROMETER}:</h4> All values are in SI units (m/s^2)
kmccormick5d555a72013-04-24 16:52:43 -070068 *
Mathias Agopian74cde2c2010-06-16 18:55:46 -070069 * <ul>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -080070 * <li> values[0]: Acceleration minus Gx on the x-axis </li>
71 * <li> values[1]: Acceleration minus Gy on the y-axis </li>
72 * <li> values[2]: Acceleration minus Gz on the z-axis </li>
Mathias Agopian74cde2c2010-06-16 18:55:46 -070073 * </ul>
kmccormick5d555a72013-04-24 16:52:43 -070074 *
Mathias Agopian74cde2c2010-06-16 18:55:46 -070075 * <p>
Mathias Agopian0f791a72010-06-22 21:55:01 -070076 * A sensor of this type measures the acceleration applied to the device
77 * (<b>Ad</b>). Conceptually, it does so by measuring forces applied to the
78 * sensor itself (<b>Fs</b>) using the relation:
79 * </p>
kmccormick5d555a72013-04-24 16:52:43 -070080 *
Brad Fitzpatrick612ff272010-09-06 19:22:09 -070081 * <b><center>Ad = - &#8721;Fs / mass</center></b>
kmccormick5d555a72013-04-24 16:52:43 -070082 *
Mathias Agopian0f791a72010-06-22 21:55:01 -070083 * <p>
84 * In particular, the force of gravity is always influencing the measured
85 * acceleration:
86 * </p>
kmccormick5d555a72013-04-24 16:52:43 -070087 *
Brad Fitzpatrick612ff272010-09-06 19:22:09 -070088 * <b><center>Ad = -g - &#8721;F / mass</center></b>
kmccormick5d555a72013-04-24 16:52:43 -070089 *
Mathias Agopian0f791a72010-06-22 21:55:01 -070090 * <p>
91 * For this reason, when the device is sitting on a table (and obviously not
92 * accelerating), the accelerometer reads a magnitude of <b>g</b> = 9.81
93 * m/s^2
94 * </p>
kmccormick5d555a72013-04-24 16:52:43 -070095 *
Mathias Agopian0f791a72010-06-22 21:55:01 -070096 * <p>
97 * Similarly, when the device is in free-fall and therefore dangerously
98 * accelerating towards to ground at 9.81 m/s^2, its accelerometer reads a
99 * magnitude of 0 m/s^2.
100 * </p>
kmccormick5d555a72013-04-24 16:52:43 -0700101 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700102 * <p>
103 * It should be apparent that in order to measure the real acceleration of
104 * the device, the contribution of the force of gravity must be eliminated.
105 * This can be achieved by applying a <i>high-pass</i> filter. Conversely, a
106 * <i>low-pass</i> filter can be used to isolate the force of gravity.
107 * </p>
Mathias Agopianfa335652010-11-09 13:40:41 -0800108 *
109 * <pre class="prettyprint">
110 *
111 * public void onSensorChanged(SensorEvent event)
112 * {
113 * // alpha is calculated as t / (t + dT)
114 * // with t, the low-pass filter's time-constant
115 * // and dT, the event delivery rate
116 *
117 * final float alpha = 0.8;
118 *
Scott Maind11ee902011-02-23 10:55:17 -0800119 * gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
120 * gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
121 * gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
Mathias Agopianfa335652010-11-09 13:40:41 -0800122 *
Scott Maind11ee902011-02-23 10:55:17 -0800123 * linear_acceleration[0] = event.values[0] - gravity[0];
124 * linear_acceleration[1] = event.values[1] - gravity[1];
125 * linear_acceleration[2] = event.values[2] - gravity[2];
Mathias Agopianfa335652010-11-09 13:40:41 -0800126 * }
127 * </pre>
128 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700129 * <p>
130 * <u>Examples</u>:
131 * <ul>
132 * <li>When the device lies flat on a table and is pushed on its left side
133 * toward the right, the x acceleration value is positive.</li>
kmccormick5d555a72013-04-24 16:52:43 -0700134 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700135 * <li>When the device lies flat on a table, the acceleration value is
136 * +9.81, which correspond to the acceleration of the device (0 m/s^2) minus
137 * the force of gravity (-9.81 m/s^2).</li>
kmccormick5d555a72013-04-24 16:52:43 -0700138 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700139 * <li>When the device lies flat on a table and is pushed toward the sky
140 * with an acceleration of A m/s^2, the acceleration value is equal to
141 * A+9.81 which correspond to the acceleration of the device (+A m/s^2)
142 * minus the force of gravity (-9.81 m/s^2).</li>
143 * </ul>
kmccormick5d555a72013-04-24 16:52:43 -0700144 *
145 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700146 * <h4>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD
147 * Sensor.TYPE_MAGNETIC_FIELD}:</h4>
148 * All values are in micro-Tesla (uT) and measure the ambient magnetic field
149 * in the X, Y and Z axis.
kmccormick5d555a72013-04-24 16:52:43 -0700150 *
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700151 * <h4>{@link android.hardware.Sensor#TYPE_GYROSCOPE Sensor.TYPE_GYROSCOPE}:
152 * </h4> All values are in radians/second and measure the rate of rotation
153 * around the device's local X, Y and Z axis. The coordinate system is the
154 * same as is used for the acceleration sensor. Rotation is positive in the
155 * counter-clockwise direction. That is, an observer looking from some
156 * positive location on the x, y or z axis at a device positioned on the
157 * origin would report positive rotation if the device appeared to be
158 * rotating counter clockwise. Note that this is the standard mathematical
159 * definition of positive rotation and does not agree with the definition of
160 * roll given earlier.
Mathias Agopianfa335652010-11-09 13:40:41 -0800161 * <ul>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800162 * <li> values[0]: Angular speed around the x-axis </li>
163 * <li> values[1]: Angular speed around the y-axis </li>
164 * <li> values[2]: Angular speed around the z-axis </li>
Mathias Agopianfa335652010-11-09 13:40:41 -0800165 * </ul>
166 * <p>
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700167 * Typically the output of the gyroscope is integrated over time to
Peng Xufb1c9412016-03-29 21:50:43 -0700168 * calculate a rotation describing the change of angles over the time step,
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700169 * for example:
Mathias Agopianfa335652010-11-09 13:40:41 -0800170 * </p>
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700171 *
Mathias Agopianfa335652010-11-09 13:40:41 -0800172 * <pre class="prettyprint">
173 * private static final float NS2S = 1.0f / 1000000000.0f;
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700174 * private final float[] deltaRotationVector = new float[4]();
Mathias Agopianfa335652010-11-09 13:40:41 -0800175 * private float timestamp;
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700176 *
177 * public void onSensorChanged(SensorEvent event) {
Peng Xufb1c9412016-03-29 21:50:43 -0700178 * // This time step's delta rotation to be multiplied by the current rotation
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700179 * // after computing it from the gyro sample data.
Mathias Agopianfa335652010-11-09 13:40:41 -0800180 * if (timestamp != 0) {
181 * final float dT = (event.timestamp - timestamp) * NS2S;
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700182 * // Axis of the rotation sample, not normalized yet.
183 * float axisX = event.values[0];
184 * float axisY = event.values[1];
185 * float axisZ = event.values[2];
186 *
187 * // Calculate the angular speed of the sample
188 * float omegaMagnitude = sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
189 *
190 * // Normalize the rotation vector if it's big enough to get the axis
191 * if (omegaMagnitude > EPSILON) {
192 * axisX /= omegaMagnitude;
193 * axisY /= omegaMagnitude;
194 * axisZ /= omegaMagnitude;
195 * }
196 *
Peng Xufb1c9412016-03-29 21:50:43 -0700197 * // Integrate around this axis with the angular speed by the time step
198 * // in order to get a delta rotation from this sample over the time step
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700199 * // We will convert this axis-angle representation of the delta rotation
200 * // into a quaternion before turning it into the rotation matrix.
201 * float thetaOverTwo = omegaMagnitude * dT / 2.0f;
202 * float sinThetaOverTwo = sin(thetaOverTwo);
203 * float cosThetaOverTwo = cos(thetaOverTwo);
204 * deltaRotationVector[0] = sinThetaOverTwo * axisX;
205 * deltaRotationVector[1] = sinThetaOverTwo * axisY;
206 * deltaRotationVector[2] = sinThetaOverTwo * axisZ;
207 * deltaRotationVector[3] = cosThetaOverTwo;
Mathias Agopianfa335652010-11-09 13:40:41 -0800208 * }
209 * timestamp = event.timestamp;
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700210 * float[] deltaRotationMatrix = new float[9];
211 * SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector);
Peng Xu62f2c872017-09-22 11:50:33 -0700212 * // User code should concatenate the delta rotation we computed with the current
213 * // rotation in order to get the updated rotation.
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700214 * // rotationCurrent = rotationCurrent * deltaRotationMatrix;
Mathias Agopianfa335652010-11-09 13:40:41 -0800215 * }
216 * </pre>
Mathias Agopianad7f33a2011-09-07 15:56:03 -0700217 * <p>
218 * In practice, the gyroscope noise and offset will introduce some errors
219 * which need to be compensated for. This is usually done using the
220 * information from other sensors, but is beyond the scope of this document.
221 * </p>
Mathias Agopian0f791a72010-06-22 21:55:01 -0700222 * <h4>{@link android.hardware.Sensor#TYPE_LIGHT Sensor.TYPE_LIGHT}:</h4>
Mathias Agopian0f791a72010-06-22 21:55:01 -0700223 * <ul>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800224 * <li>values[0]: Ambient light level in SI lux units </li>
Mathias Agopian0f791a72010-06-22 21:55:01 -0700225 * </ul>
kmccormick5d555a72013-04-24 16:52:43 -0700226 *
Mathias Agopian1260a892011-05-02 18:57:38 -0700227 * <h4>{@link android.hardware.Sensor#TYPE_PRESSURE Sensor.TYPE_PRESSURE}:</h4>
228 * <ul>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800229 * <li>values[0]: Atmospheric pressure in hPa (millibar) </li>
Mathias Agopian1260a892011-05-02 18:57:38 -0700230 * </ul>
231 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700232 * <h4>{@link android.hardware.Sensor#TYPE_PROXIMITY Sensor.TYPE_PROXIMITY}:
233 * </h4>
kmccormick5d555a72013-04-24 16:52:43 -0700234 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700235 * <ul>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800236 * <li>values[0]: Proximity sensor distance measured in centimeters </li>
Mathias Agopian0f791a72010-06-22 21:55:01 -0700237 * </ul>
kmccormick5d555a72013-04-24 16:52:43 -0700238 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700239 * <p>
240 * <b>Note:</b> Some proximity sensors only support a binary <i>near</i> or
241 * <i>far</i> measurement. In this case, the sensor should report its
242 * {@link android.hardware.Sensor#getMaximumRange() maximum range} value in
243 * the <i>far</i> state and a lesser value in the <i>near</i> state.
244 * </p>
kmccormick5d555a72013-04-24 16:52:43 -0700245 *
Kevin Powell7a0541d2010-07-19 19:10:40 -0700246 * <h4>{@link android.hardware.Sensor#TYPE_GRAVITY Sensor.TYPE_GRAVITY}:</h4>
Mathias Agopian7badd2c2010-11-22 15:48:10 -0800247 * <p>A three dimensional vector indicating the direction and magnitude of gravity. Units
248 * are m/s^2. The coordinate system is the same as is used by the acceleration sensor.</p>
Peng Xu62f2c872017-09-22 11:50:33 -0700249 * <p><b>Note:</b> When the device is at rest, the output of the gravity sensor should be
250 * identical to that of the accelerometer.</p>
Kevin Powell7a0541d2010-07-19 19:10:40 -0700251 *
Peng Xu62f2c872017-09-22 11:50:33 -0700252 * <h4>
253 * {@link android.hardware.Sensor#TYPE_LINEAR_ACCELERATION Sensor.TYPE_LINEAR_ACCELERATION}:
254 * </h4> A three dimensional vector indicating acceleration along each device axis, not
255 * including gravity. All values have units of m/s^2. The coordinate system is the same as is
256 * used by the acceleration sensor.
Mathias Agopian7badd2c2010-11-22 15:48:10 -0800257 * <p>The output of the accelerometer, gravity and linear-acceleration sensors must obey the
258 * following relation:</p>
Peng Xu62f2c872017-09-22 11:50:33 -0700259 * <p><ul>acceleration = gravity + linear-acceleration</ul></p>
Kevin Powell7a0541d2010-07-19 19:10:40 -0700260 *
261 * <h4>{@link android.hardware.Sensor#TYPE_ROTATION_VECTOR Sensor.TYPE_ROTATION_VECTOR}:</h4>
Peng Xu62f2c872017-09-22 11:50:33 -0700262 * <p>The rotation vector represents the orientation of the device as a combination of an
263 * <i>angle</i> and an <i>axis</i>, in which the device has rotated through an angle &#952
264 * around an axis &lt;x, y, z>.</p>
Mathias Agopian7badd2c2010-11-22 15:48:10 -0800265 * <p>The three elements of the rotation vector are
266 * &lt;x*sin(&#952/2), y*sin(&#952/2), z*sin(&#952/2)>, such that the magnitude of the rotation
267 * vector is equal to sin(&#952/2), and the direction of the rotation vector is equal to the
268 * direction of the axis of rotation.</p>
269 * </p>The three elements of the rotation vector are equal to
270 * the last three components of a <b>unit</b> quaternion
271 * &lt;cos(&#952/2), x*sin(&#952/2), y*sin(&#952/2), z*sin(&#952/2)>.</p>
272 * <p>Elements of the rotation vector are unitless.
273 * The x,y, and z axis are defined in the same way as the acceleration
274 * sensor.</p>
Mathias Agopiand84d2b7b2011-05-02 19:08:53 -0700275 * The reference coordinate system is defined as a direct orthonormal basis,
276 * where:
277 * </p>
278 *
279 * <ul>
280 * <li>X is defined as the vector product <b>Y.Z</b> (It is tangential to
281 * the ground at the device's current location and roughly points East).</li>
282 * <li>Y is tangential to the ground at the device's current location and
Scott Main52bfc242012-02-09 10:09:14 -0800283 * points towards magnetic north.</li>
Mathias Agopiand84d2b7b2011-05-02 19:08:53 -0700284 * <li>Z points towards the sky and is perpendicular to the ground.</li>
285 * </ul>
286 *
287 * <p>
288 * <center><img src="../../../images/axis_globe.png"
289 * alt="World coordinate-system diagram." border="0" /></center>
290 * </p>
291 *
Mathias Agopian7badd2c2010-11-22 15:48:10 -0800292 * <ul>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800293 * <li> values[0]: x*sin(&#952/2) </li>
294 * <li> values[1]: y*sin(&#952/2) </li>
295 * <li> values[2]: z*sin(&#952/2) </li>
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700296 * <li> values[3]: cos(&#952/2) </li>
297 * <li> values[4]: estimated heading Accuracy (in radians) (-1 if unavailable)</li>
Mathias Agopian7badd2c2010-11-22 15:48:10 -0800298 * </ul>
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700299 * <p> values[3], originally optional, will always be present from SDK Level 18 onwards.
300 * values[4] is a new value that has been added in SDK Level 18.
301 * </p>
Kevin Powell7a0541d2010-07-19 19:10:40 -0700302 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700303 * <h4>{@link android.hardware.Sensor#TYPE_ORIENTATION
304 * Sensor.TYPE_ORIENTATION}:</h4> All values are angles in degrees.
kmccormick5d555a72013-04-24 16:52:43 -0700305 *
Mathias Agopian0f791a72010-06-22 21:55:01 -0700306 * <ul>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800307 * <li> values[0]: Azimuth, angle between the magnetic north direction and the
Mathias Agopian0f791a72010-06-22 21:55:01 -0700308 * y-axis, around the z-axis (0 to 359). 0=North, 90=East, 180=South,
kmccormick5d555a72013-04-24 16:52:43 -0700309 * 270=West
310 * </p>
311 *
312 * <p>
313 * values[1]: Pitch, rotation around x-axis (-180 to 180), with positive
314 * values when the z-axis moves <b>toward</b> the y-axis.
315 * </p>
316 *
317 * <p>
Peng Xuca09d8c2015-05-21 18:06:06 -0700318 * values[2]: Roll, rotation around the y-axis (-90 to 90)
kmccormick5d555a72013-04-24 16:52:43 -0700319 * increasing as the device moves clockwise.
320 * </p>
Mathias Agopian0f791a72010-06-22 21:55:01 -0700321 * </ul>
kmccormick5d555a72013-04-24 16:52:43 -0700322 *
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700323 * <p>
324 * <b>Note:</b> This definition is different from <b>yaw, pitch and roll</b>
325 * used in aviation where the X axis is along the long side of the plane
326 * (tail to nose).
Mathias Agopian0f791a72010-06-22 21:55:01 -0700327 * </p>
kmccormick5d555a72013-04-24 16:52:43 -0700328 *
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700329 * <p>
330 * <b>Note:</b> This sensor type exists for legacy reasons, please use
Peng Xuca09d8c2015-05-21 18:06:06 -0700331 * {@link android.hardware.Sensor#TYPE_ROTATION_VECTOR
332 * rotation vector sensor type} and
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700333 * {@link android.hardware.SensorManager#getRotationMatrix
334 * getRotationMatrix()} in conjunction with
335 * {@link android.hardware.SensorManager#remapCoordinateSystem
336 * remapCoordinateSystem()} and
337 * {@link android.hardware.SensorManager#getOrientation getOrientation()} to
338 * compute these values instead.
Mathias Agopian0f791a72010-06-22 21:55:01 -0700339 * </p>
kmccormick5d555a72013-04-24 16:52:43 -0700340 *
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700341 * <p>
Mathias Agopian0f791a72010-06-22 21:55:01 -0700342 * <b>Important note:</b> For historical reasons the roll angle is positive
343 * in the clockwise direction (mathematically speaking, it should be
344 * positive in the counter-clockwise direction).
345 * </p>
Urs Fleisch58190512010-12-29 17:02:02 +0100346 *
347 * <h4>{@link android.hardware.Sensor#TYPE_RELATIVE_HUMIDITY
348 * Sensor.TYPE_RELATIVE_HUMIDITY}:</h4>
349 * <ul>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800350 * <li> values[0]: Relative ambient air humidity in percent </li>
Urs Fleisch58190512010-12-29 17:02:02 +0100351 * </ul>
352 * <p>
353 * When relative ambient air humidity and ambient temperature are
354 * measured, the dew point and absolute humidity can be calculated.
355 * </p>
356 * <u>Dew Point</u>
357 * <p>
358 * The dew point is the temperature to which a given parcel of air must be
359 * cooled, at constant barometric pressure, for water vapor to condense
360 * into water.
361 * </p>
362 * <center><pre>
363 * ln(RH/100%) + m&#183;t/(T<sub>n</sub>+t)
364 * t<sub>d</sub>(t,RH) = T<sub>n</sub> &#183; ------------------------------
365 * m - [ln(RH/100%) + m&#183;t/(T<sub>n</sub>+t)]
366 * </pre></center>
367 * <dl>
368 * <dt>t<sub>d</sub></dt> <dd>dew point temperature in &deg;C</dd>
369 * <dt>t</dt> <dd>actual temperature in &deg;C</dd>
370 * <dt>RH</dt> <dd>actual relative humidity in %</dd>
371 * <dt>m</dt> <dd>17.62</dd>
372 * <dt>T<sub>n</sub></dt> <dd>243.12 &deg;C</dd>
373 * </dl>
374 * <p>for example:</p>
375 * <pre class="prettyprint">
376 * h = Math.log(rh / 100.0) + (17.62 * t) / (243.12 + t);
377 * td = 243.12 * h / (17.62 - h);
378 * </pre>
379 * <u>Absolute Humidity</u>
380 * <p>
381 * The absolute humidity is the mass of water vapor in a particular volume
382 * of dry air. The unit is g/m<sup>3</sup>.
383 * </p>
384 * <center><pre>
385 * RH/100%&#183;A&#183;exp(m&#183;t/(T<sub>n</sub>+t))
386 * d<sub>v</sub>(t,RH) = 216.7 &#183; -------------------------
387 * 273.15 + t
388 * </pre></center>
389 * <dl>
390 * <dt>d<sub>v</sub></dt> <dd>absolute humidity in g/m<sup>3</sup></dd>
391 * <dt>t</dt> <dd>actual temperature in &deg;C</dd>
392 * <dt>RH</dt> <dd>actual relative humidity in %</dd>
393 * <dt>m</dt> <dd>17.62</dd>
394 * <dt>T<sub>n</sub></dt> <dd>243.12 &deg;C</dd>
395 * <dt>A</dt> <dd>6.112 hPa</dd>
396 * </dl>
397 * <p>for example:</p>
398 * <pre class="prettyprint">
399 * dv = 216.7 *
400 * (rh / 100.0 * 6.112 * Math.exp(17.62 * t / (243.12 + t)) / (273.15 + t));
401 * </pre>
Ashutosh Joshiaf1a2662016-01-25 20:24:20 -0800402 *
Mathias Agopian462db222011-03-22 18:44:26 -0700403 * <h4>{@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE Sensor.TYPE_AMBIENT_TEMPERATURE}:
404 * </h4>
405 *
406 * <ul>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800407 * <li> values[0]: ambient (room) temperature in degree Celsius.</li>
Mathias Agopian462db222011-03-22 18:44:26 -0700408 * </ul>
409 *
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800410 *
Scott Main92053f82013-06-13 16:32:50 -0700411 * <h4>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD_UNCALIBRATED
412 * Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED}:</h4>
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700413 * Similar to {@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD},
414 * but the hard iron calibration is reported separately instead of being included
415 * in the measurement. Factory calibration and temperature compensation will still
416 * be applied to the "uncalibrated" measurement. Assumptions that the magnetic field
417 * is due to the Earth's poles is avoided.
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800418 * <p>
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700419 * The values array is shown below:
420 * <ul>
421 * <li> values[0] = x_uncalib </li>
422 * <li> values[1] = y_uncalib </li>
423 * <li> values[2] = z_uncalib </li>
424 * <li> values[3] = x_bias </li>
425 * <li> values[4] = y_bias </li>
426 * <li> values[5] = z_bias </li>
427 * </ul>
428 * </p>
429 * <p>
430 * x_uncalib, y_uncalib, z_uncalib are the measured magnetic field in X, Y, Z axes.
431 * Soft iron and temperature calibrations are applied. But the hard iron
432 * calibration is not applied. The values are in micro-Tesla (uT).
433 * </p>
434 * <p>
435 * x_bias, y_bias, z_bias give the iron bias estimated in X, Y, Z axes.
436 * Each field is a component of the estimated hard iron calibration.
437 * The values are in micro-Tesla (uT).
438 * </p>
Peng Xufb1c9412016-03-29 21:50:43 -0700439 * <p> Hard iron - These distortions arise due to the magnetized iron, steel or permanent
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700440 * magnets on the device.
Peng Xufb1c9412016-03-29 21:50:43 -0700441 * Soft iron - These distortions arise due to the interaction with the earth's magnetic
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700442 * field.
443 * </p>
Ashutosh Joshi576ea412017-01-13 17:06:41 -0800444 * <h4> {@link android.hardware.Sensor#TYPE_GAME_ROTATION_VECTOR
445 * Sensor.TYPE_GAME_ROTATION_VECTOR}:</h4>
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700446 * Identical to {@link android.hardware.Sensor#TYPE_ROTATION_VECTOR} except that it
447 * doesn't use the geomagnetic field. Therefore the Y axis doesn't
448 * point north, but instead to some other reference, that reference is
449 * allowed to drift by the same order of magnitude as the gyroscope
450 * drift around the Z axis.
451 * <p>
452 * In the ideal case, a phone rotated and returning to the same real-world
453 * orientation will report the same game rotation vector
454 * (without using the earth's geomagnetic field). However, the orientation
455 * may drift somewhat over time. See {@link android.hardware.Sensor#TYPE_ROTATION_VECTOR}
456 * for a detailed description of the values. This sensor will not have
457 * the estimated heading accuracy value.
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800458 * </p>
459 *
Scott Main92053f82013-06-13 16:32:50 -0700460 * <h4> {@link android.hardware.Sensor#TYPE_GYROSCOPE_UNCALIBRATED
461 * Sensor.TYPE_GYROSCOPE_UNCALIBRATED}:</h4>
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800462 * All values are in radians/second and measure the rate of rotation
463 * around the X, Y and Z axis. An estimation of the drift on each axis is
464 * reported as well.
465 * <p>
466 * No gyro-drift compensation is performed. Factory calibration and temperature
467 * compensation is still applied to the rate of rotation (angular speeds).
468 * </p>
469 * <p>
470 * The coordinate system is the same as is used for the
471 * {@link android.hardware.Sensor#TYPE_ACCELEROMETER}
472 * Rotation is positive in the counter-clockwise direction (right-hand rule).
473 * That is, an observer looking from some positive location on the x, y or z axis
474 * at a device positioned on the origin would report positive rotation if the device
475 * appeared to be rotating counter clockwise.
476 * The range would at least be 17.45 rad/s (ie: ~1000 deg/s).
477 * <ul>
478 * <li> values[0] : angular speed (w/o drift compensation) around the X axis in rad/s </li>
479 * <li> values[1] : angular speed (w/o drift compensation) around the Y axis in rad/s </li>
480 * <li> values[2] : angular speed (w/o drift compensation) around the Z axis in rad/s </li>
481 * <li> values[3] : estimated drift around X axis in rad/s </li>
482 * <li> values[4] : estimated drift around Y axis in rad/s </li>
483 * <li> values[5] : estimated drift around Z axis in rad/s </li>
484 * </ul>
485 * </p>
Scott Main92053f82013-06-13 16:32:50 -0700486 * <p><b>Pro Tip:</b> Always use the length of the values array while performing operations
487 * on it. In earlier versions, this used to be always 3 which has changed now. </p>
488 *
Ashutosh Joshi17efe022016-01-14 22:23:58 -0800489 * <h4>{@link android.hardware.Sensor#TYPE_POSE_6DOF
490 * Sensor.TYPE_POSE_6DOF}:</h4>
491 *
492 * A TYPE_POSE_6DOF event consists of a rotation expressed as a quaternion and a translation
493 * expressed in SI units. The event also contains a delta rotation and translation that show
494 * how the device?s pose has changed since the previous sequence numbered pose.
495 * The event uses the cannonical Android Sensor axes.
496 *
497 *
498 * <ul>
Peng Xufb1c9412016-03-29 21:50:43 -0700499 * <li> values[0]: x*sin(&#952/2) </li>
500 * <li> values[1]: y*sin(&#952/2) </li>
501 * <li> values[2]: z*sin(&#952/2) </li>
502 * <li> values[3]: cos(&#952/2) </li>
Ashutosh Joshi17efe022016-01-14 22:23:58 -0800503 *
504 *
505 * <li> values[4]: Translation along x axis from an arbitrary origin. </li>
Peng Xufb1c9412016-03-29 21:50:43 -0700506 * <li> values[5]: Translation along y axis from an arbitrary origin. </li>
Ashutosh Joshi17efe022016-01-14 22:23:58 -0800507 * <li> values[6]: Translation along z axis from an arbitrary origin. </li>
508 *
509 * <li> values[7]: Delta quaternion rotation x*sin(&#952/2) </li>
510 * <li> values[8]: Delta quaternion rotation y*sin(&#952/2) </li>
511 * <li> values[9]: Delta quaternion rotation z*sin(&#952/2) </li>
512 * <li> values[10]: Delta quaternion rotation cos(&#952/2) </li>
513 *
514 * <li> values[11]: Delta translation along x axis. </li>
515 * <li> values[12]: Delta translation along y axis. </li>
516 * <li> values[13]: Delta translation along z axis. </li>
517 *
518 * <li> values[14]: Sequence number </li>
519 *
520 * </ul>
521 *
Ashutosh Joshiaf1a2662016-01-25 20:24:20 -0800522 * <h4>{@link android.hardware.Sensor#TYPE_STATIONARY_DETECT
523 * Sensor.TYPE_STATIONARY_DETECT}:</h4>
524 *
525 * A TYPE_STATIONARY_DETECT event is produced if the device has been
526 * stationary for at least 5 seconds with a maximal latency of 5
527 * additional seconds. ie: it may take up anywhere from 5 to 10 seconds
528 * afte the device has been at rest to trigger this event.
529 *
530 * The only allowed value is 1.0.
531 *
532 * <ul>
533 * <li> values[0]: 1.0 </li>
534 * </ul>
535 *
536 * <h4>{@link android.hardware.Sensor#TYPE_MOTION_DETECT
537 * Sensor.TYPE_MOTION_DETECT}:</h4>
538 *
539 * A TYPE_MOTION_DETECT event is produced if the device has been in
540 * motion for at least 5 seconds with a maximal latency of 5
541 * additional seconds. ie: it may take up anywhere from 5 to 10 seconds
542 * afte the device has been at rest to trigger this event.
543 *
544 * The only allowed value is 1.0.
545 *
546 * <ul>
547 * <li> values[0]: 1.0 </li>
548 * </ul>
549 *
550 * <h4>{@link android.hardware.Sensor#TYPE_HEART_BEAT
551 * Sensor.TYPE_HEART_BEAT}:</h4>
552 *
553 * A sensor of this type returns an event everytime a hear beat peak is
554 * detected.
555 *
556 * Peak here ideally corresponds to the positive peak in the QRS complex of
557 * an ECG signal.
558 *
559 * <ul>
560 * <li> values[0]: confidence</li>
561 * </ul>
562 *
563 * <p>
564 * A confidence value of 0.0 indicates complete uncertainty - that a peak
565 * is as likely to be at the indicated timestamp as anywhere else.
566 * A confidence value of 1.0 indicates complete certainly - that a peak is
567 * completely unlikely to be anywhere else on the QRS complex.
568 * </p>
Ashutosh Joshie33eb922017-01-10 21:55:50 -0800569 *
Nick Vaccaro6432bf72017-01-12 21:09:37 -0800570 * <h4>{@link android.hardware.Sensor#TYPE_LOW_LATENCY_OFFBODY_DETECT
571 * Sensor.TYPE_LOW_LATENCY_OFFBODY_DETECT}:</h4>
572 *
573 * <p>
574 * A sensor of this type returns an event every time the device transitions
575 * from off-body to on-body and from on-body to off-body (e.g. a wearable
576 * device being removed from the wrist would trigger an event indicating an
577 * off-body transition). The event returned will contain a single value to
578 * indicate off-body state:
579 * </p>
580 *
581 * <ul>
582 * <li> values[0]: off-body state</li>
583 * </ul>
584 *
585 * <p>
586 * Valid values for off-body state:
587 * <ul>
588 * <li> 1.0 (device is on-body)</li>
589 * <li> 0.0 (device is off-body)</li>
590 * </ul>
591 * </p>
592 *
593 * <p>
594 * When a sensor of this type is activated, it must deliver the initial
595 * on-body or off-body event representing the current device state within
596 * 5 seconds of activating the sensor.
597 * </p>
598 *
599 * <p>
600 * This sensor must be able to detect and report an on-body to off-body
601 * transition within 1 second of the device being removed from the body,
602 * and must be able to detect and report an off-body to on-body transition
603 * within 5 seconds of the device being put back onto the body.
604 * </p>
605 *
Ashutosh Joshie33eb922017-01-10 21:55:50 -0800606 * <h4>{@link android.hardware.Sensor#TYPE_ACCELEROMETER_UNCALIBRATED
607 * Sensor.TYPE_ACCELEROMETER_UNCALIBRATED}:</h4> All values are in SI
608 * units (m/s^2)
609 *
610 * Similar to {@link android.hardware.Sensor#TYPE_ACCELEROMETER},
611 * Factory calibration and temperature compensation will still be applied
612 * to the "uncalibrated" measurement.
613 *
614 * <p>
615 * The values array is shown below:
616 * <ul>
617 * <li> values[0] = x_uncalib without bias compensation </li>
618 * <li> values[1] = y_uncalib without bias compensation </li>
619 * <li> values[2] = z_uncalib without bias compensation </li>
620 * <li> values[3] = estimated x_bias </li>
621 * <li> values[4] = estimated y_bias </li>
622 * <li> values[5] = estimated z_bias </li>
623 * </ul>
624 * </p>
625 * <p>
626 * x_uncalib, y_uncalib, z_uncalib are the measured acceleration in X, Y, Z
627 * axes similar to the {@link android.hardware.Sensor#TYPE_ACCELEROMETER},
628 * without any bias correction (factory bias compensation and any
629 * temperature compensation is allowed).
630 * x_bias, y_bias, z_bias are the estimated biases.
631 * </p>
Ashutosh Joshi576ea412017-01-13 17:06:41 -0800632 *
Anthony Stange51a0c352020-01-16 14:56:27 -0500633 * <h4>{@link android.hardware.Sensor#TYPE_HINGE_ANGLE Sensor.TYPE_HINGE_ANGLE}:</h4>
634 *
635 * A sensor of this type measures the angle, in degrees, between two integral parts of the
636 * device. Movement of a hinge measured by this sensor type is expected to alter the ways in
637 * which the user may interact with the device, for example by unfolding or revealing a display.
638 *
639 * <ul>
640 * <li> values[0]: Measured hinge angle between 0 and 360 degrees inclusive</li>
641 * </ul>
642 *
Ashutosh Joshi576ea412017-01-13 17:06:41 -0800643 * @see GeomagneticField
Mike Lockwood4115c512009-11-03 10:35:43 -0500644 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 public final float[] values;
646
647 /**
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700648 * The sensor that generated this event. See
649 * {@link android.hardware.SensorManager SensorManager} for details.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 */
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800651 public Sensor sensor;
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 /**
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700654 * The accuracy of this event. See {@link android.hardware.SensorManager
655 * SensorManager} for details.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 */
657 public int accuracy;
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700658
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 /**
Anthony Stanged2c11592020-03-16 17:31:03 -0400660 * The time in nanoseconds at which the event happened. For a given sensor,
661 * each new sensor event should be monotonically increasing using the same
662 * time base as {@link android.os.SystemClock#elapsedRealtimeNanos()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 */
664 public long timestamp;
665
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100666 @UnsupportedAppUsage
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700667 SensorEvent(int valueSize) {
668 values = new float[valueSize];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669 }
670}