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 | 477fbd5 | 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 | /** |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 39 | * Please see the Sensors section of source.android.com for an |
| 40 | * introduction to and detailed descriptions of Android sensor types: |
| 41 | * http://source.android.com/devices/sensors/index.html |
| 42 | */ |
| 43 | |
| 44 | /** |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 45 | * The id of this module |
| 46 | */ |
| 47 | #define SENSORS_HARDWARE_MODULE_ID "sensors" |
| 48 | |
| 49 | /** |
| 50 | * Name of the sensors device to open |
| 51 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 52 | #define SENSORS_HARDWARE_POLL "poll" |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Handles must be higher than SENSORS_HANDLE_BASE and must be unique. |
| 56 | * A Handle identifies a given sensors. The handle is used to activate |
| 57 | * and/or deactivate sensors. |
| 58 | * In this version of the API there can only be 256 handles. |
| 59 | */ |
| 60 | #define SENSORS_HANDLE_BASE 0 |
| 61 | #define SENSORS_HANDLE_BITS 8 |
| 62 | #define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS) |
| 63 | |
| 64 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 65 | /* |
| 66 | * flags for (*batch)() |
| 67 | * Availability: SENSORS_DEVICE_API_VERSION_1_0 |
| 68 | * see (*batch)() documentation for details |
| 69 | */ |
| 70 | enum { |
| 71 | SENSORS_BATCH_DRY_RUN = 0x00000001, |
| 72 | SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002 |
| 73 | }; |
| 74 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 75 | /* |
| 76 | * what field for meta_data_event_t |
| 77 | */ |
| 78 | enum { |
| 79 | /* a previous flush operation has completed */ |
Mathias Agopian | af32a8d | 2013-08-06 20:33:38 -0700 | [diff] [blame] | 80 | META_DATA_FLUSH_COMPLETE = 1, |
| 81 | META_DATA_VERSION /* always last, leave auto-assigned */ |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 84 | /* |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 85 | * The permission to use for body sensors (like heart rate monitors). |
| 86 | * See sensor types for more details on what sensors should require this |
| 87 | * permission. |
| 88 | */ |
| 89 | #define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS" |
| 90 | |
| 91 | /* |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 92 | * Sensor type |
| 93 | * |
| 94 | * Each sensor has a type which defines what this sensor measures and how |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 95 | * measures are reported. See the Base sensors and Composite sensors lists |
| 96 | * for complete descriptions: |
| 97 | * http://source.android.com/devices/sensors/base_triggers.html |
| 98 | * http://source.android.com/devices/sensors/composite_sensors.html |
Mathias Agopian | 1599ec6 | 2013-08-19 14:34:47 -0700 | [diff] [blame] | 99 | * |
| 100 | * Device manufacturers (OEMs) can define their own sensor types, for |
| 101 | * their private use by applications or services provided by them. Such |
| 102 | * sensor types are specific to an OEM and can't be exposed in the SDK. |
| 103 | * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE. |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 104 | * |
| 105 | * All sensors defined outside of the device private range must correspond to |
| 106 | * a type defined in this file, and must satisfy the characteristics listed in |
| 107 | * the description of the sensor type. |
| 108 | * |
| 109 | * Starting with version SENSORS_DEVICE_API_VERSION_1_2, each sensor also |
| 110 | * has a stringType. |
| 111 | * - StringType of sensors inside of the device private range MUST be prefixed |
| 112 | * by the sensor provider's or OEM reverse domain name. In particular, they |
| 113 | * cannot use the "android.sensor" prefix. |
| 114 | * - StringType of sensors outside of the device private range MUST correspond |
| 115 | * to the one defined in this file (starting with "android.sensor"). |
| 116 | * For example, accelerometers must have |
| 117 | * type=SENSOR_TYPE_ACCELEROMETER and |
| 118 | * stringType=SENSOR_STRING_TYPE_ACCELEROMETER |
| 119 | * |
| 120 | * When android introduces a new sensor type that can replace an OEM-defined |
| 121 | * sensor type, the OEM must use the official sensor type and stringType on |
| 122 | * versions of the HAL that support this new official sensor type. |
| 123 | * |
| 124 | * Example (made up): Suppose Google's Glass team wants to surface a sensor |
| 125 | * detecting that Glass is on a head. |
| 126 | * - Such a sensor is not officially supported in android KitKat |
| 127 | * - Glass devices launching on KitKat can implement a sensor with |
| 128 | * type = 0x10001 and stringType = "com.google.glass.onheaddetector" |
| 129 | * - In L android release, if android decides to define |
| 130 | * SENSOR_TYPE_ON_HEAD_DETECTOR and STRING_SENSOR_TYPE_ON_HEAD_DETECTOR, |
| 131 | * those types should replace the Glass-team-specific types in all future |
| 132 | * launches. |
| 133 | * - When launching glass on the L release, Google should now use the official |
| 134 | * type (SENSOR_TYPE_ON_HEAD_DETECTOR) and stringType. |
| 135 | * - This way, all applications can now use this sensor. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 136 | */ |
| 137 | |
| 138 | /* |
Mathias Agopian | 1599ec6 | 2013-08-19 14:34:47 -0700 | [diff] [blame] | 139 | * Base for device manufacturers private sensor types. |
| 140 | * These sensor types can't be exposed in the SDK. |
| 141 | */ |
| 142 | #define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000 |
| 143 | |
| 144 | /* |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 145 | * SENSOR_TYPE_META_DATA |
| 146 | * trigger-mode: n/a |
| 147 | * wake-up sensor: n/a |
| 148 | * |
| 149 | * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)() |
| 150 | * |
| 151 | * SENSOR_TYPE_META_DATA is a special token used to populate the |
| 152 | * sensors_meta_data_event structure. It doesn't correspond to a physical |
| 153 | * sensor. sensors_meta_data_event are special, they exist only inside |
| 154 | * the HAL and are generated spontaneously, as opposed to be related to |
| 155 | * a physical sensor. |
| 156 | * |
Mathias Agopian | af32a8d | 2013-08-06 20:33:38 -0700 | [diff] [blame] | 157 | * sensors_meta_data_event_t.version must be META_DATA_VERSION |
| 158 | * sensors_meta_data_event_t.sensor must be 0 |
| 159 | * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA |
| 160 | * sensors_meta_data_event_t.reserved must be 0 |
| 161 | * sensors_meta_data_event_t.timestamp must be 0 |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 162 | * |
| 163 | * The payload is a meta_data_event_t, where: |
| 164 | * meta_data_event_t.what can take the following values: |
| 165 | * |
| 166 | * META_DATA_FLUSH_COMPLETE |
| 167 | * This event indicates that a previous (*flush)() call has completed for the sensor |
| 168 | * handle specified in meta_data_event_t.sensor. |
| 169 | * see (*flush)() for more details |
| 170 | * |
| 171 | * All other values for meta_data_event_t.what are reserved and |
| 172 | * must not be used. |
| 173 | * |
| 174 | */ |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 175 | #define SENSOR_TYPE_META_DATA (0) |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 176 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 177 | /* |
| 178 | * SENSOR_TYPE_ACCELEROMETER |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 179 | * trigger-mode: continuous |
| 180 | * wake-up sensor: no |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 181 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 182 | * All values are in SI units (m/s^2) and measure the acceleration of the |
| 183 | * device minus the force of gravity. |
| 184 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 185 | */ |
| 186 | #define SENSOR_TYPE_ACCELEROMETER (1) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 187 | #define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * SENSOR_TYPE_GEOMAGNETIC_FIELD |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 191 | * trigger-mode: continuous |
| 192 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 193 | * |
| 194 | * All values are in micro-Tesla (uT) and measure the geomagnetic |
| 195 | * field in the X, Y and Z axis. |
| 196 | * |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 197 | */ |
| 198 | #define SENSOR_TYPE_GEOMAGNETIC_FIELD (2) |
| 199 | #define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 200 | #define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 201 | |
| 202 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 203 | * SENSOR_TYPE_ORIENTATION |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 204 | * trigger-mode: continuous |
| 205 | * wake-up sensor: no |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 206 | * |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 207 | * All values are angles in degrees. |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 208 | * |
Mathias Agopian | 66a4095 | 2010-07-22 17:11:50 -0700 | [diff] [blame] | 209 | * Orientation sensors return sensor events for all 3 axes at a constant |
| 210 | * rate defined by setDelay(). |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 211 | */ |
| 212 | #define SENSOR_TYPE_ORIENTATION (3) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 213 | #define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 214 | |
| 215 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 216 | * SENSOR_TYPE_GYROSCOPE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 217 | * trigger-mode: continuous |
| 218 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 219 | * |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 220 | * All values are in radians/second and measure the rate of rotation |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 221 | * around the X, Y and Z axis. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 222 | */ |
| 223 | #define SENSOR_TYPE_GYROSCOPE (4) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 224 | #define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * SENSOR_TYPE_LIGHT |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 228 | * trigger-mode: on-change |
| 229 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 230 | * |
| 231 | * The light sensor value is returned in SI lux units. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 232 | */ |
| 233 | #define SENSOR_TYPE_LIGHT (5) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 234 | #define SENSOR_STRING_TYPE_LIGHT "android.sensor.light" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 235 | |
| 236 | /* |
| 237 | * SENSOR_TYPE_PRESSURE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 238 | * trigger-mode: continuous |
| 239 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 240 | * |
| 241 | * The pressure sensor return the athmospheric pressure in hectopascal (hPa) |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 242 | */ |
| 243 | #define SENSOR_TYPE_PRESSURE (6) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 244 | #define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 245 | |
| 246 | /* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */ |
| 247 | #define SENSOR_TYPE_TEMPERATURE (7) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 248 | #define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 249 | |
| 250 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 251 | * SENSOR_TYPE_PROXIMITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 252 | * trigger-mode: on-change |
| 253 | * wake-up sensor: yes |
Mike Lockwood | a241431 | 2009-11-03 10:29:50 -0500 | [diff] [blame] | 254 | * |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 255 | * The value corresponds to the distance to the nearest object in centimeters. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 256 | */ |
| 257 | #define SENSOR_TYPE_PROXIMITY (8) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 258 | #define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 259 | |
| 260 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 261 | * SENSOR_TYPE_GRAVITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 262 | * trigger-mode: continuous |
| 263 | * wake-up sensor: no |
Mathias Agopian | 42b743c | 2010-11-22 15:55:32 -0800 | [diff] [blame] | 264 | * |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 265 | * A gravity output indicates the direction of and magnitude of gravity in |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 266 | * the devices's coordinates. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 267 | */ |
| 268 | #define SENSOR_TYPE_GRAVITY (9) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 269 | #define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 270 | |
| 271 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 272 | * SENSOR_TYPE_LINEAR_ACCELERATION |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 273 | * trigger-mode: continuous |
| 274 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 275 | * |
| 276 | * Indicates the linear acceleration of the device in device coordinates, |
| 277 | * not including gravity. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 278 | */ |
| 279 | #define SENSOR_TYPE_LINEAR_ACCELERATION (10) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 280 | #define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 281 | |
| 282 | |
| 283 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 284 | * SENSOR_TYPE_ROTATION_VECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 285 | * trigger-mode: continuous |
| 286 | * wake-up sensor: no |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 287 | * |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 288 | * The rotation vector symbolizes the orientation of the device relative to the |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 289 | * East-North-Up coordinates frame. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 290 | */ |
| 291 | #define SENSOR_TYPE_ROTATION_VECTOR (11) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 292 | #define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 293 | |
| 294 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 295 | * SENSOR_TYPE_RELATIVE_HUMIDITY |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 296 | * trigger-mode: on-change |
| 297 | * wake-up sensor: no |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 298 | * |
| 299 | * A relative humidity sensor measures relative ambient air humidity and |
| 300 | * returns a value in percent. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 301 | */ |
| 302 | #define SENSOR_TYPE_RELATIVE_HUMIDITY (12) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 303 | #define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 304 | |
| 305 | /* |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 306 | * SENSOR_TYPE_AMBIENT_TEMPERATURE |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 307 | * trigger-mode: on-change |
| 308 | * wake-up sensor: no |
Mathias Agopian | 54f9dd0 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 309 | * |
| 310 | * The ambient (room) temperature in degree Celsius. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 311 | */ |
| 312 | #define SENSOR_TYPE_AMBIENT_TEMPERATURE (13) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 313 | #define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 317 | * trigger-mode: continuous |
| 318 | * wake-up sensor: no |
Mathias Agopian | 54f9dd0 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 319 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 320 | * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is |
| 321 | * reported separately instead of being included in the measurement. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 322 | */ |
| 323 | #define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 324 | #define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 325 | |
| 326 | /* |
| 327 | * SENSOR_TYPE_GAME_ROTATION_VECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 328 | * trigger-mode: continuous |
| 329 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 330 | * |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 331 | * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 332 | * field. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 333 | */ |
| 334 | #define SENSOR_TYPE_GAME_ROTATION_VECTOR (15) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 335 | #define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 339 | * trigger-mode: continuous |
| 340 | * wake-up sensor: no |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 341 | * |
| 342 | * All values are in radians/second and measure the rate of rotation |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 343 | * around the X, Y and Z axis. |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 344 | */ |
| 345 | #define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 346 | #define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated" |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 347 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 348 | /* |
| 349 | * SENSOR_TYPE_SIGNIFICANT_MOTION |
| 350 | * trigger-mode: one-shot |
| 351 | * wake-up sensor: yes |
| 352 | * |
| 353 | * A sensor of this type triggers an event each time significant motion |
| 354 | * is detected and automatically disables itself. |
| 355 | * The only allowed value to return is 1.0. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 356 | */ |
| 357 | |
| 358 | #define SENSOR_TYPE_SIGNIFICANT_MOTION (17) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 359 | #define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion" |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 360 | |
| 361 | /* |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 362 | * SENSOR_TYPE_STEP_DETECTOR |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 363 | * trigger-mode: special |
| 364 | * wake-up sensor: no |
| 365 | * |
| 366 | * A sensor of this type triggers an event each time a step is taken |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 367 | * by the user. The only allowed value to return is 1.0 and an event |
| 368 | * is generated for each step. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 369 | */ |
| 370 | |
Mathias Agopian | 2f276f5 | 2013-01-28 17:54:41 -0800 | [diff] [blame] | 371 | #define SENSOR_TYPE_STEP_DETECTOR (18) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 372 | #define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector" |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 373 | |
| 374 | |
| 375 | /* |
| 376 | * SENSOR_TYPE_STEP_COUNTER |
| 377 | * trigger-mode: on-change |
| 378 | * wake-up sensor: no |
| 379 | * |
| 380 | * 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] | 381 | * 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] | 382 | * reset to zero only on a system / android reboot. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 383 | */ |
| 384 | |
| 385 | #define SENSOR_TYPE_STEP_COUNTER (19) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 386 | #define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter" |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 387 | |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 388 | /* |
| 389 | * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR |
| 390 | * trigger-mode: continuous |
| 391 | * wake-up sensor: no |
| 392 | * |
| 393 | * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead |
| 394 | * of using a gyroscope. |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 395 | */ |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 396 | #define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20) |
| 397 | #define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector" |
| 398 | |
| 399 | /* |
| 400 | * SENSOR_TYPE_HEART_RATE |
| 401 | * trigger-mode: on-change |
| 402 | * wake-up sensor: no |
| 403 | * |
| 404 | * A sensor of this type returns the current heart rate if activated. |
| 405 | * The value is returned as a float which represents the heart rate in beats |
| 406 | * per minute (BPM). |
| 407 | * When the sensor cannot measure the heart rate, the returned value must be 0. |
| 408 | * sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS. |
| 409 | */ |
| 410 | #define SENSOR_TYPE_HEART_RATE (21) |
| 411 | #define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate" |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 412 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 413 | /** |
| 414 | * Values returned by the accelerometer in various locations in the universe. |
| 415 | * all values are in SI units (m/s^2) |
| 416 | */ |
| 417 | #define GRAVITY_SUN (275.0f) |
| 418 | #define GRAVITY_EARTH (9.80665f) |
| 419 | |
| 420 | /** Maximum magnetic field on Earth's surface */ |
| 421 | #define MAGNETIC_FIELD_EARTH_MAX (60.0f) |
| 422 | |
| 423 | /** Minimum magnetic field on Earth's surface */ |
| 424 | #define MAGNETIC_FIELD_EARTH_MIN (30.0f) |
| 425 | |
| 426 | |
| 427 | /** |
| 428 | * status of orientation sensor |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 429 | */ |
Kevin Powell | b01a043 | 2010-07-19 19:12:15 -0700 | [diff] [blame] | 430 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 431 | #define SENSOR_STATUS_UNRELIABLE 0 |
| 432 | #define SENSOR_STATUS_ACCURACY_LOW 1 |
| 433 | #define SENSOR_STATUS_ACCURACY_MEDIUM 2 |
| 434 | #define SENSOR_STATUS_ACCURACY_HIGH 3 |
| 435 | |
| 436 | |
| 437 | /** |
| 438 | * sensor event data |
| 439 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 440 | typedef struct { |
| 441 | union { |
| 442 | float v[3]; |
| 443 | struct { |
| 444 | float x; |
| 445 | float y; |
| 446 | float z; |
| 447 | }; |
| 448 | struct { |
| 449 | float azimuth; |
| 450 | float pitch; |
| 451 | float roll; |
| 452 | }; |
| 453 | }; |
| 454 | int8_t status; |
| 455 | uint8_t reserved[3]; |
| 456 | } sensors_vec_t; |
| 457 | |
| 458 | /** |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 459 | * uncalibrated gyroscope and magnetometer event data |
| 460 | */ |
| 461 | typedef struct { |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 462 | union { |
| 463 | float uncalib[3]; |
| 464 | struct { |
| 465 | float x_uncalib; |
| 466 | float y_uncalib; |
| 467 | float z_uncalib; |
| 468 | }; |
| 469 | }; |
| 470 | union { |
| 471 | float bias[3]; |
| 472 | struct { |
| 473 | float x_bias; |
| 474 | float y_bias; |
| 475 | float z_bias; |
| 476 | }; |
| 477 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 478 | } uncalibrated_event_t; |
| 479 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 480 | typedef struct meta_data_event { |
| 481 | int32_t what; |
| 482 | int32_t sensor; |
| 483 | } meta_data_event_t; |
| 484 | |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 485 | /** |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 486 | * Union of the various types of sensor data |
| 487 | * that can be returned. |
| 488 | */ |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 489 | typedef struct sensors_event_t { |
| 490 | /* must be sizeof(struct sensors_event_t) */ |
| 491 | int32_t version; |
| 492 | |
| 493 | /* sensor identifier */ |
| 494 | int32_t sensor; |
| 495 | |
| 496 | /* sensor type */ |
| 497 | int32_t type; |
| 498 | |
| 499 | /* reserved */ |
| 500 | int32_t reserved0; |
| 501 | |
| 502 | /* time is in nanosecond */ |
| 503 | int64_t timestamp; |
| 504 | |
| 505 | union { |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 506 | union { |
| 507 | float data[16]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 508 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 509 | /* acceleration values are in meter per second per second (m/s^2) */ |
| 510 | sensors_vec_t acceleration; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 511 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 512 | /* magnetic vector values are in micro-Tesla (uT) */ |
| 513 | sensors_vec_t magnetic; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 514 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 515 | /* orientation values are in degrees */ |
| 516 | sensors_vec_t orientation; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 517 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 518 | /* gyroscope values are in rad/s */ |
| 519 | sensors_vec_t gyro; |
Makarand Karvekar | 3120b58 | 2010-08-11 15:10:10 -0700 | [diff] [blame] | 520 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 521 | /* temperature is in degrees centigrade (Celsius) */ |
| 522 | float temperature; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 523 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 524 | /* distance in centimeters */ |
| 525 | float distance; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 526 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 527 | /* light in SI lux units */ |
| 528 | float light; |
Mathias Agopian | 1832f55 | 2010-07-29 15:22:30 -0700 | [diff] [blame] | 529 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 530 | /* pressure in hectopascal (hPa) */ |
| 531 | float pressure; |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 532 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 533 | /* relative humidity in percent */ |
| 534 | float relative_humidity; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 535 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 536 | /* uncalibrated gyroscope values are in rad/s */ |
| 537 | uncalibrated_event_t uncalibrated_gyro; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 538 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 539 | /* uncalibrated magnetometer values are in micro-Teslas */ |
| 540 | uncalibrated_event_t uncalibrated_magnetic; |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 541 | |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 542 | /* heart rate in bpm */ |
| 543 | float heart_rate; |
| 544 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 545 | /* this is a special event. see SENSOR_TYPE_META_DATA above. |
| 546 | * sensors_meta_data_event_t events are all reported with a type of |
| 547 | * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero. |
| 548 | */ |
| 549 | meta_data_event_t meta_data; |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 550 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 551 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 552 | union { |
| 553 | uint64_t data[8]; |
| 554 | |
| 555 | /* step-counter */ |
| 556 | uint64_t step_counter; |
| 557 | } u64; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 558 | }; |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 559 | uint32_t reserved1[4]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 560 | } sensors_event_t; |
| 561 | |
| 562 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 563 | /* see SENSOR_TYPE_META_DATA */ |
| 564 | typedef sensors_event_t sensors_meta_data_event_t; |
| 565 | |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 566 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 567 | struct sensor_t; |
| 568 | |
| 569 | /** |
| 570 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 571 | * and the fields of this data structure must begin with hw_module_t |
| 572 | * followed by module specific information. |
| 573 | */ |
| 574 | struct sensors_module_t { |
| 575 | struct hw_module_t common; |
| 576 | |
| 577 | /** |
| 578 | * Enumerate all available sensors. The list is returned in "list". |
| 579 | * @return number of sensors in the list |
| 580 | */ |
| 581 | int (*get_sensors_list)(struct sensors_module_t* module, |
| 582 | struct sensor_t const** list); |
| 583 | }; |
| 584 | |
| 585 | struct sensor_t { |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 586 | |
| 587 | /* Name of this sensor. |
| 588 | * All sensors of the same "type" must have a different "name". |
| 589 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 590 | const char* name; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 591 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 592 | /* vendor of the hardware part */ |
| 593 | const char* vendor; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 594 | |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 595 | /* version of the hardware part + driver. The value of this field |
| 596 | * must increase when the driver is updated in a way that changes the |
| 597 | * output of this sensor. This is important for fused sensors when the |
| 598 | * fusion algorithm is updated. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 599 | */ |
| 600 | int version; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 601 | |
| 602 | /* handle that identifies this sensors. This handle is used to reference |
| 603 | * this sensor throughout the HAL API. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 604 | */ |
| 605 | int handle; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 606 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 607 | /* this sensor's type. */ |
| 608 | int type; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 609 | |
| 610 | /* 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] | 611 | float maxRange; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 612 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 613 | /* smallest difference between two values reported by this sensor */ |
| 614 | float resolution; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 615 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 616 | /* rough estimate of this sensor's power consumption in mA */ |
| 617 | float power; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 618 | |
| 619 | /* this value depends on the trigger mode: |
| 620 | * |
| 621 | * continuous: minimum sample period allowed in microseconds |
| 622 | * on-change : 0 |
| 623 | * one-shot :-1 |
| 624 | * special : 0, unless otherwise noted |
| 625 | */ |
Mathias Agopian | 1511e20 | 2010-07-29 15:33:22 -0700 | [diff] [blame] | 626 | int32_t minDelay; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 627 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 628 | /* number of events reserved for this sensor in the batch mode FIFO. |
| 629 | * If there is a dedicated FIFO for this sensor, then this is the |
| 630 | * size of this FIFO. If the FIFO is shared with other sensors, |
| 631 | * this is the size reserved for that sensor and it can be zero. |
| 632 | */ |
| 633 | uint32_t fifoReservedEventCount; |
| 634 | |
| 635 | /* maximum number of events of this sensor that could be batched. |
| 636 | * This is especially relevant when the FIFO is shared between |
| 637 | * several sensors; this value is then set to the size of that FIFO. |
| 638 | */ |
| 639 | uint32_t fifoMaxEventCount; |
| 640 | |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 641 | /* type of this sensor as a string. Set to corresponding |
| 642 | * SENSOR_STRING_TYPE_*. |
| 643 | * When defining an OEM specific sensor or sensor manufacturer specific |
| 644 | * sensor, use your reserve domain name as a prefix. |
| 645 | * ex: com.google.glass.onheaddetector |
| 646 | * For sensors of known type, the android framework might overwrite this |
| 647 | * string automatically. |
| 648 | */ |
| 649 | const char* stringType; |
| 650 | |
| 651 | /* permission required to see this sensor, register to it and receive data. |
| 652 | * Set to "" if no permission is required. Some sensor types like the |
| 653 | * heart rate monitor have a mandatory require_permission. |
| 654 | * For sensors that always require a specific permission, like the heart |
| 655 | * rate monitor, the android framework might overwrite this string |
| 656 | * automatically. |
| 657 | */ |
| 658 | const char* requiredPermission; |
| 659 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 660 | /* reserved fields, must be zero */ |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame^] | 661 | void* reserved[4]; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 662 | }; |
| 663 | |
| 664 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 665 | /* |
| 666 | * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1 |
| 667 | * and is present for backward binary and source compatibility. |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 668 | * See the Sensors HAL interface section for complete descriptions of the |
| 669 | * following functions: |
| 670 | * http://source.android.com/devices/sensors/index.html#hal |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 671 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 672 | struct sensors_poll_device_t { |
| 673 | struct hw_device_t common; |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 674 | int (*activate)(struct sensors_poll_device_t *dev, |
| 675 | int handle, int enabled); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 676 | int (*setDelay)(struct sensors_poll_device_t *dev, |
| 677 | int handle, int64_t ns); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 678 | int (*poll)(struct sensors_poll_device_t *dev, |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 679 | sensors_event_t* data, int count); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 680 | }; |
| 681 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 682 | /* |
| 683 | * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0 |
| 684 | */ |
| 685 | typedef struct sensors_poll_device_1 { |
| 686 | union { |
| 687 | /* sensors_poll_device_1 is compatible with sensors_poll_device_t, |
| 688 | * and can be down-cast to it |
| 689 | */ |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 690 | struct sensors_poll_device_t v0; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 691 | |
| 692 | struct { |
| 693 | struct hw_device_t common; |
| 694 | |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 695 | /* Activate/de-activate one sensor. Return 0 on success, negative |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 696 | * |
| 697 | * handle is the handle of the sensor to change. |
| 698 | * enabled set to 1 to enable, or 0 to disable the sensor. |
| 699 | * |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 700 | * Return 0 on success, negative errno code otherwise. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 701 | */ |
| 702 | int (*activate)(struct sensors_poll_device_t *dev, |
| 703 | int handle, int enabled); |
| 704 | |
| 705 | /** |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 706 | * Set the events's period in nanoseconds for a given sensor. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 707 | */ |
| 708 | int (*setDelay)(struct sensors_poll_device_t *dev, |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 709 | int handle, int64_t period_ns); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 710 | |
| 711 | /** |
| 712 | * Returns an array of sensor data. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 713 | */ |
| 714 | int (*poll)(struct sensors_poll_device_t *dev, |
| 715 | sensors_event_t* data, int count); |
| 716 | }; |
| 717 | }; |
| 718 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 719 | |
| 720 | /* |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 721 | * Enables batch mode for the given sensor and sets the delay between events. |
| 722 | * See the Batching sensor results page for details: |
| 723 | * http://source.android.com/devices/sensors/batching.html |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 724 | */ |
| 725 | int (*batch)(struct sensors_poll_device_1* dev, |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 726 | int handle, int flags, int64_t period_ns, int64_t timeout); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 727 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 728 | /* |
| 729 | * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t) |
| 730 | * to the end of the "batch mode" FIFO for the specified sensor and flushes |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 731 | * the FIFO. |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 732 | */ |
| 733 | int (*flush)(struct sensors_poll_device_1* dev, int handle); |
| 734 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 735 | void (*reserved_procs[8])(void); |
| 736 | |
| 737 | } sensors_poll_device_1_t; |
| 738 | |
| 739 | |
| 740 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 741 | /** convenience API for opening and closing a device */ |
| 742 | |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 743 | static inline int sensors_open(const struct hw_module_t* module, |
| 744 | struct sensors_poll_device_t** device) { |
| 745 | return module->methods->open(module, |
| 746 | SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); |
| 747 | } |
| 748 | |
| 749 | static inline int sensors_close(struct sensors_poll_device_t* device) { |
| 750 | return device->common.close(&device->common); |
| 751 | } |
| 752 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 753 | static inline int sensors_open_1(const struct hw_module_t* module, |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 754 | sensors_poll_device_1_t** device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 755 | return module->methods->open(module, |
| 756 | SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); |
| 757 | } |
| 758 | |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 759 | static inline int sensors_close_1(sensors_poll_device_1_t* device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 760 | return device->common.close(&device->common); |
| 761 | } |
| 762 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 763 | __END_DECLS |
| 764 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 765 | #endif // ANDROID_SENSORS_INTERFACE_H |