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 | /** |
| 18 | * @addtogroup Sensor |
| 19 | * @{ |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * @file sensor.h |
| 24 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 25 | |
| 26 | #ifndef ANDROID_SENSOR_H |
| 27 | #define ANDROID_SENSOR_H |
| 28 | |
| 29 | /****************************************************************** |
| 30 | * |
| 31 | * IMPORTANT NOTICE: |
| 32 | * |
| 33 | * This file is part of Android's set of stable system headers |
| 34 | * exposed by the Android NDK (Native Development Kit). |
| 35 | * |
| 36 | * Third-party source AND binary code relies on the definitions |
| 37 | * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. |
| 38 | * |
| 39 | * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) |
| 40 | * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS |
| 41 | * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY |
| 42 | * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES |
| 43 | */ |
| 44 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 45 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 46 | * Structures and functions to receive and process sensor events in |
| 47 | * native code. |
| 48 | * |
| 49 | */ |
| 50 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 51 | #include <android/looper.h> |
| 52 | |
Dan Albert | 43dcd0e | 2017-04-25 12:24:28 -0700 | [diff] [blame] | 53 | #include <stdbool.h> |
Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 54 | #include <sys/types.h> |
| 55 | #include <math.h> |
| 56 | #include <stdint.h> |
| 57 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 58 | #ifdef __cplusplus |
| 59 | extern "C" { |
| 60 | #endif |
| 61 | |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 62 | typedef struct AHardwareBuffer AHardwareBuffer; |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 63 | |
Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 64 | #define ASENSOR_RESOLUTION_INVALID (nanf("")) |
| 65 | #define ASENSOR_FIFO_COUNT_INVALID (-1) |
| 66 | #define ASENSOR_DELAY_INVALID INT32_MIN |
| 67 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Sensor types. |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 70 | * (keep in sync with hardware/sensors.h) |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 71 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 72 | enum { |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 73 | /** |
Peng Xu | 37317b6 | 2017-03-07 17:49:31 -0800 | [diff] [blame] | 74 | * Invalid sensor type. Returned by {@link ASensor_getType} as error value. |
| 75 | */ |
| 76 | ASENSOR_TYPE_INVALID = -1, |
| 77 | /** |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 78 | * {@link ASENSOR_TYPE_ACCELEROMETER} |
| 79 | * reporting-mode: continuous |
| 80 | * |
| 81 | * All values are in SI units (m/s^2) and measure the acceleration of the |
| 82 | * device minus the force of gravity. |
| 83 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 84 | ASENSOR_TYPE_ACCELEROMETER = 1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 85 | /** |
| 86 | * {@link ASENSOR_TYPE_MAGNETIC_FIELD} |
| 87 | * reporting-mode: continuous |
| 88 | * |
| 89 | * All values are in micro-Tesla (uT) and measure the geomagnetic |
| 90 | * field in the X, Y and Z axis. |
| 91 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 92 | ASENSOR_TYPE_MAGNETIC_FIELD = 2, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 93 | /** |
| 94 | * {@link ASENSOR_TYPE_GYROSCOPE} |
| 95 | * reporting-mode: continuous |
| 96 | * |
| 97 | * All values are in radians/second and measure the rate of rotation |
| 98 | * around the X, Y and Z axis. |
| 99 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 100 | ASENSOR_TYPE_GYROSCOPE = 4, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 101 | /** |
| 102 | * {@link ASENSOR_TYPE_LIGHT} |
| 103 | * reporting-mode: on-change |
| 104 | * |
| 105 | * The light sensor value is returned in SI lux units. |
| 106 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 107 | ASENSOR_TYPE_LIGHT = 5, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 108 | /** |
| 109 | * {@link ASENSOR_TYPE_PROXIMITY} |
| 110 | * reporting-mode: on-change |
| 111 | * |
| 112 | * The proximity sensor which turns the screen off and back on during calls is the |
| 113 | * wake-up proximity sensor. Implement wake-up proximity sensor before implementing |
| 114 | * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag |
| 115 | * SENSOR_FLAG_WAKE_UP. |
| 116 | * The value corresponds to the distance to the nearest object in centimeters. |
| 117 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 118 | ASENSOR_TYPE_PROXIMITY = 8, |
| 119 | /** |
| 120 | * {@link ASENSOR_TYPE_LINEAR_ACCELERATION} |
| 121 | * reporting-mode: continuous |
| 122 | * |
| 123 | * All values are in SI units (m/s^2) and measure the acceleration of the |
| 124 | * device not including the force of gravity. |
| 125 | */ |
Peng Xu | 37317b6 | 2017-03-07 17:49:31 -0800 | [diff] [blame] | 126 | ASENSOR_TYPE_LINEAR_ACCELERATION = 10 |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 129 | /** |
| 130 | * Sensor accuracy measure. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 131 | */ |
| 132 | enum { |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 133 | /** no contact */ |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 134 | ASENSOR_STATUS_NO_CONTACT = -1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 135 | /** unreliable */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 136 | ASENSOR_STATUS_UNRELIABLE = 0, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 137 | /** low accuracy */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 138 | ASENSOR_STATUS_ACCURACY_LOW = 1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 139 | /** medium accuracy */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 140 | ASENSOR_STATUS_ACCURACY_MEDIUM = 2, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 141 | /** high accuracy */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 142 | ASENSOR_STATUS_ACCURACY_HIGH = 3 |
| 143 | }; |
| 144 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 145 | /** |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 146 | * Sensor Reporting Modes. |
| 147 | */ |
| 148 | enum { |
Peng Xu | 37317b6 | 2017-03-07 17:49:31 -0800 | [diff] [blame] | 149 | /** invalid reporting mode */ |
| 150 | AREPORTING_MODE_INVALID = -1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 151 | /** continuous reporting */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 152 | AREPORTING_MODE_CONTINUOUS = 0, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 153 | /** reporting on change */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 154 | AREPORTING_MODE_ON_CHANGE = 1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 155 | /** on shot reporting */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 156 | AREPORTING_MODE_ONE_SHOT = 2, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 157 | /** special trigger reporting */ |
Peng Xu | 37317b6 | 2017-03-07 17:49:31 -0800 | [diff] [blame] | 158 | AREPORTING_MODE_SPECIAL_TRIGGER = 3 |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 161 | /** |
| 162 | * Sensor Direct Report Rates. |
| 163 | */ |
| 164 | enum { |
| 165 | /** stopped */ |
| 166 | ASENSOR_DIRECT_RATE_STOP = 0, |
| 167 | /** nominal 50Hz */ |
| 168 | ASENSOR_DIRECT_RATE_NORMAL = 1, |
| 169 | /** nominal 200Hz */ |
| 170 | ASENSOR_DIRECT_RATE_FAST = 2, |
| 171 | /** nominal 800Hz */ |
| 172 | ASENSOR_DIRECT_RATE_VERY_FAST = 3 |
| 173 | }; |
| 174 | |
| 175 | /** |
| 176 | * Sensor Direct Channel Type. |
| 177 | */ |
| 178 | enum { |
| 179 | /** shared memory created by ASharedMemory_create */ |
| 180 | ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1, |
| 181 | /** AHardwareBuffer */ |
| 182 | ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2 |
| 183 | }; |
| 184 | |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 185 | /* |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 186 | * A few useful constants |
| 187 | */ |
| 188 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 189 | /** Earth's gravity in m/s^2 */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 190 | #define ASENSOR_STANDARD_GRAVITY (9.80665f) |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 191 | /** Maximum magnetic field on Earth's surface in uT */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 192 | #define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f) |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 193 | /** Minimum magnetic field on Earth's surface in uT*/ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 194 | #define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f) |
| 195 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 196 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 197 | * A sensor event. |
| 198 | */ |
| 199 | |
| 200 | /* NOTE: Must match hardware/sensors.h */ |
| 201 | typedef struct ASensorVector { |
| 202 | union { |
| 203 | float v[3]; |
| 204 | struct { |
| 205 | float x; |
| 206 | float y; |
| 207 | float z; |
| 208 | }; |
| 209 | struct { |
| 210 | float azimuth; |
| 211 | float pitch; |
| 212 | float roll; |
| 213 | }; |
| 214 | }; |
| 215 | int8_t status; |
| 216 | uint8_t reserved[3]; |
| 217 | } ASensorVector; |
| 218 | |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 219 | typedef struct AMetaDataEvent { |
| 220 | int32_t what; |
| 221 | int32_t sensor; |
| 222 | } AMetaDataEvent; |
| 223 | |
| 224 | typedef struct AUncalibratedEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 225 | union { |
| 226 | float uncalib[3]; |
| 227 | struct { |
| 228 | float x_uncalib; |
| 229 | float y_uncalib; |
| 230 | float z_uncalib; |
| 231 | }; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 232 | }; |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 233 | union { |
| 234 | float bias[3]; |
| 235 | struct { |
| 236 | float x_bias; |
| 237 | float y_bias; |
| 238 | float z_bias; |
| 239 | }; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 240 | }; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 241 | } AUncalibratedEvent; |
| 242 | |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 243 | typedef struct AHeartRateEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 244 | float bpm; |
| 245 | int8_t status; |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 246 | } AHeartRateEvent; |
| 247 | |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 248 | typedef struct ADynamicSensorEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 249 | int32_t connected; |
| 250 | int32_t handle; |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 251 | } ADynamicSensorEvent; |
| 252 | |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 253 | typedef struct { |
| 254 | int32_t type; |
| 255 | int32_t serial; |
| 256 | union { |
| 257 | int32_t data_int32[14]; |
| 258 | float data_float[14]; |
| 259 | }; |
| 260 | } AAdditionalInfoEvent; |
| 261 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 262 | /* NOTE: Must match hardware/sensors.h */ |
| 263 | typedef struct ASensorEvent { |
| 264 | int32_t version; /* sizeof(struct ASensorEvent) */ |
| 265 | int32_t sensor; |
| 266 | int32_t type; |
| 267 | int32_t reserved0; |
| 268 | int64_t timestamp; |
| 269 | union { |
Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 270 | union { |
| 271 | float data[16]; |
| 272 | ASensorVector vector; |
| 273 | ASensorVector acceleration; |
| 274 | ASensorVector magnetic; |
| 275 | float temperature; |
| 276 | float distance; |
| 277 | float light; |
| 278 | float pressure; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 279 | float relative_humidity; |
| 280 | AUncalibratedEvent uncalibrated_gyro; |
| 281 | AUncalibratedEvent uncalibrated_magnetic; |
| 282 | AMetaDataEvent meta_data; |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 283 | AHeartRateEvent heart_rate; |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 284 | ADynamicSensorEvent dynamic_sensor_meta; |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 285 | AAdditionalInfoEvent additional_info; |
Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 286 | }; |
| 287 | union { |
| 288 | uint64_t data[8]; |
| 289 | uint64_t step_counter; |
| 290 | } u64; |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 291 | }; |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 292 | |
| 293 | uint32_t flags; |
| 294 | int32_t reserved1[3]; |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 295 | } ASensorEvent; |
| 296 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 297 | struct ASensorManager; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 298 | /** |
| 299 | * {@link ASensorManager} is an opaque type to manage sensors and |
| 300 | * events queues. |
| 301 | * |
| 302 | * {@link ASensorManager} is a singleton that can be obtained using |
| 303 | * ASensorManager_getInstance(). |
| 304 | * |
| 305 | * This file provides a set of functions that uses {@link |
| 306 | * ASensorManager} to access and list hardware sensors, and |
| 307 | * create and destroy event queues: |
| 308 | * - ASensorManager_getSensorList() |
| 309 | * - ASensorManager_getDefaultSensor() |
| 310 | * - ASensorManager_getDefaultSensorEx() |
| 311 | * - ASensorManager_createEventQueue() |
| 312 | * - ASensorManager_destroyEventQueue() |
| 313 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 314 | typedef struct ASensorManager ASensorManager; |
| 315 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 316 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 317 | struct ASensorEventQueue; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 318 | /** |
| 319 | * {@link ASensorEventQueue} is an opaque type that provides access to |
| 320 | * {@link ASensorEvent} from hardware sensors. |
| 321 | * |
| 322 | * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue(). |
| 323 | * |
| 324 | * This file provides a set of functions to enable and disable |
| 325 | * sensors, check and get events, and set event rates on a {@link |
| 326 | * ASensorEventQueue}. |
| 327 | * - ASensorEventQueue_enableSensor() |
| 328 | * - ASensorEventQueue_disableSensor() |
| 329 | * - ASensorEventQueue_hasEvents() |
| 330 | * - ASensorEventQueue_getEvents() |
| 331 | * - ASensorEventQueue_setEventRate() |
| 332 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 333 | typedef struct ASensorEventQueue ASensorEventQueue; |
| 334 | |
| 335 | struct ASensor; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 336 | /** |
| 337 | * {@link ASensor} is an opaque type that provides information about |
| 338 | * an hardware sensors. |
| 339 | * |
| 340 | * A {@link ASensor} pointer can be obtained using |
| 341 | * ASensorManager_getDefaultSensor(), |
| 342 | * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}. |
| 343 | * |
| 344 | * This file provides a set of functions to access properties of a |
| 345 | * {@link ASensor}: |
| 346 | * - ASensor_getName() |
| 347 | * - ASensor_getVendor() |
| 348 | * - ASensor_getType() |
| 349 | * - ASensor_getResolution() |
| 350 | * - ASensor_getMinDelay() |
| 351 | * - ASensor_getFifoMaxEventCount() |
| 352 | * - ASensor_getFifoReservedEventCount() |
| 353 | * - ASensor_getStringType() |
| 354 | * - ASensor_getReportingMode() |
| 355 | * - ASensor_isWakeUpSensor() |
| 356 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 357 | typedef struct ASensor ASensor; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 358 | /** |
| 359 | * {@link ASensorRef} is a type for constant pointers to {@link ASensor}. |
| 360 | * |
| 361 | * This is used to define entry in {@link ASensorList} arrays. |
| 362 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 363 | typedef ASensor const* ASensorRef; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 364 | /** |
| 365 | * {@link ASensorList} is an array of reference to {@link ASensor}. |
| 366 | * |
| 367 | * A {@link ASensorList} can be initialized using ASensorManager_getSensorList(). |
| 368 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 369 | typedef ASensorRef const* ASensorList; |
| 370 | |
| 371 | /*****************************************************************************/ |
| 372 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 373 | /** |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 374 | * Get a reference to the sensor manager. ASensorManager is a singleton |
| 375 | * per package as different packages may have access to different sensors. |
| 376 | * |
| 377 | * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead. |
| 378 | * |
| 379 | * Example: |
| 380 | * |
| 381 | * ASensorManager* sensorManager = ASensorManager_getInstance(); |
| 382 | * |
| 383 | */ |
Peng Xu | 77a61e5 | 2017-07-17 16:40:50 -0700 | [diff] [blame] | 384 | #if __ANDROID_API__ >= __ANDROID_API_O__ |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 385 | __attribute__ ((deprecated)) ASensorManager* ASensorManager_getInstance(); |
Peng Xu | 77a61e5 | 2017-07-17 16:40:50 -0700 | [diff] [blame] | 386 | #else |
| 387 | ASensorManager* ASensorManager_getInstance(); |
| 388 | #endif |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 389 | |
Peng Xu | 77a61e5 | 2017-07-17 16:40:50 -0700 | [diff] [blame] | 390 | #if __ANDROID_API__ >= __ANDROID_API_O__ |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 391 | /** |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 392 | * Get a reference to the sensor manager. ASensorManager is a singleton |
| 393 | * per package as different packages may have access to different sensors. |
| 394 | * |
| 395 | * Example: |
| 396 | * |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 397 | * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz"); |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 398 | * |
| 399 | */ |
| 400 | ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName); |
Peng Xu | 77a61e5 | 2017-07-17 16:40:50 -0700 | [diff] [blame] | 401 | #endif |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 402 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 403 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 404 | * Returns the list of available sensors. |
| 405 | */ |
| 406 | int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list); |
| 407 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 408 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 409 | * 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] | 410 | * of that type exists. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 411 | */ |
| 412 | ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type); |
| 413 | |
Dan Albert | 494ed55 | 2016-09-23 15:57:45 -0700 | [diff] [blame] | 414 | #if __ANDROID_API__ >= 21 |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 415 | /** |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 416 | * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor |
| 417 | * of this type and wakeUp properties exists. |
| 418 | */ |
Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 419 | ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp); |
Dan Albert | 494ed55 | 2016-09-23 15:57:45 -0700 | [diff] [blame] | 420 | #endif |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 421 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 422 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 423 | * Creates a new sensor event queue and associate it with a looper. |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 424 | * |
| 425 | * "ident" is a identifier for the events that will be returned when |
| 426 | * calling ALooper_pollOnce(). The identifier must be >= 0, or |
| 427 | * ALOOPER_POLL_CALLBACK if providing a non-NULL callback. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 428 | */ |
| 429 | ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, |
| 430 | ALooper* looper, int ident, ALooper_callbackFunc callback, void* data); |
| 431 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 432 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 433 | * Destroys the event queue and free all resources associated to it. |
| 434 | */ |
| 435 | int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue); |
| 436 | |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 437 | #if __ANDROID_API__ >= __ANDROID_API_O__ |
| 438 | /** |
| 439 | * Create direct channel based on shared memory |
| 440 | * |
| 441 | * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used |
| 442 | * for configuring sensor direct report. |
| 443 | * |
| 444 | * \param manager the {@link ASensorManager} instance obtained from |
| 445 | * {@link ASensorManager_getInstanceForPackage}. |
| 446 | * \param fd file descriptor representing a shared memory created by |
| 447 | * {@link ASharedMemory_create} |
| 448 | * \param size size to be used, must be less or equal to size of shared memory. |
| 449 | * |
| 450 | * \return a positive integer as a channel id to be used in |
| 451 | * {@link ASensorManager_destroyDirectChannel} and |
| 452 | * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures. |
| 453 | */ |
| 454 | int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int fd, size_t size); |
| 455 | |
| 456 | /** |
| 457 | * Create direct channel based on AHardwareBuffer |
| 458 | * |
| 459 | * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used |
| 460 | * for configuring sensor direct report. |
| 461 | * |
| 462 | * \param manager the {@link ASensorManager} instance obtained from |
| 463 | * {@link ASensorManager_getInstanceForPackage}. |
| 464 | * \param buffer {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}. |
| 465 | * \param size the intended size to be used, must be less or equal to size of buffer. |
| 466 | * |
| 467 | * \return a positive integer as a channel id to be used in |
| 468 | * {@link ASensorManager_destroyDirectChannel} and |
| 469 | * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures. |
| 470 | */ |
| 471 | int ASensorManager_createHardwareBufferDirectChannel( |
| 472 | ASensorManager* manager, AHardwareBuffer const * buffer, size_t size); |
| 473 | |
| 474 | /** |
| 475 | * Destroy a direct channel |
| 476 | * |
| 477 | * Destroy a direct channel previously created using {@link ASensorManager_createDirectChannel}. |
| 478 | * The buffer used for creating direct channel does not get destroyed with |
| 479 | * {@link ASensorManager_destroy} and has to be close or released separately. |
| 480 | * |
| 481 | * \param manager the {@link ASensorManager} instance obtained from |
| 482 | * {@link ASensorManager_getInstanceForPackage}. |
| 483 | * \param channelId channel id (a positive integer) returned from |
| 484 | * {@link ASensorManager_createSharedMemoryDirectChannel} or |
| 485 | * {@link ASensorManager_createHardwareBufferDirectChannel}. |
| 486 | */ |
| 487 | void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId); |
| 488 | |
| 489 | /** |
| 490 | * Configure direct report on channel |
| 491 | * |
| 492 | * Configure sensor direct report on a direct channel: set rate to value other than |
| 493 | * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly |
Peng Xu | ec53d02 | 2017-04-06 18:02:29 -0700 | [diff] [blame] | 494 | * written into the shared memory region used for creating the buffer. It returns a positive token |
| 495 | * which can be used for identify sensor events from different sensors on success. Calling with rate |
| 496 | * {@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] | 497 | * |
| 498 | * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to |
| 499 | * {@link ASENSOR_DIRECT_RATE_STOP}. |
| 500 | * |
| 501 | * In order to successfully configure a direct report, the sensor has to support the specified rate |
| 502 | * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and |
| 503 | * {@link ASensor_isDirectChannelTypeSupported}, respectively. |
| 504 | * |
| 505 | * Example: |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 506 | * |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 507 | * ASensorManager *manager = ...; |
| 508 | * ASensor *sensor = ...; |
| 509 | * int channelId = ...; |
| 510 | * |
| 511 | * ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST); |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 512 | * |
| 513 | * \param manager the {@link ASensorManager} instance obtained from |
| 514 | * {@link ASensorManager_getInstanceForPackage}. |
| 515 | * \param sensor a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate |
| 516 | * is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor |
| 517 | * direct report. |
| 518 | * \param channelId channel id (a positive integer) returned from |
| 519 | * {@link ASensorManager_createSharedMemoryDirectChannel} or |
| 520 | * {@link ASensorManager_createHardwareBufferDirectChannel}. |
| 521 | * |
Peng Xu | ec53d02 | 2017-04-06 18:02:29 -0700 | [diff] [blame] | 522 | * \return positive token for success or negative error code. |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 523 | */ |
| 524 | int ASensorManager_configureDirectReport( |
| 525 | ASensorManager* manager, ASensor const* sensor, int channelId, int rate); |
| 526 | #endif |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 527 | |
| 528 | /*****************************************************************************/ |
| 529 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 530 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 531 | * Enable the selected sensor with sampling and report parameters |
| 532 | * |
| 533 | * Enable the selected sensor at a specified sampling period and max batch report latency. |
| 534 | * To disable sensor, use {@link ASensorEventQueue_disableSensor}. |
| 535 | * |
| 536 | * \param queue {@link ASensorEventQueue} for sensor event to be report to. |
| 537 | * \param sensor {@link ASensor} to be enabled. |
| 538 | * \param samplingPeriodUs sampling period of sensor in microseconds. |
| 539 | * \param maxBatchReportLatencyus maximum time interval between two batch of sensor events are |
| 540 | * delievered in microseconds. For sensor streaming, set to 0. |
| 541 | * \return 0 on success or a negative error code on failure. |
Aniroop Mathur | da94fd8 | 2015-11-03 01:47:46 +0530 | [diff] [blame] | 542 | */ |
| 543 | int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor, |
Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 544 | int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs); |
Aniroop Mathur | da94fd8 | 2015-11-03 01:47:46 +0530 | [diff] [blame] | 545 | |
| 546 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 547 | * Enable the selected sensor at default sampling rate. |
| 548 | * |
| 549 | * Start event reports of a sensor to specified sensor event queue at a default rate. |
| 550 | * |
| 551 | * \param queue {@link ASensorEventQueue} for sensor event to be report to. |
| 552 | * \param sensor {@link ASensor} to be enabled. |
| 553 | * |
| 554 | * \return 0 on success or a negative error code on failure. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 555 | */ |
| 556 | int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor); |
| 557 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 558 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 559 | * Disable the selected sensor. |
| 560 | * |
| 561 | * Stop event reports from the sensor to specified sensor event queue. |
| 562 | * |
| 563 | * \param queue {@link ASensorEventQueue} to be changed |
| 564 | * \param sensor {@link ASensor} to be disabled |
| 565 | * \return 0 on success or a negative error code on failure. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 566 | */ |
| 567 | int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor); |
| 568 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 569 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 570 | * Sets the delivery rate of events in microseconds for the given sensor. |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 571 | * |
| 572 | * This function has to be called after {@link ASensorEventQueue_enableSensor}. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 573 | * Note that this is a hint only, generally event will arrive at a higher |
| 574 | * rate. It is an error to set a rate inferior to the value returned by |
| 575 | * ASensor_getMinDelay(). |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 576 | * |
| 577 | * \param queue {@link ASensorEventQueue} to which sensor event is delivered. |
| 578 | * \param sensor {@link ASensor} of which sampling rate to be updated. |
| 579 | * \param usec sensor sampling period (1/sampling rate) in microseconds |
| 580 | * \return 0 on sucess or a negative error code on failure. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 581 | */ |
| 582 | int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec); |
| 583 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 584 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 585 | * Determine if a sensor event queue has pending event to be processed. |
| 586 | * |
| 587 | * \param queue {@link ASensorEventQueue} to be queried |
| 588 | * \return 1 if the queue has events; 0 if it does not have events; |
| 589 | * or a negative value if there is an error. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 590 | */ |
| 591 | int ASensorEventQueue_hasEvents(ASensorEventQueue* queue); |
| 592 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 593 | /** |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 594 | * Retrieve pending events in sensor event queue |
| 595 | * |
| 596 | * Retrieve next available events from the queue to a specified event array. |
| 597 | * |
| 598 | * \param queue {@link ASensorEventQueue} to get events from |
| 599 | * \param events pointer to an array of {@link ASensorEvents}. |
| 600 | * \param count max number of event that can be filled into array event. |
| 601 | * \return number of events returned on success; negative error code when |
| 602 | * no events are pending or an error has occurred. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 603 | * |
| 604 | * Examples: |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 605 | * |
Peng Xu | 80df016 | 2017-08-05 19:00:23 -0700 | [diff] [blame^] | 606 | * ASensorEvent event; |
| 607 | * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1); |
| 608 | * |
| 609 | * ASensorEvent eventBuffer[8]; |
| 610 | * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8); |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 611 | * |
| 612 | */ |
Peng Xu | da8385c | 2017-02-28 20:19:47 -0800 | [diff] [blame] | 613 | ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count); |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 614 | |
| 615 | |
| 616 | /*****************************************************************************/ |
| 617 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 618 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 619 | * Returns this sensor's name (non localized) |
| 620 | */ |
| 621 | const char* ASensor_getName(ASensor const* sensor); |
| 622 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 623 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 624 | * Returns this sensor's vendor's name (non localized) |
| 625 | */ |
| 626 | const char* ASensor_getVendor(ASensor const* sensor); |
| 627 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 628 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 629 | * Return this sensor's type |
| 630 | */ |
| 631 | int ASensor_getType(ASensor const* sensor); |
| 632 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 633 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 634 | * Returns this sensors's resolution |
| 635 | */ |
| 636 | float ASensor_getResolution(ASensor const* sensor); |
| 637 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 638 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 639 | * Returns the minimum delay allowed between events in microseconds. |
| 640 | * A value of zero means that this sensor doesn't report events at a |
| 641 | * constant rate, but rather only when a new data is available. |
| 642 | */ |
| 643 | int ASensor_getMinDelay(ASensor const* sensor); |
| 644 | |
Dan Albert | 494ed55 | 2016-09-23 15:57:45 -0700 | [diff] [blame] | 645 | #if __ANDROID_API__ >= 21 |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 646 | /** |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 647 | * Returns the maximum size of batches for this sensor. Batches will often be |
| 648 | * smaller, as the hardware fifo might be used for other sensors. |
| 649 | */ |
| 650 | int ASensor_getFifoMaxEventCount(ASensor const* sensor); |
| 651 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 652 | /** |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 653 | * Returns the hardware batch fifo size reserved to this sensor. |
| 654 | */ |
| 655 | int ASensor_getFifoReservedEventCount(ASensor const* sensor); |
| 656 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 657 | /** |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 658 | * Returns this sensor's string type. |
| 659 | */ |
| 660 | const char* ASensor_getStringType(ASensor const* sensor); |
| 661 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 662 | /** |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 663 | * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants. |
| 664 | */ |
| 665 | int ASensor_getReportingMode(ASensor const* sensor); |
| 666 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 667 | /** |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 668 | * Returns true if this is a wake up sensor, false otherwise. |
| 669 | */ |
| 670 | bool ASensor_isWakeUpSensor(ASensor const* sensor); |
Dan Albert | 494ed55 | 2016-09-23 15:57:45 -0700 | [diff] [blame] | 671 | #endif /* __ANDROID_API__ >= 21 */ |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 672 | |
Peng Xu | 47cddca | 2017-02-15 23:31:22 -0800 | [diff] [blame] | 673 | #if __ANDROID_API__ >= __ANDROID_API_O__ |
| 674 | /** |
| 675 | * Test if sensor supports a certain type of direct channel. |
| 676 | * |
| 677 | * \param sensor a {@link ASensor} to denote the sensor to be checked. |
| 678 | * \param channelType Channel type constant, either |
| 679 | * {@ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} |
| 680 | * or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}. |
| 681 | * \returns true if sensor supports the specified direct channel type. |
| 682 | */ |
| 683 | bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType); |
| 684 | /** |
| 685 | * Get the highest direct rate level that a sensor support. |
| 686 | * |
| 687 | * \param sensor a {@link ASensor} to denote the sensor to be checked. |
| 688 | * |
| 689 | * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor. |
| 690 | * If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor |
| 691 | * does not support direct report. |
| 692 | */ |
| 693 | int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor); |
| 694 | #endif |
| 695 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 696 | #ifdef __cplusplus |
| 697 | }; |
| 698 | #endif |
| 699 | |
| 700 | #endif // ANDROID_SENSOR_H |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 701 | |
| 702 | /** @} */ |