| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 17 | /** | 
| Leon Scroggins III | 4883c52 | 2020-01-30 15:10:11 -0500 | [diff] [blame] | 18 | * Structures and functions to receive and process sensor events in | 
|  | 19 | * native code. | 
|  | 20 | * | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 21 | * @addtogroup Sensor | 
|  | 22 | * @{ | 
|  | 23 | */ | 
|  | 24 |  | 
|  | 25 | /** | 
|  | 26 | * @file sensor.h | 
|  | 27 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 28 |  | 
|  | 29 | #ifndef ANDROID_SENSOR_H | 
|  | 30 | #define ANDROID_SENSOR_H | 
|  | 31 |  | 
|  | 32 | /****************************************************************** | 
|  | 33 | * | 
|  | 34 | * IMPORTANT NOTICE: | 
|  | 35 | * | 
|  | 36 | *   This file is part of Android's set of stable system headers | 
|  | 37 | *   exposed by the Android NDK (Native Development Kit). | 
|  | 38 | * | 
|  | 39 | *   Third-party source AND binary code relies on the definitions | 
|  | 40 | *   here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. | 
|  | 41 | * | 
|  | 42 | *   - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) | 
|  | 43 | *   - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS | 
|  | 44 | *   - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY | 
|  | 45 | *   - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES | 
|  | 46 | */ | 
|  | 47 |  | 
| Ady Abraham | 2a6c186 | 2022-07-28 22:54:19 +0000 | [diff] [blame] | 48 | // This file is included by modules that have host support but android/looper.h is not supported | 
|  | 49 | // on host. __REMOVED_IN needs to be defined in order for android/looper.h to be compiled. | 
|  | 50 | #ifndef __BIONIC__ | 
|  | 51 | #define __REMOVED_IN(x) __attribute__((deprecated)) | 
|  | 52 | #endif | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 53 | #include <android/looper.h> | 
|  | 54 |  | 
| Dan Albert | 8f860fd | 2017-04-25 12:24:28 -0700 | [diff] [blame] | 55 | #include <stdbool.h> | 
| Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 56 | #include <sys/types.h> | 
|  | 57 | #include <math.h> | 
|  | 58 | #include <stdint.h> | 
|  | 59 |  | 
| Elliott Hughes | 23e82b4 | 2021-01-26 14:55:48 -0800 | [diff] [blame] | 60 | #if !defined(__INTRODUCED_IN) | 
|  | 61 | #define __INTRODUCED_IN(__api_level) /* nothing */ | 
|  | 62 | #endif | 
|  | 63 | #if !defined(__DEPRECATED_IN) | 
|  | 64 | #define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__)) | 
|  | 65 | #endif | 
|  | 66 |  | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 67 | #ifdef __cplusplus | 
|  | 68 | extern "C" { | 
|  | 69 | #endif | 
|  | 70 |  | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 71 | typedef struct AHardwareBuffer AHardwareBuffer; | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 72 |  | 
| Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 73 | #define ASENSOR_RESOLUTION_INVALID     (nanf("")) | 
|  | 74 | #define ASENSOR_FIFO_COUNT_INVALID     (-1) | 
|  | 75 | #define ASENSOR_DELAY_INVALID          INT32_MIN | 
| Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 76 | #define ASENSOR_INVALID                (-1) | 
| Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 77 |  | 
| Elliott Hughes | f78be36 | 2018-01-23 15:33:56 -0800 | [diff] [blame] | 78 | /* (Keep in sync with hardware/sensors-base.h and Sensor.java.) */ | 
|  | 79 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 80 | /** | 
|  | 81 | * Sensor types. | 
| Elliott Hughes | f78be36 | 2018-01-23 15:33:56 -0800 | [diff] [blame] | 82 | * | 
|  | 83 | * See | 
|  | 84 | * [android.hardware.SensorEvent#values](https://developer.android.com/reference/android/hardware/SensorEvent.html#values) | 
|  | 85 | * for detailed explanations of the data returned for each of these types. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 86 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 87 | enum { | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 88 | /** | 
| Peng Xu | 37317b6 | 2017-03-07 17:49:31 -0800 | [diff] [blame] | 89 | * Invalid sensor type. Returned by {@link ASensor_getType} as error value. | 
|  | 90 | */ | 
|  | 91 | ASENSOR_TYPE_INVALID = -1, | 
|  | 92 | /** | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 93 | * {@link ASENSOR_TYPE_ACCELEROMETER} | 
|  | 94 | * reporting-mode: continuous | 
|  | 95 | * | 
|  | 96 | *  All values are in SI units (m/s^2) and measure the acceleration of the | 
|  | 97 | *  device minus the force of gravity. | 
|  | 98 | */ | 
| Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 99 | ASENSOR_TYPE_ACCELEROMETER       = 1, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 100 | /** | 
|  | 101 | * {@link ASENSOR_TYPE_MAGNETIC_FIELD} | 
|  | 102 | * reporting-mode: continuous | 
|  | 103 | * | 
|  | 104 | *  All values are in micro-Tesla (uT) and measure the geomagnetic | 
|  | 105 | *  field in the X, Y and Z axis. | 
|  | 106 | */ | 
| Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 107 | ASENSOR_TYPE_MAGNETIC_FIELD      = 2, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 108 | /** | 
|  | 109 | * {@link ASENSOR_TYPE_GYROSCOPE} | 
|  | 110 | * reporting-mode: continuous | 
|  | 111 | * | 
|  | 112 | *  All values are in radians/second and measure the rate of rotation | 
|  | 113 | *  around the X, Y and Z axis. | 
|  | 114 | */ | 
| Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 115 | ASENSOR_TYPE_GYROSCOPE           = 4, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 116 | /** | 
|  | 117 | * {@link ASENSOR_TYPE_LIGHT} | 
|  | 118 | * reporting-mode: on-change | 
|  | 119 | * | 
|  | 120 | * The light sensor value is returned in SI lux units. | 
|  | 121 | */ | 
| Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 122 | ASENSOR_TYPE_LIGHT               = 5, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 123 | /** | 
| Elliott Hughes | f78be36 | 2018-01-23 15:33:56 -0800 | [diff] [blame] | 124 | * {@link ASENSOR_TYPE_PRESSURE} | 
|  | 125 | * | 
|  | 126 | * The pressure sensor value is returned in hPa (millibar). | 
|  | 127 | */ | 
|  | 128 | ASENSOR_TYPE_PRESSURE            = 6, | 
|  | 129 | /** | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 130 | * {@link ASENSOR_TYPE_PROXIMITY} | 
|  | 131 | * reporting-mode: on-change | 
|  | 132 | * | 
|  | 133 | * The proximity sensor which turns the screen off and back on during calls is the | 
|  | 134 | * wake-up proximity sensor. Implement wake-up proximity sensor before implementing | 
|  | 135 | * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag | 
|  | 136 | * SENSOR_FLAG_WAKE_UP. | 
|  | 137 | * The value corresponds to the distance to the nearest object in centimeters. | 
|  | 138 | */ | 
| Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 139 | ASENSOR_TYPE_PROXIMITY           = 8, | 
|  | 140 | /** | 
| Elliott Hughes | f78be36 | 2018-01-23 15:33:56 -0800 | [diff] [blame] | 141 | * {@link ASENSOR_TYPE_GRAVITY} | 
|  | 142 | * | 
|  | 143 | * All values are in SI units (m/s^2) and measure the direction and | 
|  | 144 | * magnitude of gravity. When the device is at rest, the output of | 
|  | 145 | * the gravity sensor should be identical to that of the accelerometer. | 
|  | 146 | */ | 
|  | 147 | ASENSOR_TYPE_GRAVITY             = 9, | 
|  | 148 | /** | 
| Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 149 | * {@link ASENSOR_TYPE_LINEAR_ACCELERATION} | 
|  | 150 | * reporting-mode: continuous | 
|  | 151 | * | 
|  | 152 | *  All values are in SI units (m/s^2) and measure the acceleration of the | 
|  | 153 | *  device not including the force of gravity. | 
|  | 154 | */ | 
| Elliott Hughes | f78be36 | 2018-01-23 15:33:56 -0800 | [diff] [blame] | 155 | ASENSOR_TYPE_LINEAR_ACCELERATION = 10, | 
|  | 156 | /** | 
|  | 157 | * {@link ASENSOR_TYPE_ROTATION_VECTOR} | 
|  | 158 | */ | 
|  | 159 | ASENSOR_TYPE_ROTATION_VECTOR     = 11, | 
|  | 160 | /** | 
|  | 161 | * {@link ASENSOR_TYPE_RELATIVE_HUMIDITY} | 
|  | 162 | * | 
|  | 163 | * The relative humidity sensor value is returned in percent. | 
|  | 164 | */ | 
|  | 165 | ASENSOR_TYPE_RELATIVE_HUMIDITY   = 12, | 
|  | 166 | /** | 
|  | 167 | * {@link ASENSOR_TYPE_AMBIENT_TEMPERATURE} | 
|  | 168 | * | 
|  | 169 | * The ambient temperature sensor value is returned in Celcius. | 
|  | 170 | */ | 
|  | 171 | ASENSOR_TYPE_AMBIENT_TEMPERATURE = 13, | 
|  | 172 | /** | 
|  | 173 | * {@link ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED} | 
|  | 174 | */ | 
|  | 175 | ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14, | 
|  | 176 | /** | 
|  | 177 | * {@link ASENSOR_TYPE_GAME_ROTATION_VECTOR} | 
|  | 178 | */ | 
|  | 179 | ASENSOR_TYPE_GAME_ROTATION_VECTOR = 15, | 
|  | 180 | /** | 
|  | 181 | * {@link ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED} | 
|  | 182 | */ | 
|  | 183 | ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 16, | 
|  | 184 | /** | 
|  | 185 | * {@link ASENSOR_TYPE_SIGNIFICANT_MOTION} | 
|  | 186 | */ | 
|  | 187 | ASENSOR_TYPE_SIGNIFICANT_MOTION = 17, | 
|  | 188 | /** | 
|  | 189 | * {@link ASENSOR_TYPE_STEP_DETECTOR} | 
|  | 190 | */ | 
|  | 191 | ASENSOR_TYPE_STEP_DETECTOR = 18, | 
|  | 192 | /** | 
|  | 193 | * {@link ASENSOR_TYPE_STEP_COUNTER} | 
|  | 194 | */ | 
|  | 195 | ASENSOR_TYPE_STEP_COUNTER = 19, | 
|  | 196 | /** | 
|  | 197 | * {@link ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR} | 
|  | 198 | */ | 
|  | 199 | ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20, | 
|  | 200 | /** | 
|  | 201 | * {@link ASENSOR_TYPE_HEART_RATE} | 
|  | 202 | */ | 
|  | 203 | ASENSOR_TYPE_HEART_RATE = 21, | 
|  | 204 | /** | 
|  | 205 | * {@link ASENSOR_TYPE_POSE_6DOF} | 
|  | 206 | */ | 
|  | 207 | ASENSOR_TYPE_POSE_6DOF = 28, | 
|  | 208 | /** | 
|  | 209 | * {@link ASENSOR_TYPE_STATIONARY_DETECT} | 
|  | 210 | */ | 
|  | 211 | ASENSOR_TYPE_STATIONARY_DETECT = 29, | 
|  | 212 | /** | 
|  | 213 | * {@link ASENSOR_TYPE_MOTION_DETECT} | 
|  | 214 | */ | 
|  | 215 | ASENSOR_TYPE_MOTION_DETECT = 30, | 
|  | 216 | /** | 
|  | 217 | * {@link ASENSOR_TYPE_HEART_BEAT} | 
|  | 218 | */ | 
|  | 219 | ASENSOR_TYPE_HEART_BEAT = 31, | 
|  | 220 | /** | 
| Erik Staats | b1f7795 | 2022-03-25 11:49:58 -0700 | [diff] [blame] | 221 | * A constant describing a dynamic sensor meta event sensor. | 
|  | 222 | * | 
|  | 223 | * A sensor event of this type is received when a dynamic sensor is added to or removed from | 
|  | 224 | * the system. This sensor type should always use special trigger report mode. | 
|  | 225 | */ | 
|  | 226 | ASENSOR_TYPE_DYNAMIC_SENSOR_META = 32, | 
|  | 227 | /** | 
| Brian Stack | ccd8843 | 2019-01-08 17:04:18 -0800 | [diff] [blame] | 228 | * This sensor type is for delivering additional sensor information aside | 
|  | 229 | * from sensor event data. | 
|  | 230 | * | 
|  | 231 | * Additional information may include: | 
|  | 232 | *     - {@link ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE} | 
|  | 233 | *     - {@link ASENSOR_ADDITIONAL_INFO_SAMPLING} | 
|  | 234 | *     - {@link ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT} | 
|  | 235 | *     - {@link ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY} | 
|  | 236 | *     - {@link ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION} | 
|  | 237 | * | 
|  | 238 | * This type will never bind to a sensor. In other words, no sensor in the | 
|  | 239 | * sensor list can have the type {@link ASENSOR_TYPE_ADDITIONAL_INFO}. | 
|  | 240 | * | 
|  | 241 | * If a device supports the sensor additional information feature, it will | 
|  | 242 | * report additional information events via {@link ASensorEvent} and will | 
| gfan | c150ea1 | 2021-04-14 09:27:55 -0700 | [diff] [blame] | 243 | * have the type of {@link ASensorEvent} set to | 
|  | 244 | * {@link ASENSOR_TYPE_ADDITIONAL_INFO} and the sensor of {@link ASensorEvent} set | 
| Brian Stack | ccd8843 | 2019-01-08 17:04:18 -0800 | [diff] [blame] | 245 | * to the handle of the reporting sensor. | 
|  | 246 | * | 
|  | 247 | * Additional information reports consist of multiple frames ordered by | 
|  | 248 | * {@link ASensorEvent#timestamp}. The first frame in the report will have | 
|  | 249 | * a {@link AAdditionalInfoEvent#type} of | 
|  | 250 | * {@link ASENSOR_ADDITIONAL_INFO_BEGIN}, and the last frame in the report | 
|  | 251 | * will have a {@link AAdditionalInfoEvent#type} of | 
|  | 252 | * {@link ASENSOR_ADDITIONAL_INFO_END}. | 
|  | 253 | * | 
|  | 254 | */ | 
|  | 255 | ASENSOR_TYPE_ADDITIONAL_INFO = 33, | 
|  | 256 | /** | 
| Elliott Hughes | f78be36 | 2018-01-23 15:33:56 -0800 | [diff] [blame] | 257 | * {@link ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT} | 
|  | 258 | */ | 
|  | 259 | ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34, | 
|  | 260 | /** | 
|  | 261 | * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED} | 
|  | 262 | */ | 
|  | 263 | ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35, | 
| Anthony Stange | fdb1fc8 | 2020-01-16 15:02:48 -0500 | [diff] [blame] | 264 | /** | 
|  | 265 | * {@link ASENSOR_TYPE_HINGE_ANGLE} | 
| Anthony Stange | d7a703c | 2020-02-18 12:02:22 -0500 | [diff] [blame] | 266 | * reporting-mode: on-change | 
|  | 267 | * | 
|  | 268 | * The hinge angle sensor value is returned in degrees. | 
| Anthony Stange | fdb1fc8 | 2020-01-16 15:02:48 -0500 | [diff] [blame] | 269 | */ | 
|  | 270 | ASENSOR_TYPE_HINGE_ANGLE = 36, | 
| Brian Duddie | 573da3b | 2021-12-10 14:34:07 -0800 | [diff] [blame] | 271 | /** | 
|  | 272 | * {@link ASENSOR_TYPE_HEAD_TRACKER} | 
|  | 273 | * reporting-mode: continuous | 
|  | 274 | * | 
| Brian Duddie | 4a4d046 | 2022-05-09 16:49:49 -0700 | [diff] [blame] | 275 | * Measures the orientation and rotational velocity of a user's head. Only for internal use | 
|  | 276 | * within the Android system. | 
| Brian Duddie | 573da3b | 2021-12-10 14:34:07 -0800 | [diff] [blame] | 277 | */ | 
|  | 278 | ASENSOR_TYPE_HEAD_TRACKER = 37, | 
| Eva Chen | c0420b7 | 2021-04-09 15:44:12 -0700 | [diff] [blame] | 279 | /** | 
|  | 280 | * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES} | 
|  | 281 | * reporting-mode: continuous | 
|  | 282 | * | 
|  | 283 | * The first three values are in SI units (m/s^2) and measure the acceleration of the device | 
|  | 284 | * minus the force of gravity. The last three values indicate which acceleration axes are | 
|  | 285 | * supported. A value of 1.0 means supported and a value of 0 means not supported. | 
|  | 286 | */ | 
|  | 287 | ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES = 38, | 
|  | 288 | /** | 
|  | 289 | * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES} | 
|  | 290 | * reporting-mode: continuous | 
|  | 291 | * | 
|  | 292 | * The first three values are in radians/second and measure the rate of rotation around the X, | 
|  | 293 | * Y and Z axis. The last three values indicate which rotation axes are supported. A value of | 
|  | 294 | * 1.0 means supported and a value of 0 means not supported. | 
|  | 295 | */ | 
|  | 296 | ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES = 39, | 
|  | 297 | /** | 
|  | 298 | * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED} | 
|  | 299 | * reporting-mode: continuous | 
|  | 300 | * | 
|  | 301 | * The first three values are in SI units (m/s^2) and measure the acceleration of the device | 
|  | 302 | * minus the force of gravity. The middle three values represent the estimated bias for each | 
|  | 303 | * axis. The last three values indicate which acceleration axes are supported. A value of 1.0 | 
|  | 304 | * means supported and a value of 0 means not supported. | 
|  | 305 | */ | 
|  | 306 | ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED = 40, | 
|  | 307 | /** | 
|  | 308 | * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED} | 
|  | 309 | * reporting-mode: continuous | 
|  | 310 | * | 
|  | 311 | * The first three values are in radians/second and measure the rate of rotation around the X, | 
|  | 312 | * Y and Z axis. The middle three values represent the estimated drift around each axis in | 
|  | 313 | * rad/s. The last three values indicate which rotation axes are supported. A value of 1.0 means | 
|  | 314 | * supported and a value of 0 means not supported. | 
|  | 315 | */ | 
|  | 316 | ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41, | 
| Eva Chen | 72c7104 | 2022-01-10 21:07:51 -0800 | [diff] [blame] | 317 | /** | 
|  | 318 | * {@link ASENSOR_TYPE_HEADING} | 
|  | 319 | * reporting-mode: continuous | 
|  | 320 | * | 
|  | 321 | * A heading sensor measures the direction in which the device is pointing | 
|  | 322 | * relative to true north in degrees. | 
|  | 323 | */ | 
|  | 324 | ASENSOR_TYPE_HEADING = 42, | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 325 | }; | 
|  | 326 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 327 | /** | 
|  | 328 | * Sensor accuracy measure. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 329 | */ | 
|  | 330 | enum { | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 331 | /** no contact */ | 
| Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 332 | ASENSOR_STATUS_NO_CONTACT       = -1, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 333 | /** unreliable */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 334 | ASENSOR_STATUS_UNRELIABLE       = 0, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 335 | /** low accuracy */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 336 | ASENSOR_STATUS_ACCURACY_LOW     = 1, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 337 | /** medium accuracy */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 338 | ASENSOR_STATUS_ACCURACY_MEDIUM  = 2, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 339 | /** high accuracy */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 340 | ASENSOR_STATUS_ACCURACY_HIGH    = 3 | 
|  | 341 | }; | 
|  | 342 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 343 | /** | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 344 | * Sensor Reporting Modes. | 
|  | 345 | */ | 
|  | 346 | enum { | 
| Peng Xu | 37317b6 | 2017-03-07 17:49:31 -0800 | [diff] [blame] | 347 | /** invalid reporting mode */ | 
|  | 348 | AREPORTING_MODE_INVALID = -1, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 349 | /** continuous reporting */ | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 350 | AREPORTING_MODE_CONTINUOUS = 0, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 351 | /** reporting on change */ | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 352 | AREPORTING_MODE_ON_CHANGE = 1, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 353 | /** on shot reporting */ | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 354 | AREPORTING_MODE_ONE_SHOT = 2, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 355 | /** special trigger reporting */ | 
| Peng Xu | 37317b6 | 2017-03-07 17:49:31 -0800 | [diff] [blame] | 356 | AREPORTING_MODE_SPECIAL_TRIGGER = 3 | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 357 | }; | 
|  | 358 |  | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 359 | /** | 
|  | 360 | * Sensor Direct Report Rates. | 
|  | 361 | */ | 
|  | 362 | enum { | 
|  | 363 | /** stopped */ | 
|  | 364 | ASENSOR_DIRECT_RATE_STOP = 0, | 
|  | 365 | /** nominal 50Hz */ | 
|  | 366 | ASENSOR_DIRECT_RATE_NORMAL = 1, | 
|  | 367 | /** nominal 200Hz */ | 
|  | 368 | ASENSOR_DIRECT_RATE_FAST = 2, | 
|  | 369 | /** nominal 800Hz */ | 
|  | 370 | ASENSOR_DIRECT_RATE_VERY_FAST = 3 | 
|  | 371 | }; | 
|  | 372 |  | 
|  | 373 | /** | 
|  | 374 | * Sensor Direct Channel Type. | 
|  | 375 | */ | 
|  | 376 | enum { | 
|  | 377 | /** shared memory created by ASharedMemory_create */ | 
|  | 378 | ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1, | 
|  | 379 | /** AHardwareBuffer */ | 
|  | 380 | ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2 | 
|  | 381 | }; | 
|  | 382 |  | 
| Brian Stack | ccd8843 | 2019-01-08 17:04:18 -0800 | [diff] [blame] | 383 | /** | 
|  | 384 | * Sensor Additional Info Types. | 
|  | 385 | * | 
|  | 386 | * Used to populate {@link AAdditionalInfoEvent#type}. | 
|  | 387 | */ | 
|  | 388 | enum { | 
|  | 389 | /** Marks the beginning of additional information frames */ | 
|  | 390 | ASENSOR_ADDITIONAL_INFO_BEGIN = 0, | 
|  | 391 |  | 
|  | 392 | /** Marks the end of additional information frames */ | 
|  | 393 | ASENSOR_ADDITIONAL_INFO_END = 1, | 
|  | 394 |  | 
|  | 395 | /** | 
|  | 396 | * Estimation of the delay that is not tracked by sensor timestamps. This | 
|  | 397 | * includes delay introduced by sensor front-end filtering, data transport, | 
|  | 398 | * etc. | 
|  | 399 | * float[2]: delay in seconds, standard deviation of estimated value | 
|  | 400 | */ | 
|  | 401 | ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY = 0x10000, | 
|  | 402 |  | 
|  | 403 | /** float: Celsius temperature */ | 
|  | 404 | ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE, | 
|  | 405 |  | 
|  | 406 | /** | 
|  | 407 | * First three rows of a homogeneous matrix, which represents calibration to | 
|  | 408 | * a three-element vector raw sensor reading. | 
|  | 409 | * float[12]: 3x4 matrix in row major order | 
|  | 410 | */ | 
|  | 411 | ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION, | 
|  | 412 |  | 
|  | 413 | /** | 
|  | 414 | * Location and orientation of sensor element in the device frame: origin is | 
|  | 415 | * the geometric center of the mobile device screen surface; the axis | 
|  | 416 | * definition corresponds to Android sensor definitions. | 
|  | 417 | * float[12]: 3x4 matrix in row major order | 
|  | 418 | */ | 
|  | 419 | ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT, | 
|  | 420 |  | 
|  | 421 | /** | 
|  | 422 | * float[2]: raw sample period in seconds, | 
|  | 423 | *           standard deviation of sampling period | 
|  | 424 | */ | 
|  | 425 | ASENSOR_ADDITIONAL_INFO_SAMPLING, | 
|  | 426 | }; | 
|  | 427 |  | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 428 | /* | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 429 | * A few useful constants | 
|  | 430 | */ | 
|  | 431 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 432 | /** Earth's gravity in m/s^2 */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 433 | #define ASENSOR_STANDARD_GRAVITY            (9.80665f) | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 434 | /** Maximum magnetic field on Earth's surface in uT */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 435 | #define ASENSOR_MAGNETIC_FIELD_EARTH_MAX    (60.0f) | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 436 | /** Minimum magnetic field on Earth's surface in uT*/ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 437 | #define ASENSOR_MAGNETIC_FIELD_EARTH_MIN    (30.0f) | 
|  | 438 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 439 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 440 | * A sensor event. | 
|  | 441 | */ | 
|  | 442 |  | 
| Peng Xu | 70b9838 | 2017-08-07 14:09:11 -0700 | [diff] [blame] | 443 | /* NOTE: changes to these structs have to be backward compatible */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 444 | typedef struct ASensorVector { | 
|  | 445 | union { | 
|  | 446 | float v[3]; | 
|  | 447 | struct { | 
|  | 448 | float x; | 
|  | 449 | float y; | 
|  | 450 | float z; | 
|  | 451 | }; | 
|  | 452 | struct { | 
|  | 453 | float azimuth; | 
|  | 454 | float pitch; | 
|  | 455 | float roll; | 
|  | 456 | }; | 
|  | 457 | }; | 
|  | 458 | int8_t status; | 
|  | 459 | uint8_t reserved[3]; | 
|  | 460 | } ASensorVector; | 
|  | 461 |  | 
| Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 462 | typedef struct AMetaDataEvent { | 
|  | 463 | int32_t what; | 
|  | 464 | int32_t sensor; | 
|  | 465 | } AMetaDataEvent; | 
|  | 466 |  | 
|  | 467 | typedef struct AUncalibratedEvent { | 
| Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 468 | union { | 
|  | 469 | float uncalib[3]; | 
|  | 470 | struct { | 
|  | 471 | float x_uncalib; | 
|  | 472 | float y_uncalib; | 
|  | 473 | float z_uncalib; | 
|  | 474 | }; | 
| Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 475 | }; | 
| Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 476 | union { | 
|  | 477 | float bias[3]; | 
|  | 478 | struct { | 
|  | 479 | float x_bias; | 
|  | 480 | float y_bias; | 
|  | 481 | float z_bias; | 
|  | 482 | }; | 
| Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 483 | }; | 
| Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 484 | } AUncalibratedEvent; | 
|  | 485 |  | 
| Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 486 | typedef struct AHeartRateEvent { | 
| Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 487 | float bpm; | 
|  | 488 | int8_t status; | 
| Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 489 | } AHeartRateEvent; | 
|  | 490 |  | 
| Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 491 | typedef struct ADynamicSensorEvent { | 
| Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 492 | int32_t  connected; | 
|  | 493 | int32_t  handle; | 
| Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 494 | } ADynamicSensorEvent; | 
|  | 495 |  | 
| Brian Stack | ccd8843 | 2019-01-08 17:04:18 -0800 | [diff] [blame] | 496 | typedef struct AAdditionalInfoEvent { | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 497 | /** | 
|  | 498 | * Event type, such as ASENSOR_ADDITIONAL_INFO_BEGIN, ASENSOR_ADDITIONAL_INFO_END and others. | 
|  | 499 | * Refer to {@link ASENSOR_TYPE_ADDITIONAL_INFO} for the expected reporting behavior. | 
|  | 500 | */ | 
| Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 501 | int32_t type; | 
|  | 502 | int32_t serial; | 
|  | 503 | union { | 
|  | 504 | int32_t data_int32[14]; | 
|  | 505 | float   data_float[14]; | 
|  | 506 | }; | 
|  | 507 | } AAdditionalInfoEvent; | 
|  | 508 |  | 
| Brian Duddie | 573da3b | 2021-12-10 14:34:07 -0800 | [diff] [blame] | 509 | typedef struct AHeadTrackerEvent { | 
|  | 510 | /** | 
|  | 511 | * The fields rx, ry, rz are an Euler vector (rotation vector, i.e. a vector | 
|  | 512 | * whose direction indicates the axis of rotation and magnitude indicates | 
|  | 513 | * the angle to rotate around that axis) representing the transform from | 
|  | 514 | * the (arbitrary, possibly slowly drifting) reference frame to the | 
|  | 515 | * head frame. Expressed in radians. Magnitude of the vector must be | 
|  | 516 | * in the range [0, pi], while the value of individual axes are | 
|  | 517 | * in the range [-pi, pi]. | 
|  | 518 | */ | 
|  | 519 | float rx; | 
|  | 520 | float ry; | 
|  | 521 | float rz; | 
|  | 522 |  | 
|  | 523 | /** | 
|  | 524 | * The fields vx, vy, vz are an Euler vector (rotation vector) representing | 
|  | 525 | * the angular velocity of the head (relative to itself), in radians per | 
|  | 526 | * second. The direction of this vector indicates the axis of rotation, and | 
|  | 527 | * the magnitude indicates the rate of rotation. | 
|  | 528 | */ | 
|  | 529 | float vx; | 
|  | 530 | float vy; | 
|  | 531 | float vz; | 
|  | 532 |  | 
|  | 533 | /** | 
|  | 534 | * This value changes each time the reference frame is suddenly and | 
|  | 535 | * significantly changed, for example if an orientation filter algorithm | 
|  | 536 | * used for determining the orientation has had its state reset. | 
|  | 537 | */ | 
|  | 538 | int32_t discontinuity_count; | 
|  | 539 | } AHeadTrackerEvent; | 
|  | 540 |  | 
| Eva Chen | c0420b7 | 2021-04-09 15:44:12 -0700 | [diff] [blame] | 541 | typedef struct ALimitedAxesImuEvent { | 
|  | 542 | union { | 
|  | 543 | float calib[3]; | 
|  | 544 | struct { | 
|  | 545 | float x; | 
|  | 546 | float y; | 
|  | 547 | float z; | 
|  | 548 | }; | 
|  | 549 | }; | 
|  | 550 | union { | 
|  | 551 | float supported[3]; | 
|  | 552 | struct { | 
|  | 553 | float x_supported; | 
|  | 554 | float y_supported; | 
|  | 555 | float z_supported; | 
|  | 556 | }; | 
|  | 557 | }; | 
|  | 558 | } ALimitedAxesImuEvent; | 
|  | 559 |  | 
|  | 560 | typedef struct ALimitedAxesImuUncalibratedEvent { | 
|  | 561 | union { | 
|  | 562 | float uncalib[3]; | 
|  | 563 | struct { | 
|  | 564 | float x_uncalib; | 
|  | 565 | float y_uncalib; | 
|  | 566 | float z_uncalib; | 
|  | 567 | }; | 
|  | 568 | }; | 
|  | 569 | union { | 
|  | 570 | float bias[3]; | 
|  | 571 | struct { | 
|  | 572 | float x_bias; | 
|  | 573 | float y_bias; | 
|  | 574 | float z_bias; | 
|  | 575 | }; | 
|  | 576 | }; | 
|  | 577 | union { | 
|  | 578 | float supported[3]; | 
|  | 579 | struct { | 
|  | 580 | float x_supported; | 
|  | 581 | float y_supported; | 
|  | 582 | float z_supported; | 
|  | 583 | }; | 
|  | 584 | }; | 
|  | 585 | } ALimitedAxesImuUncalibratedEvent; | 
|  | 586 |  | 
| Eva Chen | 72c7104 | 2022-01-10 21:07:51 -0800 | [diff] [blame] | 587 | typedef struct AHeadingEvent { | 
|  | 588 | /** | 
|  | 589 | * The direction in which the device is pointing relative to true north in | 
|  | 590 | * degrees. The value must be between 0.0 (inclusive) and 360.0 (exclusive), | 
|  | 591 | * with 0 indicating north, 90 east, 180 south, and 270 west. | 
|  | 592 | */ | 
|  | 593 | float heading; | 
|  | 594 | /** | 
|  | 595 | * Accuracy is defined at 68% confidence. In the case where the underlying | 
|  | 596 | * distribution is assumed Gaussian normal, this would be considered one | 
|  | 597 | * standard deviation. For example, if the heading returns 60 degrees, and | 
|  | 598 | * accuracy returns 10 degrees, then there is a 68 percent probability of | 
|  | 599 | * the true heading being between 50 degrees and 70 degrees. | 
|  | 600 | */ | 
|  | 601 | float accuracy; | 
|  | 602 | } AHeadingEvent; | 
|  | 603 |  | 
| Devin Moore | d047068 | 2022-11-29 19:12:55 +0000 | [diff] [blame] | 604 | // LINT.IfChange | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 605 | /** | 
|  | 606 | * Information that describes a sensor event, refer to | 
|  | 607 | * <a href="/reference/android/hardware/SensorEvent">SensorEvent</a> for additional | 
|  | 608 | * documentation. | 
| Devin Moore | d047068 | 2022-11-29 19:12:55 +0000 | [diff] [blame] | 609 | * | 
|  | 610 | * NOTE: changes to this struct has to be backward compatible and reflected in | 
|  | 611 | * sensors_event_t | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 612 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 613 | typedef struct ASensorEvent { | 
| Brian Duddie | 2c5692b | 2023-05-18 15:04:32 -0700 | [diff] [blame] | 614 | /* sizeof(struct ASensorEvent) */ | 
|  | 615 | int32_t version; | 
|  | 616 | /** The sensor that generates this event */ | 
|  | 617 | int32_t sensor; | 
|  | 618 | /** Sensor type for the event, such as {@link ASENSOR_TYPE_ACCELEROMETER} */ | 
|  | 619 | int32_t type; | 
|  | 620 | /** do not use */ | 
|  | 621 | int32_t reserved0; | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 622 | /** | 
|  | 623 | * The time in nanoseconds at which the event happened, and its behavior | 
|  | 624 | * is identical to <a href="/reference/android/hardware/SensorEvent#timestamp"> | 
|  | 625 | * SensorEvent::timestamp</a> in Java API. | 
|  | 626 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 627 | int64_t timestamp; | 
|  | 628 | union { | 
| Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 629 | union { | 
|  | 630 | float           data[16]; | 
|  | 631 | ASensorVector   vector; | 
|  | 632 | ASensorVector   acceleration; | 
| Brian Duddie | e02c066 | 2021-03-16 09:53:20 -0700 | [diff] [blame] | 633 | ASensorVector   gyro; | 
| Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 634 | ASensorVector   magnetic; | 
|  | 635 | float           temperature; | 
|  | 636 | float           distance; | 
|  | 637 | float           light; | 
|  | 638 | float           pressure; | 
| Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 639 | float           relative_humidity; | 
| Brian Duddie | e02c066 | 2021-03-16 09:53:20 -0700 | [diff] [blame] | 640 | AUncalibratedEvent uncalibrated_acceleration; | 
| Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 641 | AUncalibratedEvent uncalibrated_gyro; | 
|  | 642 | AUncalibratedEvent uncalibrated_magnetic; | 
|  | 643 | AMetaDataEvent meta_data; | 
| Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 644 | AHeartRateEvent heart_rate; | 
| Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 645 | ADynamicSensorEvent dynamic_sensor_meta; | 
| Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 646 | AAdditionalInfoEvent additional_info; | 
| Brian Duddie | 573da3b | 2021-12-10 14:34:07 -0800 | [diff] [blame] | 647 | AHeadTrackerEvent head_tracker; | 
| Eva Chen | c0420b7 | 2021-04-09 15:44:12 -0700 | [diff] [blame] | 648 | ALimitedAxesImuEvent limited_axes_imu; | 
|  | 649 | ALimitedAxesImuUncalibratedEvent limited_axes_imu_uncalibrated; | 
| Eva Chen | 72c7104 | 2022-01-10 21:07:51 -0800 | [diff] [blame] | 650 | AHeadingEvent heading; | 
| Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 651 | }; | 
|  | 652 | union { | 
|  | 653 | uint64_t        data[8]; | 
|  | 654 | uint64_t        step_counter; | 
|  | 655 | } u64; | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 656 | }; | 
| Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 657 |  | 
|  | 658 | uint32_t flags; | 
|  | 659 | int32_t reserved1[3]; | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 660 | } ASensorEvent; | 
| Devin Moore | d047068 | 2022-11-29 19:12:55 +0000 | [diff] [blame] | 661 | // LINT.ThenChange (hardware/libhardware/include/hardware/sensors.h) | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 662 |  | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 663 | struct ASensorManager; | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 664 | /** | 
|  | 665 | * {@link ASensorManager} is an opaque type to manage sensors and | 
|  | 666 | * events queues. | 
|  | 667 | * | 
|  | 668 | * {@link ASensorManager} is a singleton that can be obtained using | 
|  | 669 | * ASensorManager_getInstance(). | 
|  | 670 | * | 
|  | 671 | * This file provides a set of functions that uses {@link | 
|  | 672 | * ASensorManager} to access and list hardware sensors, and | 
|  | 673 | * create and destroy event queues: | 
|  | 674 | * - ASensorManager_getSensorList() | 
|  | 675 | * - ASensorManager_getDefaultSensor() | 
|  | 676 | * - ASensorManager_getDefaultSensorEx() | 
|  | 677 | * - ASensorManager_createEventQueue() | 
|  | 678 | * - ASensorManager_destroyEventQueue() | 
|  | 679 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 680 | typedef struct ASensorManager ASensorManager; | 
|  | 681 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 682 |  | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 683 | struct ASensorEventQueue; | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 684 | /** | 
|  | 685 | * {@link ASensorEventQueue} is an opaque type that provides access to | 
|  | 686 | * {@link ASensorEvent} from hardware sensors. | 
|  | 687 | * | 
|  | 688 | * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue(). | 
|  | 689 | * | 
|  | 690 | * This file provides a set of functions to enable and disable | 
|  | 691 | * sensors, check and get events, and set event rates on a {@link | 
|  | 692 | * ASensorEventQueue}. | 
|  | 693 | * - ASensorEventQueue_enableSensor() | 
|  | 694 | * - ASensorEventQueue_disableSensor() | 
|  | 695 | * - ASensorEventQueue_hasEvents() | 
|  | 696 | * - ASensorEventQueue_getEvents() | 
|  | 697 | * - ASensorEventQueue_setEventRate() | 
| Brian Stack | 65089d5 | 2019-01-11 10:52:07 -0800 | [diff] [blame] | 698 | * - ASensorEventQueue_requestAdditionalInfoEvents() | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 699 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 700 | typedef struct ASensorEventQueue ASensorEventQueue; | 
|  | 701 |  | 
|  | 702 | struct ASensor; | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 703 | /** | 
|  | 704 | * {@link ASensor} is an opaque type that provides information about | 
|  | 705 | * an hardware sensors. | 
|  | 706 | * | 
|  | 707 | * A {@link ASensor} pointer can be obtained using | 
|  | 708 | * ASensorManager_getDefaultSensor(), | 
|  | 709 | * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}. | 
|  | 710 | * | 
|  | 711 | * This file provides a set of functions to access properties of a | 
|  | 712 | * {@link ASensor}: | 
|  | 713 | * - ASensor_getName() | 
|  | 714 | * - ASensor_getVendor() | 
|  | 715 | * - ASensor_getType() | 
|  | 716 | * - ASensor_getResolution() | 
|  | 717 | * - ASensor_getMinDelay() | 
|  | 718 | * - ASensor_getFifoMaxEventCount() | 
|  | 719 | * - ASensor_getFifoReservedEventCount() | 
|  | 720 | * - ASensor_getStringType() | 
|  | 721 | * - ASensor_getReportingMode() | 
|  | 722 | * - ASensor_isWakeUpSensor() | 
| Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 723 | * - ASensor_getHandle() | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 724 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 725 | typedef struct ASensor ASensor; | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 726 | /** | 
|  | 727 | * {@link ASensorRef} is a type for constant pointers to {@link ASensor}. | 
|  | 728 | * | 
|  | 729 | * This is used to define entry in {@link ASensorList} arrays. | 
|  | 730 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 731 | typedef ASensor const* ASensorRef; | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 732 | /** | 
|  | 733 | * {@link ASensorList} is an array of reference to {@link ASensor}. | 
|  | 734 | * | 
|  | 735 | * A {@link ASensorList} can be initialized using ASensorManager_getSensorList(). | 
|  | 736 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 737 | typedef ASensorRef const* ASensorList; | 
|  | 738 |  | 
|  | 739 | /*****************************************************************************/ | 
|  | 740 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 741 | /** | 
| Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 742 | * Get a reference to the sensor manager. ASensorManager is a singleton | 
|  | 743 | * per package as different packages may have access to different sensors. | 
|  | 744 | * | 
|  | 745 | * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead. | 
|  | 746 | * | 
|  | 747 | * Example: | 
|  | 748 | * | 
|  | 749 | *     ASensorManager* sensorManager = ASensorManager_getInstance(); | 
|  | 750 | * | 
|  | 751 | */ | 
| Elliott Hughes | 23e82b4 | 2021-01-26 14:55:48 -0800 | [diff] [blame] | 752 | ASensorManager* ASensorManager_getInstance() __DEPRECATED_IN(26); | 
| Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 753 |  | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 754 | /** | 
| Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 755 | * Get a reference to the sensor manager. ASensorManager is a singleton | 
|  | 756 | * per package as different packages may have access to different sensors. | 
|  | 757 | * | 
|  | 758 | * Example: | 
|  | 759 | * | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 760 | *     ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz"); | 
| Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 761 | * | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 762 | * Available since API level 26. | 
| Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 763 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 764 | ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26); | 
| Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 765 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 766 | /** | 
| Erik Staats | d35a574 | 2022-02-04 06:37:58 -0800 | [diff] [blame] | 767 | * Returns the list of available sensors. The returned list is owned by the | 
|  | 768 | * sensor manager and will not change between calls to this function. | 
|  | 769 | * | 
|  | 770 | * \param manager the {@link ASensorManager} instance obtained from | 
|  | 771 | *                {@link ASensorManager_getInstanceForPackage}. | 
|  | 772 | * \param list    the returned list of sensors. | 
|  | 773 | * \return positive number of returned sensors or negative error code. | 
|  | 774 | *         BAD_VALUE: manager is NULL. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 775 | */ | 
|  | 776 | int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list); | 
|  | 777 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 778 | /** | 
| Erik Staats | d35a574 | 2022-02-04 06:37:58 -0800 | [diff] [blame] | 779 | * Returns the list of available dynamic sensors. If there are no dynamic | 
|  | 780 | * sensors available, returns nullptr in list. | 
|  | 781 | * | 
|  | 782 | * Each time this is called, the previously returned list is deallocated and | 
|  | 783 | * must no longer be used. | 
|  | 784 | * | 
| Erik Staats | b1f7795 | 2022-03-25 11:49:58 -0700 | [diff] [blame] | 785 | * Clients should call this if they receive a sensor update from | 
|  | 786 | * {@link ASENSOR_TYPE_DYNAMIC_SENSOR_META} indicating the sensors have changed. | 
|  | 787 | * If this happens, previously received lists from this method will be stale. | 
|  | 788 | * | 
| Erik Staats | d35a574 | 2022-02-04 06:37:58 -0800 | [diff] [blame] | 789 | * Available since API level 33. | 
|  | 790 | * | 
|  | 791 | * \param manager the {@link ASensorManager} instance obtained from | 
|  | 792 | *                {@link ASensorManager_getInstanceForPackage}. | 
|  | 793 | * \param list    the returned list of dynamic sensors. | 
|  | 794 | * \return positive number of returned sensors or negative error code. | 
|  | 795 | *         BAD_VALUE: manager is NULL. | 
|  | 796 | */ | 
|  | 797 | ssize_t ASensorManager_getDynamicSensorList( | 
|  | 798 | ASensorManager* manager, ASensorList* list) __INTRODUCED_IN(33); | 
|  | 799 |  | 
|  | 800 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 801 | * Returns the default sensor for the given type, or NULL if no sensor | 
| Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 802 | * of that type exists. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 803 | */ | 
|  | 804 | ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type); | 
|  | 805 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 806 | /** | 
| Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 807 | * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor | 
|  | 808 | * of this type and wakeUp properties exists. | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 809 | * | 
|  | 810 | * Available since API level 21. | 
| Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 811 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 812 | ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) __INTRODUCED_IN(21); | 
| Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 813 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 814 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 815 | * Creates a new sensor event queue and associate it with a looper. | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 816 | * | 
|  | 817 | * "ident" is a identifier for the events that will be returned when | 
|  | 818 | * calling ALooper_pollOnce(). The identifier must be >= 0, or | 
|  | 819 | * ALOOPER_POLL_CALLBACK if providing a non-NULL callback. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 820 | */ | 
|  | 821 | ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, | 
|  | 822 | ALooper* looper, int ident, ALooper_callbackFunc callback, void* data); | 
|  | 823 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 824 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 825 | * Destroys the event queue and free all resources associated to it. | 
|  | 826 | */ | 
|  | 827 | int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue); | 
|  | 828 |  | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 829 | /** | 
|  | 830 | * Create direct channel based on shared memory | 
|  | 831 | * | 
|  | 832 | * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used | 
|  | 833 | * for configuring sensor direct report. | 
|  | 834 | * | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 835 | * Available since API level 26. | 
|  | 836 | * | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 837 | * \param manager the {@link ASensorManager} instance obtained from | 
|  | 838 | *                {@link ASensorManager_getInstanceForPackage}. | 
|  | 839 | * \param fd      file descriptor representing a shared memory created by | 
|  | 840 | *                {@link ASharedMemory_create} | 
|  | 841 | * \param size    size to be used, must be less or equal to size of shared memory. | 
|  | 842 | * | 
|  | 843 | * \return a positive integer as a channel id to be used in | 
|  | 844 | *         {@link ASensorManager_destroyDirectChannel} and | 
|  | 845 | *         {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures. | 
|  | 846 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 847 | int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int fd, size_t size) __INTRODUCED_IN(26); | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 848 |  | 
|  | 849 | /** | 
|  | 850 | * Create direct channel based on AHardwareBuffer | 
|  | 851 | * | 
|  | 852 | * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used | 
|  | 853 | * for configuring sensor direct report. | 
|  | 854 | * | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 855 | * Available since API level 26. | 
|  | 856 | * | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 857 | * \param manager the {@link ASensorManager} instance obtained from | 
|  | 858 | *                {@link ASensorManager_getInstanceForPackage}. | 
|  | 859 | * \param buffer  {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}. | 
|  | 860 | * \param size    the intended size to be used, must be less or equal to size of buffer. | 
|  | 861 | * | 
|  | 862 | * \return a positive integer as a channel id to be used in | 
|  | 863 | *         {@link ASensorManager_destroyDirectChannel} and | 
|  | 864 | *         {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures. | 
|  | 865 | */ | 
|  | 866 | int ASensorManager_createHardwareBufferDirectChannel( | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 867 | ASensorManager* manager, AHardwareBuffer const * buffer, size_t size) __INTRODUCED_IN(26); | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 868 |  | 
|  | 869 | /** | 
|  | 870 | * Destroy a direct channel | 
|  | 871 | * | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 872 | * Destroy a direct channel previously created by using one of | 
|  | 873 | * ASensorManager_create*DirectChannel() derivative functions. | 
|  | 874 | * Note that the buffer used for creating the direct channel does not get destroyed with | 
|  | 875 | * ASensorManager_destroyDirectChannel and has to be closed or released separately. | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 876 | * | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 877 | * Available since API level 26. | 
|  | 878 | * | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 879 | * \param manager the {@link ASensorManager} instance obtained from | 
|  | 880 | *                {@link ASensorManager_getInstanceForPackage}. | 
|  | 881 | * \param channelId channel id (a positive integer) returned from | 
|  | 882 | *                  {@link ASensorManager_createSharedMemoryDirectChannel} or | 
|  | 883 | *                  {@link ASensorManager_createHardwareBufferDirectChannel}. | 
|  | 884 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 885 | void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId) __INTRODUCED_IN(26); | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 886 |  | 
|  | 887 | /** | 
|  | 888 | * Configure direct report on channel | 
|  | 889 | * | 
|  | 890 | * Configure sensor direct report on a direct channel: set rate to value other than | 
|  | 891 | * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly | 
| Peng Xu | ec53d02 | 2017-04-06 18:02:29 -0700 | [diff] [blame] | 892 | * written into the shared memory region used for creating the buffer. It returns a positive token | 
|  | 893 | * which can be used for identify sensor events from different sensors on success. Calling with rate | 
|  | 894 | * {@link ASENSOR_DIRECT_RATE_STOP} will stop direct report of the sensor specified in the channel. | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 895 | * | 
|  | 896 | * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to | 
|  | 897 | * {@link ASENSOR_DIRECT_RATE_STOP}. | 
|  | 898 | * | 
|  | 899 | * In order to successfully configure a direct report, the sensor has to support the specified rate | 
|  | 900 | * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and | 
|  | 901 | * {@link ASensor_isDirectChannelTypeSupported}, respectively. | 
|  | 902 | * | 
|  | 903 | * Example: | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 904 | * | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 905 | *     ASensorManager *manager = ...; | 
|  | 906 | *     ASensor *sensor = ...; | 
|  | 907 | *     int channelId = ...; | 
|  | 908 | * | 
|  | 909 | *     ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST); | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 910 | * | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 911 | * Available since API level 26. | 
|  | 912 | * | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 913 | * \param manager   the {@link ASensorManager} instance obtained from | 
|  | 914 | *                  {@link ASensorManager_getInstanceForPackage}. | 
|  | 915 | * \param sensor    a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate | 
|  | 916 | *                  is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor | 
|  | 917 | *                  direct report. | 
|  | 918 | * \param channelId channel id (a positive integer) returned from | 
|  | 919 | *                  {@link ASensorManager_createSharedMemoryDirectChannel} or | 
|  | 920 | *                  {@link ASensorManager_createHardwareBufferDirectChannel}. | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 921 | * \param rate      one of predefined ASENSOR_DIRECT_RATE_... that is supported by the sensor. | 
| Peng Xu | ec53d02 | 2017-04-06 18:02:29 -0700 | [diff] [blame] | 922 | * \return positive token for success or negative error code. | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 923 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 924 | int ASensorManager_configureDirectReport(ASensorManager* manager, | 
|  | 925 | ASensor const* sensor, int channelId, int rate) __INTRODUCED_IN(26); | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 926 |  | 
|  | 927 | /*****************************************************************************/ | 
|  | 928 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 929 | /** | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 930 | * Enable the selected sensor with sampling and report parameters | 
|  | 931 | * | 
|  | 932 | * Enable the selected sensor at a specified sampling period and max batch report latency. | 
|  | 933 | * To disable  sensor, use {@link ASensorEventQueue_disableSensor}. | 
|  | 934 | * | 
|  | 935 | * \param queue {@link ASensorEventQueue} for sensor event to be report to. | 
|  | 936 | * \param sensor {@link ASensor} to be enabled. | 
|  | 937 | * \param samplingPeriodUs sampling period of sensor in microseconds. | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 938 | * \param maxBatchReportLatencyUs maximum time interval between two batches of sensor events are | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 939 | *                                delievered in microseconds. For sensor streaming, set to 0. | 
|  | 940 | * \return 0 on success or a negative error code on failure. | 
| Aniroop Mathur | da94fd8 | 2015-11-03 01:47:46 +0530 | [diff] [blame] | 941 | */ | 
|  | 942 | int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor, | 
| Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 943 | int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs); | 
| Aniroop Mathur | da94fd8 | 2015-11-03 01:47:46 +0530 | [diff] [blame] | 944 |  | 
|  | 945 | /** | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 946 | * Enable the selected sensor at default sampling rate. | 
|  | 947 | * | 
|  | 948 | * Start event reports of a sensor to specified sensor event queue at a default rate. | 
|  | 949 | * | 
|  | 950 | * \param queue {@link ASensorEventQueue} for sensor event to be report to. | 
|  | 951 | * \param sensor {@link ASensor} to be enabled. | 
|  | 952 | * | 
|  | 953 | * \return 0 on success or a negative error code on failure. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 954 | */ | 
|  | 955 | int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor); | 
|  | 956 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 957 | /** | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 958 | * Disable the selected sensor. | 
|  | 959 | * | 
|  | 960 | * Stop event reports from the sensor to specified sensor event queue. | 
|  | 961 | * | 
|  | 962 | * \param queue {@link ASensorEventQueue} to be changed | 
|  | 963 | * \param sensor {@link ASensor} to be disabled | 
|  | 964 | * \return 0 on success or a negative error code on failure. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 965 | */ | 
|  | 966 | int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor); | 
|  | 967 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 968 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 969 | * Sets the delivery rate of events in microseconds for the given sensor. | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 970 | * | 
|  | 971 | * This function has to be called after {@link ASensorEventQueue_enableSensor}. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 972 | * Note that this is a hint only, generally event will arrive at a higher | 
|  | 973 | * rate. It is an error to set a rate inferior to the value returned by | 
|  | 974 | * ASensor_getMinDelay(). | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 975 | * | 
|  | 976 | * \param queue {@link ASensorEventQueue} to which sensor event is delivered. | 
|  | 977 | * \param sensor {@link ASensor} of which sampling rate to be updated. | 
|  | 978 | * \param usec sensor sampling period (1/sampling rate) in microseconds | 
|  | 979 | * \return 0 on sucess or a negative error code on failure. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 980 | */ | 
|  | 981 | int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec); | 
|  | 982 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 983 | /** | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 984 | * Determine if a sensor event queue has pending event to be processed. | 
|  | 985 | * | 
|  | 986 | * \param queue {@link ASensorEventQueue} to be queried | 
|  | 987 | * \return 1 if the queue has events; 0 if it does not have events; | 
|  | 988 | *         or a negative value if there is an error. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 989 | */ | 
|  | 990 | int ASensorEventQueue_hasEvents(ASensorEventQueue* queue); | 
|  | 991 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 992 | /** | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 993 | * Retrieve pending events in sensor event queue | 
|  | 994 | * | 
|  | 995 | * Retrieve next available events from the queue to a specified event array. | 
|  | 996 | * | 
|  | 997 | * \param queue {@link ASensorEventQueue} to get events from | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 998 | * \param events pointer to an array of {@link ASensorEvent}. | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 999 | * \param count max number of event that can be filled into array event. | 
|  | 1000 | * \return number of events returned on success; negative error code when | 
|  | 1001 | *         no events are pending or an error has occurred. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1002 | * | 
|  | 1003 | * Examples: | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1004 | * | 
| Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 1005 | *     ASensorEvent event; | 
|  | 1006 | *     ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1); | 
|  | 1007 | * | 
|  | 1008 | *     ASensorEvent eventBuffer[8]; | 
|  | 1009 | *     ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8); | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1010 | * | 
|  | 1011 | */ | 
| Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 1012 | ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count); | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1013 |  | 
| Brian Stack | 65089d5 | 2019-01-11 10:52:07 -0800 | [diff] [blame] | 1014 | /** | 
|  | 1015 | * Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on | 
|  | 1016 | * the given {@link ASensorEventQueue}. | 
|  | 1017 | * | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 1018 | * Sensor data events are always delivered to the {@link ASensorEventQueue}. | 
| Brian Stack | 65089d5 | 2019-01-11 10:52:07 -0800 | [diff] [blame] | 1019 | * | 
|  | 1020 | * The {@link ASENSOR_TYPE_ADDITIONAL_INFO} events will be returned through | 
|  | 1021 | * {@link ASensorEventQueue_getEvents}. The client is responsible for checking | 
|  | 1022 | * {@link ASensorEvent#type} to determine the event type prior to handling of | 
|  | 1023 | * the event. | 
|  | 1024 | * | 
|  | 1025 | * The client must be tolerant of any value for | 
|  | 1026 | * {@link AAdditionalInfoEvent#type}, as new values may be defined in the future | 
|  | 1027 | * and may delivered to the client. | 
|  | 1028 | * | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1029 | * Available since API level 29. | 
|  | 1030 | * | 
| Brian Stack | 65089d5 | 2019-01-11 10:52:07 -0800 | [diff] [blame] | 1031 | * \param queue {@link ASensorEventQueue} to configure | 
|  | 1032 | * \param enable true to request {@link ASENSOR_TYPE_ADDITIONAL_INFO} events, | 
|  | 1033 | *        false to stop receiving events | 
|  | 1034 | * \return 0 on success or a negative error code on failure | 
|  | 1035 | */ | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1036 | int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable) __INTRODUCED_IN(29); | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1037 |  | 
|  | 1038 | /*****************************************************************************/ | 
|  | 1039 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1040 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1041 | * Returns this sensor's name (non localized) | 
|  | 1042 | */ | 
|  | 1043 | const char* ASensor_getName(ASensor const* sensor); | 
|  | 1044 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1045 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1046 | * Returns this sensor's vendor's name (non localized) | 
|  | 1047 | */ | 
|  | 1048 | const char* ASensor_getVendor(ASensor const* sensor); | 
|  | 1049 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1050 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1051 | * Return this sensor's type | 
|  | 1052 | */ | 
|  | 1053 | int ASensor_getType(ASensor const* sensor); | 
|  | 1054 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1055 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1056 | * Returns this sensors's resolution | 
|  | 1057 | */ | 
|  | 1058 | float ASensor_getResolution(ASensor const* sensor); | 
|  | 1059 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1060 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1061 | * Returns the minimum delay allowed between events in microseconds. | 
|  | 1062 | * A value of zero means that this sensor doesn't report events at a | 
|  | 1063 | * constant rate, but rather only when a new data is available. | 
|  | 1064 | */ | 
|  | 1065 | int ASensor_getMinDelay(ASensor const* sensor); | 
|  | 1066 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1067 | /** | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 1068 | * Returns the maximum size of batches for this sensor. Batches will often be | 
|  | 1069 | * smaller, as the hardware fifo might be used for other sensors. | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1070 | * | 
|  | 1071 | * Available since API level 21. | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 1072 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 1073 | int ASensor_getFifoMaxEventCount(ASensor const* sensor) __INTRODUCED_IN(21); | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 1074 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1075 | /** | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 1076 | * Returns the hardware batch fifo size reserved to this sensor. | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1077 | * | 
|  | 1078 | * Available since API level 21. | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 1079 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 1080 | int ASensor_getFifoReservedEventCount(ASensor const* sensor) __INTRODUCED_IN(21); | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 1081 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1082 | /** | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 1083 | * Returns this sensor's string type. | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1084 | * | 
|  | 1085 | * Available since API level 21. | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 1086 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 1087 | const char* ASensor_getStringType(ASensor const* sensor) __INTRODUCED_IN(21); | 
| Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 1088 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1089 | /** | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 1090 | * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants. | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1091 | * | 
|  | 1092 | * Available since API level 21. | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 1093 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 1094 | int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21); | 
| Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 1095 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1096 | /** | 
| Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 1097 | * Returns true if this is a wake up sensor, false otherwise. | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1098 | * | 
|  | 1099 | * Available since API level 21. | 
| Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 1100 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 1101 | bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21); | 
| Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 1102 |  | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 1103 | /** | 
|  | 1104 | * Test if sensor supports a certain type of direct channel. | 
|  | 1105 | * | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1106 | * Available since API level 26. | 
|  | 1107 | * | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 1108 | * \param sensor  a {@link ASensor} to denote the sensor to be checked. | 
|  | 1109 | * \param channelType  Channel type constant, either | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 1110 | *                     {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 1111 | *                     or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}. | 
|  | 1112 | * \returns true if sensor supports the specified direct channel type. | 
|  | 1113 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 1114 | bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType) __INTRODUCED_IN(26); | 
|  | 1115 |  | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 1116 | /** | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1117 | * Get the highest direct rate level that a sensor supports. | 
|  | 1118 | * | 
|  | 1119 | * Available since API level 26. | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 1120 | * | 
|  | 1121 | * \param sensor  a {@link ASensor} to denote the sensor to be checked. | 
|  | 1122 | * | 
|  | 1123 | * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor. | 
|  | 1124 | *         If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor | 
|  | 1125 | *         does not support direct report. | 
|  | 1126 | */ | 
| Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 1127 | int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26); | 
| Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 1128 |  | 
| Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 1129 | /** | 
|  | 1130 | * Returns the sensor's handle. | 
|  | 1131 | * | 
|  | 1132 | * The handle identifies the sensor within the system and is included in the | 
| gfan | c150ea1 | 2021-04-14 09:27:55 -0700 | [diff] [blame] | 1133 | * sensor field of {@link ASensorEvent}, including those sent with type | 
| Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 1134 | * {@link ASENSOR_TYPE_ADDITIONAL_INFO}. | 
|  | 1135 | * | 
|  | 1136 | * A sensor's handle is able to be used to map {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to the | 
|  | 1137 | * sensor that generated the event. | 
|  | 1138 | * | 
|  | 1139 | * It is important to note that the value returned by {@link ASensor_getHandle} is not the same as | 
| gfan | 5d5faa4 | 2021-04-12 15:14:29 -0700 | [diff] [blame] | 1140 | * the value returned by the Java API <a href="/reference/android/hardware/Sensor#getId()"> | 
|  | 1141 | * android.hardware.Sensor's getId()</a> and no mapping exists between the values. | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1142 | * | 
|  | 1143 | * Available since API level 29. | 
| Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 1144 | */ | 
| Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 1145 | int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(29); | 
| Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 1146 |  | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 1147 | #ifdef __cplusplus | 
|  | 1148 | }; | 
|  | 1149 | #endif | 
|  | 1150 |  | 
|  | 1151 | #endif // ANDROID_SENSOR_H | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 1152 |  | 
|  | 1153 | /** @} */ |