1 /* 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 17 package android.hardware; 18 19 /** 20 * This class represents a {@link android.hardware.Sensor Sensor} event and 21 * holds information such as the sensor's type, the time-stamp, accuracy and of 22 * course the sensor's {@link SensorEvent#values data}. 23 * 24 * <p> 25 * <u>Definition of the coordinate system used by the SensorEvent API.</u> 26 * </p> 27 * 28 * <p> 29 * The coordinate-system is defined relative to the screen of the phone in its 30 * default orientation. The axes are not swapped when the device's screen 31 * orientation changes. 32 * </p> 33 * 34 * <p> 35 * The X axis is horizontal and points to the right, the Y axis is vertical and 36 * points up and the Z axis points towards the outside of the front face of the 37 * screen. In this system, coordinates behind the screen have negative Z values. 38 * </p> 39 * 40 * <p> 41 * <center><img src="../../../images/axis_device.png" 42 * alt="Sensors coordinate-system diagram." border="0" /></center> 43 * </p> 44 * 45 * <p> 46 * <b>Note:</b> This coordinate system is different from the one used in the 47 * Android 2D APIs where the origin is in the top-left corner. 48 * </p> 49 * 50 * @see SensorManager 51 * @see SensorEvent 52 * @see Sensor 53 * 54 */ 55 56 public class SensorEvent { 57 /** 58 * <p> 59 * The length and contents of the {@link #values values} array depends on 60 * which {@link android.hardware.Sensor sensor} type is being monitored (see 61 * also {@link SensorEvent} for a definition of the coordinate system used). 62 * </p> 63 * 64 * <h4>{@link android.hardware.Sensor#TYPE_ACCELEROMETER 65 * Sensor.TYPE_ACCELEROMETER}:</h4> All values are in SI units (m/s^2) 66 * 67 * <ul> 68 * <li> values[0]: Acceleration minus Gx on the x-axis </li> 69 * <li> values[1]: Acceleration minus Gy on the y-axis </li> 70 * <li> values[2]: Acceleration minus Gz on the z-axis </li> 71 * </ul> 72 * 73 * <p> 74 * A sensor of this type measures the acceleration applied to the device 75 * (<b>Ad</b>). Conceptually, it does so by measuring forces applied to the 76 * sensor itself (<b>Fs</b>) using the relation: 77 * </p> 78 * 79 * <b><center>Ad = - ∑Fs / mass</center></b> 80 * 81 * <p> 82 * In particular, the force of gravity is always influencing the measured 83 * acceleration: 84 * </p> 85 * 86 * <b><center>Ad = -g - ∑F / mass</center></b> 87 * 88 * <p> 89 * For this reason, when the device is sitting on a table (and obviously not 90 * accelerating), the accelerometer reads a magnitude of <b>g</b> = 9.81 91 * m/s^2 92 * </p> 93 * 94 * <p> 95 * Similarly, when the device is in free-fall and therefore dangerously 96 * accelerating towards to ground at 9.81 m/s^2, its accelerometer reads a 97 * magnitude of 0 m/s^2. 98 * </p> 99 * 100 * <p> 101 * It should be apparent that in order to measure the real acceleration of 102 * the device, the contribution of the force of gravity must be eliminated. 103 * This can be achieved by applying a <i>high-pass</i> filter. Conversely, a 104 * <i>low-pass</i> filter can be used to isolate the force of gravity. 105 * </p> 106 * 107 * <pre class="prettyprint"> 108 * 109 * public void onSensorChanged(SensorEvent event) 110 * { 111 * // alpha is calculated as t / (t + dT) 112 * // with t, the low-pass filter's time-constant 113 * // and dT, the event delivery rate 114 * 115 * final float alpha = 0.8; 116 * 117 * gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0]; 118 * gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1]; 119 * gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2]; 120 * 121 * linear_acceleration[0] = event.values[0] - gravity[0]; 122 * linear_acceleration[1] = event.values[1] - gravity[1]; 123 * linear_acceleration[2] = event.values[2] - gravity[2]; 124 * } 125 * </pre> 126 * 127 * <p> 128 * <u>Examples</u>: 129 * <ul> 130 * <li>When the device lies flat on a table and is pushed on its left side 131 * toward the right, the x acceleration value is positive.</li> 132 * 133 * <li>When the device lies flat on a table, the acceleration value is 134 * +9.81, which correspond to the acceleration of the device (0 m/s^2) minus 135 * the force of gravity (-9.81 m/s^2).</li> 136 * 137 * <li>When the device lies flat on a table and is pushed toward the sky 138 * with an acceleration of A m/s^2, the acceleration value is equal to 139 * A+9.81 which correspond to the acceleration of the device (+A m/s^2) 140 * minus the force of gravity (-9.81 m/s^2).</li> 141 * </ul> 142 * 143 * 144 * <h4>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD 145 * Sensor.TYPE_MAGNETIC_FIELD}:</h4> 146 * All values are in micro-Tesla (uT) and measure the ambient magnetic field 147 * in the X, Y and Z axis. 148 * 149 * <h4>{@link android.hardware.Sensor#TYPE_GYROSCOPE Sensor.TYPE_GYROSCOPE}: 150 * </h4> All values are in radians/second and measure the rate of rotation 151 * around the device's local X, Y and Z axis. The coordinate system is the 152 * same as is used for the acceleration sensor. Rotation is positive in the 153 * counter-clockwise direction. That is, an observer looking from some 154 * positive location on the x, y or z axis at a device positioned on the 155 * origin would report positive rotation if the device appeared to be 156 * rotating counter clockwise. Note that this is the standard mathematical 157 * definition of positive rotation and does not agree with the definition of 158 * roll given earlier. 159 * <ul> 160 * <li> values[0]: Angular speed around the x-axis </li> 161 * <li> values[1]: Angular speed around the y-axis </li> 162 * <li> values[2]: Angular speed around the z-axis </li> 163 * </ul> 164 * <p> 165 * Typically the output of the gyroscope is integrated over time to 166 * calculate a rotation describing the change of angles over the time step, 167 * for example: 168 * </p> 169 * 170 * <pre class="prettyprint"> 171 * private static final float NS2S = 1.0f / 1000000000.0f; 172 * private final float[] deltaRotationVector = new float[4](); 173 * private float timestamp; 174 * 175 * public void onSensorChanged(SensorEvent event) { 176 * // This time step's delta rotation to be multiplied by the current rotation 177 * // after computing it from the gyro sample data. 178 * if (timestamp != 0) { 179 * final float dT = (event.timestamp - timestamp) * NS2S; 180 * // Axis of the rotation sample, not normalized yet. 181 * float axisX = event.values[0]; 182 * float axisY = event.values[1]; 183 * float axisZ = event.values[2]; 184 * 185 * // Calculate the angular speed of the sample 186 * float omegaMagnitude = sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ); 187 * 188 * // Normalize the rotation vector if it's big enough to get the axis 189 * if (omegaMagnitude > EPSILON) { 190 * axisX /= omegaMagnitude; 191 * axisY /= omegaMagnitude; 192 * axisZ /= omegaMagnitude; 193 * } 194 * 195 * // Integrate around this axis with the angular speed by the time step 196 * // in order to get a delta rotation from this sample over the time step 197 * // We will convert this axis-angle representation of the delta rotation 198 * // into a quaternion before turning it into the rotation matrix. 199 * float thetaOverTwo = omegaMagnitude * dT / 2.0f; 200 * float sinThetaOverTwo = sin(thetaOverTwo); 201 * float cosThetaOverTwo = cos(thetaOverTwo); 202 * deltaRotationVector[0] = sinThetaOverTwo * axisX; 203 * deltaRotationVector[1] = sinThetaOverTwo * axisY; 204 * deltaRotationVector[2] = sinThetaOverTwo * axisZ; 205 * deltaRotationVector[3] = cosThetaOverTwo; 206 * } 207 * timestamp = event.timestamp; 208 * float[] deltaRotationMatrix = new float[9]; 209 * SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector); 210 * // User code should concatenate the delta rotation we computed with the current 211 * // rotation in order to get the updated rotation. 212 * // rotationCurrent = rotationCurrent * deltaRotationMatrix; 213 * } 214 * </pre> 215 * <p> 216 * In practice, the gyroscope noise and offset will introduce some errors 217 * which need to be compensated for. This is usually done using the 218 * information from other sensors, but is beyond the scope of this document. 219 * </p> 220 * <h4>{@link android.hardware.Sensor#TYPE_LIGHT Sensor.TYPE_LIGHT}:</h4> 221 * <ul> 222 * <li>values[0]: Ambient light level in SI lux units </li> 223 * </ul> 224 * 225 * <h4>{@link android.hardware.Sensor#TYPE_PRESSURE Sensor.TYPE_PRESSURE}:</h4> 226 * <ul> 227 * <li>values[0]: Atmospheric pressure in hPa (millibar) </li> 228 * </ul> 229 * 230 * <h4>{@link android.hardware.Sensor#TYPE_PROXIMITY Sensor.TYPE_PROXIMITY}: 231 * </h4> 232 * 233 * <ul> 234 * <li>values[0]: Proximity sensor distance measured in centimeters </li> 235 * </ul> 236 * 237 * <p> 238 * <b>Note:</b> Some proximity sensors only support a binary <i>near</i> or 239 * <i>far</i> measurement. In this case, the sensor should report its 240 * {@link android.hardware.Sensor#getMaximumRange() maximum range} value in 241 * the <i>far</i> state and a lesser value in the <i>near</i> state. 242 * </p> 243 * 244 * <h4>{@link android.hardware.Sensor#TYPE_GRAVITY Sensor.TYPE_GRAVITY}:</h4> 245 * <p>A three dimensional vector indicating the direction and magnitude of gravity. Units 246 * are m/s^2. The coordinate system is the same as is used by the acceleration sensor.</p> 247 * <p><b>Note:</b> When the device is at rest, the output of the gravity sensor should be 248 * identical to that of the accelerometer.</p> 249 * 250 * <h4> 251 * {@link android.hardware.Sensor#TYPE_LINEAR_ACCELERATION Sensor.TYPE_LINEAR_ACCELERATION}: 252 * </h4> A three dimensional vector indicating acceleration along each device axis, not 253 * including gravity. All values have units of m/s^2. The coordinate system is the same as is 254 * used by the acceleration sensor. 255 * <p>The output of the accelerometer, gravity and linear-acceleration sensors must obey the 256 * following relation:</p> 257 * <p><ul>acceleration = gravity + linear-acceleration</ul></p> 258 * 259 * <h4>{@link android.hardware.Sensor#TYPE_ROTATION_VECTOR Sensor.TYPE_ROTATION_VECTOR}:</h4> 260 * <p>The rotation vector represents the orientation of the device as a combination of an 261 * <i>angle</i> and an <i>axis</i>, in which the device has rotated through an angle θ 262 * around an axis <x, y, z>.</p> 263 * <p>The three elements of the rotation vector are 264 * <x*sin(θ/2), y*sin(θ/2), z*sin(θ/2)>, such that the magnitude of the rotation 265 * vector is equal to sin(θ/2), and the direction of the rotation vector is equal to the 266 * direction of the axis of rotation.</p> 267 * </p>The three elements of the rotation vector are equal to 268 * the last three components of a <b>unit</b> quaternion 269 * <cos(θ/2), x*sin(θ/2), y*sin(θ/2), z*sin(θ/2)>.</p> 270 * <p>Elements of the rotation vector are unitless. 271 * The x,y, and z axis are defined in the same way as the acceleration 272 * sensor.</p> 273 * The reference coordinate system is defined as a direct orthonormal basis, 274 * where: 275 * </p> 276 * 277 * <ul> 278 * <li>X is defined as the vector product <b>Y.Z</b> (It is tangential to 279 * the ground at the device's current location and roughly points East).</li> 280 * <li>Y is tangential to the ground at the device's current location and 281 * points towards magnetic north.</li> 282 * <li>Z points towards the sky and is perpendicular to the ground.</li> 283 * </ul> 284 * 285 * <p> 286 * <center><img src="../../../images/axis_globe.png" 287 * alt="World coordinate-system diagram." border="0" /></center> 288 * </p> 289 * 290 * <ul> 291 * <li> values[0]: x*sin(θ/2) </li> 292 * <li> values[1]: y*sin(θ/2) </li> 293 * <li> values[2]: z*sin(θ/2) </li> 294 * <li> values[3]: cos(θ/2) </li> 295 * <li> values[4]: estimated heading Accuracy (in radians) (-1 if unavailable)</li> 296 * </ul> 297 * <p> values[3], originally optional, will always be present from SDK Level 18 onwards. 298 * values[4] is a new value that has been added in SDK Level 18. 299 * </p> 300 * 301 * <h4>{@link android.hardware.Sensor#TYPE_ORIENTATION 302 * Sensor.TYPE_ORIENTATION}:</h4> All values are angles in degrees. 303 * 304 * <ul> 305 * <li> values[0]: Azimuth, angle between the magnetic north direction and the 306 * y-axis, around the z-axis (0 to 359). 0=North, 90=East, 180=South, 307 * 270=West 308 * </p> 309 * 310 * <p> 311 * values[1]: Pitch, rotation around x-axis (-180 to 180), with positive 312 * values when the z-axis moves <b>toward</b> the y-axis. 313 * </p> 314 * 315 * <p> 316 * values[2]: Roll, rotation around the y-axis (-90 to 90) 317 * increasing as the device moves clockwise. 318 * </p> 319 * </ul> 320 * 321 * <p> 322 * <b>Note:</b> This definition is different from <b>yaw, pitch and roll</b> 323 * used in aviation where the X axis is along the long side of the plane 324 * (tail to nose). 325 * </p> 326 * 327 * <p> 328 * <b>Note:</b> This sensor type exists for legacy reasons, please use 329 * {@link android.hardware.Sensor#TYPE_ROTATION_VECTOR 330 * rotation vector sensor type} and 331 * {@link android.hardware.SensorManager#getRotationMatrix 332 * getRotationMatrix()} in conjunction with 333 * {@link android.hardware.SensorManager#remapCoordinateSystem 334 * remapCoordinateSystem()} and 335 * {@link android.hardware.SensorManager#getOrientation getOrientation()} to 336 * compute these values instead. 337 * </p> 338 * 339 * <p> 340 * <b>Important note:</b> For historical reasons the roll angle is positive 341 * in the clockwise direction (mathematically speaking, it should be 342 * positive in the counter-clockwise direction). 343 * </p> 344 * 345 * <h4>{@link android.hardware.Sensor#TYPE_RELATIVE_HUMIDITY 346 * Sensor.TYPE_RELATIVE_HUMIDITY}:</h4> 347 * <ul> 348 * <li> values[0]: Relative ambient air humidity in percent </li> 349 * </ul> 350 * <p> 351 * When relative ambient air humidity and ambient temperature are 352 * measured, the dew point and absolute humidity can be calculated. 353 * </p> 354 * <u>Dew Point</u> 355 * <p> 356 * The dew point is the temperature to which a given parcel of air must be 357 * cooled, at constant barometric pressure, for water vapor to condense 358 * into water. 359 * </p> 360 * <center><pre> 361 * ln(RH/100%) + m·t/(T<sub>n</sub>+t) 362 * t<sub>d</sub>(t,RH) = T<sub>n</sub> · ------------------------------ 363 * m - [ln(RH/100%) + m·t/(T<sub>n</sub>+t)] 364 * </pre></center> 365 * <dl> 366 * <dt>t<sub>d</sub></dt> <dd>dew point temperature in °C</dd> 367 * <dt>t</dt> <dd>actual temperature in °C</dd> 368 * <dt>RH</dt> <dd>actual relative humidity in %</dd> 369 * <dt>m</dt> <dd>17.62</dd> 370 * <dt>T<sub>n</sub></dt> <dd>243.12 °C</dd> 371 * </dl> 372 * <p>for example:</p> 373 * <pre class="prettyprint"> 374 * h = Math.log(rh / 100.0) + (17.62 * t) / (243.12 + t); 375 * td = 243.12 * h / (17.62 - h); 376 * </pre> 377 * <u>Absolute Humidity</u> 378 * <p> 379 * The absolute humidity is the mass of water vapor in a particular volume 380 * of dry air. The unit is g/m<sup>3</sup>. 381 * </p> 382 * <center><pre> 383 * RH/100%·A·exp(m·t/(T<sub>n</sub>+t)) 384 * d<sub>v</sub>(t,RH) = 216.7 · ------------------------- 385 * 273.15 + t 386 * </pre></center> 387 * <dl> 388 * <dt>d<sub>v</sub></dt> <dd>absolute humidity in g/m<sup>3</sup></dd> 389 * <dt>t</dt> <dd>actual temperature in °C</dd> 390 * <dt>RH</dt> <dd>actual relative humidity in %</dd> 391 * <dt>m</dt> <dd>17.62</dd> 392 * <dt>T<sub>n</sub></dt> <dd>243.12 °C</dd> 393 * <dt>A</dt> <dd>6.112 hPa</dd> 394 * </dl> 395 * <p>for example:</p> 396 * <pre class="prettyprint"> 397 * dv = 216.7 * 398 * (rh / 100.0 * 6.112 * Math.exp(17.62 * t / (243.12 + t)) / (273.15 + t)); 399 * </pre> 400 * 401 * <h4>{@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE Sensor.TYPE_AMBIENT_TEMPERATURE}: 402 * </h4> 403 * 404 * <ul> 405 * <li> values[0]: ambient (room) temperature in degree Celsius.</li> 406 * </ul> 407 * 408 * 409 * <h4>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD_UNCALIBRATED 410 * Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED}:</h4> 411 * Similar to {@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD}, 412 * but the hard iron calibration is reported separately instead of being included 413 * in the measurement. Factory calibration and temperature compensation will still 414 * be applied to the "uncalibrated" measurement. Assumptions that the magnetic field 415 * is due to the Earth's poles is avoided. 416 * <p> 417 * The values array is shown below: 418 * <ul> 419 * <li> values[0] = x_uncalib </li> 420 * <li> values[1] = y_uncalib </li> 421 * <li> values[2] = z_uncalib </li> 422 * <li> values[3] = x_bias </li> 423 * <li> values[4] = y_bias </li> 424 * <li> values[5] = z_bias </li> 425 * </ul> 426 * </p> 427 * <p> 428 * x_uncalib, y_uncalib, z_uncalib are the measured magnetic field in X, Y, Z axes. 429 * Soft iron and temperature calibrations are applied. But the hard iron 430 * calibration is not applied. The values are in micro-Tesla (uT). 431 * </p> 432 * <p> 433 * x_bias, y_bias, z_bias give the iron bias estimated in X, Y, Z axes. 434 * Each field is a component of the estimated hard iron calibration. 435 * The values are in micro-Tesla (uT). 436 * </p> 437 * <p> Hard iron - These distortions arise due to the magnetized iron, steel or permanent 438 * magnets on the device. 439 * Soft iron - These distortions arise due to the interaction with the earth's magnetic 440 * field. 441 * </p> 442 * <h4> {@link android.hardware.Sensor#TYPE_GAME_ROTATION_VECTOR 443 * Sensor.TYPE_GAME_ROTATION_VECTOR}:</h4> 444 * Identical to {@link android.hardware.Sensor#TYPE_ROTATION_VECTOR} except that it 445 * doesn't use the geomagnetic field. Therefore the Y axis doesn't 446 * point north, but instead to some other reference, that reference is 447 * allowed to drift by the same order of magnitude as the gyroscope 448 * drift around the Z axis. 449 * <p> 450 * In the ideal case, a phone rotated and returning to the same real-world 451 * orientation will report the same game rotation vector 452 * (without using the earth's geomagnetic field). However, the orientation 453 * may drift somewhat over time. See {@link android.hardware.Sensor#TYPE_ROTATION_VECTOR} 454 * for a detailed description of the values. This sensor will not have 455 * the estimated heading accuracy value. 456 * </p> 457 * 458 * <h4> {@link android.hardware.Sensor#TYPE_GYROSCOPE_UNCALIBRATED 459 * Sensor.TYPE_GYROSCOPE_UNCALIBRATED}:</h4> 460 * All values are in radians/second and measure the rate of rotation 461 * around the X, Y and Z axis. An estimation of the drift on each axis is 462 * reported as well. 463 * <p> 464 * No gyro-drift compensation is performed. Factory calibration and temperature 465 * compensation is still applied to the rate of rotation (angular speeds). 466 * </p> 467 * <p> 468 * The coordinate system is the same as is used for the 469 * {@link android.hardware.Sensor#TYPE_ACCELEROMETER} 470 * Rotation is positive in the counter-clockwise direction (right-hand rule). 471 * That is, an observer looking from some positive location on the x, y or z axis 472 * at a device positioned on the origin would report positive rotation if the device 473 * appeared to be rotating counter clockwise. 474 * The range would at least be 17.45 rad/s (ie: ~1000 deg/s). 475 * <ul> 476 * <li> values[0] : angular speed (w/o drift compensation) around the X axis in rad/s </li> 477 * <li> values[1] : angular speed (w/o drift compensation) around the Y axis in rad/s </li> 478 * <li> values[2] : angular speed (w/o drift compensation) around the Z axis in rad/s </li> 479 * <li> values[3] : estimated drift around X axis in rad/s </li> 480 * <li> values[4] : estimated drift around Y axis in rad/s </li> 481 * <li> values[5] : estimated drift around Z axis in rad/s </li> 482 * </ul> 483 * </p> 484 * <p><b>Pro Tip:</b> Always use the length of the values array while performing operations 485 * on it. In earlier versions, this used to be always 3 which has changed now. </p> 486 * 487 * <h4>{@link android.hardware.Sensor#TYPE_POSE_6DOF 488 * Sensor.TYPE_POSE_6DOF}:</h4> 489 * 490 * A TYPE_POSE_6DOF event consists of a rotation expressed as a quaternion and a translation 491 * expressed in SI units. The event also contains a delta rotation and translation that show 492 * how the device?s pose has changed since the previous sequence numbered pose. 493 * The event uses the cannonical Android Sensor axes. 494 * 495 * 496 * <ul> 497 * <li> values[0]: x*sin(θ/2) </li> 498 * <li> values[1]: y*sin(θ/2) </li> 499 * <li> values[2]: z*sin(θ/2) </li> 500 * <li> values[3]: cos(θ/2) </li> 501 * 502 * 503 * <li> values[4]: Translation along x axis from an arbitrary origin. </li> 504 * <li> values[5]: Translation along y axis from an arbitrary origin. </li> 505 * <li> values[6]: Translation along z axis from an arbitrary origin. </li> 506 * 507 * <li> values[7]: Delta quaternion rotation x*sin(θ/2) </li> 508 * <li> values[8]: Delta quaternion rotation y*sin(θ/2) </li> 509 * <li> values[9]: Delta quaternion rotation z*sin(θ/2) </li> 510 * <li> values[10]: Delta quaternion rotation cos(θ/2) </li> 511 * 512 * <li> values[11]: Delta translation along x axis. </li> 513 * <li> values[12]: Delta translation along y axis. </li> 514 * <li> values[13]: Delta translation along z axis. </li> 515 * 516 * <li> values[14]: Sequence number </li> 517 * 518 * </ul> 519 * 520 * <h4>{@link android.hardware.Sensor#TYPE_STATIONARY_DETECT 521 * Sensor.TYPE_STATIONARY_DETECT}:</h4> 522 * 523 * A TYPE_STATIONARY_DETECT event is produced if the device has been 524 * stationary for at least 5 seconds with a maximal latency of 5 525 * additional seconds. ie: it may take up anywhere from 5 to 10 seconds 526 * afte the device has been at rest to trigger this event. 527 * 528 * The only allowed value is 1.0. 529 * 530 * <ul> 531 * <li> values[0]: 1.0 </li> 532 * </ul> 533 * 534 * <h4>{@link android.hardware.Sensor#TYPE_MOTION_DETECT 535 * Sensor.TYPE_MOTION_DETECT}:</h4> 536 * 537 * A TYPE_MOTION_DETECT event is produced if the device has been in 538 * motion for at least 5 seconds with a maximal latency of 5 539 * additional seconds. ie: it may take up anywhere from 5 to 10 seconds 540 * afte the device has been at rest to trigger this event. 541 * 542 * The only allowed value is 1.0. 543 * 544 * <ul> 545 * <li> values[0]: 1.0 </li> 546 * </ul> 547 * 548 * <h4>{@link android.hardware.Sensor#TYPE_HEART_BEAT 549 * Sensor.TYPE_HEART_BEAT}:</h4> 550 * 551 * A sensor of this type returns an event everytime a hear beat peak is 552 * detected. 553 * 554 * Peak here ideally corresponds to the positive peak in the QRS complex of 555 * an ECG signal. 556 * 557 * <ul> 558 * <li> values[0]: confidence</li> 559 * </ul> 560 * 561 * <p> 562 * A confidence value of 0.0 indicates complete uncertainty - that a peak 563 * is as likely to be at the indicated timestamp as anywhere else. 564 * A confidence value of 1.0 indicates complete certainly - that a peak is 565 * completely unlikely to be anywhere else on the QRS complex. 566 * </p> 567 * 568 * <h4>{@link android.hardware.Sensor#TYPE_LOW_LATENCY_OFFBODY_DETECT 569 * Sensor.TYPE_LOW_LATENCY_OFFBODY_DETECT}:</h4> 570 * 571 * <p> 572 * A sensor of this type returns an event every time the device transitions 573 * from off-body to on-body and from on-body to off-body (e.g. a wearable 574 * device being removed from the wrist would trigger an event indicating an 575 * off-body transition). The event returned will contain a single value to 576 * indicate off-body state: 577 * </p> 578 * 579 * <ul> 580 * <li> values[0]: off-body state</li> 581 * </ul> 582 * 583 * <p> 584 * Valid values for off-body state: 585 * <ul> 586 * <li> 1.0 (device is on-body)</li> 587 * <li> 0.0 (device is off-body)</li> 588 * </ul> 589 * </p> 590 * 591 * <p> 592 * When a sensor of this type is activated, it must deliver the initial 593 * on-body or off-body event representing the current device state within 594 * 5 seconds of activating the sensor. 595 * </p> 596 * 597 * <p> 598 * This sensor must be able to detect and report an on-body to off-body 599 * transition within 1 second of the device being removed from the body, 600 * and must be able to detect and report an off-body to on-body transition 601 * within 5 seconds of the device being put back onto the body. 602 * </p> 603 * 604 * <h4>{@link android.hardware.Sensor#TYPE_ACCELEROMETER_UNCALIBRATED 605 * Sensor.TYPE_ACCELEROMETER_UNCALIBRATED}:</h4> All values are in SI 606 * units (m/s^2) 607 * 608 * Similar to {@link android.hardware.Sensor#TYPE_ACCELEROMETER}, 609 * Factory calibration and temperature compensation will still be applied 610 * to the "uncalibrated" measurement. 611 * 612 * <p> 613 * The values array is shown below: 614 * <ul> 615 * <li> values[0] = x_uncalib without bias compensation </li> 616 * <li> values[1] = y_uncalib without bias compensation </li> 617 * <li> values[2] = z_uncalib without bias compensation </li> 618 * <li> values[3] = estimated x_bias </li> 619 * <li> values[4] = estimated y_bias </li> 620 * <li> values[5] = estimated z_bias </li> 621 * </ul> 622 * </p> 623 * <p> 624 * x_uncalib, y_uncalib, z_uncalib are the measured acceleration in X, Y, Z 625 * axes similar to the {@link android.hardware.Sensor#TYPE_ACCELEROMETER}, 626 * without any bias correction (factory bias compensation and any 627 * temperature compensation is allowed). 628 * x_bias, y_bias, z_bias are the estimated biases. 629 * </p> 630 * 631 * @see GeomagneticField 632 */ 633 public final float[] values; 634 635 /** 636 * The sensor that generated this event. See 637 * {@link android.hardware.SensorManager SensorManager} for details. 638 */ 639 public Sensor sensor; 640 641 /** 642 * The accuracy of this event. See {@link android.hardware.SensorManager 643 * SensorManager} for details. 644 */ 645 public int accuracy; 646 647 /** 648 * The time in nanosecond at which the event happened 649 */ 650 public long timestamp; 651 SensorEvent(int valueSize)652 SensorEvent(int valueSize) { 653 values = new float[valueSize]; 654 } 655 } 656