blob: e63ac4b4079422e586791a5ec57bd743c86b522a [file] [log] [blame]
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001/*
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 Euphrosinebf6d5e02015-03-27 17:15:43 -070017/**
Leon Scroggins III4883c522020-01-30 15:10:11 -050018 * Structures and functions to receive and process sensor events in
19 * native code.
20 *
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070021 * @addtogroup Sensor
22 * @{
23 */
24
25/**
26 * @file sensor.h
27 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070028
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 Agopiane1c61d32012-03-23 14:19:36 -070048#include <android/looper.h>
49
Dan Albert8f860fd2017-04-25 12:24:28 -070050#include <stdbool.h>
Peng Xuda8385c2017-02-28 20:19:47 -080051#include <sys/types.h>
52#include <math.h>
53#include <stdint.h>
54
Mathias Agopiane1c61d32012-03-23 14:19:36 -070055#ifdef __cplusplus
56extern "C" {
57#endif
58
Peng Xu47cddca2017-02-15 23:31:22 -080059typedef struct AHardwareBuffer AHardwareBuffer;
Mathias Agopiane1c61d32012-03-23 14:19:36 -070060
Peng Xuda8385c2017-02-28 20:19:47 -080061#define ASENSOR_RESOLUTION_INVALID (nanf(""))
62#define ASENSOR_FIFO_COUNT_INVALID (-1)
63#define ASENSOR_DELAY_INVALID INT32_MIN
Brian Stack8228fa72019-01-04 14:15:13 -080064#define ASENSOR_INVALID (-1)
Peng Xuda8385c2017-02-28 20:19:47 -080065
Elliott Hughesf78be362018-01-23 15:33:56 -080066/* (Keep in sync with hardware/sensors-base.h and Sensor.java.) */
67
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070068/**
69 * Sensor types.
Elliott Hughesf78be362018-01-23 15:33:56 -080070 *
71 * See
72 * [android.hardware.SensorEvent#values](https://developer.android.com/reference/android/hardware/SensorEvent.html#values)
73 * for detailed explanations of the data returned for each of these types.
Mathias Agopiane1c61d32012-03-23 14:19:36 -070074 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070075enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070076 /**
Peng Xu37317b62017-03-07 17:49:31 -080077 * Invalid sensor type. Returned by {@link ASensor_getType} as error value.
78 */
79 ASENSOR_TYPE_INVALID = -1,
80 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070081 * {@link ASENSOR_TYPE_ACCELEROMETER}
82 * reporting-mode: continuous
83 *
84 * All values are in SI units (m/s^2) and measure the acceleration of the
85 * device minus the force of gravity.
86 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -070087 ASENSOR_TYPE_ACCELEROMETER = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070088 /**
89 * {@link ASENSOR_TYPE_MAGNETIC_FIELD}
90 * reporting-mode: continuous
91 *
92 * All values are in micro-Tesla (uT) and measure the geomagnetic
93 * field in the X, Y and Z axis.
94 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -070095 ASENSOR_TYPE_MAGNETIC_FIELD = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070096 /**
97 * {@link ASENSOR_TYPE_GYROSCOPE}
98 * reporting-mode: continuous
99 *
100 * All values are in radians/second and measure the rate of rotation
101 * around the X, Y and Z axis.
102 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700103 ASENSOR_TYPE_GYROSCOPE = 4,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700104 /**
105 * {@link ASENSOR_TYPE_LIGHT}
106 * reporting-mode: on-change
107 *
108 * The light sensor value is returned in SI lux units.
109 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700110 ASENSOR_TYPE_LIGHT = 5,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700111 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800112 * {@link ASENSOR_TYPE_PRESSURE}
113 *
114 * The pressure sensor value is returned in hPa (millibar).
115 */
116 ASENSOR_TYPE_PRESSURE = 6,
117 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700118 * {@link ASENSOR_TYPE_PROXIMITY}
119 * reporting-mode: on-change
120 *
121 * The proximity sensor which turns the screen off and back on during calls is the
122 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
123 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
124 * SENSOR_FLAG_WAKE_UP.
125 * The value corresponds to the distance to the nearest object in centimeters.
126 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700127 ASENSOR_TYPE_PROXIMITY = 8,
128 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800129 * {@link ASENSOR_TYPE_GRAVITY}
130 *
131 * All values are in SI units (m/s^2) and measure the direction and
132 * magnitude of gravity. When the device is at rest, the output of
133 * the gravity sensor should be identical to that of the accelerometer.
134 */
135 ASENSOR_TYPE_GRAVITY = 9,
136 /**
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700137 * {@link ASENSOR_TYPE_LINEAR_ACCELERATION}
138 * reporting-mode: continuous
139 *
140 * All values are in SI units (m/s^2) and measure the acceleration of the
141 * device not including the force of gravity.
142 */
Elliott Hughesf78be362018-01-23 15:33:56 -0800143 ASENSOR_TYPE_LINEAR_ACCELERATION = 10,
144 /**
145 * {@link ASENSOR_TYPE_ROTATION_VECTOR}
146 */
147 ASENSOR_TYPE_ROTATION_VECTOR = 11,
148 /**
149 * {@link ASENSOR_TYPE_RELATIVE_HUMIDITY}
150 *
151 * The relative humidity sensor value is returned in percent.
152 */
153 ASENSOR_TYPE_RELATIVE_HUMIDITY = 12,
154 /**
155 * {@link ASENSOR_TYPE_AMBIENT_TEMPERATURE}
156 *
157 * The ambient temperature sensor value is returned in Celcius.
158 */
159 ASENSOR_TYPE_AMBIENT_TEMPERATURE = 13,
160 /**
161 * {@link ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED}
162 */
163 ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14,
164 /**
165 * {@link ASENSOR_TYPE_GAME_ROTATION_VECTOR}
166 */
167 ASENSOR_TYPE_GAME_ROTATION_VECTOR = 15,
168 /**
169 * {@link ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED}
170 */
171 ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 16,
172 /**
173 * {@link ASENSOR_TYPE_SIGNIFICANT_MOTION}
174 */
175 ASENSOR_TYPE_SIGNIFICANT_MOTION = 17,
176 /**
177 * {@link ASENSOR_TYPE_STEP_DETECTOR}
178 */
179 ASENSOR_TYPE_STEP_DETECTOR = 18,
180 /**
181 * {@link ASENSOR_TYPE_STEP_COUNTER}
182 */
183 ASENSOR_TYPE_STEP_COUNTER = 19,
184 /**
185 * {@link ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR}
186 */
187 ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20,
188 /**
189 * {@link ASENSOR_TYPE_HEART_RATE}
190 */
191 ASENSOR_TYPE_HEART_RATE = 21,
192 /**
193 * {@link ASENSOR_TYPE_POSE_6DOF}
194 */
195 ASENSOR_TYPE_POSE_6DOF = 28,
196 /**
197 * {@link ASENSOR_TYPE_STATIONARY_DETECT}
198 */
199 ASENSOR_TYPE_STATIONARY_DETECT = 29,
200 /**
201 * {@link ASENSOR_TYPE_MOTION_DETECT}
202 */
203 ASENSOR_TYPE_MOTION_DETECT = 30,
204 /**
205 * {@link ASENSOR_TYPE_HEART_BEAT}
206 */
207 ASENSOR_TYPE_HEART_BEAT = 31,
208 /**
Brian Stackccd88432019-01-08 17:04:18 -0800209 * This sensor type is for delivering additional sensor information aside
210 * from sensor event data.
211 *
212 * Additional information may include:
213 * - {@link ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE}
214 * - {@link ASENSOR_ADDITIONAL_INFO_SAMPLING}
215 * - {@link ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT}
216 * - {@link ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY}
217 * - {@link ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION}
218 *
219 * This type will never bind to a sensor. In other words, no sensor in the
220 * sensor list can have the type {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
221 *
222 * If a device supports the sensor additional information feature, it will
223 * report additional information events via {@link ASensorEvent} and will
224 * have {@link ASensorEvent#type} set to
225 * {@link ASENSOR_TYPE_ADDITIONAL_INFO} and {@link ASensorEvent#sensor} set
226 * to the handle of the reporting sensor.
227 *
228 * Additional information reports consist of multiple frames ordered by
229 * {@link ASensorEvent#timestamp}. The first frame in the report will have
230 * a {@link AAdditionalInfoEvent#type} of
231 * {@link ASENSOR_ADDITIONAL_INFO_BEGIN}, and the last frame in the report
232 * will have a {@link AAdditionalInfoEvent#type} of
233 * {@link ASENSOR_ADDITIONAL_INFO_END}.
234 *
235 */
236 ASENSOR_TYPE_ADDITIONAL_INFO = 33,
237 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800238 * {@link ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT}
239 */
240 ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34,
241 /**
242 * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED}
243 */
244 ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35,
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500245 /**
246 * {@link ASENSOR_TYPE_HINGE_ANGLE}
247 */
248 ASENSOR_TYPE_HINGE_ANGLE = 36,
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700249};
250
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700251/**
252 * Sensor accuracy measure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700253 */
254enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700255 /** no contact */
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700256 ASENSOR_STATUS_NO_CONTACT = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700257 /** unreliable */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700258 ASENSOR_STATUS_UNRELIABLE = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700259 /** low accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700260 ASENSOR_STATUS_ACCURACY_LOW = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700261 /** medium accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700262 ASENSOR_STATUS_ACCURACY_MEDIUM = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700263 /** high accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700264 ASENSOR_STATUS_ACCURACY_HIGH = 3
265};
266
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700267/**
Aravind Akella0e025c52014-06-03 19:19:57 -0700268 * Sensor Reporting Modes.
269 */
270enum {
Peng Xu37317b62017-03-07 17:49:31 -0800271 /** invalid reporting mode */
272 AREPORTING_MODE_INVALID = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700273 /** continuous reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700274 AREPORTING_MODE_CONTINUOUS = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700275 /** reporting on change */
Aravind Akella0e025c52014-06-03 19:19:57 -0700276 AREPORTING_MODE_ON_CHANGE = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700277 /** on shot reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700278 AREPORTING_MODE_ONE_SHOT = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700279 /** special trigger reporting */
Peng Xu37317b62017-03-07 17:49:31 -0800280 AREPORTING_MODE_SPECIAL_TRIGGER = 3
Aravind Akella0e025c52014-06-03 19:19:57 -0700281};
282
Peng Xu47cddca2017-02-15 23:31:22 -0800283/**
284 * Sensor Direct Report Rates.
285 */
286enum {
287 /** stopped */
288 ASENSOR_DIRECT_RATE_STOP = 0,
289 /** nominal 50Hz */
290 ASENSOR_DIRECT_RATE_NORMAL = 1,
291 /** nominal 200Hz */
292 ASENSOR_DIRECT_RATE_FAST = 2,
293 /** nominal 800Hz */
294 ASENSOR_DIRECT_RATE_VERY_FAST = 3
295};
296
297/**
298 * Sensor Direct Channel Type.
299 */
300enum {
301 /** shared memory created by ASharedMemory_create */
302 ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1,
303 /** AHardwareBuffer */
304 ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2
305};
306
Brian Stackccd88432019-01-08 17:04:18 -0800307/**
308 * Sensor Additional Info Types.
309 *
310 * Used to populate {@link AAdditionalInfoEvent#type}.
311 */
312enum {
313 /** Marks the beginning of additional information frames */
314 ASENSOR_ADDITIONAL_INFO_BEGIN = 0,
315
316 /** Marks the end of additional information frames */
317 ASENSOR_ADDITIONAL_INFO_END = 1,
318
319 /**
320 * Estimation of the delay that is not tracked by sensor timestamps. This
321 * includes delay introduced by sensor front-end filtering, data transport,
322 * etc.
323 * float[2]: delay in seconds, standard deviation of estimated value
324 */
325 ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY = 0x10000,
326
327 /** float: Celsius temperature */
328 ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE,
329
330 /**
331 * First three rows of a homogeneous matrix, which represents calibration to
332 * a three-element vector raw sensor reading.
333 * float[12]: 3x4 matrix in row major order
334 */
335 ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION,
336
337 /**
338 * Location and orientation of sensor element in the device frame: origin is
339 * the geometric center of the mobile device screen surface; the axis
340 * definition corresponds to Android sensor definitions.
341 * float[12]: 3x4 matrix in row major order
342 */
343 ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT,
344
345 /**
346 * float[2]: raw sample period in seconds,
347 * standard deviation of sampling period
348 */
349 ASENSOR_ADDITIONAL_INFO_SAMPLING,
350};
351
Aravind Akella0e025c52014-06-03 19:19:57 -0700352/*
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700353 * A few useful constants
354 */
355
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700356/** Earth's gravity in m/s^2 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700357#define ASENSOR_STANDARD_GRAVITY (9.80665f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700358/** Maximum magnetic field on Earth's surface in uT */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700359#define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700360/** Minimum magnetic field on Earth's surface in uT*/
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700361#define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f)
362
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700363/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700364 * A sensor event.
365 */
366
Peng Xu70b98382017-08-07 14:09:11 -0700367/* NOTE: changes to these structs have to be backward compatible */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700368typedef struct ASensorVector {
369 union {
370 float v[3];
371 struct {
372 float x;
373 float y;
374 float z;
375 };
376 struct {
377 float azimuth;
378 float pitch;
379 float roll;
380 };
381 };
382 int8_t status;
383 uint8_t reserved[3];
384} ASensorVector;
385
Aravind Akella724d91d2013-06-27 12:04:23 -0700386typedef struct AMetaDataEvent {
387 int32_t what;
388 int32_t sensor;
389} AMetaDataEvent;
390
391typedef struct AUncalibratedEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800392 union {
393 float uncalib[3];
394 struct {
395 float x_uncalib;
396 float y_uncalib;
397 float z_uncalib;
398 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700399 };
Peng Xu9e720462016-01-26 18:48:54 -0800400 union {
401 float bias[3];
402 struct {
403 float x_bias;
404 float y_bias;
405 float z_bias;
406 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700407 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700408} AUncalibratedEvent;
409
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700410typedef struct AHeartRateEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800411 float bpm;
412 int8_t status;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700413} AHeartRateEvent;
414
Peng Xu2576cb62016-01-20 00:22:09 -0800415typedef struct ADynamicSensorEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800416 int32_t connected;
417 int32_t handle;
Peng Xu2576cb62016-01-20 00:22:09 -0800418} ADynamicSensorEvent;
419
Brian Stackccd88432019-01-08 17:04:18 -0800420typedef struct AAdditionalInfoEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800421 int32_t type;
422 int32_t serial;
423 union {
424 int32_t data_int32[14];
425 float data_float[14];
426 };
427} AAdditionalInfoEvent;
428
Peng Xu70b98382017-08-07 14:09:11 -0700429/* NOTE: changes to this struct has to be backward compatible */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700430typedef struct ASensorEvent {
431 int32_t version; /* sizeof(struct ASensorEvent) */
432 int32_t sensor;
433 int32_t type;
434 int32_t reserved0;
435 int64_t timestamp;
436 union {
Mathias Agopianba02cd22013-07-03 16:20:57 -0700437 union {
438 float data[16];
439 ASensorVector vector;
440 ASensorVector acceleration;
441 ASensorVector magnetic;
442 float temperature;
443 float distance;
444 float light;
445 float pressure;
Aravind Akella724d91d2013-06-27 12:04:23 -0700446 float relative_humidity;
447 AUncalibratedEvent uncalibrated_gyro;
448 AUncalibratedEvent uncalibrated_magnetic;
449 AMetaDataEvent meta_data;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700450 AHeartRateEvent heart_rate;
Peng Xu2576cb62016-01-20 00:22:09 -0800451 ADynamicSensorEvent dynamic_sensor_meta;
Peng Xu9e720462016-01-26 18:48:54 -0800452 AAdditionalInfoEvent additional_info;
Mathias Agopianba02cd22013-07-03 16:20:57 -0700453 };
454 union {
455 uint64_t data[8];
456 uint64_t step_counter;
457 } u64;
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700458 };
Aravind Akella9a844cf2014-02-11 18:58:52 -0800459
460 uint32_t flags;
461 int32_t reserved1[3];
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700462} ASensorEvent;
463
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700464struct ASensorManager;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700465/**
466 * {@link ASensorManager} is an opaque type to manage sensors and
467 * events queues.
468 *
469 * {@link ASensorManager} is a singleton that can be obtained using
470 * ASensorManager_getInstance().
471 *
472 * This file provides a set of functions that uses {@link
473 * ASensorManager} to access and list hardware sensors, and
474 * create and destroy event queues:
475 * - ASensorManager_getSensorList()
476 * - ASensorManager_getDefaultSensor()
477 * - ASensorManager_getDefaultSensorEx()
478 * - ASensorManager_createEventQueue()
479 * - ASensorManager_destroyEventQueue()
480 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700481typedef struct ASensorManager ASensorManager;
482
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700483
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700484struct ASensorEventQueue;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700485/**
486 * {@link ASensorEventQueue} is an opaque type that provides access to
487 * {@link ASensorEvent} from hardware sensors.
488 *
489 * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue().
490 *
491 * This file provides a set of functions to enable and disable
492 * sensors, check and get events, and set event rates on a {@link
493 * ASensorEventQueue}.
494 * - ASensorEventQueue_enableSensor()
495 * - ASensorEventQueue_disableSensor()
496 * - ASensorEventQueue_hasEvents()
497 * - ASensorEventQueue_getEvents()
498 * - ASensorEventQueue_setEventRate()
Brian Stack65089d52019-01-11 10:52:07 -0800499 * - ASensorEventQueue_requestAdditionalInfoEvents()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700500 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700501typedef struct ASensorEventQueue ASensorEventQueue;
502
503struct ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700504/**
505 * {@link ASensor} is an opaque type that provides information about
506 * an hardware sensors.
507 *
508 * A {@link ASensor} pointer can be obtained using
509 * ASensorManager_getDefaultSensor(),
510 * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}.
511 *
512 * This file provides a set of functions to access properties of a
513 * {@link ASensor}:
514 * - ASensor_getName()
515 * - ASensor_getVendor()
516 * - ASensor_getType()
517 * - ASensor_getResolution()
518 * - ASensor_getMinDelay()
519 * - ASensor_getFifoMaxEventCount()
520 * - ASensor_getFifoReservedEventCount()
521 * - ASensor_getStringType()
522 * - ASensor_getReportingMode()
523 * - ASensor_isWakeUpSensor()
Brian Stack8228fa72019-01-04 14:15:13 -0800524 * - ASensor_getHandle()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700525 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700526typedef struct ASensor ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700527/**
528 * {@link ASensorRef} is a type for constant pointers to {@link ASensor}.
529 *
530 * This is used to define entry in {@link ASensorList} arrays.
531 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700532typedef ASensor const* ASensorRef;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700533/**
534 * {@link ASensorList} is an array of reference to {@link ASensor}.
535 *
536 * A {@link ASensorList} can be initialized using ASensorManager_getSensorList().
537 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700538typedef ASensorRef const* ASensorList;
539
540/*****************************************************************************/
541
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700542/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700543 * Get a reference to the sensor manager. ASensorManager is a singleton
544 * per package as different packages may have access to different sensors.
545 *
546 * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead.
547 *
548 * Example:
549 *
550 * ASensorManager* sensorManager = ASensorManager_getInstance();
551 *
552 */
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700553#if __ANDROID_API__ >= 26
Svet Ganov5fa32d42015-05-07 10:50:59 -0700554__attribute__ ((deprecated)) ASensorManager* ASensorManager_getInstance();
Peng Xu477db442017-07-17 16:40:50 -0700555#else
556ASensorManager* ASensorManager_getInstance();
557#endif
Svet Ganov5fa32d42015-05-07 10:50:59 -0700558
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700559#if __ANDROID_API__ >= 26
Peng Xu80df0162017-08-05 19:00:23 -0700560/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700561 * Get a reference to the sensor manager. ASensorManager is a singleton
562 * per package as different packages may have access to different sensors.
563 *
564 * Example:
565 *
Peng Xu80df0162017-08-05 19:00:23 -0700566 * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz");
Svet Ganov5fa32d42015-05-07 10:50:59 -0700567 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700568 * Available since API level 26.
Svet Ganov5fa32d42015-05-07 10:50:59 -0700569 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700570ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26);
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700571#endif
Svet Ganov5fa32d42015-05-07 10:50:59 -0700572
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700573/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700574 * Returns the list of available sensors.
575 */
576int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list);
577
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700578/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700579 * Returns the default sensor for the given type, or NULL if no sensor
Aravind Akellab37ba392014-08-05 14:53:07 -0700580 * of that type exists.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700581 */
582ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type);
583
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700584#if __ANDROID_API__ >= 21
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700585/**
Aravind Akellab37ba392014-08-05 14:53:07 -0700586 * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor
587 * of this type and wakeUp properties exists.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700588 *
589 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -0700590 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700591ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) __INTRODUCED_IN(21);
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700592#endif
Aravind Akellab37ba392014-08-05 14:53:07 -0700593
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700594/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700595 * Creates a new sensor event queue and associate it with a looper.
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700596 *
597 * "ident" is a identifier for the events that will be returned when
598 * calling ALooper_pollOnce(). The identifier must be >= 0, or
599 * ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700600 */
601ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
602 ALooper* looper, int ident, ALooper_callbackFunc callback, void* data);
603
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700604/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700605 * Destroys the event queue and free all resources associated to it.
606 */
607int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue);
608
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700609#if __ANDROID_API__ >= 26
Peng Xu47cddca2017-02-15 23:31:22 -0800610/**
611 * Create direct channel based on shared memory
612 *
613 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used
614 * for configuring sensor direct report.
615 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700616 * Available since API level 26.
617 *
Peng Xu47cddca2017-02-15 23:31:22 -0800618 * \param manager the {@link ASensorManager} instance obtained from
619 * {@link ASensorManager_getInstanceForPackage}.
620 * \param fd file descriptor representing a shared memory created by
621 * {@link ASharedMemory_create}
622 * \param size size to be used, must be less or equal to size of shared memory.
623 *
624 * \return a positive integer as a channel id to be used in
625 * {@link ASensorManager_destroyDirectChannel} and
626 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
627 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700628int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int fd, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800629
630/**
631 * Create direct channel based on AHardwareBuffer
632 *
633 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used
634 * for configuring sensor direct report.
635 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700636 * Available since API level 26.
637 *
Peng Xu47cddca2017-02-15 23:31:22 -0800638 * \param manager the {@link ASensorManager} instance obtained from
639 * {@link ASensorManager_getInstanceForPackage}.
640 * \param buffer {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}.
641 * \param size the intended size to be used, must be less or equal to size of buffer.
642 *
643 * \return a positive integer as a channel id to be used in
644 * {@link ASensorManager_destroyDirectChannel} and
645 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
646 */
647int ASensorManager_createHardwareBufferDirectChannel(
Elliott Hughes9db409b2018-06-18 12:28:46 -0700648 ASensorManager* manager, AHardwareBuffer const * buffer, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800649
650/**
651 * Destroy a direct channel
652 *
653 * Destroy a direct channel previously created using {@link ASensorManager_createDirectChannel}.
654 * The buffer used for creating direct channel does not get destroyed with
655 * {@link ASensorManager_destroy} and has to be close or released separately.
656 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700657 * Available since API level 26.
658 *
Peng Xu47cddca2017-02-15 23:31:22 -0800659 * \param manager the {@link ASensorManager} instance obtained from
660 * {@link ASensorManager_getInstanceForPackage}.
661 * \param channelId channel id (a positive integer) returned from
662 * {@link ASensorManager_createSharedMemoryDirectChannel} or
663 * {@link ASensorManager_createHardwareBufferDirectChannel}.
664 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700665void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800666
667/**
668 * Configure direct report on channel
669 *
670 * Configure sensor direct report on a direct channel: set rate to value other than
671 * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly
Peng Xuec53d022017-04-06 18:02:29 -0700672 * written into the shared memory region used for creating the buffer. It returns a positive token
673 * which can be used for identify sensor events from different sensors on success. Calling with rate
674 * {@link ASENSOR_DIRECT_RATE_STOP} will stop direct report of the sensor specified in the channel.
Peng Xu47cddca2017-02-15 23:31:22 -0800675 *
676 * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to
677 * {@link ASENSOR_DIRECT_RATE_STOP}.
678 *
679 * In order to successfully configure a direct report, the sensor has to support the specified rate
680 * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and
681 * {@link ASensor_isDirectChannelTypeSupported}, respectively.
682 *
683 * Example:
Peng Xu47cddca2017-02-15 23:31:22 -0800684 *
Peng Xu80df0162017-08-05 19:00:23 -0700685 * ASensorManager *manager = ...;
686 * ASensor *sensor = ...;
687 * int channelId = ...;
688 *
689 * ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);
Peng Xu47cddca2017-02-15 23:31:22 -0800690 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700691 * Available since API level 26.
692 *
Peng Xu47cddca2017-02-15 23:31:22 -0800693 * \param manager the {@link ASensorManager} instance obtained from
694 * {@link ASensorManager_getInstanceForPackage}.
695 * \param sensor a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate
696 * is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor
697 * direct report.
698 * \param channelId channel id (a positive integer) returned from
699 * {@link ASensorManager_createSharedMemoryDirectChannel} or
700 * {@link ASensorManager_createHardwareBufferDirectChannel}.
701 *
Peng Xuec53d022017-04-06 18:02:29 -0700702 * \return positive token for success or negative error code.
Peng Xu47cddca2017-02-15 23:31:22 -0800703 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700704int ASensorManager_configureDirectReport(ASensorManager* manager,
705 ASensor const* sensor, int channelId, int rate) __INTRODUCED_IN(26);
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700706#endif /* __ANDROID_API__ >= 26 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700707
708/*****************************************************************************/
709
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700710/**
Peng Xu80df0162017-08-05 19:00:23 -0700711 * Enable the selected sensor with sampling and report parameters
712 *
713 * Enable the selected sensor at a specified sampling period and max batch report latency.
714 * To disable sensor, use {@link ASensorEventQueue_disableSensor}.
715 *
716 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
717 * \param sensor {@link ASensor} to be enabled.
718 * \param samplingPeriodUs sampling period of sensor in microseconds.
719 * \param maxBatchReportLatencyus maximum time interval between two batch of sensor events are
720 * delievered in microseconds. For sensor streaming, set to 0.
721 * \return 0 on success or a negative error code on failure.
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530722 */
723int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor,
Peng Xuda8385c2017-02-28 20:19:47 -0800724 int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs);
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530725
726/**
Peng Xu80df0162017-08-05 19:00:23 -0700727 * Enable the selected sensor at default sampling rate.
728 *
729 * Start event reports of a sensor to specified sensor event queue at a default rate.
730 *
731 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
732 * \param sensor {@link ASensor} to be enabled.
733 *
734 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700735 */
736int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor);
737
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700738/**
Peng Xu80df0162017-08-05 19:00:23 -0700739 * Disable the selected sensor.
740 *
741 * Stop event reports from the sensor to specified sensor event queue.
742 *
743 * \param queue {@link ASensorEventQueue} to be changed
744 * \param sensor {@link ASensor} to be disabled
745 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700746 */
747int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor);
748
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700749/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700750 * Sets the delivery rate of events in microseconds for the given sensor.
Peng Xu80df0162017-08-05 19:00:23 -0700751 *
752 * This function has to be called after {@link ASensorEventQueue_enableSensor}.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700753 * Note that this is a hint only, generally event will arrive at a higher
754 * rate. It is an error to set a rate inferior to the value returned by
755 * ASensor_getMinDelay().
Peng Xu80df0162017-08-05 19:00:23 -0700756 *
757 * \param queue {@link ASensorEventQueue} to which sensor event is delivered.
758 * \param sensor {@link ASensor} of which sampling rate to be updated.
759 * \param usec sensor sampling period (1/sampling rate) in microseconds
760 * \return 0 on sucess or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700761 */
762int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec);
763
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700764/**
Peng Xu80df0162017-08-05 19:00:23 -0700765 * Determine if a sensor event queue has pending event to be processed.
766 *
767 * \param queue {@link ASensorEventQueue} to be queried
768 * \return 1 if the queue has events; 0 if it does not have events;
769 * or a negative value if there is an error.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700770 */
771int ASensorEventQueue_hasEvents(ASensorEventQueue* queue);
772
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700773/**
Peng Xu80df0162017-08-05 19:00:23 -0700774 * Retrieve pending events in sensor event queue
775 *
776 * Retrieve next available events from the queue to a specified event array.
777 *
778 * \param queue {@link ASensorEventQueue} to get events from
779 * \param events pointer to an array of {@link ASensorEvents}.
780 * \param count max number of event that can be filled into array event.
781 * \return number of events returned on success; negative error code when
782 * no events are pending or an error has occurred.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700783 *
784 * Examples:
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700785 *
Peng Xu80df0162017-08-05 19:00:23 -0700786 * ASensorEvent event;
787 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);
788 *
789 * ASensorEvent eventBuffer[8];
790 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700791 *
792 */
Peng Xuda8385c2017-02-28 20:19:47 -0800793ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700794
Elliott Hughes3d70e532019-10-29 08:59:39 -0700795#if __ANDROID_API__ >= 29
Brian Stack65089d52019-01-11 10:52:07 -0800796/**
797 * Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on
798 * the given {@link ASensorEventQueue}.
799 *
800 * Sensor data events are always delivered to the {@ASensorEventQueue}.
801 *
802 * The {@link ASENSOR_TYPE_ADDITIONAL_INFO} events will be returned through
803 * {@link ASensorEventQueue_getEvents}. The client is responsible for checking
804 * {@link ASensorEvent#type} to determine the event type prior to handling of
805 * the event.
806 *
807 * The client must be tolerant of any value for
808 * {@link AAdditionalInfoEvent#type}, as new values may be defined in the future
809 * and may delivered to the client.
810 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700811 * Available since API level 29.
812 *
Brian Stack65089d52019-01-11 10:52:07 -0800813 * \param queue {@link ASensorEventQueue} to configure
814 * \param enable true to request {@link ASENSOR_TYPE_ADDITIONAL_INFO} events,
815 * false to stop receiving events
816 * \return 0 on success or a negative error code on failure
817 */
Elliott Hughes3d70e532019-10-29 08:59:39 -0700818int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable) __INTRODUCED_IN(29);
819#endif /* __ANDROID_API__ >= 29 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700820
821/*****************************************************************************/
822
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700823/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700824 * Returns this sensor's name (non localized)
825 */
826const char* ASensor_getName(ASensor const* sensor);
827
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700828/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700829 * Returns this sensor's vendor's name (non localized)
830 */
831const char* ASensor_getVendor(ASensor const* sensor);
832
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700833/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700834 * Return this sensor's type
835 */
836int ASensor_getType(ASensor const* sensor);
837
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700838/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700839 * Returns this sensors's resolution
840 */
841float ASensor_getResolution(ASensor const* sensor);
842
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700843/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700844 * 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 */
848int ASensor_getMinDelay(ASensor const* sensor);
849
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700850#if __ANDROID_API__ >= 21
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700851/**
Aravind Akella70018042014-04-07 22:52:37 +0000852 * Returns the maximum size of batches for this sensor. Batches will often be
853 * smaller, as the hardware fifo might be used for other sensors.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700854 *
855 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +0000856 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700857int ASensor_getFifoMaxEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +0000858
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700859/**
Aravind Akella70018042014-04-07 22:52:37 +0000860 * Returns the hardware batch fifo size reserved to this sensor.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700861 *
862 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +0000863 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700864int ASensor_getFifoReservedEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +0000865
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700866/**
Aravind Akella70018042014-04-07 22:52:37 +0000867 * Returns this sensor's string type.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700868 *
869 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +0000870 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700871const char* ASensor_getStringType(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +0000872
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700873/**
Aravind Akella0e025c52014-06-03 19:19:57 -0700874 * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700875 *
876 * Available since API level 21.
Aravind Akella0e025c52014-06-03 19:19:57 -0700877 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700878int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella0e025c52014-06-03 19:19:57 -0700879
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700880/**
Aravind Akellab37ba392014-08-05 14:53:07 -0700881 * Returns true if this is a wake up sensor, false otherwise.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700882 *
883 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -0700884 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700885bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21);
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700886#endif /* __ANDROID_API__ >= 21 */
Aravind Akellab37ba392014-08-05 14:53:07 -0700887
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700888#if __ANDROID_API__ >= 26
Peng Xu47cddca2017-02-15 23:31:22 -0800889/**
890 * Test if sensor supports a certain type of direct channel.
891 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700892 * Available since API level 26.
893 *
Peng Xu47cddca2017-02-15 23:31:22 -0800894 * \param sensor a {@link ASensor} to denote the sensor to be checked.
895 * \param channelType Channel type constant, either
896 * {@ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY}
897 * or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}.
898 * \returns true if sensor supports the specified direct channel type.
899 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700900bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType) __INTRODUCED_IN(26);
901
Peng Xu47cddca2017-02-15 23:31:22 -0800902/**
Elliott Hughes3d70e532019-10-29 08:59:39 -0700903 * Get the highest direct rate level that a sensor supports.
904 *
905 * Available since API level 26.
Peng Xu47cddca2017-02-15 23:31:22 -0800906 *
907 * \param sensor a {@link ASensor} to denote the sensor to be checked.
908 *
909 * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor.
910 * If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor
911 * does not support direct report.
912 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700913int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26);
Ryan Prichard92b1ebe2018-07-19 20:32:19 -0700914#endif /* __ANDROID_API__ >= 26 */
Peng Xu47cddca2017-02-15 23:31:22 -0800915
Elliott Hughes3d70e532019-10-29 08:59:39 -0700916#if __ANDROID_API__ >= 29
Brian Stack8228fa72019-01-04 14:15:13 -0800917/**
918 * Returns the sensor's handle.
919 *
920 * The handle identifies the sensor within the system and is included in the
921 * {@link ASensorEvent#sensor} field of sensor events, including those sent with type
922 * {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
923 *
924 * A sensor's handle is able to be used to map {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to the
925 * sensor that generated the event.
926 *
927 * It is important to note that the value returned by {@link ASensor_getHandle} is not the same as
928 * the value returned by the Java API {@link android.hardware.Sensor#getId} and no mapping exists
929 * between the values.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700930 *
931 * Available since API level 29.
Brian Stack8228fa72019-01-04 14:15:13 -0800932 */
Elliott Hughes3d70e532019-10-29 08:59:39 -0700933int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(29);
934#endif /* __ANDROID_API__ >= 29 */
Brian Stack8228fa72019-01-04 14:15:13 -0800935
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700936#ifdef __cplusplus
937};
938#endif
939
940#endif // ANDROID_SENSOR_H
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700941
942/** @} */