The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 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 | #ifndef ANDROID_SENSORS_INTERFACE_H |
| 18 | #define ANDROID_SENSORS_INTERFACE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/cdefs.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <hardware/hardware.h> |
Mike Lockwood | 21b652f | 2009-05-22 10:05:48 -0400 | [diff] [blame] | 25 | #include <cutils/native_handle.h> |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 26 | |
| 27 | __BEGIN_DECLS |
| 28 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 29 | /*****************************************************************************/ |
| 30 | |
| 31 | #define SENSORS_HEADER_VERSION 1 |
| 32 | #define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
| 33 | #define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION) |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 34 | #define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION) |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 35 | #define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 36 | #define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION) |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 37 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 38 | /** |
| 39 | * The id of this module |
| 40 | */ |
| 41 | #define SENSORS_HARDWARE_MODULE_ID "sensors" |
| 42 | |
| 43 | /** |
| 44 | * Name of the sensors device to open |
| 45 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 46 | #define SENSORS_HARDWARE_POLL "poll" |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Handles must be higher than SENSORS_HANDLE_BASE and must be unique. |
| 50 | * A Handle identifies a given sensors. The handle is used to activate |
| 51 | * and/or deactivate sensors. |
| 52 | * In this version of the API there can only be 256 handles. |
| 53 | */ |
| 54 | #define SENSORS_HANDLE_BASE 0 |
| 55 | #define SENSORS_HANDLE_BITS 8 |
| 56 | #define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS) |
| 57 | |
| 58 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 59 | /* |
| 60 | * flags for (*batch)() |
| 61 | * Availability: SENSORS_DEVICE_API_VERSION_1_0 |
| 62 | * see (*batch)() documentation for details |
| 63 | */ |
| 64 | enum { |
| 65 | SENSORS_BATCH_DRY_RUN = 0x00000001, |
| 66 | SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002 |
| 67 | }; |
| 68 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 69 | /* |
| 70 | * what field for meta_data_event_t |
| 71 | */ |
| 72 | enum { |
| 73 | /* a previous flush operation has completed */ |
Mathias Agopian | af32a8d | 2013-08-06 20:33:38 -0700 | [diff] [blame] | 74 | META_DATA_FLUSH_COMPLETE = 1, |
| 75 | META_DATA_VERSION /* always last, leave auto-assigned */ |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 78 | /* |
| 79 | * The permission to use for body sensors (like heart rate monitors). |
| 80 | * See sensor types for more details on what sensors should require this |
| 81 | * permission. |
| 82 | */ |
| 83 | #define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS" |
| 84 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 85 | /** |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 86 | * Definition of the axis used by the sensor HAL API |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 87 | * |
| 88 | * This API is relative to the screen of the device in its default orientation, |
| 89 | * that is, if the device can be used in portrait or landscape, this API |
| 90 | * is only relative to the NATURAL orientation of the screen. In other words, |
| 91 | * the axis are not swapped when the device's screen orientation changes. |
| 92 | * Higher level services /may/ perform this transformation. |
| 93 | * |
| 94 | * x<0 x>0 |
| 95 | * ^ |
| 96 | * | |
| 97 | * +-----------+--> y>0 |
| 98 | * | | |
| 99 | * | | |
| 100 | * | | |
| 101 | * | | / z<0 |
| 102 | * | | / |
| 103 | * | | / |
| 104 | * O-----------+/ |
| 105 | * |[] [ ] []/ |
| 106 | * +----------/+ y<0 |
| 107 | * / |
| 108 | * / |
| 109 | * |/ z>0 (toward the sky) |
| 110 | * |
| 111 | * O: Origin (x=0,y=0,z=0) |
| 112 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 113 | */ |
| 114 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 115 | /* |
| 116 | * Interaction with suspend mode |
| 117 | * |
| 118 | * Unless otherwise noted, an enabled sensor shall not prevent the |
| 119 | * SoC to go into suspend mode. It is the responsibility of applications |
| 120 | * to keep a partial wake-lock should they wish to receive sensor |
| 121 | * events while the screen is off. While in suspend mode, and unless |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 122 | * otherwise noted (batch mode, sensor particularities, ...), enabled sensors' |
| 123 | * events are lost. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 124 | * |
| 125 | * Note that conceptually, the sensor itself is not de-activated while in |
| 126 | * suspend mode -- it's just that the data it returns are lost. As soon as |
| 127 | * the SoC gets out of suspend mode, operations resume as usual. Of course, |
| 128 | * in practice sensors shall be disabled while in suspend mode to |
| 129 | * save power, unless batch mode is active, in which case they must |
| 130 | * continue fill their internal FIFO (see the documentation of batch() to |
| 131 | * learn how suspend interacts with batch mode). |
| 132 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 133 | * In batch mode, and only when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 134 | * set and supported, the specified sensor must be able to wake-up the SoC and |
| 135 | * be able to buffer at least 10 seconds worth of the requested sensor events. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 136 | * |
| 137 | * There are notable exceptions to this behavior, which are sensor-dependent |
| 138 | * (see sensor types definitions below) |
| 139 | * |
| 140 | * |
| 141 | * The sensor type documentation below specifies the wake-up behavior of |
| 142 | * each sensor: |
| 143 | * wake-up: yes this sensor must wake-up the SoC to deliver events |
| 144 | * wake-up: no this sensor shall not wake-up the SoC, events are dropped |
| 145 | * |
| 146 | */ |
| 147 | |
| 148 | /* |
| 149 | * Sensor type |
| 150 | * |
| 151 | * Each sensor has a type which defines what this sensor measures and how |
| 152 | * measures are reported. All types are defined below. |
Mathias Agopian | 1599ec6 | 2013-08-19 14:34:47 -0700 | [diff] [blame] | 153 | * |
| 154 | * Device manufacturers (OEMs) can define their own sensor types, for |
| 155 | * their private use by applications or services provided by them. Such |
| 156 | * sensor types are specific to an OEM and can't be exposed in the SDK. |
| 157 | * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE. |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 158 | * |
| 159 | * All sensors defined outside of the device private range must correspond to |
| 160 | * a type defined in this file, and must satisfy the characteristics listed in |
| 161 | * the description of the sensor type. |
| 162 | * |
| 163 | * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also |
| 164 | * has a stringType. |
| 165 | * - StringType of sensors inside of the device private range MUST be prefixed |
| 166 | * by the sensor provider's or OEM reverse domain name. In particular, they |
| 167 | * cannot use the "android.sensor" prefix. |
| 168 | * - StringType of sensors outside of the device private range MUST correspond |
| 169 | * to the one defined in this file (starting with "android.sensor"). |
| 170 | * For example, accelerometers must have |
| 171 | * type=SENSOR_TYPE_ACCELEROMETER and |
| 172 | * stringType=SENSOR_STRING_TYPE_ACCELEROMETER |
| 173 | * |
| 174 | * When android introduces a new sensor type that can replace an OEM-defined |
| 175 | * sensor type, the OEM must use the official sensor type and stringType on |
| 176 | * versions of the HAL that support this new official sensor type. |
| 177 | * |
| 178 | * Example (made up): Suppose Google's Glass team wants to surface a sensor |
| 179 | * detecting that Glass is on a head. |
| 180 | * - Such a sensor is not officially supported in android KitKat |
| 181 | * - Glass devices launching on KitKat can implement a sensor with |
| 182 | * type = 0x10001 and stringType = "com.google.glass.onheaddetector" |
| 183 | * - In L android release, if android decides to define |
| 184 | * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR, |
| 185 | * those types should replace the Glass-team-specific types in all future |
| 186 | * launches. |
| 187 | * - When launching glass on the L release, Google should now use the official |
| 188 | * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType. |
| 189 | * - This way, all applications can now use this sensor. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 190 | */ |
| 191 | |
| 192 | /* |
Mathias Agopian | 1599ec6 | 2013-08-19 14:34:47 -0700 | [diff] [blame] | 193 | * Base for device manufacturers private sensor types. |
| 194 | * These sensor types can't be exposed in the SDK. |
| 195 | */ |
| 196 | #define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000 |
| 197 | |
| 198 | /* |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 199 | * Sensor fusion and virtual sensors |
| 200 | * |
| 201 | * Many sensor types are or can be implemented as virtual sensors from |
| 202 | * physical sensors on the device. For instance the rotation vector sensor, |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 203 | * orientation sensor, step-detector, step-counter, etc... |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 204 | * |
| 205 | * From the point of view of this API these virtual sensors MUST appear as |
| 206 | * real, individual sensors. It is the responsibility of the driver and HAL |
| 207 | * to make sure this is the case. |
| 208 | * |
| 209 | * In particular, all sensors must be able to function concurrently. |
| 210 | * For example, if defining both an accelerometer and a step counter, |
| 211 | * then both must be able to work concurrently. |
| 212 | */ |
| 213 | |
| 214 | /* |
| 215 | * Trigger modes |
| 216 | * |
| 217 | * Sensors can report events in different ways called trigger modes, |
| 218 | * each sensor type has one and only one trigger mode associated to it. |
| 219 | * Currently there are four trigger modes defined: |
| 220 | * |
| 221 | * continuous: events are reported at a constant rate defined by setDelay(). |
| 222 | * eg: accelerometers, gyroscopes. |
| 223 | * on-change: events are reported only if the sensor's value has changed. |
| 224 | * setDelay() is used to set a lower limit to the reporting |
| 225 | * period (minimum time between two events). |
| 226 | * The HAL must return an event immediately when an on-change |
| 227 | * sensor is activated. |
| 228 | * eg: proximity, light sensors |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 229 | * one-shot: upon detection of an event, the sensor deactivates itself and |
| 230 | * then sends a single event. Order matters to avoid race |
| 231 | * conditions. No other event is sent until the sensor get |
| 232 | * reactivated. setDelay() is ignored. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 233 | * eg: significant motion sensor |
| 234 | * special: see details in the sensor type specification below |
| 235 | * |
| 236 | */ |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 237 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 238 | |
| 239 | /* |
| 240 | * SENSOR_TYPE_META_DATA |
| 241 | * trigger-mode: n/a |
| 242 | * wake-up sensor: n/a |
| 243 | * |
| 244 | * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)() |
| 245 | * |
| 246 | * SENSOR_TYPE_META_DATA is a special token used to populate the |
| 247 | * sensors_meta_data_event structure. It doesn't correspond to a physical |
| 248 | * sensor. sensors_meta_data_event are special, they exist only inside |
| 249 | * the HAL and are generated spontaneously, as opposed to be related to |
| 250 | * a physical sensor. |
| 251 | * |
Mathias Agopian | af32a8d | 2013-08-06 20:33:38 -0700 | [diff] [blame] | 252 | * sensors_meta_data_event_t.version must be META_DATA_VERSION |
| 253 | * sensors_meta_data_event_t.sensor must be 0 |
| 254 | * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA |
| 255 | * sensors_meta_data_event_t.reserved must be 0 |
| 256 | * sensors_meta_data_event_t.timestamp must be 0 |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 257 | * |
| 258 | * The payload is a meta_data_event_t, where: |
| 259 | * meta_data_event_t.what can take the following values: |
| 260 | * |
| 261 | * META_DATA_FLUSH_COMPLETE |
| 262 | * This event indicates that a previous (*flush)() call has completed for the sensor |
| 263 | * handle specified in meta_data_event_t.sensor. |
| 264 | * see (*flush)() for more details |
| 265 | * |
| 266 | * All other values for meta_data_event_t.what are reserved and |
| 267 | * must not be used. |
| 268 | * |
| 269 | */ |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 270 | #define SENSOR_TYPE_META_DATA (0) |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 271 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 272 | /* |
| 273 | * SENSOR_TYPE_ACCELEROMETER |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 274 | * trigger-mode: continuous |
| 275 | * wake-up sensor: no |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 276 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 277 | * All values are in SI units (m/s^2) and measure the acceleration of the |
| 278 | * device minus the force of gravity. |
| 279 | * |
| 280 | * Acceleration sensors return sensor events for all 3 axes at a constant |
| 281 | * rate defined by setDelay(). |
| 282 | * |
| 283 | * x: Acceleration on the x-axis |
| 284 | * y: Acceleration on the y-axis |
| 285 | * z: Acceleration on the z-axis |
| 286 | * |
| 287 | * Note that the readings from the accelerometer include the acceleration |
| 288 | * due to gravity (which is opposite to the direction of the gravity vector). |
| 289 | * |
| 290 | * Examples: |
| 291 | * The norm of <x, y, z> should be close to 0 when in free fall. |
| 292 | * |
| 293 | * When the device lies flat on a table and is pushed on its left side |
| 294 | * toward the right, the x acceleration value is positive. |
| 295 | * |
| 296 | * When the device lies flat on a table, the acceleration value is +9.81, |
| 297 | * which correspond to the acceleration of the device (0 m/s^2) minus the |
| 298 | * force of gravity (-9.81 m/s^2). |
| 299 | * |
| 300 | * When the device lies flat on a table and is pushed toward the sky, the |
| 301 | * acceleration value is greater than +9.81, which correspond to the |
| 302 | * acceleration of the device (+A m/s^2) minus the force of |
| 303 | * gravity (-9.81 m/s^2). |
| 304 | */ |
| 305 | #define SENSOR_TYPE_ACCELEROMETER (1) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 306 | #define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 307 | |
| 308 | /* |
| 309 | * SENSOR_TYPE_GEOMAGNETIC_FIELD |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 310 | * trigger-mode: continuous |
| 311 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 312 | * |
| 313 | * All values are in micro-Tesla (uT) and measure the geomagnetic |
| 314 | * field in the X, Y and Z axis. |
| 315 | * |
| 316 | * Returned values include calibration mechanisms such that the vector is |
| 317 | * aligned with the magnetic declination and heading of the earth's |
| 318 | * geomagnetic field. |
| 319 | * |
| 320 | * Magnetic Field sensors return sensor events for all 3 axes at a constant |
| 321 | * rate defined by setDelay(). |
| 322 | */ |
| 323 | #define SENSOR_TYPE_GEOMAGNETIC_FIELD (2) |
| 324 | #define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 325 | #define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 326 | |
| 327 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 328 | * SENSOR_TYPE_ORIENTATION |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 329 | * trigger-mode: continuous |
| 330 | * wake-up sensor: no |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 331 | * |
| 332 | * All values are angles in degrees. |
| 333 | * |
Mathias Agopian | 66a4095 | 2010-07-22 17:11:50 -0700 | [diff] [blame] | 334 | * Orientation sensors return sensor events for all 3 axes at a constant |
| 335 | * rate defined by setDelay(). |
| 336 | * |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 337 | * azimuth: angle between the magnetic north direction and the Y axis, around |
| 338 | * the Z axis (0<=azimuth<360). |
| 339 | * 0=North, 90=East, 180=South, 270=West |
| 340 | * |
| 341 | * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when |
| 342 | * the z-axis moves toward the y-axis. |
| 343 | * |
| 344 | * roll: Rotation around Y axis (-90<=roll<=90), with positive values when |
Mathias Agopian | 19ea59f | 2010-02-26 13:15:18 -0800 | [diff] [blame] | 345 | * the x-axis moves towards the z-axis. |
| 346 | * |
| 347 | * Note: For historical reasons the roll angle is positive in the clockwise |
| 348 | * direction (mathematically speaking, it should be positive in the |
| 349 | * counter-clockwise direction): |
| 350 | * |
| 351 | * Z |
| 352 | * ^ |
| 353 | * (+roll) .--> | |
| 354 | * / | |
| 355 | * | | roll: rotation around Y axis |
| 356 | * X <-------(.) |
| 357 | * Y |
| 358 | * note that +Y == -roll |
| 359 | * |
| 360 | * |
| 361 | * |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 362 | * Note: This definition is different from yaw, pitch and roll used in aviation |
| 363 | * where the X axis is along the long side of the plane (tail to nose). |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 364 | */ |
| 365 | #define SENSOR_TYPE_ORIENTATION (3) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 366 | #define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 367 | |
| 368 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 369 | * SENSOR_TYPE_GYROSCOPE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 370 | * trigger-mode: continuous |
| 371 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 372 | * |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 373 | * All values are in radians/second and measure the rate of rotation |
| 374 | * around the X, Y and Z axis. The coordinate system is the same as is |
Mathias Agopian | c04e5f6 | 2010-09-14 10:53:55 -0700 | [diff] [blame] | 375 | * used for the acceleration sensor. Rotation is positive in the |
| 376 | * counter-clockwise direction (right-hand rule). That is, an observer |
| 377 | * looking from some positive location on the x, y or z axis at a device |
| 378 | * positioned on the origin would report positive rotation if the device |
| 379 | * appeared to be rotating counter clockwise. Note that this is the |
| 380 | * standard mathematical definition of positive rotation and does not agree |
| 381 | * with the definition of roll given earlier. |
| 382 | * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 383 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 384 | * automatic gyro-drift compensation is allowed but not required. |
| 385 | */ |
| 386 | #define SENSOR_TYPE_GYROSCOPE (4) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 387 | #define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 388 | |
| 389 | /* |
| 390 | * SENSOR_TYPE_LIGHT |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 391 | * trigger-mode: on-change |
| 392 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 393 | * |
| 394 | * The light sensor value is returned in SI lux units. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 395 | */ |
| 396 | #define SENSOR_TYPE_LIGHT (5) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 397 | #define SENSOR_STRING_TYPE_LIGHT "android.sensor.light" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 398 | |
| 399 | /* |
| 400 | * SENSOR_TYPE_PRESSURE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 401 | * trigger-mode: continuous |
| 402 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 403 | * |
| 404 | * The pressure sensor return the athmospheric pressure in hectopascal (hPa) |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 405 | */ |
| 406 | #define SENSOR_TYPE_PRESSURE (6) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 407 | #define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 408 | |
| 409 | /* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */ |
| 410 | #define SENSOR_TYPE_TEMPERATURE (7) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 411 | #define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 412 | |
| 413 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 414 | * SENSOR_TYPE_PROXIMITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 415 | * trigger-mode: on-change |
| 416 | * wake-up sensor: yes |
Mike Lockwood | a241431 | 2009-11-03 10:29:50 -0500 | [diff] [blame] | 417 | * |
| 418 | * The distance value is measured in centimeters. Note that some proximity |
| 419 | * sensors only support a binary "close" or "far" measurement. In this case, |
| 420 | * the sensor should report its maxRange value in the "far" state and a value |
| 421 | * less than maxRange in the "near" state. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 422 | */ |
| 423 | #define SENSOR_TYPE_PROXIMITY (8) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 424 | #define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 425 | |
| 426 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 427 | * SENSOR_TYPE_GRAVITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 428 | * trigger-mode: continuous |
| 429 | * wake-up sensor: no |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 430 | * |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 431 | * A gravity output indicates the direction of and magnitude of gravity in |
| 432 | * the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2. |
| 433 | * Units are m/s^2. The coordinate system is the same as is used for the |
| 434 | * acceleration sensor. When the device is at rest, the output of the |
| 435 | * gravity sensor should be identical to that of the accelerometer. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 436 | */ |
| 437 | #define SENSOR_TYPE_GRAVITY (9) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 438 | #define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 439 | |
| 440 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 441 | * SENSOR_TYPE_LINEAR_ACCELERATION |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 442 | * trigger-mode: continuous |
| 443 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 444 | * |
| 445 | * Indicates the linear acceleration of the device in device coordinates, |
| 446 | * not including gravity. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 447 | * |
| 448 | * The output is conceptually: |
| 449 | * output of TYPE_ACCELERATION - output of TYPE_GRAVITY |
| 450 | * |
| 451 | * Readings on all axes should be close to 0 when device lies on a table. |
| 452 | * Units are m/s^2. |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 453 | * The coordinate system is the same as is used for the acceleration sensor. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 454 | */ |
| 455 | #define SENSOR_TYPE_LINEAR_ACCELERATION (10) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 456 | #define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 457 | |
| 458 | |
| 459 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 460 | * SENSOR_TYPE_ROTATION_VECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 461 | * trigger-mode: continuous |
| 462 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 463 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 464 | * The rotation vector symbolizes the orientation of the device relative to the |
| 465 | * East-North-Up coordinates frame. It is usually obtained by integration of |
| 466 | * accelerometer, gyroscope and magnetometer readings. |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 467 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 468 | * The East-North-Up coordinate system is defined as a direct orthonormal basis |
Mathias Agopian | d93ff97 | 2011-05-02 19:10:31 -0700 | [diff] [blame] | 469 | * where: |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 470 | * - X points east and is tangential to the ground. |
| 471 | * - Y points north and is tangential to the ground. |
Mathias Agopian | d93ff97 | 2011-05-02 19:10:31 -0700 | [diff] [blame] | 472 | * - Z points towards the sky and is perpendicular to the ground. |
| 473 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 474 | * The orientation of the phone is represented by the rotation necessary to |
| 475 | * align the East-North-Up coordinates with the phone's coordinates. That is, |
| 476 | * applying the rotation to the world frame (X,Y,Z) would align them with the |
| 477 | * phone coordinates (x,y,z). |
Mathias Agopian | d93ff97 | 2011-05-02 19:10:31 -0700 | [diff] [blame] | 478 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 479 | * The rotation can be seen as rotating the phone by an angle theta around |
| 480 | * an axis rot_axis to go from the reference (East-North-Up aligned) device |
| 481 | * orientation to the current device orientation. |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 482 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 483 | * The rotation is encoded as the 4 (reordered) components of a unit quaternion: |
| 484 | * sensors_event_t.data[0] = rot_axis.x*sin(theta/2) |
| 485 | * sensors_event_t.data[1] = rot_axis.y*sin(theta/2) |
| 486 | * sensors_event_t.data[2] = rot_axis.z*sin(theta/2) |
| 487 | * sensors_event_t.data[3] = cos(theta/2) |
| 488 | * where |
| 489 | * - rot_axis.x,y,z are the North-East-Up coordinates of a unit length vector |
| 490 | * representing the rotation axis |
| 491 | * - theta is the rotation angle |
| 492 | * |
| 493 | * The quaternion must be of norm 1 (it is a unit quaternion). Failure to ensure |
| 494 | * this will cause erratic client behaviour. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 495 | * |
| 496 | * In addition, this sensor reports an estimated heading accuracy. |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 497 | * sensors_event_t.data[4] = estimated_accuracy (in radians) |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 498 | * The heading error must be less than estimated_accuracy 95% of the time |
| 499 | * |
| 500 | * This sensor must use a gyroscope and an accelerometer as main orientation |
| 501 | * change input. |
| 502 | * |
| 503 | * This sensor can also include magnetometer input to make up for gyro drift, |
| 504 | * but it cannot be implemented using only a magnetometer. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 505 | */ |
| 506 | #define SENSOR_TYPE_ROTATION_VECTOR (11) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 507 | #define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 508 | |
| 509 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 510 | * SENSOR_TYPE_RELATIVE_HUMIDITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 511 | * trigger-mode: on-change |
| 512 | * wake-up sensor: no |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 513 | * |
| 514 | * A relative humidity sensor measures relative ambient air humidity and |
| 515 | * returns a value in percent. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 516 | */ |
| 517 | #define SENSOR_TYPE_RELATIVE_HUMIDITY (12) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 518 | #define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 519 | |
| 520 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 521 | * SENSOR_TYPE_AMBIENT_TEMPERATURE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 522 | * trigger-mode: on-change |
| 523 | * wake-up sensor: no |
Mathias Agopian | 54f9dd0 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 524 | * |
| 525 | * The ambient (room) temperature in degree Celsius. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 526 | */ |
| 527 | #define SENSOR_TYPE_AMBIENT_TEMPERATURE (13) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 528 | #define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 529 | |
| 530 | /* |
| 531 | * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 532 | * trigger-mode: continuous |
| 533 | * wake-up sensor: no |
Mathias Agopian | 54f9dd0 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 534 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 535 | * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is |
| 536 | * reported separately instead of being included in the measurement. |
| 537 | * Factory calibration and temperature compensation should still be applied to |
| 538 | * the "uncalibrated" measurement. |
| 539 | * Separating away the hard iron calibration estimation allows the system to |
| 540 | * better recover from bad hard iron estimation. |
| 541 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 542 | * All values are in micro-Tesla (uT) and measure the ambient magnetic |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 543 | * field in the X, Y and Z axis. Assumptions that the the magnetic field |
| 544 | * is due to the Earth's poles should be avoided. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 545 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 546 | * The uncalibrated_magnetic event contains |
| 547 | * - 3 fields for uncalibrated measurement: x_uncalib, y_uncalib, z_uncalib. |
| 548 | * Each is a component of the measured magnetic field, with soft iron |
| 549 | * and temperature compensation applied, but not hard iron calibration. |
| 550 | * These values should be continuous (no re-calibration should cause a jump). |
| 551 | * - 3 fields for hard iron bias estimates: x_bias, y_bias, z_bias. |
| 552 | * Each field is a component of the estimated hard iron calibration. |
Etienne Le Grand | 7a813e8 | 2013-04-23 14:22:23 -0700 | [diff] [blame] | 553 | * They represent the offsets to apply to the calibrated readings to obtain |
| 554 | * uncalibrated readings (x_uncalib ~= x_calibrated + x_bias) |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 555 | * These values are expected to jump as soon as the estimate of the hard iron |
Etienne Le Grand | 7a813e8 | 2013-04-23 14:22:23 -0700 | [diff] [blame] | 556 | * changes, and they should be stable the rest of the time. |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 557 | * |
| 558 | * If this sensor is present, then the corresponding |
| 559 | * SENSOR_TYPE_MAGNETIC_FIELD must be present and both must return the |
| 560 | * same sensor_t::name and sensor_t::vendor. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 561 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame] | 562 | * Minimum filtering should be applied to this sensor. In particular, low pass |
| 563 | * filters should be avoided. |
| 564 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 565 | * See SENSOR_TYPE_MAGNETIC_FIELD for more information |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 566 | */ |
| 567 | #define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 568 | #define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 569 | |
| 570 | /* |
| 571 | * SENSOR_TYPE_GAME_ROTATION_VECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 572 | * trigger-mode: continuous |
| 573 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 574 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 575 | * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic |
| 576 | * field. Therefore the Y axis doesn't point north, but instead to some other |
| 577 | * reference. That reference is allowed to drift by the same order of |
| 578 | * magnitude than the gyroscope drift around the Z axis. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 579 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 580 | * This sensor does not report an estimated heading accuracy: |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 581 | * sensors_event_t.data[4] is reserved and should be set to 0 |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 582 | * |
| 583 | * In the ideal case, a phone rotated and returning to the same real-world |
| 584 | * orientation should report the same game rotation vector |
| 585 | * (without using the earth's geomagnetic field). |
| 586 | * |
| 587 | * This sensor must be based on a gyroscope. It cannot be implemented using |
| 588 | * a magnetometer. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 589 | * |
| 590 | * see SENSOR_TYPE_ROTATION_VECTOR for more details |
| 591 | */ |
| 592 | #define SENSOR_TYPE_GAME_ROTATION_VECTOR (15) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 593 | #define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 594 | |
| 595 | /* |
| 596 | * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 597 | * trigger-mode: continuous |
| 598 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 599 | * |
| 600 | * All values are in radians/second and measure the rate of rotation |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 601 | * around the X, Y and Z axis. An estimation of the drift on each axis is |
| 602 | * reported as well. |
| 603 | * |
| 604 | * No gyro-drift compensation shall be performed. |
| 605 | * Factory calibration and temperature compensation should still be applied |
| 606 | * to the rate of rotation (angular speeds). |
| 607 | * |
| 608 | * The coordinate system is the same as is |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 609 | * used for the acceleration sensor. Rotation is positive in the |
| 610 | * counter-clockwise direction (right-hand rule). That is, an observer |
| 611 | * looking from some positive location on the x, y or z axis at a device |
| 612 | * positioned on the origin would report positive rotation if the device |
| 613 | * appeared to be rotating counter clockwise. Note that this is the |
| 614 | * standard mathematical definition of positive rotation and does not agree |
| 615 | * with the definition of roll given earlier. |
| 616 | * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). |
| 617 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 618 | * Content of an uncalibrated_gyro event: (units are rad/sec) |
| 619 | * x_uncalib : angular speed (w/o drift compensation) around the X axis |
| 620 | * y_uncalib : angular speed (w/o drift compensation) around the Y axis |
| 621 | * z_uncalib : angular speed (w/o drift compensation) around the Z axis |
| 622 | * x_bias : estimated drift around X axis in rad/s |
| 623 | * y_bias : estimated drift around Y axis in rad/s |
| 624 | * z_bias : estimated drift around Z axis in rad/s |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 625 | * |
| 626 | * IMPLEMENTATION NOTES: |
| 627 | * |
| 628 | * If the implementation is not able to estimate the drift, then this |
| 629 | * sensor MUST NOT be reported by this HAL. Instead, the regular |
| 630 | * SENSOR_TYPE_GYROSCOPE is used without drift compensation. |
| 631 | * |
| 632 | * If this sensor is present, then the corresponding |
| 633 | * SENSOR_TYPE_GYROSCOPE must be present and both must return the |
| 634 | * same sensor_t::name and sensor_t::vendor. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 635 | */ |
| 636 | #define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 637 | #define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 638 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 639 | |
| 640 | /* |
| 641 | * SENSOR_TYPE_SIGNIFICANT_MOTION |
| 642 | * trigger-mode: one-shot |
| 643 | * wake-up sensor: yes |
| 644 | * |
| 645 | * A sensor of this type triggers an event each time significant motion |
| 646 | * is detected and automatically disables itself. |
| 647 | * The only allowed value to return is 1.0. |
| 648 | * |
Etienne Le Grand | 1461f28 | 2013-03-05 22:00:33 -0800 | [diff] [blame] | 649 | * A significant motion is a motion that might lead to a change in the user |
| 650 | * location. |
| 651 | * Examples of such motions are: |
| 652 | * walking, biking, sitting in a moving car, coach or train. |
| 653 | * Examples of situations that should not trigger significant motion: |
| 654 | * - phone in pocket and person is not moving |
| 655 | * - phone is on a table, even if the table shakes a bit due to nearby traffic |
| 656 | * or washing machine |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 657 | * |
Etienne Le Grand | 1461f28 | 2013-03-05 22:00:33 -0800 | [diff] [blame] | 658 | * A note on false positive / false negative / power consumption tradeoff |
| 659 | * - The goal of this sensor is to save power. |
| 660 | * - Triggering an event when the user is not moving (false positive) is costly |
| 661 | * in terms of power, so it should be avoided. |
| 662 | * - Not triggering an event when the user is moving (false negative) is |
Etienne Le Grand | 2e7d3cd | 2013-03-07 12:22:32 -0800 | [diff] [blame] | 663 | * acceptable as long as it is not done repeatedly. If the user has been |
Etienne Le Grand | 1461f28 | 2013-03-05 22:00:33 -0800 | [diff] [blame] | 664 | * walking for 10 seconds, not triggering an event within those 10 seconds |
| 665 | * is not acceptable. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 666 | * |
| 667 | * IMPORTANT NOTE: this sensor type is very different from other types |
| 668 | * in that it must work when the screen is off without the need of |
| 669 | * holding a partial wake-lock and MUST allow the SoC to go into suspend. |
| 670 | * When significant motion is detected, the sensor must awaken the SoC and |
| 671 | * the event be reported. |
| 672 | * |
| 673 | * If a particular hardware cannot support this mode of operation then this |
| 674 | * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable |
| 675 | * to "emulate" this sensor in the HAL. |
| 676 | * |
| 677 | * The whole point of this sensor type is to save power by keeping the |
| 678 | * SoC in suspend mode when the device is at rest. |
| 679 | * |
| 680 | * When the sensor is not activated, it must also be deactivated in the |
| 681 | * hardware: it must not wake up the SoC anymore, even in case of |
| 682 | * significant motion. |
| 683 | * |
| 684 | * setDelay() has no effect and is ignored. |
| 685 | * Once a "significant motion" event is returned, a sensor of this type |
| 686 | * must disables itself automatically, as if activate(..., 0) had been called. |
| 687 | */ |
| 688 | |
| 689 | #define SENSOR_TYPE_SIGNIFICANT_MOTION (17) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 690 | #define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion" |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 691 | |
| 692 | /* |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 693 | * SENSOR_TYPE_STEP_DETECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 694 | * trigger-mode: special |
| 695 | * wake-up sensor: no |
| 696 | * |
| 697 | * A sensor of this type triggers an event each time a step is taken |
| 698 | * by the user. The only allowed value to return is 1.0 and an event is |
| 699 | * generated for each step. Like with any other event, the timestamp |
| 700 | * indicates when the event (here the step) occurred, this corresponds to when |
| 701 | * the foot hit the ground, generating a high variation in acceleration. |
| 702 | * |
| 703 | * While this sensor operates, it shall not disrupt any other sensors, in |
| 704 | * particular, but not limited to, the accelerometer; which might very well |
| 705 | * be in use as well. |
| 706 | * |
| 707 | * This sensor must be low power. That is, if the step detection cannot be |
| 708 | * done in hardware, this sensor should not be defined. Also, when the |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 709 | * step detector is activated and the accelerometer is not, only steps should |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 710 | * trigger interrupts (not accelerometer data). |
| 711 | * |
| 712 | * setDelay() has no impact on this sensor type |
| 713 | */ |
| 714 | |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 715 | #define SENSOR_TYPE_STEP_DETECTOR (18) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 716 | #define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector" |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 717 | |
| 718 | |
| 719 | /* |
| 720 | * SENSOR_TYPE_STEP_COUNTER |
| 721 | * trigger-mode: on-change |
| 722 | * wake-up sensor: no |
| 723 | * |
| 724 | * A sensor of this type returns the number of steps taken by the user since |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 725 | * the last reboot while activated. The value is returned as a uint64_t and is |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame] | 726 | * reset to zero only on a system / android reboot. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 727 | * |
| 728 | * The timestamp of the event is set to the time when the first step |
| 729 | * for that event was taken. |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 730 | * See SENSOR_TYPE_STEP_DETECTOR for the signification of the time of a step. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 731 | * |
| 732 | * The minimum size of the hardware's internal counter shall be 16 bits |
| 733 | * (this restriction is here to avoid too frequent wake-ups when the |
| 734 | * delay is very large). |
| 735 | * |
| 736 | * IMPORTANT NOTE: this sensor type is different from other types |
| 737 | * in that it must work when the screen is off without the need of |
| 738 | * holding a partial wake-lock and MUST allow the SoC to go into suspend. |
| 739 | * Unlike other sensors, while in suspend mode this sensor must stay active, |
| 740 | * no events are reported during that time but, steps continue to be |
| 741 | * accounted for; an event will be reported as soon as the SoC resumes if |
| 742 | * the timeout has expired. |
| 743 | * |
| 744 | * In other words, when the screen is off and the device allowed to |
| 745 | * go into suspend mode, we don't want to be woken up, regardless of the |
| 746 | * setDelay() value, but the steps shall continue to be counted. |
| 747 | * |
| 748 | * The driver must however ensure that the internal step count never |
| 749 | * overflows. It is allowed in this situation to wake the SoC up so the |
| 750 | * driver can do the counter maintenance. |
| 751 | * |
| 752 | * While this sensor operates, it shall not disrupt any other sensors, in |
| 753 | * particular, but not limited to, the accelerometer; which might very well |
| 754 | * be in use as well. |
| 755 | * |
| 756 | * If a particular hardware cannot support these modes of operation then this |
| 757 | * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable |
| 758 | * to "emulate" this sensor in the HAL. |
| 759 | * |
| 760 | * This sensor must be low power. That is, if the step detection cannot be |
| 761 | * done in hardware, this sensor should not be defined. Also, when the |
| 762 | * step counter is activated and the accelerometer is not, only steps should |
| 763 | * trigger interrupts (not accelerometer data). |
| 764 | * |
| 765 | * The whole point of this sensor type is to save power by keeping the |
| 766 | * SoC in suspend mode when the device is at rest. |
| 767 | */ |
| 768 | |
| 769 | #define SENSOR_TYPE_STEP_COUNTER (19) |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 770 | #define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter" |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 771 | |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 772 | /* |
| 773 | * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR |
| 774 | * trigger-mode: continuous |
| 775 | * wake-up sensor: no |
| 776 | * |
| 777 | * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead |
| 778 | * of using a gyroscope. |
| 779 | * |
| 780 | * This sensor must be based on a magnetometer. It cannot be implemented using |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame] | 781 | * a gyroscope, and gyroscope input cannot be used by this sensor, as the |
| 782 | * goal of this sensor is to be low power. |
| 783 | * The accelerometer can be (and usually is) used. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 784 | * |
| 785 | * Just like SENSOR_TYPE_ROTATION_VECTOR, this sensor reports an estimated |
| 786 | * heading accuracy: |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 787 | * sensors_event_t.data[4] = estimated_accuracy (in radians) |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 788 | * The heading error must be less than estimated_accuracy 95% of the time |
| 789 | * |
| 790 | * see SENSOR_TYPE_ROTATION_VECTOR for more details |
| 791 | */ |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 792 | #define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20) |
| 793 | #define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector" |
| 794 | |
| 795 | /* |
| 796 | * SENSOR_TYPE_HEART_RATE |
| 797 | * trigger-mode: on-change |
| 798 | * wake-up sensor: no |
| 799 | * |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 800 | * A sensor of this type returns the current heart rate. |
| 801 | * The events contain the current heart rate in beats per minute (BPM) and the |
| 802 | * status of the sensor during the measurement. See heart_rate_event_t for more |
| 803 | * details. |
| 804 | * |
| 805 | * Because this sensor is on-change, events must be generated when and only |
| 806 | * when heart_rate.bpm or heart_rate.status have changed since the last |
Vinod Krishnan | 74279e3 | 2014-08-28 15:25:13 -0700 | [diff] [blame^] | 807 | * event. In particular, upon the first activation, unless the device is known |
| 808 | * to not be on the body, the status field of the first event must be set to |
| 809 | * SENSOR_STATUS_UNRELIABLE. The event should be generated no faster than every |
| 810 | * period_ns passed to setDelay() or to batch(). |
| 811 | * See the definition of the on-change trigger mode for more information. |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 812 | * |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 813 | * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS. |
| 814 | */ |
| 815 | #define SENSOR_TYPE_HEART_RATE (21) |
| 816 | #define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate" |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 817 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 818 | /** |
| 819 | * Values returned by the accelerometer in various locations in the universe. |
| 820 | * all values are in SI units (m/s^2) |
| 821 | */ |
| 822 | #define GRAVITY_SUN (275.0f) |
| 823 | #define GRAVITY_EARTH (9.80665f) |
| 824 | |
| 825 | /** Maximum magnetic field on Earth's surface */ |
| 826 | #define MAGNETIC_FIELD_EARTH_MAX (60.0f) |
| 827 | |
| 828 | /** Minimum magnetic field on Earth's surface */ |
| 829 | #define MAGNETIC_FIELD_EARTH_MIN (30.0f) |
| 830 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 831 | /** |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 832 | * Possible values of the status field of sensor events. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 833 | */ |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 834 | #define SENSOR_STATUS_NO_CONTACT -1 |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 835 | #define SENSOR_STATUS_UNRELIABLE 0 |
| 836 | #define SENSOR_STATUS_ACCURACY_LOW 1 |
| 837 | #define SENSOR_STATUS_ACCURACY_MEDIUM 2 |
| 838 | #define SENSOR_STATUS_ACCURACY_HIGH 3 |
| 839 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 840 | /** |
| 841 | * sensor event data |
| 842 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 843 | typedef struct { |
| 844 | union { |
| 845 | float v[3]; |
| 846 | struct { |
| 847 | float x; |
| 848 | float y; |
| 849 | float z; |
| 850 | }; |
| 851 | struct { |
| 852 | float azimuth; |
| 853 | float pitch; |
| 854 | float roll; |
| 855 | }; |
| 856 | }; |
| 857 | int8_t status; |
| 858 | uint8_t reserved[3]; |
| 859 | } sensors_vec_t; |
| 860 | |
| 861 | /** |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 862 | * uncalibrated gyroscope and magnetometer event data |
| 863 | */ |
| 864 | typedef struct { |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 865 | union { |
| 866 | float uncalib[3]; |
| 867 | struct { |
| 868 | float x_uncalib; |
| 869 | float y_uncalib; |
| 870 | float z_uncalib; |
| 871 | }; |
| 872 | }; |
| 873 | union { |
| 874 | float bias[3]; |
| 875 | struct { |
| 876 | float x_bias; |
| 877 | float y_bias; |
| 878 | float z_bias; |
| 879 | }; |
| 880 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 881 | } uncalibrated_event_t; |
| 882 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 883 | typedef struct meta_data_event { |
| 884 | int32_t what; |
| 885 | int32_t sensor; |
| 886 | } meta_data_event_t; |
| 887 | |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 888 | /** |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 889 | * Heart rate event data |
| 890 | */ |
| 891 | typedef struct { |
| 892 | // Heart rate in beats per minute. |
| 893 | // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT |
| 894 | float bpm; |
| 895 | // Status of the sensor for this reading. Set to one SENSOR_STATUS_... |
| 896 | int8_t status; |
| 897 | } heart_rate_event_t; |
| 898 | |
| 899 | /** |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 900 | * Union of the various types of sensor data |
| 901 | * that can be returned. |
| 902 | */ |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 903 | typedef struct sensors_event_t { |
| 904 | /* must be sizeof(struct sensors_event_t) */ |
| 905 | int32_t version; |
| 906 | |
| 907 | /* sensor identifier */ |
| 908 | int32_t sensor; |
| 909 | |
| 910 | /* sensor type */ |
| 911 | int32_t type; |
| 912 | |
| 913 | /* reserved */ |
| 914 | int32_t reserved0; |
| 915 | |
| 916 | /* time is in nanosecond */ |
| 917 | int64_t timestamp; |
| 918 | |
| 919 | union { |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 920 | union { |
| 921 | float data[16]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 922 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 923 | /* acceleration values are in meter per second per second (m/s^2) */ |
| 924 | sensors_vec_t acceleration; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 925 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 926 | /* magnetic vector values are in micro-Tesla (uT) */ |
| 927 | sensors_vec_t magnetic; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 928 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 929 | /* orientation values are in degrees */ |
| 930 | sensors_vec_t orientation; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 931 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 932 | /* gyroscope values are in rad/s */ |
| 933 | sensors_vec_t gyro; |
Makarand Karvekar | 3120b58 | 2010-08-11 15:10:10 -0700 | [diff] [blame] | 934 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 935 | /* temperature is in degrees centigrade (Celsius) */ |
| 936 | float temperature; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 937 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 938 | /* distance in centimeters */ |
| 939 | float distance; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 940 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 941 | /* light in SI lux units */ |
| 942 | float light; |
Mathias Agopian | 1832f55 | 2010-07-29 15:22:30 -0700 | [diff] [blame] | 943 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 944 | /* pressure in hectopascal (hPa) */ |
| 945 | float pressure; |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 946 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 947 | /* relative humidity in percent */ |
| 948 | float relative_humidity; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 949 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 950 | /* uncalibrated gyroscope values are in rad/s */ |
| 951 | uncalibrated_event_t uncalibrated_gyro; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 952 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 953 | /* uncalibrated magnetometer values are in micro-Teslas */ |
| 954 | uncalibrated_event_t uncalibrated_magnetic; |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 955 | |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 956 | /* heart rate data containing value in bpm and status */ |
| 957 | heart_rate_event_t heart_rate; |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 958 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 959 | /* this is a special event. see SENSOR_TYPE_META_DATA above. |
| 960 | * sensors_meta_data_event_t events are all reported with a type of |
| 961 | * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero. |
| 962 | */ |
| 963 | meta_data_event_t meta_data; |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 964 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 965 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 966 | union { |
| 967 | uint64_t data[8]; |
| 968 | |
| 969 | /* step-counter */ |
| 970 | uint64_t step_counter; |
| 971 | } u64; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 972 | }; |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 973 | uint32_t reserved1[4]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 974 | } sensors_event_t; |
| 975 | |
| 976 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 977 | /* see SENSOR_TYPE_META_DATA */ |
| 978 | typedef sensors_event_t sensors_meta_data_event_t; |
| 979 | |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 980 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 981 | struct sensor_t; |
| 982 | |
| 983 | /** |
| 984 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 985 | * and the fields of this data structure must begin with hw_module_t |
| 986 | * followed by module specific information. |
| 987 | */ |
| 988 | struct sensors_module_t { |
| 989 | struct hw_module_t common; |
| 990 | |
| 991 | /** |
| 992 | * Enumerate all available sensors. The list is returned in "list". |
| 993 | * @return number of sensors in the list |
| 994 | */ |
| 995 | int (*get_sensors_list)(struct sensors_module_t* module, |
| 996 | struct sensor_t const** list); |
| 997 | }; |
| 998 | |
| 999 | struct sensor_t { |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1000 | |
| 1001 | /* Name of this sensor. |
| 1002 | * All sensors of the same "type" must have a different "name". |
| 1003 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1004 | const char* name; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1005 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1006 | /* vendor of the hardware part */ |
| 1007 | const char* vendor; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1008 | |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 1009 | /* version of the hardware part + driver. The value of this field |
| 1010 | * must increase when the driver is updated in a way that changes the |
| 1011 | * output of this sensor. This is important for fused sensors when the |
| 1012 | * fusion algorithm is updated. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1013 | */ |
| 1014 | int version; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1015 | |
| 1016 | /* handle that identifies this sensors. This handle is used to reference |
| 1017 | * this sensor throughout the HAL API. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1018 | */ |
| 1019 | int handle; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1020 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1021 | /* this sensor's type. */ |
| 1022 | int type; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1023 | |
| 1024 | /* maximum range of this sensor's value in SI units */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1025 | float maxRange; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1026 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1027 | /* smallest difference between two values reported by this sensor */ |
| 1028 | float resolution; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1029 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1030 | /* rough estimate of this sensor's power consumption in mA */ |
| 1031 | float power; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1032 | |
| 1033 | /* this value depends on the trigger mode: |
| 1034 | * |
| 1035 | * continuous: minimum sample period allowed in microseconds |
| 1036 | * on-change : 0 |
| 1037 | * one-shot :-1 |
| 1038 | * special : 0, unless otherwise noted |
| 1039 | */ |
Mathias Agopian | 1511e20 | 2010-07-29 15:33:22 -0700 | [diff] [blame] | 1040 | int32_t minDelay; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1041 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 1042 | /* number of events reserved for this sensor in the batch mode FIFO. |
| 1043 | * If there is a dedicated FIFO for this sensor, then this is the |
| 1044 | * size of this FIFO. If the FIFO is shared with other sensors, |
| 1045 | * this is the size reserved for that sensor and it can be zero. |
| 1046 | */ |
| 1047 | uint32_t fifoReservedEventCount; |
| 1048 | |
| 1049 | /* maximum number of events of this sensor that could be batched. |
| 1050 | * This is especially relevant when the FIFO is shared between |
| 1051 | * several sensors; this value is then set to the size of that FIFO. |
| 1052 | */ |
| 1053 | uint32_t fifoMaxEventCount; |
| 1054 | |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 1055 | /* type of this sensor as a string. Set to corresponding |
| 1056 | * SENSOR_STRING_TYPE_*. |
| 1057 | * When defining an OEM specific sensor or sensor manufacturer specific |
| 1058 | * sensor, use your reserve domain name as a prefix. |
| 1059 | * ex: com.google.glass.onheaddetector |
| 1060 | * For sensors of known type, the android framework might overwrite this |
| 1061 | * string automatically. |
| 1062 | */ |
| 1063 | const char* stringType; |
| 1064 | |
| 1065 | /* permission required to see this sensor, register to it and receive data. |
| 1066 | * Set to "" if no permission is required. Some sensor types like the |
| 1067 | * heart rate monitor have a mandatory require_permission. |
| 1068 | * For sensors that always require a specific permission, like the heart |
| 1069 | * rate monitor, the android framework might overwrite this string |
| 1070 | * automatically. |
| 1071 | */ |
| 1072 | const char* requiredPermission; |
| 1073 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1074 | /* reserved fields, must be zero */ |
Aravind Akella | b20f1a3 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 1075 | void* reserved[4]; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1076 | }; |
| 1077 | |
| 1078 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1079 | /* |
| 1080 | * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1 |
| 1081 | * and is present for backward binary and source compatibility. |
| 1082 | * (see documentation of the hooks in struct sensors_poll_device_1 below) |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1083 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 1084 | struct sensors_poll_device_t { |
| 1085 | struct hw_device_t common; |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 1086 | int (*activate)(struct sensors_poll_device_t *dev, |
| 1087 | int handle, int enabled); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 1088 | int (*setDelay)(struct sensors_poll_device_t *dev, |
| 1089 | int handle, int64_t ns); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 1090 | int (*poll)(struct sensors_poll_device_t *dev, |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 1091 | sensors_event_t* data, int count); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 1092 | }; |
| 1093 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1094 | /* |
| 1095 | * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0 |
| 1096 | */ |
| 1097 | typedef struct sensors_poll_device_1 { |
| 1098 | union { |
| 1099 | /* sensors_poll_device_1 is compatible with sensors_poll_device_t, |
| 1100 | * and can be down-cast to it |
| 1101 | */ |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 1102 | struct sensors_poll_device_t v0; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1103 | |
| 1104 | struct { |
| 1105 | struct hw_device_t common; |
| 1106 | |
| 1107 | /* Activate/de-activate one sensor. |
| 1108 | * |
| 1109 | * handle is the handle of the sensor to change. |
| 1110 | * enabled set to 1 to enable, or 0 to disable the sensor. |
| 1111 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame] | 1112 | * if enabled is set to 1, the sensor is activated even if |
| 1113 | * setDelay() wasn't called before. In this case, a default rate |
| 1114 | * should be used. |
| 1115 | * |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1116 | * unless otherwise noted in the sensor types definitions, an |
| 1117 | * activated sensor never prevents the SoC to go into suspend |
| 1118 | * mode; that is, the HAL shall not hold a partial wake-lock on |
| 1119 | * behalf of applications. |
| 1120 | * |
| 1121 | * one-shot sensors de-activate themselves automatically upon |
| 1122 | * receiving an event and they must still accept to be deactivated |
| 1123 | * through a call to activate(..., ..., 0). |
| 1124 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame] | 1125 | * if "enabled" is 1 and the sensor is already activated, this |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1126 | * function is a no-op and succeeds. |
| 1127 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame] | 1128 | * if "enabled" is 0 and the sensor is already de-activated, |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1129 | * this function is a no-op and succeeds. |
| 1130 | * |
| 1131 | * return 0 on success, negative errno code otherwise |
| 1132 | */ |
| 1133 | int (*activate)(struct sensors_poll_device_t *dev, |
| 1134 | int handle, int enabled); |
| 1135 | |
| 1136 | /** |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1137 | * Set the events's period in nanoseconds for a given sensor. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1138 | * |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1139 | * What the period_ns parameter means depends on the specified |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1140 | * sensor's trigger mode: |
| 1141 | * |
| 1142 | * continuous: setDelay() sets the sampling rate. |
| 1143 | * on-change: setDelay() limits the delivery rate of events |
| 1144 | * one-shot: setDelay() is ignored. it has no effect. |
| 1145 | * special: see specific sensor type definitions |
| 1146 | * |
| 1147 | * For continuous and on-change sensors, if the requested value is |
| 1148 | * less than sensor_t::minDelay, then it's silently clamped to |
| 1149 | * sensor_t::minDelay unless sensor_t::minDelay is 0, in which |
| 1150 | * case it is clamped to >= 1ms. |
| 1151 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame] | 1152 | * setDelay will not be called when the sensor is in batching mode. |
| 1153 | * In this case, batch() will be called with the new period. |
| 1154 | * |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1155 | * @return 0 if successful, < 0 on error |
| 1156 | */ |
| 1157 | int (*setDelay)(struct sensors_poll_device_t *dev, |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1158 | int handle, int64_t period_ns); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1159 | |
| 1160 | /** |
| 1161 | * Returns an array of sensor data. |
| 1162 | * This function must block until events are available. |
| 1163 | * |
| 1164 | * return the number of events read on success, or -errno in case |
| 1165 | * of an error. |
| 1166 | * |
| 1167 | * The number of events returned in data must be less or equal |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1168 | * to the "count" argument. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1169 | * |
| 1170 | * This function shall never return 0 (no event). |
| 1171 | */ |
| 1172 | int (*poll)(struct sensors_poll_device_t *dev, |
| 1173 | sensors_event_t* data, int count); |
| 1174 | }; |
| 1175 | }; |
| 1176 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1177 | |
| 1178 | /* |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1179 | * Enables batch mode for the given sensor and sets the delay between events |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1180 | * |
| 1181 | * A timeout value of zero disables batch mode for the given sensor. |
| 1182 | * |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1183 | * The period_ns parameter is equivalent to calling setDelay() -- this |
| 1184 | * function both enables or disables the batch mode AND sets the events's |
| 1185 | * period in nanosecond. See setDelay() above for a detailed explanation of |
| 1186 | * the period_ns parameter. |
| 1187 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1188 | * BATCH MODE: |
| 1189 | * ----------- |
| 1190 | * In non-batch mode, all sensor events must be reported as soon as they |
| 1191 | * are detected. For example, an accelerometer activated at 50Hz will |
| 1192 | * trigger interrupts 50 times per second. |
| 1193 | * While in batch mode, sensor events do not need to be reported as soon |
| 1194 | * as they are detected. They can be temporarily stored in batches and |
| 1195 | * reported in batches, as long as no event is delayed by more than |
| 1196 | * "timeout" nanoseconds. That is, all events since the previous batch |
| 1197 | * are recorded and returned all at once. This allows to reduce the amount |
| 1198 | * of interrupts sent to the SoC, and allow the SoC to switch to a lower |
| 1199 | * power state (Idle) while the sensor is capturing and batching data. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1200 | * |
| 1201 | * setDelay() is not affected and it behaves as usual. |
| 1202 | * |
| 1203 | * Each event has a timestamp associated with it, the timestamp |
| 1204 | * must be accurate and correspond to the time at which the event |
| 1205 | * physically happened. |
| 1206 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1207 | * Batching does not modify the behavior of poll(): batches from different |
| 1208 | * sensors can be interleaved and split. As usual, all events from the same |
| 1209 | * sensor are time-ordered. |
| 1210 | * |
| 1211 | * BEHAVIOUR OUTSIDE OF SUSPEND MODE: |
| 1212 | * ---------------------------------- |
| 1213 | * |
| 1214 | * When the SoC is awake (not in suspend mode), events must be reported in |
| 1215 | * batches at least every "timeout". No event shall be dropped or lost. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1216 | * If internal h/w FIFOs fill-up before the timeout, then events are |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1217 | * reported at that point to ensure no event is lost. |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1218 | * |
| 1219 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1220 | * NORMAL BEHAVIOR IN SUSPEND MODE: |
| 1221 | * --------------------------------- |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1222 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1223 | * By default, batch mode doesn't significantly change the interaction with |
| 1224 | * suspend mode. That is, sensors must continue to allow the SoC to |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1225 | * go into suspend mode and sensors must stay active to fill their |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1226 | * internal FIFO. In this mode, when the FIFO fills up, it shall wrap |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1227 | * around (basically behave like a circular buffer, overwriting events). |
| 1228 | * As soon as the SoC comes out of suspend mode, a batch is produced with |
| 1229 | * as much as the recent history as possible, and batch operation |
| 1230 | * resumes as usual. |
| 1231 | * |
| 1232 | * The behavior described above allows applications to record the recent |
| 1233 | * history of a set of sensor while keeping the SoC into suspend. It |
| 1234 | * also allows the hardware to not have to rely on a wake-up interrupt line. |
| 1235 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1236 | * WAKE_UPON_FIFO_FULL BEHAVIOR IN SUSPEND MODE: |
| 1237 | * ---------------------------------------------- |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1238 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1239 | * There are cases, however, where an application cannot afford to lose |
| 1240 | * any events, even when the device goes into suspend mode. |
| 1241 | * For a given rate, if a sensor has the capability to store at least 10 |
| 1242 | * seconds worth of events in its FIFO and is able to wake up the Soc, it |
| 1243 | * can implement an optional secondary mode: the WAKE_UPON_FIFO_FULL mode. |
| 1244 | * |
| 1245 | * The caller will set the SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag to |
| 1246 | * activate this mode. If the sensor does not support this mode, batch() |
| 1247 | * will fail when the flag is set. |
| 1248 | * |
| 1249 | * When running with the WAKE_UPON_FIFO_FULL flag set, no events can be |
| 1250 | * lost. When the FIFO is getting full, the sensor must wake up the SoC from |
| 1251 | * suspend and return a batch before the FIFO fills-up. |
| 1252 | * Depending on the device, it might take a few miliseconds for the SoC to |
| 1253 | * entirely come out of suspend and start flushing the FIFO. Enough head |
| 1254 | * room must be allocated in the FIFO to allow the device to entirely come |
| 1255 | * out of suspend without the FIFO overflowing (no events shall be lost). |
| 1256 | * |
| 1257 | * Implementing the WAKE_UPON_FIFO_FULL mode is optional. |
| 1258 | * If the hardware cannot support this mode, or if the physical |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1259 | * FIFO is so small that the device would never be allowed to go into |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1260 | * suspend for at least 10 seconds, then this function MUST fail when |
| 1261 | * the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of |
| 1262 | * the value of the timeout parameter. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1263 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1264 | * |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1265 | * DRY RUN: |
| 1266 | * -------- |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1267 | * |
| 1268 | * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1269 | * without modifying the batch mode or the event period and has no side |
| 1270 | * effects, but returns errors as usual (as it would if this flag was |
| 1271 | * not set). This flag is used to check if batch mode is available for a |
| 1272 | * given configuration -- in particular for a given sensor at a given rate. |
| 1273 | * |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1274 | * |
| 1275 | * Return values: |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1276 | * -------------- |
| 1277 | * |
| 1278 | * Because sensors must be independent, the return value must not depend |
| 1279 | * on the state of the system (whether another sensor is on or not), |
| 1280 | * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words, |
| 1281 | * if a batch call with SENSORS_BATCH_DRY_RUN is successful, |
| 1282 | * the same call without SENSORS_BATCH_DRY_RUN must succeed as well). |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1283 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame] | 1284 | * When timeout is not 0: |
| 1285 | * If successful, 0 is returned. |
| 1286 | * If the specified sensor doesn't support batch mode, return -EINVAL. |
| 1287 | * If the specified sensor's trigger-mode is one-shot, return -EINVAL. |
| 1288 | * If WAKE_UPON_FIFO_FULL is specified and the specified sensor's internal |
| 1289 | * FIFO is too small to store at least 10 seconds worth of data at the |
| 1290 | * given rate, -EINVAL is returned. Note that as stated above, this has to |
| 1291 | * be determined at compile time, and not based on the state of the |
| 1292 | * system. |
| 1293 | * If some other constraints above cannot be satisfied, return -EINVAL. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1294 | * |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1295 | * Note: the timeout parameter, when > 0, has no impact on whether this |
| 1296 | * function succeeds or fails. |
| 1297 | * |
Etienne Le Grand | f770b7a | 2013-07-10 14:08:40 -0700 | [diff] [blame] | 1298 | * When timeout is 0: |
| 1299 | * The caller will never set the wake_upon_fifo_full flag. |
| 1300 | * The function must succeed, and batch mode must be deactivated. |
| 1301 | * |
| 1302 | * Independently of whether DRY_RUN is specified, When the call to batch() |
| 1303 | * fails, no state should be changed. In particular, a failed call to |
| 1304 | * batch() should not change the rate of the sensor. Example: |
| 1305 | * setDelay(..., 10ms) |
| 1306 | * batch(..., 20ms, ...) fails |
| 1307 | * rate should stay 10ms. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1308 | * |
| 1309 | * |
| 1310 | * IMPLEMENTATION NOTES: |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1311 | * --------------------- |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1312 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1313 | * Batch mode, if supported, should happen at the hardware level, |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1314 | * typically using hardware FIFOs. In particular, it SHALL NOT be |
| 1315 | * implemented in the HAL, as this would be counter productive. |
| 1316 | * The goal here is to save significant amounts of power. |
| 1317 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1318 | * In some implementations, events from several sensors can share the |
| 1319 | * same physical FIFO. In that case, all events in the FIFO can be sent and |
| 1320 | * processed by the HAL as soon as one batch must be reported. |
| 1321 | * For example, if the following sensors are activated: |
| 1322 | * - accelerometer batched with timeout = 20s |
| 1323 | * - gyroscope batched with timeout = 5s |
| 1324 | * then the accelerometer batches can be reported at the same time the |
| 1325 | * gyroscope batches are reported (every 5 seconds) |
| 1326 | * |
| 1327 | * Batch mode can be enabled or disabled at any time, in particular |
| 1328 | * while the specified sensor is already enabled, and this shall not |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1329 | * result in the loss of events. |
| 1330 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1331 | * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS: |
| 1332 | * --------------------------------------------------------- |
| 1333 | * |
| 1334 | * On platforms on which hardware fifo size is limited, the system designers |
| 1335 | * might have to choose how much fifo to reserve for each sensor. To help |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1336 | * with this choice, here is a list of applications made possible when |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1337 | * batching is implemented on the different sensors. |
| 1338 | * |
| 1339 | * High value: Low power pedestrian dead reckoning |
| 1340 | * Target batching time: 20 seconds to 1 minute |
| 1341 | * Sensors to batch: |
| 1342 | * - Step detector |
| 1343 | * - Rotation vector or game rotation vector at 5Hz |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1344 | * Gives us step and heading while letting the SoC go to Suspend. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1345 | * |
| 1346 | * High value: Medium power activity/gesture recognition |
| 1347 | * Target batching time: 3 seconds |
| 1348 | * Sensors to batch: accelerometer between 20Hz and 50Hz |
| 1349 | * Allows recognizing arbitrary activities and gestures without having |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1350 | * to keep the SoC fully awake while the data is collected. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1351 | * |
| 1352 | * Medium-high value: Interrupt load reduction |
| 1353 | * Target batching time: < 1 second |
| 1354 | * Sensors to batch: any high frequency sensor. |
| 1355 | * If the gyroscope is set at 800Hz, even batching just 10 gyro events can |
| 1356 | * reduce the number of interrupts from 800/second to 80/second. |
| 1357 | * |
| 1358 | * Medium value: Continuous low frequency data collection |
| 1359 | * Target batching time: > 1 minute |
| 1360 | * Sensors to batch: barometer, humidity sensor, other low frequency |
| 1361 | * sensors. |
| 1362 | * Allows creating monitoring applications at low power. |
| 1363 | * |
| 1364 | * Medium value: Continuous full-sensors collection |
| 1365 | * Target batching time: > 1 minute |
| 1366 | * Sensors to batch: all, at high frequencies |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1367 | * Allows full collection of sensor data while leaving the SoC in |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 1368 | * suspend mode. Only to consider if fifo space is not an issue. |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 1369 | * |
| 1370 | * In each of the cases above, if WAKE_UPON_FIFO_FULL is implemented, the |
| 1371 | * applications might decide to let the SoC go to suspend, allowing for even |
| 1372 | * more power savings. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1373 | */ |
| 1374 | int (*batch)(struct sensors_poll_device_1* dev, |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 1375 | int handle, int flags, int64_t period_ns, int64_t timeout); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1376 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 1377 | /* |
| 1378 | * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t) |
| 1379 | * to the end of the "batch mode" FIFO for the specified sensor and flushes |
| 1380 | * the FIFO; those events are delivered as usual (i.e.: as if the batch |
| 1381 | * timeout had expired) and removed from the FIFO. |
| 1382 | * |
| 1383 | * See the META_DATA_FLUSH_COMPLETE section for details about the |
| 1384 | * META_DATA_FLUSH_COMPLETE event. |
| 1385 | * |
| 1386 | * The flush happens asynchronously (i.e.: this function must return |
| 1387 | * immediately). |
| 1388 | * |
| 1389 | * If the implementation uses a single FIFO for several sensors, that |
| 1390 | * FIFO is flushed and the META_DATA_FLUSH_COMPLETE event is added only |
| 1391 | * for the specified sensor. |
| 1392 | * |
| 1393 | * If the specified sensor wasn't in batch mode, flush succeeds and |
| 1394 | * promptly sends a META_DATA_FLUSH_COMPLETE event for that sensor. |
| 1395 | * |
| 1396 | * If the FIFO was empty at the time of the call, flush returns |
| 1397 | * 0 (success) and promptly sends a META_DATA_FLUSH_COMPLETE event |
| 1398 | * for that sensor. |
| 1399 | * |
| 1400 | * If the specified sensor wasn't enabled, flush returns -EINVAL. |
| 1401 | * |
| 1402 | * return 0 on success, negative errno code otherwise. |
| 1403 | */ |
| 1404 | int (*flush)(struct sensors_poll_device_1* dev, int handle); |
| 1405 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1406 | void (*reserved_procs[8])(void); |
| 1407 | |
| 1408 | } sensors_poll_device_1_t; |
| 1409 | |
| 1410 | |
| 1411 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1412 | /** convenience API for opening and closing a device */ |
| 1413 | |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 1414 | static inline int sensors_open(const struct hw_module_t* module, |
| 1415 | struct sensors_poll_device_t** device) { |
| 1416 | return module->methods->open(module, |
| 1417 | SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); |
| 1418 | } |
| 1419 | |
| 1420 | static inline int sensors_close(struct sensors_poll_device_t* device) { |
| 1421 | return device->common.close(&device->common); |
| 1422 | } |
| 1423 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1424 | static inline int sensors_open_1(const struct hw_module_t* module, |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 1425 | sensors_poll_device_1_t** device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1426 | return module->methods->open(module, |
| 1427 | SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); |
| 1428 | } |
| 1429 | |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 1430 | static inline int sensors_close_1(sensors_poll_device_1_t* device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 1431 | return device->common.close(&device->common); |
| 1432 | } |
| 1433 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1434 | __END_DECLS |
| 1435 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1436 | #endif // ANDROID_SENSORS_INTERFACE_H |