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 | |
Dan Albert | 43dcd0e | 2017-04-25 12:24:28 -0700 | [diff] [blame] | 51 | #include <stdbool.h> |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 52 | #include <sys/types.h> |
| 53 | |
| 54 | #include <android/looper.h> |
| 55 | |
| 56 | #ifdef __cplusplus |
| 57 | extern "C" { |
| 58 | #endif |
| 59 | |
| 60 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Sensor types. |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 63 | * (keep in sync with hardware/sensors.h) |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 64 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 65 | enum { |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 66 | /** |
| 67 | * {@link ASENSOR_TYPE_ACCELEROMETER} |
| 68 | * reporting-mode: continuous |
| 69 | * |
| 70 | * All values are in SI units (m/s^2) and measure the acceleration of the |
| 71 | * device minus the force of gravity. |
| 72 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 73 | ASENSOR_TYPE_ACCELEROMETER = 1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 74 | /** |
| 75 | * {@link ASENSOR_TYPE_MAGNETIC_FIELD} |
| 76 | * reporting-mode: continuous |
| 77 | * |
| 78 | * All values are in micro-Tesla (uT) and measure the geomagnetic |
| 79 | * field in the X, Y and Z axis. |
| 80 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 81 | ASENSOR_TYPE_MAGNETIC_FIELD = 2, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 82 | /** |
| 83 | * {@link ASENSOR_TYPE_GYROSCOPE} |
| 84 | * reporting-mode: continuous |
| 85 | * |
| 86 | * All values are in radians/second and measure the rate of rotation |
| 87 | * around the X, Y and Z axis. |
| 88 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 89 | ASENSOR_TYPE_GYROSCOPE = 4, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 90 | /** |
| 91 | * {@link ASENSOR_TYPE_LIGHT} |
| 92 | * reporting-mode: on-change |
| 93 | * |
| 94 | * The light sensor value is returned in SI lux units. |
| 95 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 96 | ASENSOR_TYPE_LIGHT = 5, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 97 | /** |
| 98 | * {@link ASENSOR_TYPE_PROXIMITY} |
| 99 | * reporting-mode: on-change |
| 100 | * |
| 101 | * The proximity sensor which turns the screen off and back on during calls is the |
| 102 | * wake-up proximity sensor. Implement wake-up proximity sensor before implementing |
| 103 | * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag |
| 104 | * SENSOR_FLAG_WAKE_UP. |
| 105 | * The value corresponds to the distance to the nearest object in centimeters. |
| 106 | */ |
Johan Euphrosine | 7d319fc | 2015-08-20 18:13:43 -0700 | [diff] [blame] | 107 | ASENSOR_TYPE_PROXIMITY = 8, |
| 108 | /** |
| 109 | * {@link ASENSOR_TYPE_LINEAR_ACCELERATION} |
| 110 | * reporting-mode: continuous |
| 111 | * |
| 112 | * All values are in SI units (m/s^2) and measure the acceleration of the |
| 113 | * device not including the force of gravity. |
| 114 | */ |
| 115 | ASENSOR_TYPE_LINEAR_ACCELERATION = 10 |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 118 | /** |
| 119 | * Sensor accuracy measure. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 120 | */ |
| 121 | enum { |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 122 | /** no contact */ |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 123 | ASENSOR_STATUS_NO_CONTACT = -1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 124 | /** unreliable */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 125 | ASENSOR_STATUS_UNRELIABLE = 0, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 126 | /** low accuracy */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 127 | ASENSOR_STATUS_ACCURACY_LOW = 1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 128 | /** medium accuracy */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 129 | ASENSOR_STATUS_ACCURACY_MEDIUM = 2, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 130 | /** high accuracy */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 131 | ASENSOR_STATUS_ACCURACY_HIGH = 3 |
| 132 | }; |
| 133 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 134 | /** |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 135 | * Sensor Reporting Modes. |
| 136 | */ |
| 137 | enum { |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 138 | /** continuous reporting */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 139 | AREPORTING_MODE_CONTINUOUS = 0, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 140 | /** reporting on change */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 141 | AREPORTING_MODE_ON_CHANGE = 1, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 142 | /** on shot reporting */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 143 | AREPORTING_MODE_ONE_SHOT = 2, |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 144 | /** special trigger reporting */ |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 145 | AREPORTING_MODE_SPECIAL_TRIGGER = 3 |
| 146 | }; |
| 147 | |
| 148 | /* |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 149 | * A few useful constants |
| 150 | */ |
| 151 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 152 | /** Earth's gravity in m/s^2 */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 153 | #define ASENSOR_STANDARD_GRAVITY (9.80665f) |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 154 | /** Maximum magnetic field on Earth's surface in uT */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 155 | #define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f) |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 156 | /** Minimum magnetic field on Earth's surface in uT*/ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 157 | #define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f) |
| 158 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 159 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 160 | * A sensor event. |
| 161 | */ |
| 162 | |
| 163 | /* NOTE: Must match hardware/sensors.h */ |
| 164 | typedef struct ASensorVector { |
| 165 | union { |
| 166 | float v[3]; |
| 167 | struct { |
| 168 | float x; |
| 169 | float y; |
| 170 | float z; |
| 171 | }; |
| 172 | struct { |
| 173 | float azimuth; |
| 174 | float pitch; |
| 175 | float roll; |
| 176 | }; |
| 177 | }; |
| 178 | int8_t status; |
| 179 | uint8_t reserved[3]; |
| 180 | } ASensorVector; |
| 181 | |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 182 | typedef struct AMetaDataEvent { |
| 183 | int32_t what; |
| 184 | int32_t sensor; |
| 185 | } AMetaDataEvent; |
| 186 | |
| 187 | typedef struct AUncalibratedEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 188 | union { |
| 189 | float uncalib[3]; |
| 190 | struct { |
| 191 | float x_uncalib; |
| 192 | float y_uncalib; |
| 193 | float z_uncalib; |
| 194 | }; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 195 | }; |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 196 | union { |
| 197 | float bias[3]; |
| 198 | struct { |
| 199 | float x_bias; |
| 200 | float y_bias; |
| 201 | float z_bias; |
| 202 | }; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 203 | }; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 204 | } AUncalibratedEvent; |
| 205 | |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 206 | typedef struct AHeartRateEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 207 | float bpm; |
| 208 | int8_t status; |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 209 | } AHeartRateEvent; |
| 210 | |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 211 | typedef struct ADynamicSensorEvent { |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 212 | int32_t connected; |
| 213 | int32_t handle; |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 214 | } ADynamicSensorEvent; |
| 215 | |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 216 | typedef struct { |
| 217 | int32_t type; |
| 218 | int32_t serial; |
| 219 | union { |
| 220 | int32_t data_int32[14]; |
| 221 | float data_float[14]; |
| 222 | }; |
| 223 | } AAdditionalInfoEvent; |
| 224 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 225 | /* NOTE: Must match hardware/sensors.h */ |
| 226 | typedef struct ASensorEvent { |
| 227 | int32_t version; /* sizeof(struct ASensorEvent) */ |
| 228 | int32_t sensor; |
| 229 | int32_t type; |
| 230 | int32_t reserved0; |
| 231 | int64_t timestamp; |
| 232 | union { |
Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 233 | union { |
| 234 | float data[16]; |
| 235 | ASensorVector vector; |
| 236 | ASensorVector acceleration; |
| 237 | ASensorVector magnetic; |
| 238 | float temperature; |
| 239 | float distance; |
| 240 | float light; |
| 241 | float pressure; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 242 | float relative_humidity; |
| 243 | AUncalibratedEvent uncalibrated_gyro; |
| 244 | AUncalibratedEvent uncalibrated_magnetic; |
| 245 | AMetaDataEvent meta_data; |
Etienne Le Grand | 630e31d | 2014-05-22 17:15:08 -0700 | [diff] [blame] | 246 | AHeartRateEvent heart_rate; |
Peng Xu | 2576cb6 | 2016-01-20 00:22:09 -0800 | [diff] [blame] | 247 | ADynamicSensorEvent dynamic_sensor_meta; |
Peng Xu | 9e72046 | 2016-01-26 18:48:54 -0800 | [diff] [blame] | 248 | AAdditionalInfoEvent additional_info; |
Mathias Agopian | ba02cd2 | 2013-07-03 16:20:57 -0700 | [diff] [blame] | 249 | }; |
| 250 | union { |
| 251 | uint64_t data[8]; |
| 252 | uint64_t step_counter; |
| 253 | } u64; |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 254 | }; |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 255 | |
| 256 | uint32_t flags; |
| 257 | int32_t reserved1[3]; |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 258 | } ASensorEvent; |
| 259 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 260 | struct ASensorManager; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 261 | /** |
| 262 | * {@link ASensorManager} is an opaque type to manage sensors and |
| 263 | * events queues. |
| 264 | * |
| 265 | * {@link ASensorManager} is a singleton that can be obtained using |
| 266 | * ASensorManager_getInstance(). |
| 267 | * |
| 268 | * This file provides a set of functions that uses {@link |
| 269 | * ASensorManager} to access and list hardware sensors, and |
| 270 | * create and destroy event queues: |
| 271 | * - ASensorManager_getSensorList() |
| 272 | * - ASensorManager_getDefaultSensor() |
| 273 | * - ASensorManager_getDefaultSensorEx() |
| 274 | * - ASensorManager_createEventQueue() |
| 275 | * - ASensorManager_destroyEventQueue() |
| 276 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 277 | typedef struct ASensorManager ASensorManager; |
| 278 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 279 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 280 | struct ASensorEventQueue; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 281 | /** |
| 282 | * {@link ASensorEventQueue} is an opaque type that provides access to |
| 283 | * {@link ASensorEvent} from hardware sensors. |
| 284 | * |
| 285 | * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue(). |
| 286 | * |
| 287 | * This file provides a set of functions to enable and disable |
| 288 | * sensors, check and get events, and set event rates on a {@link |
| 289 | * ASensorEventQueue}. |
| 290 | * - ASensorEventQueue_enableSensor() |
| 291 | * - ASensorEventQueue_disableSensor() |
| 292 | * - ASensorEventQueue_hasEvents() |
| 293 | * - ASensorEventQueue_getEvents() |
| 294 | * - ASensorEventQueue_setEventRate() |
| 295 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 296 | typedef struct ASensorEventQueue ASensorEventQueue; |
| 297 | |
| 298 | struct ASensor; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 299 | /** |
| 300 | * {@link ASensor} is an opaque type that provides information about |
| 301 | * an hardware sensors. |
| 302 | * |
| 303 | * A {@link ASensor} pointer can be obtained using |
| 304 | * ASensorManager_getDefaultSensor(), |
| 305 | * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}. |
| 306 | * |
| 307 | * This file provides a set of functions to access properties of a |
| 308 | * {@link ASensor}: |
| 309 | * - ASensor_getName() |
| 310 | * - ASensor_getVendor() |
| 311 | * - ASensor_getType() |
| 312 | * - ASensor_getResolution() |
| 313 | * - ASensor_getMinDelay() |
| 314 | * - ASensor_getFifoMaxEventCount() |
| 315 | * - ASensor_getFifoReservedEventCount() |
| 316 | * - ASensor_getStringType() |
| 317 | * - ASensor_getReportingMode() |
| 318 | * - ASensor_isWakeUpSensor() |
| 319 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 320 | typedef struct ASensor ASensor; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 321 | /** |
| 322 | * {@link ASensorRef} is a type for constant pointers to {@link ASensor}. |
| 323 | * |
| 324 | * This is used to define entry in {@link ASensorList} arrays. |
| 325 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 326 | typedef ASensor const* ASensorRef; |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 327 | /** |
| 328 | * {@link ASensorList} is an array of reference to {@link ASensor}. |
| 329 | * |
| 330 | * A {@link ASensorList} can be initialized using ASensorManager_getSensorList(). |
| 331 | */ |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 332 | typedef ASensorRef const* ASensorList; |
| 333 | |
| 334 | /*****************************************************************************/ |
| 335 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 336 | /** |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 337 | * Get a reference to the sensor manager. ASensorManager is a singleton |
| 338 | * per package as different packages may have access to different sensors. |
| 339 | * |
| 340 | * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead. |
| 341 | * |
| 342 | * Example: |
| 343 | * |
| 344 | * ASensorManager* sensorManager = ASensorManager_getInstance(); |
| 345 | * |
| 346 | */ |
Peng Xu | 77a61e5 | 2017-07-17 16:40:50 -0700 | [diff] [blame^] | 347 | #if __ANDROID_API__ >= __ANDROID_API_O__ |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 348 | __attribute__ ((deprecated)) ASensorManager* ASensorManager_getInstance(); |
Peng Xu | 77a61e5 | 2017-07-17 16:40:50 -0700 | [diff] [blame^] | 349 | #else |
| 350 | ASensorManager* ASensorManager_getInstance(); |
| 351 | #endif |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 352 | |
Peng Xu | 77a61e5 | 2017-07-17 16:40:50 -0700 | [diff] [blame^] | 353 | #if __ANDROID_API__ >= __ANDROID_API_O__ |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 354 | /* |
| 355 | * Get a reference to the sensor manager. ASensorManager is a singleton |
| 356 | * per package as different packages may have access to different sensors. |
| 357 | * |
| 358 | * Example: |
| 359 | * |
| 360 | * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz"); |
| 361 | * |
| 362 | */ |
| 363 | ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName); |
Peng Xu | 77a61e5 | 2017-07-17 16:40:50 -0700 | [diff] [blame^] | 364 | #endif |
Svet Ganov | 5fa32d4 | 2015-05-07 10:50:59 -0700 | [diff] [blame] | 365 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 366 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 367 | * Returns the list of available sensors. |
| 368 | */ |
| 369 | int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list); |
| 370 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 371 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 372 | * 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] | 373 | * of that type exists. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 374 | */ |
| 375 | ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type); |
| 376 | |
Dan Albert | 494ed55 | 2016-09-23 15:57:45 -0700 | [diff] [blame] | 377 | #if __ANDROID_API__ >= 21 |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 378 | /** |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 379 | * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor |
| 380 | * of this type and wakeUp properties exists. |
| 381 | */ |
| 382 | ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, |
| 383 | bool wakeUp); |
Dan Albert | 494ed55 | 2016-09-23 15:57:45 -0700 | [diff] [blame] | 384 | #endif |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 385 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 386 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 387 | * Creates a new sensor event queue and associate it with a looper. |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 388 | * |
| 389 | * "ident" is a identifier for the events that will be returned when |
| 390 | * calling ALooper_pollOnce(). The identifier must be >= 0, or |
| 391 | * ALOOPER_POLL_CALLBACK if providing a non-NULL callback. |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 392 | */ |
| 393 | ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, |
| 394 | ALooper* looper, int ident, ALooper_callbackFunc callback, void* data); |
| 395 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 396 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 397 | * Destroys the event queue and free all resources associated to it. |
| 398 | */ |
| 399 | int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue); |
| 400 | |
| 401 | |
| 402 | /*****************************************************************************/ |
| 403 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 404 | /** |
Aniroop Mathur | da94fd8 | 2015-11-03 01:47:46 +0530 | [diff] [blame] | 405 | * Enable the selected sensor with a specified sampling period and max batch report latency. |
| 406 | * Returns a negative error code on failure. |
Aniroop Mathur | e96e577 | 2016-12-13 00:04:06 +0530 | [diff] [blame] | 407 | * Note: To disable the selected sensor, use ASensorEventQueue_disableSensor() same as before. |
Aniroop Mathur | da94fd8 | 2015-11-03 01:47:46 +0530 | [diff] [blame] | 408 | */ |
| 409 | int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor, |
| 410 | int32_t samplingPeriodUs, int maxBatchReportLatencyUs); |
| 411 | |
| 412 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 413 | * Enable the selected sensor. Returns a negative error code on failure. |
| 414 | */ |
| 415 | int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor); |
| 416 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 417 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 418 | * Disable the selected sensor. Returns a negative error code on failure. |
| 419 | */ |
| 420 | int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor); |
| 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 | * Sets the delivery rate of events in microseconds for the given sensor. |
| 424 | * Note that this is a hint only, generally event will arrive at a higher |
| 425 | * rate. It is an error to set a rate inferior to the value returned by |
| 426 | * ASensor_getMinDelay(). |
| 427 | * Returns a negative error code on failure. |
| 428 | */ |
| 429 | int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec); |
| 430 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 431 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 432 | * Returns true if there are one or more events available in the |
| 433 | * sensor queue. Returns 1 if the queue has events; 0 if |
| 434 | * it does not have events; and a negative value if there is an error. |
| 435 | */ |
| 436 | int ASensorEventQueue_hasEvents(ASensorEventQueue* queue); |
| 437 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 438 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 439 | * Returns the next available events from the queue. Returns a negative |
| 440 | * value if no events are available or an error has occurred, otherwise |
| 441 | * the number of events returned. |
| 442 | * |
| 443 | * Examples: |
| 444 | * ASensorEvent event; |
| 445 | * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1); |
| 446 | * |
| 447 | * ASensorEvent eventBuffer[8]; |
| 448 | * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8); |
| 449 | * |
| 450 | */ |
| 451 | ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, |
| 452 | ASensorEvent* events, size_t count); |
| 453 | |
| 454 | |
| 455 | /*****************************************************************************/ |
| 456 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 457 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 458 | * Returns this sensor's name (non localized) |
| 459 | */ |
| 460 | const char* ASensor_getName(ASensor const* sensor); |
| 461 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 462 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 463 | * Returns this sensor's vendor's name (non localized) |
| 464 | */ |
| 465 | const char* ASensor_getVendor(ASensor const* sensor); |
| 466 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 467 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 468 | * Return this sensor's type |
| 469 | */ |
| 470 | int ASensor_getType(ASensor const* sensor); |
| 471 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 472 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 473 | * Returns this sensors's resolution |
| 474 | */ |
| 475 | float ASensor_getResolution(ASensor const* sensor); |
| 476 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 477 | /** |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 478 | * Returns the minimum delay allowed between events in microseconds. |
| 479 | * A value of zero means that this sensor doesn't report events at a |
| 480 | * constant rate, but rather only when a new data is available. |
| 481 | */ |
| 482 | int ASensor_getMinDelay(ASensor const* sensor); |
| 483 | |
Dan Albert | 494ed55 | 2016-09-23 15:57:45 -0700 | [diff] [blame] | 484 | #if __ANDROID_API__ >= 21 |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 485 | /** |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 486 | * Returns the maximum size of batches for this sensor. Batches will often be |
| 487 | * smaller, as the hardware fifo might be used for other sensors. |
| 488 | */ |
| 489 | int ASensor_getFifoMaxEventCount(ASensor const* sensor); |
| 490 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 491 | /** |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 492 | * Returns the hardware batch fifo size reserved to this sensor. |
| 493 | */ |
| 494 | int ASensor_getFifoReservedEventCount(ASensor const* sensor); |
| 495 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 496 | /** |
Aravind Akella | 7001804 | 2014-04-07 22:52:37 +0000 | [diff] [blame] | 497 | * Returns this sensor's string type. |
| 498 | */ |
| 499 | const char* ASensor_getStringType(ASensor const* sensor); |
| 500 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 501 | /** |
Aravind Akella | 0e025c5 | 2014-06-03 19:19:57 -0700 | [diff] [blame] | 502 | * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants. |
| 503 | */ |
| 504 | int ASensor_getReportingMode(ASensor const* sensor); |
| 505 | |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 506 | /** |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 507 | * Returns true if this is a wake up sensor, false otherwise. |
| 508 | */ |
| 509 | bool ASensor_isWakeUpSensor(ASensor const* sensor); |
Dan Albert | 494ed55 | 2016-09-23 15:57:45 -0700 | [diff] [blame] | 510 | #endif /* __ANDROID_API__ >= 21 */ |
Aravind Akella | b37ba39 | 2014-08-05 14:53:07 -0700 | [diff] [blame] | 511 | |
Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 512 | #ifdef __cplusplus |
| 513 | }; |
| 514 | #endif |
| 515 | |
| 516 | #endif // ANDROID_SENSOR_H |
Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 517 | |
| 518 | /** @} */ |