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 |
| 231 | * have {@link ASensorEvent#type} set to |
| 232 | * {@link ASENSOR_TYPE_ADDITIONAL_INFO} and {@link ASensorEvent#sensor} set |
| 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, |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 259 | }; |
| 260 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 261 | /** |
| 262 | * Sensor accuracy measure. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 263 | */ |
| 264 | enum { |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 265 | /** no contact */ |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 266 | ASENSOR_STATUS_NO_CONTACT = -1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 267 | /** unreliable */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 268 | ASENSOR_STATUS_UNRELIABLE = 0, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 269 | /** low accuracy */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 270 | ASENSOR_STATUS_ACCURACY_LOW = 1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 271 | /** medium accuracy */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 272 | ASENSOR_STATUS_ACCURACY_MEDIUM = 2, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 273 | /** high accuracy */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 274 | ASENSOR_STATUS_ACCURACY_HIGH = 3 |
| 275 | }; |
| 276 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 277 | /** |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 278 | * Sensor Reporting Modes. |
| 279 | */ |
| 280 | enum { |
Peng Xu | 37317b6 | 2017-03-07 17:49:31 -0800 | [diff] [blame] | 281 | /** invalid reporting mode */ |
| 282 | AREPORTING_MODE_INVALID = -1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 283 | /** continuous reporting */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 284 | AREPORTING_MODE_CONTINUOUS = 0, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 285 | /** reporting on change */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 286 | AREPORTING_MODE_ON_CHANGE = 1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 287 | /** on shot reporting */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 288 | AREPORTING_MODE_ONE_SHOT = 2, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 289 | /** special trigger reporting */ |
Peng Xu | 37317b6 | 2017-03-07 17:49:31 -0800 | [diff] [blame] | 290 | AREPORTING_MODE_SPECIAL_TRIGGER = 3 |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 293 | /** |
| 294 | * Sensor Direct Report Rates. |
| 295 | */ |
| 296 | enum { |
| 297 | /** stopped */ |
| 298 | ASENSOR_DIRECT_RATE_STOP = 0, |
| 299 | /** nominal 50Hz */ |
| 300 | ASENSOR_DIRECT_RATE_NORMAL = 1, |
| 301 | /** nominal 200Hz */ |
| 302 | ASENSOR_DIRECT_RATE_FAST = 2, |
| 303 | /** nominal 800Hz */ |
| 304 | ASENSOR_DIRECT_RATE_VERY_FAST = 3 |
| 305 | }; |
| 306 | |
| 307 | /** |
| 308 | * Sensor Direct Channel Type. |
| 309 | */ |
| 310 | enum { |
| 311 | /** shared memory created by ASharedMemory_create */ |
| 312 | ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1, |
| 313 | /** AHardwareBuffer */ |
| 314 | ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2 |
| 315 | }; |
| 316 | |
Brian Stack | ccd8843 | 2019-01-08 17:04:18 -0800 | [diff] [blame] | 317 | /** |
| 318 | * Sensor Additional Info Types. |
| 319 | * |
| 320 | * Used to populate {@link AAdditionalInfoEvent#type}. |
| 321 | */ |
| 322 | enum { |
| 323 | /** Marks the beginning of additional information frames */ |
| 324 | ASENSOR_ADDITIONAL_INFO_BEGIN = 0, |
| 325 | |
| 326 | /** Marks the end of additional information frames */ |
| 327 | ASENSOR_ADDITIONAL_INFO_END = 1, |
| 328 | |
| 329 | /** |
| 330 | * Estimation of the delay that is not tracked by sensor timestamps. This |
| 331 | * includes delay introduced by sensor front-end filtering, data transport, |
| 332 | * etc. |
| 333 | * float[2]: delay in seconds, standard deviation of estimated value |
| 334 | */ |
| 335 | ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY = 0x10000, |
| 336 | |
| 337 | /** float: Celsius temperature */ |
| 338 | ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE, |
| 339 | |
| 340 | /** |
| 341 | * First three rows of a homogeneous matrix, which represents calibration to |
| 342 | * a three-element vector raw sensor reading. |
| 343 | * float[12]: 3x4 matrix in row major order |
| 344 | */ |
| 345 | ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION, |
| 346 | |
| 347 | /** |
| 348 | * Location and orientation of sensor element in the device frame: origin is |
| 349 | * the geometric center of the mobile device screen surface; the axis |
| 350 | * definition corresponds to Android sensor definitions. |
| 351 | * float[12]: 3x4 matrix in row major order |
| 352 | */ |
| 353 | ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT, |
| 354 | |
| 355 | /** |
| 356 | * float[2]: raw sample period in seconds, |
| 357 | * standard deviation of sampling period |
| 358 | */ |
| 359 | ASENSOR_ADDITIONAL_INFO_SAMPLING, |
| 360 | }; |
| 361 | |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 362 | /* |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 363 | * A few useful constants |
| 364 | */ |
| 365 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 366 | /** Earth's gravity in m/s^2 */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 367 | #define ASENSOR_STANDARD_GRAVITY (9.80665f) |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 368 | /** Maximum magnetic field on Earth's surface in uT */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 369 | #define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f) |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 370 | /** Minimum magnetic field on Earth's surface in uT*/ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 371 | #define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f) |
| 372 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 373 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 374 | * A sensor event. |
| 375 | */ |
| 376 | |
Peng Xu | 70b9838 | 2017-08-07 14:09:11 -0700 | [diff] [blame] | 377 | /* NOTE: changes to these structs have to be backward compatible */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 378 | typedef struct ASensorVector { |
| 379 | union { |
| 380 | float v[3]; |
| 381 | struct { |
| 382 | float x; |
| 383 | float y; |
| 384 | float z; |
| 385 | }; |
| 386 | struct { |
| 387 | float azimuth; |
| 388 | float pitch; |
| 389 | float roll; |
| 390 | }; |
| 391 | }; |
| 392 | int8_t status; |
| 393 | uint8_t reserved[3]; |
| 394 | } ASensorVector; |
| 395 | |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 396 | typedef struct AMetaDataEvent { |
| 397 | int32_t what; |
| 398 | int32_t sensor; |
| 399 | } AMetaDataEvent; |
| 400 | |
| 401 | typedef struct AUncalibratedEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 402 | union { |
| 403 | float uncalib[3]; |
| 404 | struct { |
| 405 | float x_uncalib; |
| 406 | float y_uncalib; |
| 407 | float z_uncalib; |
| 408 | }; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 409 | }; |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 410 | union { |
| 411 | float bias[3]; |
| 412 | struct { |
| 413 | float x_bias; |
| 414 | float y_bias; |
| 415 | float z_bias; |
| 416 | }; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 417 | }; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 418 | } AUncalibratedEvent; |
| 419 | |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 420 | typedef struct AHeartRateEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 421 | float bpm; |
| 422 | int8_t status; |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 423 | } AHeartRateEvent; |
| 424 | |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 425 | typedef struct ADynamicSensorEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 426 | int32_t connected; |
| 427 | int32_t handle; |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 428 | } ADynamicSensorEvent; |
| 429 | |
Brian Stack | ccd8843 | 2019-01-08 17:04:18 -0800 | [diff] [blame] | 430 | typedef struct AAdditionalInfoEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 431 | int32_t type; |
| 432 | int32_t serial; |
| 433 | union { |
| 434 | int32_t data_int32[14]; |
| 435 | float data_float[14]; |
| 436 | }; |
| 437 | } AAdditionalInfoEvent; |
| 438 | |
Peng Xu | 70b9838 | 2017-08-07 14:09:11 -0700 | [diff] [blame] | 439 | /* NOTE: changes to this struct has to be backward compatible */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 440 | typedef struct ASensorEvent { |
| 441 | int32_t version; /* sizeof(struct ASensorEvent) */ |
| 442 | int32_t sensor; |
| 443 | int32_t type; |
| 444 | int32_t reserved0; |
| 445 | int64_t timestamp; |
| 446 | union { |
Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 447 | union { |
| 448 | float data[16]; |
| 449 | ASensorVector vector; |
| 450 | ASensorVector acceleration; |
Brian Duddie | e02c066 | 2021-03-16 09:53:20 -0700 | [diff] [blame^] | 451 | ASensorVector gyro; |
Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 452 | ASensorVector magnetic; |
| 453 | float temperature; |
| 454 | float distance; |
| 455 | float light; |
| 456 | float pressure; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 457 | float relative_humidity; |
Brian Duddie | e02c066 | 2021-03-16 09:53:20 -0700 | [diff] [blame^] | 458 | AUncalibratedEvent uncalibrated_acceleration; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 459 | AUncalibratedEvent uncalibrated_gyro; |
| 460 | AUncalibratedEvent uncalibrated_magnetic; |
| 461 | AMetaDataEvent meta_data; |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 462 | AHeartRateEvent heart_rate; |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 463 | ADynamicSensorEvent dynamic_sensor_meta; |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 464 | AAdditionalInfoEvent additional_info; |
Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 465 | }; |
| 466 | union { |
| 467 | uint64_t data[8]; |
| 468 | uint64_t step_counter; |
| 469 | } u64; |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 470 | }; |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 471 | |
| 472 | uint32_t flags; |
| 473 | int32_t reserved1[3]; |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 474 | } ASensorEvent; |
| 475 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 476 | struct ASensorManager; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 477 | /** |
| 478 | * {@link ASensorManager} is an opaque type to manage sensors and |
| 479 | * events queues. |
| 480 | * |
| 481 | * {@link ASensorManager} is a singleton that can be obtained using |
| 482 | * ASensorManager_getInstance(). |
| 483 | * |
| 484 | * This file provides a set of functions that uses {@link |
| 485 | * ASensorManager} to access and list hardware sensors, and |
| 486 | * create and destroy event queues: |
| 487 | * - ASensorManager_getSensorList() |
| 488 | * - ASensorManager_getDefaultSensor() |
| 489 | * - ASensorManager_getDefaultSensorEx() |
| 490 | * - ASensorManager_createEventQueue() |
| 491 | * - ASensorManager_destroyEventQueue() |
| 492 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 493 | typedef struct ASensorManager ASensorManager; |
| 494 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 495 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 496 | struct ASensorEventQueue; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 497 | /** |
| 498 | * {@link ASensorEventQueue} is an opaque type that provides access to |
| 499 | * {@link ASensorEvent} from hardware sensors. |
| 500 | * |
| 501 | * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue(). |
| 502 | * |
| 503 | * This file provides a set of functions to enable and disable |
| 504 | * sensors, check and get events, and set event rates on a {@link |
| 505 | * ASensorEventQueue}. |
| 506 | * - ASensorEventQueue_enableSensor() |
| 507 | * - ASensorEventQueue_disableSensor() |
| 508 | * - ASensorEventQueue_hasEvents() |
| 509 | * - ASensorEventQueue_getEvents() |
| 510 | * - ASensorEventQueue_setEventRate() |
Brian Stack | 65089d5 | 2019-01-11 10:52:07 -0800 | [diff] [blame] | 511 | * - ASensorEventQueue_requestAdditionalInfoEvents() |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 512 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 513 | typedef struct ASensorEventQueue ASensorEventQueue; |
| 514 | |
| 515 | struct ASensor; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 516 | /** |
| 517 | * {@link ASensor} is an opaque type that provides information about |
| 518 | * an hardware sensors. |
| 519 | * |
| 520 | * A {@link ASensor} pointer can be obtained using |
| 521 | * ASensorManager_getDefaultSensor(), |
| 522 | * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}. |
| 523 | * |
| 524 | * This file provides a set of functions to access properties of a |
| 525 | * {@link ASensor}: |
| 526 | * - ASensor_getName() |
| 527 | * - ASensor_getVendor() |
| 528 | * - ASensor_getType() |
| 529 | * - ASensor_getResolution() |
| 530 | * - ASensor_getMinDelay() |
| 531 | * - ASensor_getFifoMaxEventCount() |
| 532 | * - ASensor_getFifoReservedEventCount() |
| 533 | * - ASensor_getStringType() |
| 534 | * - ASensor_getReportingMode() |
| 535 | * - ASensor_isWakeUpSensor() |
Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 536 | * - ASensor_getHandle() |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 537 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 538 | typedef struct ASensor ASensor; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 539 | /** |
| 540 | * {@link ASensorRef} is a type for constant pointers to {@link ASensor}. |
| 541 | * |
| 542 | * This is used to define entry in {@link ASensorList} arrays. |
| 543 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 544 | typedef ASensor const* ASensorRef; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 545 | /** |
| 546 | * {@link ASensorList} is an array of reference to {@link ASensor}. |
| 547 | * |
| 548 | * A {@link ASensorList} can be initialized using ASensorManager_getSensorList(). |
| 549 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 550 | typedef ASensorRef const* ASensorList; |
| 551 | |
| 552 | /*****************************************************************************/ |
| 553 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 554 | /** |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 555 | * Get a reference to the sensor manager. ASensorManager is a singleton |
| 556 | * per package as different packages may have access to different sensors. |
| 557 | * |
| 558 | * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead. |
| 559 | * |
| 560 | * Example: |
| 561 | * |
| 562 | * ASensorManager* sensorManager = ASensorManager_getInstance(); |
| 563 | * |
| 564 | */ |
Elliott Hughes | 23e82b4 | 2021-01-26 14:55:48 -0800 | [diff] [blame] | 565 | ASensorManager* ASensorManager_getInstance() __DEPRECATED_IN(26); |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 566 | |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 567 | /** |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 568 | * Get a reference to the sensor manager. ASensorManager is a singleton |
| 569 | * per package as different packages may have access to different sensors. |
| 570 | * |
| 571 | * Example: |
| 572 | * |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 573 | * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz"); |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 574 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 575 | * Available since API level 26. |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 576 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 577 | ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26); |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 578 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 579 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 580 | * Returns the list of available sensors. |
| 581 | */ |
| 582 | int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list); |
| 583 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 584 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 585 | * 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] | 586 | * of that type exists. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 587 | */ |
| 588 | ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type); |
| 589 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 590 | /** |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 591 | * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor |
| 592 | * of this type and wakeUp properties exists. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 593 | * |
| 594 | * Available since API level 21. |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 595 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 596 | 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] | 597 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 598 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 599 | * Creates a new sensor event queue and associate it with a looper. |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 600 | * |
| 601 | * "ident" is a identifier for the events that will be returned when |
| 602 | * calling ALooper_pollOnce(). The identifier must be >= 0, or |
| 603 | * ALOOPER_POLL_CALLBACK if providing a non-NULL callback. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 604 | */ |
| 605 | ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, |
| 606 | ALooper* looper, int ident, ALooper_callbackFunc callback, void* data); |
| 607 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 608 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 609 | * Destroys the event queue and free all resources associated to it. |
| 610 | */ |
| 611 | int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue); |
| 612 | |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 613 | /** |
| 614 | * Create direct channel based on shared memory |
| 615 | * |
| 616 | * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used |
| 617 | * for configuring sensor direct report. |
| 618 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 619 | * Available since API level 26. |
| 620 | * |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 621 | * \param manager the {@link ASensorManager} instance obtained from |
| 622 | * {@link ASensorManager_getInstanceForPackage}. |
| 623 | * \param fd file descriptor representing a shared memory created by |
| 624 | * {@link ASharedMemory_create} |
| 625 | * \param size size to be used, must be less or equal to size of shared memory. |
| 626 | * |
| 627 | * \return a positive integer as a channel id to be used in |
| 628 | * {@link ASensorManager_destroyDirectChannel} and |
| 629 | * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures. |
| 630 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 631 | 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] | 632 | |
| 633 | /** |
| 634 | * Create direct channel based on AHardwareBuffer |
| 635 | * |
| 636 | * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used |
| 637 | * for configuring sensor direct report. |
| 638 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 639 | * Available since API level 26. |
| 640 | * |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 641 | * \param manager the {@link ASensorManager} instance obtained from |
| 642 | * {@link ASensorManager_getInstanceForPackage}. |
| 643 | * \param buffer {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}. |
| 644 | * \param size the intended size to be used, must be less or equal to size of buffer. |
| 645 | * |
| 646 | * \return a positive integer as a channel id to be used in |
| 647 | * {@link ASensorManager_destroyDirectChannel} and |
| 648 | * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures. |
| 649 | */ |
| 650 | int ASensorManager_createHardwareBufferDirectChannel( |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 651 | ASensorManager* manager, AHardwareBuffer const * buffer, size_t size) __INTRODUCED_IN(26); |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 652 | |
| 653 | /** |
| 654 | * Destroy a direct channel |
| 655 | * |
| 656 | * Destroy a direct channel previously created using {@link ASensorManager_createDirectChannel}. |
| 657 | * The buffer used for creating direct channel does not get destroyed with |
| 658 | * {@link ASensorManager_destroy} and has to be close or released separately. |
| 659 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 660 | * Available since API level 26. |
| 661 | * |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 662 | * \param manager the {@link ASensorManager} instance obtained from |
| 663 | * {@link ASensorManager_getInstanceForPackage}. |
| 664 | * \param channelId channel id (a positive integer) returned from |
| 665 | * {@link ASensorManager_createSharedMemoryDirectChannel} or |
| 666 | * {@link ASensorManager_createHardwareBufferDirectChannel}. |
| 667 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 668 | void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId) __INTRODUCED_IN(26); |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 669 | |
| 670 | /** |
| 671 | * Configure direct report on channel |
| 672 | * |
| 673 | * Configure sensor direct report on a direct channel: set rate to value other than |
| 674 | * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly |
Peng Xu | ec53d02 | 2017-04-06 18:02:29 -0700 | [diff] [blame] | 675 | * written into the shared memory region used for creating the buffer. It returns a positive token |
| 676 | * which can be used for identify sensor events from different sensors on success. Calling with rate |
| 677 | * {@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] | 678 | * |
| 679 | * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to |
| 680 | * {@link ASENSOR_DIRECT_RATE_STOP}. |
| 681 | * |
| 682 | * In order to successfully configure a direct report, the sensor has to support the specified rate |
| 683 | * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and |
| 684 | * {@link ASensor_isDirectChannelTypeSupported}, respectively. |
| 685 | * |
| 686 | * Example: |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 687 | * |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 688 | * ASensorManager *manager = ...; |
| 689 | * ASensor *sensor = ...; |
| 690 | * int channelId = ...; |
| 691 | * |
| 692 | * ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST); |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 693 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 694 | * Available since API level 26. |
| 695 | * |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 696 | * \param manager the {@link ASensorManager} instance obtained from |
| 697 | * {@link ASensorManager_getInstanceForPackage}. |
| 698 | * \param sensor a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate |
| 699 | * is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor |
| 700 | * direct report. |
| 701 | * \param channelId channel id (a positive integer) returned from |
| 702 | * {@link ASensorManager_createSharedMemoryDirectChannel} or |
| 703 | * {@link ASensorManager_createHardwareBufferDirectChannel}. |
| 704 | * |
Peng Xu | ec53d02 | 2017-04-06 18:02:29 -0700 | [diff] [blame] | 705 | * \return positive token for success or negative error code. |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 706 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 707 | int ASensorManager_configureDirectReport(ASensorManager* manager, |
| 708 | ASensor const* sensor, int channelId, int rate) __INTRODUCED_IN(26); |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 709 | |
| 710 | /*****************************************************************************/ |
| 711 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 712 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 713 | * Enable the selected sensor with sampling and report parameters |
| 714 | * |
| 715 | * Enable the selected sensor at a specified sampling period and max batch report latency. |
| 716 | * To disable sensor, use {@link ASensorEventQueue_disableSensor}. |
| 717 | * |
| 718 | * \param queue {@link ASensorEventQueue} for sensor event to be report to. |
| 719 | * \param sensor {@link ASensor} to be enabled. |
| 720 | * \param samplingPeriodUs sampling period of sensor in microseconds. |
| 721 | * \param maxBatchReportLatencyus maximum time interval between two batch of sensor events are |
| 722 | * delievered in microseconds. For sensor streaming, set to 0. |
| 723 | * \return 0 on success or a negative error code on failure. |
Aniroop Mathur | da94fd8 | 2015-11-03 01:47:46 +0530 | [diff] [blame] | 724 | */ |
| 725 | int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor, |
Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 726 | int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs); |
Aniroop Mathur | da94fd8 | 2015-11-03 01:47:46 +0530 | [diff] [blame] | 727 | |
| 728 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 729 | * Enable the selected sensor at default sampling rate. |
| 730 | * |
| 731 | * Start event reports of a sensor to specified sensor event queue at a default rate. |
| 732 | * |
| 733 | * \param queue {@link ASensorEventQueue} for sensor event to be report to. |
| 734 | * \param sensor {@link ASensor} to be enabled. |
| 735 | * |
| 736 | * \return 0 on success or a negative error code on failure. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 737 | */ |
| 738 | int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor); |
| 739 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 740 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 741 | * Disable the selected sensor. |
| 742 | * |
| 743 | * Stop event reports from the sensor to specified sensor event queue. |
| 744 | * |
| 745 | * \param queue {@link ASensorEventQueue} to be changed |
| 746 | * \param sensor {@link ASensor} to be disabled |
| 747 | * \return 0 on success or a negative error code on failure. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 748 | */ |
| 749 | int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor); |
| 750 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 751 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 752 | * Sets the delivery rate of events in microseconds for the given sensor. |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 753 | * |
| 754 | * This function has to be called after {@link ASensorEventQueue_enableSensor}. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 755 | * Note that this is a hint only, generally event will arrive at a higher |
| 756 | * rate. It is an error to set a rate inferior to the value returned by |
| 757 | * ASensor_getMinDelay(). |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 758 | * |
| 759 | * \param queue {@link ASensorEventQueue} to which sensor event is delivered. |
| 760 | * \param sensor {@link ASensor} of which sampling rate to be updated. |
| 761 | * \param usec sensor sampling period (1/sampling rate) in microseconds |
| 762 | * \return 0 on sucess or a negative error code on failure. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 763 | */ |
| 764 | int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec); |
| 765 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 766 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 767 | * Determine if a sensor event queue has pending event to be processed. |
| 768 | * |
| 769 | * \param queue {@link ASensorEventQueue} to be queried |
| 770 | * \return 1 if the queue has events; 0 if it does not have events; |
| 771 | * or a negative value if there is an error. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 772 | */ |
| 773 | int ASensorEventQueue_hasEvents(ASensorEventQueue* queue); |
| 774 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 775 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 776 | * Retrieve pending events in sensor event queue |
| 777 | * |
| 778 | * Retrieve next available events from the queue to a specified event array. |
| 779 | * |
| 780 | * \param queue {@link ASensorEventQueue} to get events from |
| 781 | * \param events pointer to an array of {@link ASensorEvents}. |
| 782 | * \param count max number of event that can be filled into array event. |
| 783 | * \return number of events returned on success; negative error code when |
| 784 | * no events are pending or an error has occurred. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 785 | * |
| 786 | * Examples: |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 787 | * |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame] | 788 | * ASensorEvent event; |
| 789 | * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1); |
| 790 | * |
| 791 | * ASensorEvent eventBuffer[8]; |
| 792 | * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8); |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 793 | * |
| 794 | */ |
Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 795 | ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count); |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 796 | |
Brian Stack | 65089d5 | 2019-01-11 10:52:07 -0800 | [diff] [blame] | 797 | /** |
| 798 | * Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on |
| 799 | * the given {@link ASensorEventQueue}. |
| 800 | * |
| 801 | * Sensor data events are always delivered to the {@ASensorEventQueue}. |
| 802 | * |
| 803 | * The {@link ASENSOR_TYPE_ADDITIONAL_INFO} events will be returned through |
| 804 | * {@link ASensorEventQueue_getEvents}. The client is responsible for checking |
| 805 | * {@link ASensorEvent#type} to determine the event type prior to handling of |
| 806 | * the event. |
| 807 | * |
| 808 | * The client must be tolerant of any value for |
| 809 | * {@link AAdditionalInfoEvent#type}, as new values may be defined in the future |
| 810 | * and may delivered to the client. |
| 811 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 812 | * Available since API level 29. |
| 813 | * |
Brian Stack | 65089d5 | 2019-01-11 10:52:07 -0800 | [diff] [blame] | 814 | * \param queue {@link ASensorEventQueue} to configure |
| 815 | * \param enable true to request {@link ASENSOR_TYPE_ADDITIONAL_INFO} events, |
| 816 | * false to stop receiving events |
| 817 | * \return 0 on success or a negative error code on failure |
| 818 | */ |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 819 | int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable) __INTRODUCED_IN(29); |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 820 | |
| 821 | /*****************************************************************************/ |
| 822 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 823 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 824 | * Returns this sensor's name (non localized) |
| 825 | */ |
| 826 | const char* ASensor_getName(ASensor const* sensor); |
| 827 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 828 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 829 | * Returns this sensor's vendor's name (non localized) |
| 830 | */ |
| 831 | const char* ASensor_getVendor(ASensor const* sensor); |
| 832 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 833 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 834 | * Return this sensor's type |
| 835 | */ |
| 836 | int ASensor_getType(ASensor const* sensor); |
| 837 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 838 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 839 | * Returns this sensors's resolution |
| 840 | */ |
| 841 | float ASensor_getResolution(ASensor const* sensor); |
| 842 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 843 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 844 | * Returns the minimum delay allowed between events in microseconds. |
| 845 | * A value of zero means that this sensor doesn't report events at a |
| 846 | * constant rate, but rather only when a new data is available. |
| 847 | */ |
| 848 | int ASensor_getMinDelay(ASensor const* sensor); |
| 849 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 850 | /** |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 851 | * Returns the maximum size of batches for this sensor. Batches will often be |
| 852 | * smaller, as the hardware fifo might be used for other sensors. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 853 | * |
| 854 | * Available since API level 21. |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 855 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 856 | int ASensor_getFifoMaxEventCount(ASensor const* sensor) __INTRODUCED_IN(21); |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 857 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 858 | /** |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 859 | * Returns the hardware batch fifo size reserved to this sensor. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 860 | * |
| 861 | * Available since API level 21. |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 862 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 863 | int ASensor_getFifoReservedEventCount(ASensor const* sensor) __INTRODUCED_IN(21); |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 864 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 865 | /** |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 866 | * Returns this sensor's string type. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 867 | * |
| 868 | * Available since API level 21. |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 869 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 870 | const char* ASensor_getStringType(ASensor const* sensor) __INTRODUCED_IN(21); |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 871 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 872 | /** |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 873 | * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 874 | * |
| 875 | * Available since API level 21. |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 876 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 877 | int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21); |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 878 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 879 | /** |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 880 | * Returns true if this is a wake up sensor, false otherwise. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 881 | * |
| 882 | * Available since API level 21. |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 883 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 884 | bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21); |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 885 | |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 886 | /** |
| 887 | * Test if sensor supports a certain type of direct channel. |
| 888 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 889 | * Available since API level 26. |
| 890 | * |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 891 | * \param sensor a {@link ASensor} to denote the sensor to be checked. |
| 892 | * \param channelType Channel type constant, either |
| 893 | * {@ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} |
| 894 | * or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}. |
| 895 | * \returns true if sensor supports the specified direct channel type. |
| 896 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 897 | bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType) __INTRODUCED_IN(26); |
| 898 | |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 899 | /** |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 900 | * Get the highest direct rate level that a sensor supports. |
| 901 | * |
| 902 | * Available since API level 26. |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 903 | * |
| 904 | * \param sensor a {@link ASensor} to denote the sensor to be checked. |
| 905 | * |
| 906 | * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor. |
| 907 | * If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor |
| 908 | * does not support direct report. |
| 909 | */ |
Elliott Hughes | 9db409b | 2018-06-18 12:28:46 -0700 | [diff] [blame] | 910 | int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26); |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 911 | |
Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 912 | /** |
| 913 | * Returns the sensor's handle. |
| 914 | * |
| 915 | * The handle identifies the sensor within the system and is included in the |
| 916 | * {@link ASensorEvent#sensor} field of sensor events, including those sent with type |
| 917 | * {@link ASENSOR_TYPE_ADDITIONAL_INFO}. |
| 918 | * |
| 919 | * A sensor's handle is able to be used to map {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to the |
| 920 | * sensor that generated the event. |
| 921 | * |
| 922 | * It is important to note that the value returned by {@link ASensor_getHandle} is not the same as |
| 923 | * the value returned by the Java API {@link android.hardware.Sensor#getId} and no mapping exists |
| 924 | * between the values. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 925 | * |
| 926 | * Available since API level 29. |
Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 927 | */ |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 928 | int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(29); |
Brian Stack | 8228fa7 | 2019-01-04 14:15:13 -0800 | [diff] [blame] | 929 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 930 | #ifdef __cplusplus |
| 931 | }; |
| 932 | #endif |
| 933 | |
| 934 | #endif // ANDROID_SENSOR_H |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 935 | |
| 936 | /** @} */ |