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