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