blob: eef69f4b32df2ebbf4a9ab7b07f23129d69d2282 [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
Elliott Hughes23e82b42021-01-26 14:55:48 -080055#if !defined(__INTRODUCED_IN)
56#define __INTRODUCED_IN(__api_level) /* nothing */
57#endif
58#if !defined(__DEPRECATED_IN)
59#define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__))
60#endif
61
Mathias Agopiane1c61d32012-03-23 14:19:36 -070062#ifdef __cplusplus
63extern "C" {
64#endif
65
Peng Xu47cddca2017-02-15 23:31:22 -080066typedef struct AHardwareBuffer AHardwareBuffer;
Mathias Agopiane1c61d32012-03-23 14:19:36 -070067
Peng Xuda8385c2017-02-28 20:19:47 -080068#define ASENSOR_RESOLUTION_INVALID (nanf(""))
69#define ASENSOR_FIFO_COUNT_INVALID (-1)
70#define ASENSOR_DELAY_INVALID INT32_MIN
Brian Stack8228fa72019-01-04 14:15:13 -080071#define ASENSOR_INVALID (-1)
Peng Xuda8385c2017-02-28 20:19:47 -080072
Elliott Hughesf78be362018-01-23 15:33:56 -080073/* (Keep in sync with hardware/sensors-base.h and Sensor.java.) */
74
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070075/**
76 * Sensor types.
Elliott Hughesf78be362018-01-23 15:33:56 -080077 *
78 * See
79 * [android.hardware.SensorEvent#values](https://developer.android.com/reference/android/hardware/SensorEvent.html#values)
80 * for detailed explanations of the data returned for each of these types.
Mathias Agopiane1c61d32012-03-23 14:19:36 -070081 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070082enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070083 /**
Peng Xu37317b62017-03-07 17:49:31 -080084 * Invalid sensor type. Returned by {@link ASensor_getType} as error value.
85 */
86 ASENSOR_TYPE_INVALID = -1,
87 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070088 * {@link ASENSOR_TYPE_ACCELEROMETER}
89 * reporting-mode: continuous
90 *
91 * All values are in SI units (m/s^2) and measure the acceleration of the
92 * device minus the force of gravity.
93 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -070094 ASENSOR_TYPE_ACCELEROMETER = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070095 /**
96 * {@link ASENSOR_TYPE_MAGNETIC_FIELD}
97 * reporting-mode: continuous
98 *
99 * All values are in micro-Tesla (uT) and measure the geomagnetic
100 * field in the X, Y and Z axis.
101 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700102 ASENSOR_TYPE_MAGNETIC_FIELD = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700103 /**
104 * {@link ASENSOR_TYPE_GYROSCOPE}
105 * reporting-mode: continuous
106 *
107 * All values are in radians/second and measure the rate of rotation
108 * around the X, Y and Z axis.
109 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700110 ASENSOR_TYPE_GYROSCOPE = 4,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700111 /**
112 * {@link ASENSOR_TYPE_LIGHT}
113 * reporting-mode: on-change
114 *
115 * The light sensor value is returned in SI lux units.
116 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700117 ASENSOR_TYPE_LIGHT = 5,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700118 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800119 * {@link ASENSOR_TYPE_PRESSURE}
120 *
121 * The pressure sensor value is returned in hPa (millibar).
122 */
123 ASENSOR_TYPE_PRESSURE = 6,
124 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700125 * {@link ASENSOR_TYPE_PROXIMITY}
126 * reporting-mode: on-change
127 *
128 * The proximity sensor which turns the screen off and back on during calls is the
129 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
130 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
131 * SENSOR_FLAG_WAKE_UP.
132 * The value corresponds to the distance to the nearest object in centimeters.
133 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700134 ASENSOR_TYPE_PROXIMITY = 8,
135 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800136 * {@link ASENSOR_TYPE_GRAVITY}
137 *
138 * All values are in SI units (m/s^2) and measure the direction and
139 * magnitude of gravity. When the device is at rest, the output of
140 * the gravity sensor should be identical to that of the accelerometer.
141 */
142 ASENSOR_TYPE_GRAVITY = 9,
143 /**
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700144 * {@link ASENSOR_TYPE_LINEAR_ACCELERATION}
145 * reporting-mode: continuous
146 *
147 * All values are in SI units (m/s^2) and measure the acceleration of the
148 * device not including the force of gravity.
149 */
Elliott Hughesf78be362018-01-23 15:33:56 -0800150 ASENSOR_TYPE_LINEAR_ACCELERATION = 10,
151 /**
152 * {@link ASENSOR_TYPE_ROTATION_VECTOR}
153 */
154 ASENSOR_TYPE_ROTATION_VECTOR = 11,
155 /**
156 * {@link ASENSOR_TYPE_RELATIVE_HUMIDITY}
157 *
158 * The relative humidity sensor value is returned in percent.
159 */
160 ASENSOR_TYPE_RELATIVE_HUMIDITY = 12,
161 /**
162 * {@link ASENSOR_TYPE_AMBIENT_TEMPERATURE}
163 *
164 * The ambient temperature sensor value is returned in Celcius.
165 */
166 ASENSOR_TYPE_AMBIENT_TEMPERATURE = 13,
167 /**
168 * {@link ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED}
169 */
170 ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14,
171 /**
172 * {@link ASENSOR_TYPE_GAME_ROTATION_VECTOR}
173 */
174 ASENSOR_TYPE_GAME_ROTATION_VECTOR = 15,
175 /**
176 * {@link ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED}
177 */
178 ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 16,
179 /**
180 * {@link ASENSOR_TYPE_SIGNIFICANT_MOTION}
181 */
182 ASENSOR_TYPE_SIGNIFICANT_MOTION = 17,
183 /**
184 * {@link ASENSOR_TYPE_STEP_DETECTOR}
185 */
186 ASENSOR_TYPE_STEP_DETECTOR = 18,
187 /**
188 * {@link ASENSOR_TYPE_STEP_COUNTER}
189 */
190 ASENSOR_TYPE_STEP_COUNTER = 19,
191 /**
192 * {@link ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR}
193 */
194 ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20,
195 /**
196 * {@link ASENSOR_TYPE_HEART_RATE}
197 */
198 ASENSOR_TYPE_HEART_RATE = 21,
199 /**
200 * {@link ASENSOR_TYPE_POSE_6DOF}
201 */
202 ASENSOR_TYPE_POSE_6DOF = 28,
203 /**
204 * {@link ASENSOR_TYPE_STATIONARY_DETECT}
205 */
206 ASENSOR_TYPE_STATIONARY_DETECT = 29,
207 /**
208 * {@link ASENSOR_TYPE_MOTION_DETECT}
209 */
210 ASENSOR_TYPE_MOTION_DETECT = 30,
211 /**
212 * {@link ASENSOR_TYPE_HEART_BEAT}
213 */
214 ASENSOR_TYPE_HEART_BEAT = 31,
215 /**
Erik Staatsb1f77952022-03-25 11:49:58 -0700216 * A constant describing a dynamic sensor meta event sensor.
217 *
218 * A sensor event of this type is received when a dynamic sensor is added to or removed from
219 * the system. This sensor type should always use special trigger report mode.
220 */
221 ASENSOR_TYPE_DYNAMIC_SENSOR_META = 32,
222 /**
Brian Stackccd88432019-01-08 17:04:18 -0800223 * This sensor type is for delivering additional sensor information aside
224 * from sensor event data.
225 *
226 * Additional information may include:
227 * - {@link ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE}
228 * - {@link ASENSOR_ADDITIONAL_INFO_SAMPLING}
229 * - {@link ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT}
230 * - {@link ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY}
231 * - {@link ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION}
232 *
233 * This type will never bind to a sensor. In other words, no sensor in the
234 * sensor list can have the type {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
235 *
236 * If a device supports the sensor additional information feature, it will
237 * report additional information events via {@link ASensorEvent} and will
gfanc150ea12021-04-14 09:27:55 -0700238 * have the type of {@link ASensorEvent} set to
239 * {@link ASENSOR_TYPE_ADDITIONAL_INFO} and the sensor of {@link ASensorEvent} set
Brian Stackccd88432019-01-08 17:04:18 -0800240 * to the handle of the reporting sensor.
241 *
242 * Additional information reports consist of multiple frames ordered by
243 * {@link ASensorEvent#timestamp}. The first frame in the report will have
244 * a {@link AAdditionalInfoEvent#type} of
245 * {@link ASENSOR_ADDITIONAL_INFO_BEGIN}, and the last frame in the report
246 * will have a {@link AAdditionalInfoEvent#type} of
247 * {@link ASENSOR_ADDITIONAL_INFO_END}.
248 *
249 */
250 ASENSOR_TYPE_ADDITIONAL_INFO = 33,
251 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800252 * {@link ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT}
253 */
254 ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34,
255 /**
256 * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED}
257 */
258 ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35,
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500259 /**
260 * {@link ASENSOR_TYPE_HINGE_ANGLE}
Anthony Stanged7a703c2020-02-18 12:02:22 -0500261 * reporting-mode: on-change
262 *
263 * The hinge angle sensor value is returned in degrees.
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500264 */
265 ASENSOR_TYPE_HINGE_ANGLE = 36,
Brian Duddie573da3b2021-12-10 14:34:07 -0800266 /**
267 * {@link ASENSOR_TYPE_HEAD_TRACKER}
268 * reporting-mode: continuous
269 *
Brian Duddie4a4d0462022-05-09 16:49:49 -0700270 * Measures the orientation and rotational velocity of a user's head. Only for internal use
271 * within the Android system.
Brian Duddie573da3b2021-12-10 14:34:07 -0800272 */
273 ASENSOR_TYPE_HEAD_TRACKER = 37,
Eva Chenc0420b72021-04-09 15:44:12 -0700274 /**
275 * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES}
276 * reporting-mode: continuous
277 *
278 * The first three values are in SI units (m/s^2) and measure the acceleration of the device
279 * minus the force of gravity. The last three values indicate which acceleration axes are
280 * supported. A value of 1.0 means supported and a value of 0 means not supported.
281 */
282 ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES = 38,
283 /**
284 * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES}
285 * reporting-mode: continuous
286 *
287 * The first three values are in radians/second and measure the rate of rotation around the X,
288 * Y and Z axis. The last three values indicate which rotation axes are supported. A value of
289 * 1.0 means supported and a value of 0 means not supported.
290 */
291 ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES = 39,
292 /**
293 * {@link ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED}
294 * reporting-mode: continuous
295 *
296 * The first three values are in SI units (m/s^2) and measure the acceleration of the device
297 * minus the force of gravity. The middle three values represent the estimated bias for each
298 * axis. The last three values indicate which acceleration axes are supported. A value of 1.0
299 * means supported and a value of 0 means not supported.
300 */
301 ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED = 40,
302 /**
303 * {@link ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED}
304 * reporting-mode: continuous
305 *
306 * The first three values are in radians/second and measure the rate of rotation around the X,
307 * Y and Z axis. The middle three values represent the estimated drift around each axis in
308 * rad/s. The last three values indicate which rotation axes are supported. A value of 1.0 means
309 * supported and a value of 0 means not supported.
310 */
311 ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41,
Eva Chen72c71042022-01-10 21:07:51 -0800312 /**
313 * {@link ASENSOR_TYPE_HEADING}
314 * reporting-mode: continuous
315 *
316 * A heading sensor measures the direction in which the device is pointing
317 * relative to true north in degrees.
318 */
319 ASENSOR_TYPE_HEADING = 42,
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700320};
321
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700322/**
323 * Sensor accuracy measure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700324 */
325enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700326 /** no contact */
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700327 ASENSOR_STATUS_NO_CONTACT = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700328 /** unreliable */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700329 ASENSOR_STATUS_UNRELIABLE = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700330 /** low accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700331 ASENSOR_STATUS_ACCURACY_LOW = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700332 /** medium accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700333 ASENSOR_STATUS_ACCURACY_MEDIUM = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700334 /** high accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700335 ASENSOR_STATUS_ACCURACY_HIGH = 3
336};
337
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700338/**
Aravind Akella0e025c52014-06-03 19:19:57 -0700339 * Sensor Reporting Modes.
340 */
341enum {
Peng Xu37317b62017-03-07 17:49:31 -0800342 /** invalid reporting mode */
343 AREPORTING_MODE_INVALID = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700344 /** continuous reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700345 AREPORTING_MODE_CONTINUOUS = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700346 /** reporting on change */
Aravind Akella0e025c52014-06-03 19:19:57 -0700347 AREPORTING_MODE_ON_CHANGE = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700348 /** on shot reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700349 AREPORTING_MODE_ONE_SHOT = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700350 /** special trigger reporting */
Peng Xu37317b62017-03-07 17:49:31 -0800351 AREPORTING_MODE_SPECIAL_TRIGGER = 3
Aravind Akella0e025c52014-06-03 19:19:57 -0700352};
353
Peng Xu47cddca2017-02-15 23:31:22 -0800354/**
355 * Sensor Direct Report Rates.
356 */
357enum {
358 /** stopped */
359 ASENSOR_DIRECT_RATE_STOP = 0,
360 /** nominal 50Hz */
361 ASENSOR_DIRECT_RATE_NORMAL = 1,
362 /** nominal 200Hz */
363 ASENSOR_DIRECT_RATE_FAST = 2,
364 /** nominal 800Hz */
365 ASENSOR_DIRECT_RATE_VERY_FAST = 3
366};
367
368/**
369 * Sensor Direct Channel Type.
370 */
371enum {
372 /** shared memory created by ASharedMemory_create */
373 ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1,
374 /** AHardwareBuffer */
375 ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2
376};
377
Brian Stackccd88432019-01-08 17:04:18 -0800378/**
379 * Sensor Additional Info Types.
380 *
381 * Used to populate {@link AAdditionalInfoEvent#type}.
382 */
383enum {
384 /** Marks the beginning of additional information frames */
385 ASENSOR_ADDITIONAL_INFO_BEGIN = 0,
386
387 /** Marks the end of additional information frames */
388 ASENSOR_ADDITIONAL_INFO_END = 1,
389
390 /**
391 * Estimation of the delay that is not tracked by sensor timestamps. This
392 * includes delay introduced by sensor front-end filtering, data transport,
393 * etc.
394 * float[2]: delay in seconds, standard deviation of estimated value
395 */
396 ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY = 0x10000,
397
398 /** float: Celsius temperature */
399 ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE,
400
401 /**
402 * First three rows of a homogeneous matrix, which represents calibration to
403 * a three-element vector raw sensor reading.
404 * float[12]: 3x4 matrix in row major order
405 */
406 ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION,
407
408 /**
409 * Location and orientation of sensor element in the device frame: origin is
410 * the geometric center of the mobile device screen surface; the axis
411 * definition corresponds to Android sensor definitions.
412 * float[12]: 3x4 matrix in row major order
413 */
414 ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT,
415
416 /**
417 * float[2]: raw sample period in seconds,
418 * standard deviation of sampling period
419 */
420 ASENSOR_ADDITIONAL_INFO_SAMPLING,
421};
422
Aravind Akella0e025c52014-06-03 19:19:57 -0700423/*
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700424 * A few useful constants
425 */
426
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700427/** Earth's gravity in m/s^2 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700428#define ASENSOR_STANDARD_GRAVITY (9.80665f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700429/** Maximum magnetic field on Earth's surface in uT */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700430#define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700431/** Minimum magnetic field on Earth's surface in uT*/
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700432#define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f)
433
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700434/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700435 * A sensor event.
436 */
437
Peng Xu70b98382017-08-07 14:09:11 -0700438/* NOTE: changes to these structs have to be backward compatible */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700439typedef struct ASensorVector {
440 union {
441 float v[3];
442 struct {
443 float x;
444 float y;
445 float z;
446 };
447 struct {
448 float azimuth;
449 float pitch;
450 float roll;
451 };
452 };
453 int8_t status;
454 uint8_t reserved[3];
455} ASensorVector;
456
Aravind Akella724d91d2013-06-27 12:04:23 -0700457typedef struct AMetaDataEvent {
458 int32_t what;
459 int32_t sensor;
460} AMetaDataEvent;
461
462typedef struct AUncalibratedEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800463 union {
464 float uncalib[3];
465 struct {
466 float x_uncalib;
467 float y_uncalib;
468 float z_uncalib;
469 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700470 };
Peng Xu9e720462016-01-26 18:48:54 -0800471 union {
472 float bias[3];
473 struct {
474 float x_bias;
475 float y_bias;
476 float z_bias;
477 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700478 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700479} AUncalibratedEvent;
480
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700481typedef struct AHeartRateEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800482 float bpm;
483 int8_t status;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700484} AHeartRateEvent;
485
Peng Xu2576cb62016-01-20 00:22:09 -0800486typedef struct ADynamicSensorEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800487 int32_t connected;
488 int32_t handle;
Peng Xu2576cb62016-01-20 00:22:09 -0800489} ADynamicSensorEvent;
490
Brian Stackccd88432019-01-08 17:04:18 -0800491typedef struct AAdditionalInfoEvent {
gfan5d5faa42021-04-12 15:14:29 -0700492 /**
493 * Event type, such as ASENSOR_ADDITIONAL_INFO_BEGIN, ASENSOR_ADDITIONAL_INFO_END and others.
494 * Refer to {@link ASENSOR_TYPE_ADDITIONAL_INFO} for the expected reporting behavior.
495 */
Peng Xu9e720462016-01-26 18:48:54 -0800496 int32_t type;
497 int32_t serial;
498 union {
499 int32_t data_int32[14];
500 float data_float[14];
501 };
502} AAdditionalInfoEvent;
503
Brian Duddie573da3b2021-12-10 14:34:07 -0800504typedef struct AHeadTrackerEvent {
505 /**
506 * The fields rx, ry, rz are an Euler vector (rotation vector, i.e. a vector
507 * whose direction indicates the axis of rotation and magnitude indicates
508 * the angle to rotate around that axis) representing the transform from
509 * the (arbitrary, possibly slowly drifting) reference frame to the
510 * head frame. Expressed in radians. Magnitude of the vector must be
511 * in the range [0, pi], while the value of individual axes are
512 * in the range [-pi, pi].
513 */
514 float rx;
515 float ry;
516 float rz;
517
518 /**
519 * The fields vx, vy, vz are an Euler vector (rotation vector) representing
520 * the angular velocity of the head (relative to itself), in radians per
521 * second. The direction of this vector indicates the axis of rotation, and
522 * the magnitude indicates the rate of rotation.
523 */
524 float vx;
525 float vy;
526 float vz;
527
528 /**
529 * This value changes each time the reference frame is suddenly and
530 * significantly changed, for example if an orientation filter algorithm
531 * used for determining the orientation has had its state reset.
532 */
533 int32_t discontinuity_count;
534} AHeadTrackerEvent;
535
Eva Chenc0420b72021-04-09 15:44:12 -0700536typedef struct ALimitedAxesImuEvent {
537 union {
538 float calib[3];
539 struct {
540 float x;
541 float y;
542 float z;
543 };
544 };
545 union {
546 float supported[3];
547 struct {
548 float x_supported;
549 float y_supported;
550 float z_supported;
551 };
552 };
553} ALimitedAxesImuEvent;
554
555typedef struct ALimitedAxesImuUncalibratedEvent {
556 union {
557 float uncalib[3];
558 struct {
559 float x_uncalib;
560 float y_uncalib;
561 float z_uncalib;
562 };
563 };
564 union {
565 float bias[3];
566 struct {
567 float x_bias;
568 float y_bias;
569 float z_bias;
570 };
571 };
572 union {
573 float supported[3];
574 struct {
575 float x_supported;
576 float y_supported;
577 float z_supported;
578 };
579 };
580} ALimitedAxesImuUncalibratedEvent;
581
Eva Chen72c71042022-01-10 21:07:51 -0800582typedef struct AHeadingEvent {
583 /**
584 * The direction in which the device is pointing relative to true north in
585 * degrees. The value must be between 0.0 (inclusive) and 360.0 (exclusive),
586 * with 0 indicating north, 90 east, 180 south, and 270 west.
587 */
588 float heading;
589 /**
590 * Accuracy is defined at 68% confidence. In the case where the underlying
591 * distribution is assumed Gaussian normal, this would be considered one
592 * standard deviation. For example, if the heading returns 60 degrees, and
593 * accuracy returns 10 degrees, then there is a 68 percent probability of
594 * the true heading being between 50 degrees and 70 degrees.
595 */
596 float accuracy;
597} AHeadingEvent;
598
gfan5d5faa42021-04-12 15:14:29 -0700599/**
600 * Information that describes a sensor event, refer to
601 * <a href="/reference/android/hardware/SensorEvent">SensorEvent</a> for additional
602 * documentation.
603 */
Peng Xu70b98382017-08-07 14:09:11 -0700604/* NOTE: changes to this struct has to be backward compatible */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700605typedef struct ASensorEvent {
606 int32_t version; /* sizeof(struct ASensorEvent) */
gfan5d5faa42021-04-12 15:14:29 -0700607 int32_t sensor; /** The sensor that generates this event */
gfanc150ea12021-04-14 09:27:55 -0700608 int32_t type; /** Sensor type for the event, such as {@link ASENSOR_TYPE_ACCELEROMETER} */
gfan5d5faa42021-04-12 15:14:29 -0700609 int32_t reserved0; /** do not use */
610 /**
611 * The time in nanoseconds at which the event happened, and its behavior
612 * is identical to <a href="/reference/android/hardware/SensorEvent#timestamp">
613 * SensorEvent::timestamp</a> in Java API.
614 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700615 int64_t timestamp;
616 union {
Mathias Agopianba02cd22013-07-03 16:20:57 -0700617 union {
618 float data[16];
619 ASensorVector vector;
620 ASensorVector acceleration;
Brian Duddiee02c0662021-03-16 09:53:20 -0700621 ASensorVector gyro;
Mathias Agopianba02cd22013-07-03 16:20:57 -0700622 ASensorVector magnetic;
623 float temperature;
624 float distance;
625 float light;
626 float pressure;
Aravind Akella724d91d2013-06-27 12:04:23 -0700627 float relative_humidity;
Brian Duddiee02c0662021-03-16 09:53:20 -0700628 AUncalibratedEvent uncalibrated_acceleration;
Aravind Akella724d91d2013-06-27 12:04:23 -0700629 AUncalibratedEvent uncalibrated_gyro;
630 AUncalibratedEvent uncalibrated_magnetic;
631 AMetaDataEvent meta_data;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700632 AHeartRateEvent heart_rate;
Peng Xu2576cb62016-01-20 00:22:09 -0800633 ADynamicSensorEvent dynamic_sensor_meta;
Peng Xu9e720462016-01-26 18:48:54 -0800634 AAdditionalInfoEvent additional_info;
Brian Duddie573da3b2021-12-10 14:34:07 -0800635 AHeadTrackerEvent head_tracker;
Eva Chenc0420b72021-04-09 15:44:12 -0700636 ALimitedAxesImuEvent limited_axes_imu;
637 ALimitedAxesImuUncalibratedEvent limited_axes_imu_uncalibrated;
Eva Chen72c71042022-01-10 21:07:51 -0800638 AHeadingEvent heading;
Mathias Agopianba02cd22013-07-03 16:20:57 -0700639 };
640 union {
641 uint64_t data[8];
642 uint64_t step_counter;
643 } u64;
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700644 };
Aravind Akella9a844cf2014-02-11 18:58:52 -0800645
646 uint32_t flags;
647 int32_t reserved1[3];
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700648} ASensorEvent;
649
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700650struct ASensorManager;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700651/**
652 * {@link ASensorManager} is an opaque type to manage sensors and
653 * events queues.
654 *
655 * {@link ASensorManager} is a singleton that can be obtained using
656 * ASensorManager_getInstance().
657 *
658 * This file provides a set of functions that uses {@link
659 * ASensorManager} to access and list hardware sensors, and
660 * create and destroy event queues:
661 * - ASensorManager_getSensorList()
662 * - ASensorManager_getDefaultSensor()
663 * - ASensorManager_getDefaultSensorEx()
664 * - ASensorManager_createEventQueue()
665 * - ASensorManager_destroyEventQueue()
666 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700667typedef struct ASensorManager ASensorManager;
668
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700669
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700670struct ASensorEventQueue;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700671/**
672 * {@link ASensorEventQueue} is an opaque type that provides access to
673 * {@link ASensorEvent} from hardware sensors.
674 *
675 * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue().
676 *
677 * This file provides a set of functions to enable and disable
678 * sensors, check and get events, and set event rates on a {@link
679 * ASensorEventQueue}.
680 * - ASensorEventQueue_enableSensor()
681 * - ASensorEventQueue_disableSensor()
682 * - ASensorEventQueue_hasEvents()
683 * - ASensorEventQueue_getEvents()
684 * - ASensorEventQueue_setEventRate()
Brian Stack65089d52019-01-11 10:52:07 -0800685 * - ASensorEventQueue_requestAdditionalInfoEvents()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700686 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700687typedef struct ASensorEventQueue ASensorEventQueue;
688
689struct ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700690/**
691 * {@link ASensor} is an opaque type that provides information about
692 * an hardware sensors.
693 *
694 * A {@link ASensor} pointer can be obtained using
695 * ASensorManager_getDefaultSensor(),
696 * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}.
697 *
698 * This file provides a set of functions to access properties of a
699 * {@link ASensor}:
700 * - ASensor_getName()
701 * - ASensor_getVendor()
702 * - ASensor_getType()
703 * - ASensor_getResolution()
704 * - ASensor_getMinDelay()
705 * - ASensor_getFifoMaxEventCount()
706 * - ASensor_getFifoReservedEventCount()
707 * - ASensor_getStringType()
708 * - ASensor_getReportingMode()
709 * - ASensor_isWakeUpSensor()
Brian Stack8228fa72019-01-04 14:15:13 -0800710 * - ASensor_getHandle()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700711 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700712typedef struct ASensor ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700713/**
714 * {@link ASensorRef} is a type for constant pointers to {@link ASensor}.
715 *
716 * This is used to define entry in {@link ASensorList} arrays.
717 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700718typedef ASensor const* ASensorRef;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700719/**
720 * {@link ASensorList} is an array of reference to {@link ASensor}.
721 *
722 * A {@link ASensorList} can be initialized using ASensorManager_getSensorList().
723 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700724typedef ASensorRef const* ASensorList;
725
726/*****************************************************************************/
727
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700728/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700729 * Get a reference to the sensor manager. ASensorManager is a singleton
730 * per package as different packages may have access to different sensors.
731 *
732 * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead.
733 *
734 * Example:
735 *
736 * ASensorManager* sensorManager = ASensorManager_getInstance();
737 *
738 */
Elliott Hughes23e82b42021-01-26 14:55:48 -0800739ASensorManager* ASensorManager_getInstance() __DEPRECATED_IN(26);
Svet Ganov5fa32d42015-05-07 10:50:59 -0700740
Peng Xu80df0162017-08-05 19:00:23 -0700741/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700742 * Get a reference to the sensor manager. ASensorManager is a singleton
743 * per package as different packages may have access to different sensors.
744 *
745 * Example:
746 *
Peng Xu80df0162017-08-05 19:00:23 -0700747 * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz");
Svet Ganov5fa32d42015-05-07 10:50:59 -0700748 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700749 * Available since API level 26.
Svet Ganov5fa32d42015-05-07 10:50:59 -0700750 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700751ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26);
Svet Ganov5fa32d42015-05-07 10:50:59 -0700752
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700753/**
Erik Staatsd35a5742022-02-04 06:37:58 -0800754 * Returns the list of available sensors. The returned list is owned by the
755 * sensor manager and will not change between calls to this function.
756 *
757 * \param manager the {@link ASensorManager} instance obtained from
758 * {@link ASensorManager_getInstanceForPackage}.
759 * \param list the returned list of sensors.
760 * \return positive number of returned sensors or negative error code.
761 * BAD_VALUE: manager is NULL.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700762 */
763int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list);
764
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700765/**
Erik Staatsd35a5742022-02-04 06:37:58 -0800766 * Returns the list of available dynamic sensors. If there are no dynamic
767 * sensors available, returns nullptr in list.
768 *
769 * Each time this is called, the previously returned list is deallocated and
770 * must no longer be used.
771 *
Erik Staatsb1f77952022-03-25 11:49:58 -0700772 * Clients should call this if they receive a sensor update from
773 * {@link ASENSOR_TYPE_DYNAMIC_SENSOR_META} indicating the sensors have changed.
774 * If this happens, previously received lists from this method will be stale.
775 *
Erik Staatsd35a5742022-02-04 06:37:58 -0800776 * Available since API level 33.
777 *
778 * \param manager the {@link ASensorManager} instance obtained from
779 * {@link ASensorManager_getInstanceForPackage}.
780 * \param list the returned list of dynamic sensors.
781 * \return positive number of returned sensors or negative error code.
782 * BAD_VALUE: manager is NULL.
783 */
784ssize_t ASensorManager_getDynamicSensorList(
785 ASensorManager* manager, ASensorList* list) __INTRODUCED_IN(33);
786
787/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700788 * Returns the default sensor for the given type, or NULL if no sensor
Aravind Akellab37ba392014-08-05 14:53:07 -0700789 * of that type exists.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700790 */
791ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type);
792
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700793/**
Aravind Akellab37ba392014-08-05 14:53:07 -0700794 * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor
795 * of this type and wakeUp properties exists.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700796 *
797 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -0700798 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700799ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) __INTRODUCED_IN(21);
Aravind Akellab37ba392014-08-05 14:53:07 -0700800
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700801/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700802 * Creates a new sensor event queue and associate it with a looper.
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700803 *
804 * "ident" is a identifier for the events that will be returned when
805 * calling ALooper_pollOnce(). The identifier must be >= 0, or
806 * ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700807 */
808ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
809 ALooper* looper, int ident, ALooper_callbackFunc callback, void* data);
810
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700811/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700812 * Destroys the event queue and free all resources associated to it.
813 */
814int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue);
815
Peng Xu47cddca2017-02-15 23:31:22 -0800816/**
817 * Create direct channel based on shared memory
818 *
819 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used
820 * for configuring sensor direct report.
821 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700822 * Available since API level 26.
823 *
Peng Xu47cddca2017-02-15 23:31:22 -0800824 * \param manager the {@link ASensorManager} instance obtained from
825 * {@link ASensorManager_getInstanceForPackage}.
826 * \param fd file descriptor representing a shared memory created by
827 * {@link ASharedMemory_create}
828 * \param size size to be used, must be less or equal to size of shared memory.
829 *
830 * \return a positive integer as a channel id to be used in
831 * {@link ASensorManager_destroyDirectChannel} and
832 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
833 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700834int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int fd, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800835
836/**
837 * Create direct channel based on AHardwareBuffer
838 *
839 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used
840 * for configuring sensor direct report.
841 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700842 * Available since API level 26.
843 *
Peng Xu47cddca2017-02-15 23:31:22 -0800844 * \param manager the {@link ASensorManager} instance obtained from
845 * {@link ASensorManager_getInstanceForPackage}.
846 * \param buffer {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}.
847 * \param size the intended size to be used, must be less or equal to size of buffer.
848 *
849 * \return a positive integer as a channel id to be used in
850 * {@link ASensorManager_destroyDirectChannel} and
851 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
852 */
853int ASensorManager_createHardwareBufferDirectChannel(
Elliott Hughes9db409b2018-06-18 12:28:46 -0700854 ASensorManager* manager, AHardwareBuffer const * buffer, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800855
856/**
857 * Destroy a direct channel
858 *
gfan5d5faa42021-04-12 15:14:29 -0700859 * Destroy a direct channel previously created by using one of
860 * ASensorManager_create*DirectChannel() derivative functions.
861 * Note that the buffer used for creating the direct channel does not get destroyed with
862 * ASensorManager_destroyDirectChannel and has to be closed or released separately.
Peng Xu47cddca2017-02-15 23:31:22 -0800863 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700864 * Available since API level 26.
865 *
Peng Xu47cddca2017-02-15 23:31:22 -0800866 * \param manager the {@link ASensorManager} instance obtained from
867 * {@link ASensorManager_getInstanceForPackage}.
868 * \param channelId channel id (a positive integer) returned from
869 * {@link ASensorManager_createSharedMemoryDirectChannel} or
870 * {@link ASensorManager_createHardwareBufferDirectChannel}.
871 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700872void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800873
874/**
875 * Configure direct report on channel
876 *
877 * Configure sensor direct report on a direct channel: set rate to value other than
878 * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly
Peng Xuec53d022017-04-06 18:02:29 -0700879 * written into the shared memory region used for creating the buffer. It returns a positive token
880 * which can be used for identify sensor events from different sensors on success. Calling with rate
881 * {@link ASENSOR_DIRECT_RATE_STOP} will stop direct report of the sensor specified in the channel.
Peng Xu47cddca2017-02-15 23:31:22 -0800882 *
883 * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to
884 * {@link ASENSOR_DIRECT_RATE_STOP}.
885 *
886 * In order to successfully configure a direct report, the sensor has to support the specified rate
887 * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and
888 * {@link ASensor_isDirectChannelTypeSupported}, respectively.
889 *
890 * Example:
Peng Xu47cddca2017-02-15 23:31:22 -0800891 *
Peng Xu80df0162017-08-05 19:00:23 -0700892 * ASensorManager *manager = ...;
893 * ASensor *sensor = ...;
894 * int channelId = ...;
895 *
896 * ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);
Peng Xu47cddca2017-02-15 23:31:22 -0800897 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700898 * Available since API level 26.
899 *
Peng Xu47cddca2017-02-15 23:31:22 -0800900 * \param manager the {@link ASensorManager} instance obtained from
901 * {@link ASensorManager_getInstanceForPackage}.
902 * \param sensor a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate
903 * is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor
904 * direct report.
905 * \param channelId channel id (a positive integer) returned from
906 * {@link ASensorManager_createSharedMemoryDirectChannel} or
907 * {@link ASensorManager_createHardwareBufferDirectChannel}.
gfan5d5faa42021-04-12 15:14:29 -0700908 * \param rate one of predefined ASENSOR_DIRECT_RATE_... that is supported by the sensor.
Peng Xuec53d022017-04-06 18:02:29 -0700909 * \return positive token for success or negative error code.
Peng Xu47cddca2017-02-15 23:31:22 -0800910 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700911int ASensorManager_configureDirectReport(ASensorManager* manager,
912 ASensor const* sensor, int channelId, int rate) __INTRODUCED_IN(26);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700913
914/*****************************************************************************/
915
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700916/**
Peng Xu80df0162017-08-05 19:00:23 -0700917 * Enable the selected sensor with sampling and report parameters
918 *
919 * Enable the selected sensor at a specified sampling period and max batch report latency.
920 * To disable sensor, use {@link ASensorEventQueue_disableSensor}.
921 *
922 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
923 * \param sensor {@link ASensor} to be enabled.
924 * \param samplingPeriodUs sampling period of sensor in microseconds.
gfan5d5faa42021-04-12 15:14:29 -0700925 * \param maxBatchReportLatencyUs maximum time interval between two batches of sensor events are
Peng Xu80df0162017-08-05 19:00:23 -0700926 * delievered in microseconds. For sensor streaming, set to 0.
927 * \return 0 on success or a negative error code on failure.
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530928 */
929int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor,
Peng Xuda8385c2017-02-28 20:19:47 -0800930 int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs);
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530931
932/**
Peng Xu80df0162017-08-05 19:00:23 -0700933 * Enable the selected sensor at default sampling rate.
934 *
935 * Start event reports of a sensor to specified sensor event queue at a default rate.
936 *
937 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
938 * \param sensor {@link ASensor} to be enabled.
939 *
940 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700941 */
942int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor);
943
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700944/**
Peng Xu80df0162017-08-05 19:00:23 -0700945 * Disable the selected sensor.
946 *
947 * Stop event reports from the sensor to specified sensor event queue.
948 *
949 * \param queue {@link ASensorEventQueue} to be changed
950 * \param sensor {@link ASensor} to be disabled
951 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700952 */
953int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor);
954
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700955/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700956 * Sets the delivery rate of events in microseconds for the given sensor.
Peng Xu80df0162017-08-05 19:00:23 -0700957 *
958 * This function has to be called after {@link ASensorEventQueue_enableSensor}.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700959 * Note that this is a hint only, generally event will arrive at a higher
960 * rate. It is an error to set a rate inferior to the value returned by
961 * ASensor_getMinDelay().
Peng Xu80df0162017-08-05 19:00:23 -0700962 *
963 * \param queue {@link ASensorEventQueue} to which sensor event is delivered.
964 * \param sensor {@link ASensor} of which sampling rate to be updated.
965 * \param usec sensor sampling period (1/sampling rate) in microseconds
966 * \return 0 on sucess or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700967 */
968int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec);
969
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700970/**
Peng Xu80df0162017-08-05 19:00:23 -0700971 * Determine if a sensor event queue has pending event to be processed.
972 *
973 * \param queue {@link ASensorEventQueue} to be queried
974 * \return 1 if the queue has events; 0 if it does not have events;
975 * or a negative value if there is an error.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700976 */
977int ASensorEventQueue_hasEvents(ASensorEventQueue* queue);
978
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700979/**
Peng Xu80df0162017-08-05 19:00:23 -0700980 * Retrieve pending events in sensor event queue
981 *
982 * Retrieve next available events from the queue to a specified event array.
983 *
984 * \param queue {@link ASensorEventQueue} to get events from
gfan5d5faa42021-04-12 15:14:29 -0700985 * \param events pointer to an array of {@link ASensorEvent}.
Peng Xu80df0162017-08-05 19:00:23 -0700986 * \param count max number of event that can be filled into array event.
987 * \return number of events returned on success; negative error code when
988 * no events are pending or an error has occurred.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700989 *
990 * Examples:
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700991 *
Peng Xu80df0162017-08-05 19:00:23 -0700992 * ASensorEvent event;
993 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);
994 *
995 * ASensorEvent eventBuffer[8];
996 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700997 *
998 */
Peng Xuda8385c2017-02-28 20:19:47 -0800999ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count);
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001000
Brian Stack65089d52019-01-11 10:52:07 -08001001/**
1002 * Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on
1003 * the given {@link ASensorEventQueue}.
1004 *
gfan5d5faa42021-04-12 15:14:29 -07001005 * Sensor data events are always delivered to the {@link ASensorEventQueue}.
Brian Stack65089d52019-01-11 10:52:07 -08001006 *
1007 * The {@link ASENSOR_TYPE_ADDITIONAL_INFO} events will be returned through
1008 * {@link ASensorEventQueue_getEvents}. The client is responsible for checking
1009 * {@link ASensorEvent#type} to determine the event type prior to handling of
1010 * the event.
1011 *
1012 * The client must be tolerant of any value for
1013 * {@link AAdditionalInfoEvent#type}, as new values may be defined in the future
1014 * and may delivered to the client.
1015 *
Elliott Hughes3d70e532019-10-29 08:59:39 -07001016 * Available since API level 29.
1017 *
Brian Stack65089d52019-01-11 10:52:07 -08001018 * \param queue {@link ASensorEventQueue} to configure
1019 * \param enable true to request {@link ASENSOR_TYPE_ADDITIONAL_INFO} events,
1020 * false to stop receiving events
1021 * \return 0 on success or a negative error code on failure
1022 */
Elliott Hughes3d70e532019-10-29 08:59:39 -07001023int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable) __INTRODUCED_IN(29);
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001024
1025/*****************************************************************************/
1026
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001027/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001028 * Returns this sensor's name (non localized)
1029 */
1030const char* ASensor_getName(ASensor const* sensor);
1031
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001032/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001033 * Returns this sensor's vendor's name (non localized)
1034 */
1035const char* ASensor_getVendor(ASensor const* sensor);
1036
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001037/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001038 * Return this sensor's type
1039 */
1040int ASensor_getType(ASensor const* sensor);
1041
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001042/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001043 * Returns this sensors's resolution
1044 */
1045float ASensor_getResolution(ASensor const* sensor);
1046
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001047/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001048 * Returns the minimum delay allowed between events in microseconds.
1049 * A value of zero means that this sensor doesn't report events at a
1050 * constant rate, but rather only when a new data is available.
1051 */
1052int ASensor_getMinDelay(ASensor const* sensor);
1053
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001054/**
Aravind Akella70018042014-04-07 22:52:37 +00001055 * Returns the maximum size of batches for this sensor. Batches will often be
1056 * smaller, as the hardware fifo might be used for other sensors.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001057 *
1058 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +00001059 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001060int ASensor_getFifoMaxEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +00001061
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001062/**
Aravind Akella70018042014-04-07 22:52:37 +00001063 * Returns the hardware batch fifo size reserved to this sensor.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001064 *
1065 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +00001066 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001067int ASensor_getFifoReservedEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +00001068
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001069/**
Aravind Akella70018042014-04-07 22:52:37 +00001070 * Returns this sensor's string type.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001071 *
1072 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +00001073 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001074const char* ASensor_getStringType(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +00001075
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001076/**
Aravind Akella0e025c52014-06-03 19:19:57 -07001077 * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001078 *
1079 * Available since API level 21.
Aravind Akella0e025c52014-06-03 19:19:57 -07001080 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001081int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella0e025c52014-06-03 19:19:57 -07001082
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001083/**
Aravind Akellab37ba392014-08-05 14:53:07 -07001084 * Returns true if this is a wake up sensor, false otherwise.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001085 *
1086 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -07001087 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001088bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akellab37ba392014-08-05 14:53:07 -07001089
Peng Xu47cddca2017-02-15 23:31:22 -08001090/**
1091 * Test if sensor supports a certain type of direct channel.
1092 *
Elliott Hughes3d70e532019-10-29 08:59:39 -07001093 * Available since API level 26.
1094 *
Peng Xu47cddca2017-02-15 23:31:22 -08001095 * \param sensor a {@link ASensor} to denote the sensor to be checked.
1096 * \param channelType Channel type constant, either
gfan5d5faa42021-04-12 15:14:29 -07001097 * {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY}
Peng Xu47cddca2017-02-15 23:31:22 -08001098 * or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}.
1099 * \returns true if sensor supports the specified direct channel type.
1100 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001101bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType) __INTRODUCED_IN(26);
1102
Peng Xu47cddca2017-02-15 23:31:22 -08001103/**
Elliott Hughes3d70e532019-10-29 08:59:39 -07001104 * Get the highest direct rate level that a sensor supports.
1105 *
1106 * Available since API level 26.
Peng Xu47cddca2017-02-15 23:31:22 -08001107 *
1108 * \param sensor a {@link ASensor} to denote the sensor to be checked.
1109 *
1110 * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor.
1111 * If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor
1112 * does not support direct report.
1113 */
Elliott Hughes9db409b2018-06-18 12:28:46 -07001114int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -08001115
Brian Stack8228fa72019-01-04 14:15:13 -08001116/**
1117 * Returns the sensor's handle.
1118 *
1119 * The handle identifies the sensor within the system and is included in the
gfanc150ea12021-04-14 09:27:55 -07001120 * sensor field of {@link ASensorEvent}, including those sent with type
Brian Stack8228fa72019-01-04 14:15:13 -08001121 * {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
1122 *
1123 * A sensor's handle is able to be used to map {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to the
1124 * sensor that generated the event.
1125 *
1126 * It is important to note that the value returned by {@link ASensor_getHandle} is not the same as
gfan5d5faa42021-04-12 15:14:29 -07001127 * the value returned by the Java API <a href="/reference/android/hardware/Sensor#getId()">
1128 * android.hardware.Sensor's getId()</a> and no mapping exists between the values.
Elliott Hughes3d70e532019-10-29 08:59:39 -07001129 *
1130 * Available since API level 29.
Brian Stack8228fa72019-01-04 14:15:13 -08001131 */
Elliott Hughes3d70e532019-10-29 08:59:39 -07001132int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(29);
Brian Stack8228fa72019-01-04 14:15:13 -08001133
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001134#ifdef __cplusplus
1135};
1136#endif
1137
1138#endif // ANDROID_SENSOR_H
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -07001139
1140/** @} */