The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 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 | |
| 17 | #ifndef ANDROID_SENSORS_INTERFACE_H |
| 18 | #define ANDROID_SENSORS_INTERFACE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/cdefs.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <hardware/hardware.h> |
Mike Lockwood | 21b652f | 2009-05-22 10:05:48 -0400 | [diff] [blame] | 25 | #include <cutils/native_handle.h> |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 26 | |
Andreas Huber | 9219017 | 2016-10-10 13:18:52 -0700 | [diff] [blame] | 27 | #include "sensors-base.h" |
| 28 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 29 | __BEGIN_DECLS |
| 30 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 31 | /*****************************************************************************/ |
| 32 | |
| 33 | #define SENSORS_HEADER_VERSION 1 |
| 34 | #define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
| 35 | #define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION) |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 36 | #define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION) |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 37 | #define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION) |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 38 | #define SENSORS_DEVICE_API_VERSION_1_2 HARDWARE_DEVICE_API_VERSION_2(1, 2, SENSORS_HEADER_VERSION) |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 39 | #define SENSORS_DEVICE_API_VERSION_1_3 HARDWARE_DEVICE_API_VERSION_2(1, 3, SENSORS_HEADER_VERSION) |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 40 | #define SENSORS_DEVICE_API_VERSION_1_4 HARDWARE_DEVICE_API_VERSION_2(1, 4, SENSORS_HEADER_VERSION) |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 41 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 42 | /** |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 43 | * Please see the Sensors section of source.android.com for an |
| 44 | * introduction to and detailed descriptions of Android sensor types: |
| 45 | * http://source.android.com/devices/sensors/index.html |
| 46 | */ |
| 47 | |
| 48 | /** |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 49 | * The id of this module |
| 50 | */ |
| 51 | #define SENSORS_HARDWARE_MODULE_ID "sensors" |
| 52 | |
| 53 | /** |
| 54 | * Name of the sensors device to open |
| 55 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 56 | #define SENSORS_HARDWARE_POLL "poll" |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 57 | |
| 58 | /** |
Peng Xu | f144435 | 2017-01-17 14:53:16 -0800 | [diff] [blame] | 59 | * Sensor handle is greater than 0 and less than INT32_MAX. |
| 60 | * |
| 61 | * **** Deprecated **** |
| 62 | * Defined values below are kept for code compatibility. Note sensor handle can be as large as |
| 63 | * INT32_MAX. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 64 | */ |
| 65 | #define SENSORS_HANDLE_BASE 0 |
Peng Xu | f144435 | 2017-01-17 14:53:16 -0800 | [diff] [blame] | 66 | #define SENSORS_HANDLE_BITS 31 |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 67 | #define SENSORS_HANDLE_COUNT (1ull<<SENSORS_HANDLE_BITS) |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 68 | |
| 69 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 70 | /* |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 71 | * **** Deprecated ***** |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 72 | * flags for (*batch)() |
| 73 | * Availability: SENSORS_DEVICE_API_VERSION_1_0 |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 74 | * see (*batch)() documentation for details. |
| 75 | * Deprecated as of SENSORS_DEVICE_API_VERSION_1_3. |
| 76 | * WAKE_UP_* sensors replace WAKE_UPON_FIFO_FULL concept. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 77 | */ |
| 78 | enum { |
| 79 | SENSORS_BATCH_DRY_RUN = 0x00000001, |
| 80 | SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002 |
| 81 | }; |
| 82 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 83 | /* |
| 84 | * what field for meta_data_event_t |
| 85 | */ |
| 86 | enum { |
| 87 | /* a previous flush operation has completed */ |
Andreas Huber | 9219017 | 2016-10-10 13:18:52 -0700 | [diff] [blame] | 88 | // META_DATA_FLUSH_COMPLETE = 1, |
Mathias Agopian | af32a8d | 2013-08-06 20:33:38 -0700 | [diff] [blame] | 89 | META_DATA_VERSION /* always last, leave auto-assigned */ |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 92 | /* |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 93 | * The permission to use for body sensors (like heart rate monitors). |
| 94 | * See sensor types for more details on what sensors should require this |
| 95 | * permission. |
| 96 | */ |
| 97 | #define SENSOR_PERMISSION_BODY_SENSORS "android.permission.BODY_SENSORS" |
| 98 | |
| 99 | /* |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 100 | * sensor flags legacy names |
| 101 | * |
| 102 | * please use SENSOR_FLAG_* directly for new implementation. |
| 103 | * @see sensor_t |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 104 | */ |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 105 | |
Peng Xu | d156299 | 2016-03-29 18:14:05 -0700 | [diff] [blame] | 106 | #define SENSOR_FLAG_MASK(nbit, shift) (((1<<(nbit))-1)<<(shift)) |
| 107 | #define SENSOR_FLAG_MASK_1(shift) SENSOR_FLAG_MASK(1, shift) |
| 108 | |
| 109 | /* |
| 110 | * Mask and shift for reporting mode sensor flags defined above. |
| 111 | */ |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 112 | #define REPORTING_MODE_SHIFT SENSOR_FLAG_SHIFT_REPORTING_MODE |
Peng Xu | d156299 | 2016-03-29 18:14:05 -0700 | [diff] [blame] | 113 | #define REPORTING_MODE_NBIT (3) |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 114 | #define REPORTING_MODE_MASK SENSOR_FLAG_MASK_REPORTING_MODE |
Peng Xu | d156299 | 2016-03-29 18:14:05 -0700 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * Mask and shift for data_injection mode sensor flags defined above. |
| 118 | */ |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 119 | #define DATA_INJECTION_SHIFT SENSOR_FLAG_SHIFT_DATA_INJECTION |
| 120 | #define DATA_INJECTION_MASK SENSOR_FLAG_DATA_INJECTION |
Peng Xu | d156299 | 2016-03-29 18:14:05 -0700 | [diff] [blame] | 121 | |
| 122 | /* |
| 123 | * Mask and shift for dynamic sensor flag. |
| 124 | */ |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 125 | #define DYNAMIC_SENSOR_SHIFT SENSOR_FLAG_SHIFT_DYNAMIC_SENSOR |
| 126 | #define DYNAMIC_SENSOR_MASK SENSOR_FLAG_DYNAMIC_SENSOR |
Peng Xu | d156299 | 2016-03-29 18:14:05 -0700 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * Mask and shift for sensor additional information support. |
| 130 | */ |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 131 | #define ADDITIONAL_INFO_SHIFT SENSOR_FLAG_SHIFT_ADDITIONAL_INFO |
| 132 | #define ADDITIONAL_INFO_MASK SENSOR_FLAG_ADDITIONAL_INFO |
Peng Xu | d156299 | 2016-03-29 18:14:05 -0700 | [diff] [blame] | 133 | |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame] | 134 | /* |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 135 | * Legacy alias of SENSOR_TYPE_MAGNETIC_FIELD. |
| 136 | * |
| 137 | * Previously, the type of a sensor measuring local magnetic field is named |
| 138 | * SENSOR_TYPE_GEOMAGNETIC_FIELD and SENSOR_TYPE_MAGNETIC_FIELD is its alias. |
| 139 | * SENSOR_TYPE_MAGNETIC_FIELD is redefined as primary name to avoid confusion. |
| 140 | * SENSOR_TYPE_GEOMAGNETIC_FIELD is the alias and is deprecating. New implementation must not use |
| 141 | * SENSOR_TYPE_GEOMAGNETIC_FIELD. |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame] | 142 | */ |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 143 | #define SENSOR_TYPE_GEOMAGNETIC_FIELD SENSOR_TYPE_MAGNETIC_FIELD |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame] | 144 | |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 145 | /* |
| 146 | * Sensor string types for Android defined sensor types. |
| 147 | * |
| 148 | * For Android defined sensor types, string type will be override in sensor service and thus no |
| 149 | * longer needed to be added to sensor_t data structure. |
| 150 | * |
| 151 | * These definitions are going to be removed soon. |
| 152 | */ |
| 153 | #define SENSOR_STRING_TYPE_ACCELEROMETER "android.sensor.accelerometer" |
| 154 | #define SENSOR_STRING_TYPE_MAGNETIC_FIELD "android.sensor.magnetic_field" |
| 155 | #define SENSOR_STRING_TYPE_ORIENTATION "android.sensor.orientation" |
| 156 | #define SENSOR_STRING_TYPE_GYROSCOPE "android.sensor.gyroscope" |
| 157 | #define SENSOR_STRING_TYPE_LIGHT "android.sensor.light" |
| 158 | #define SENSOR_STRING_TYPE_PRESSURE "android.sensor.pressure" |
| 159 | #define SENSOR_STRING_TYPE_TEMPERATURE "android.sensor.temperature" |
| 160 | #define SENSOR_STRING_TYPE_PROXIMITY "android.sensor.proximity" |
| 161 | #define SENSOR_STRING_TYPE_GRAVITY "android.sensor.gravity" |
| 162 | #define SENSOR_STRING_TYPE_LINEAR_ACCELERATION "android.sensor.linear_acceleration" |
| 163 | #define SENSOR_STRING_TYPE_ROTATION_VECTOR "android.sensor.rotation_vector" |
| 164 | #define SENSOR_STRING_TYPE_RELATIVE_HUMIDITY "android.sensor.relative_humidity" |
| 165 | #define SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE "android.sensor.ambient_temperature" |
| 166 | #define SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED "android.sensor.magnetic_field_uncalibrated" |
| 167 | #define SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR "android.sensor.game_rotation_vector" |
| 168 | #define SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED "android.sensor.gyroscope_uncalibrated" |
| 169 | #define SENSOR_STRING_TYPE_SIGNIFICANT_MOTION "android.sensor.significant_motion" |
| 170 | #define SENSOR_STRING_TYPE_STEP_DETECTOR "android.sensor.step_detector" |
| 171 | #define SENSOR_STRING_TYPE_STEP_COUNTER "android.sensor.step_counter" |
| 172 | #define SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR "android.sensor.geomagnetic_rotation_vector" |
| 173 | #define SENSOR_STRING_TYPE_HEART_RATE "android.sensor.heart_rate" |
| 174 | #define SENSOR_STRING_TYPE_TILT_DETECTOR "android.sensor.tilt_detector" |
| 175 | #define SENSOR_STRING_TYPE_WAKE_GESTURE "android.sensor.wake_gesture" |
| 176 | #define SENSOR_STRING_TYPE_GLANCE_GESTURE "android.sensor.glance_gesture" |
| 177 | #define SENSOR_STRING_TYPE_PICK_UP_GESTURE "android.sensor.pick_up_gesture" |
| 178 | #define SENSOR_STRING_TYPE_WRIST_TILT_GESTURE "android.sensor.wrist_tilt_gesture" |
| 179 | #define SENSOR_STRING_TYPE_DEVICE_ORIENTATION "android.sensor.device_orientation" |
| 180 | #define SENSOR_STRING_TYPE_POSE_6DOF "android.sensor.pose_6dof" |
Ashutosh Joshi | cb96331 | 2016-01-25 18:48:57 -0800 | [diff] [blame] | 181 | #define SENSOR_STRING_TYPE_STATIONARY_DETECT "android.sensor.stationary_detect" |
Ashutosh Joshi | cb96331 | 2016-01-25 18:48:57 -0800 | [diff] [blame] | 182 | #define SENSOR_STRING_TYPE_MOTION_DETECT "android.sensor.motion_detect" |
Ashutosh Joshi | cb96331 | 2016-01-25 18:48:57 -0800 | [diff] [blame] | 183 | #define SENSOR_STRING_TYPE_HEART_BEAT "android.sensor.heart_beat" |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 184 | #define SENSOR_STRING_TYPE_DYNAMIC_SENSOR_META "android.sensor.dynamic_sensor_meta" |
| 185 | #define SENSOR_STRING_TYPE_ADDITIONAL_INFO "android.sensor.additional_info" |
Ashutosh Joshi | d14335b | 2017-04-14 08:22:38 -0700 | [diff] [blame] | 186 | #define SENSOR_STRING_TYPE_LOW_LATENCY_OFFBODY_DETECT "android.sensor.low_latency_offbody_detect" |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 187 | #define SENSOR_STRING_TYPE_ACCELEROMETER_UNCALIBRATED "android.sensor.accelerometer_uncalibrated" |
Anthony Stange | e2a118a | 2020-01-16 15:34:20 -0500 | [diff] [blame] | 188 | #define SENSOR_STRING_TYPE_HINGE_ANGLE "android.sensor.hinge_angle" |
Brian Duddie | d3e67d5 | 2021-12-20 18:03:27 -0800 | [diff] [blame] | 189 | #define SENSOR_STRING_TYPE_HEAD_TRACKER "android.sensor.head_tracker" |
Eva Chen | 2588d75 | 2021-04-09 15:42:31 -0700 | [diff] [blame] | 190 | #define SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES "android.sensor.accelerometer_limited_axes" |
| 191 | #define SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES "android.sensor.gyroscope_limited_axes" |
| 192 | #define SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED "android.sensor.accelerometer_limited_axes_uncalibrated" |
| 193 | #define SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED "android.sensor.gyroscope_limited_axes_uncalibrated" |
Eva Chen | 544076b | 2022-01-10 21:17:02 -0800 | [diff] [blame] | 194 | #define SENSOR_STRING_TYPE_HEADING "android.sensor.heading" |
Peng Xu | 0743a5c | 2016-01-21 17:30:02 -0800 | [diff] [blame] | 195 | |
| 196 | /** |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 197 | * Values returned by the accelerometer in various locations in the universe. |
| 198 | * all values are in SI units (m/s^2) |
| 199 | */ |
| 200 | #define GRAVITY_SUN (275.0f) |
| 201 | #define GRAVITY_EARTH (9.80665f) |
| 202 | |
| 203 | /** Maximum magnetic field on Earth's surface */ |
| 204 | #define MAGNETIC_FIELD_EARTH_MAX (60.0f) |
| 205 | |
| 206 | /** Minimum magnetic field on Earth's surface */ |
| 207 | #define MAGNETIC_FIELD_EARTH_MIN (30.0f) |
| 208 | |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 209 | struct sensor_t; |
| 210 | |
Mathias Agopian | 56f66cc | 2012-11-08 15:57:38 -0800 | [diff] [blame] | 211 | /** |
| 212 | * sensor event data |
| 213 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 214 | typedef struct { |
| 215 | union { |
| 216 | float v[3]; |
| 217 | struct { |
| 218 | float x; |
| 219 | float y; |
| 220 | float z; |
| 221 | }; |
| 222 | struct { |
| 223 | float azimuth; |
| 224 | float pitch; |
| 225 | float roll; |
| 226 | }; |
| 227 | }; |
| 228 | int8_t status; |
| 229 | uint8_t reserved[3]; |
| 230 | } sensors_vec_t; |
| 231 | |
| 232 | /** |
Ashutosh Joshi | d1e2562 | 2017-01-10 18:33:53 -0800 | [diff] [blame] | 233 | * uncalibrated accelerometer, gyroscope and magnetometer event data |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 234 | */ |
| 235 | typedef struct { |
Etienne Le Grand | 28f0411 | 2013-03-27 18:59:10 -0700 | [diff] [blame] | 236 | union { |
| 237 | float uncalib[3]; |
| 238 | struct { |
| 239 | float x_uncalib; |
| 240 | float y_uncalib; |
| 241 | float z_uncalib; |
| 242 | }; |
| 243 | }; |
| 244 | union { |
| 245 | float bias[3]; |
| 246 | struct { |
| 247 | float x_bias; |
| 248 | float y_bias; |
| 249 | float z_bias; |
| 250 | }; |
| 251 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 252 | } uncalibrated_event_t; |
| 253 | |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 254 | /** |
| 255 | * Meta data event data |
| 256 | */ |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 257 | typedef struct meta_data_event { |
| 258 | int32_t what; |
| 259 | int32_t sensor; |
| 260 | } meta_data_event_t; |
| 261 | |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 262 | /** |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 263 | * Dynamic sensor meta event. See the description of SENSOR_TYPE_DYNAMIC_SENSOR_META type for |
| 264 | * details. |
| 265 | */ |
| 266 | typedef struct dynamic_sensor_meta_event { |
Peng Xu | e20707a | 2016-01-27 18:26:10 -0800 | [diff] [blame] | 267 | int32_t connected; |
| 268 | int32_t handle; |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 269 | const struct sensor_t * sensor; // should be NULL if connected == false |
Peng Xu | 69b5dba | 2016-04-22 22:34:51 -0700 | [diff] [blame] | 270 | uint8_t uuid[16]; // UUID of a dynamic sensor (using RFC 4122 byte order) |
| 271 | // For UUID 12345678-90AB-CDEF-1122-334455667788 the uuid field |
| 272 | // should be initialized as: |
| 273 | // {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x11, ...} |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 274 | } dynamic_sensor_meta_event_t; |
| 275 | |
| 276 | /** |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 277 | * Heart rate event data |
| 278 | */ |
| 279 | typedef struct { |
| 280 | // Heart rate in beats per minute. |
| 281 | // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT |
| 282 | float bpm; |
| 283 | // Status of the sensor for this reading. Set to one SENSOR_STATUS_... |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 284 | // Note that this value should only be set for sensors that explicitly define |
| 285 | // the meaning of this field. This field is not piped through the framework |
| 286 | // for other sensors. |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 287 | int8_t status; |
| 288 | } heart_rate_event_t; |
| 289 | |
Peng Xu | 0743a5c | 2016-01-21 17:30:02 -0800 | [diff] [blame] | 290 | typedef struct { |
| 291 | int32_t type; // type of payload data, see additional_info_type_t |
| 292 | int32_t serial; // sequence number of this frame for this type |
| 293 | union { |
| 294 | // for each frame, a single data type, either int32_t or float, should be used. |
| 295 | int32_t data_int32[14]; |
| 296 | float data_float[14]; |
| 297 | }; |
| 298 | } additional_info_event_t; |
| 299 | |
Brian Duddie | 373a1b9 | 2022-01-19 16:06:13 -0800 | [diff] [blame] | 300 | typedef struct { |
| 301 | float rx; |
| 302 | float ry; |
| 303 | float rz; |
| 304 | float vx; |
| 305 | float vy; |
| 306 | float vz; |
| 307 | int32_t discontinuity_count; |
| 308 | } head_tracker_event_t; |
| 309 | |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 310 | /** |
Tyler Trephan | 6515145 | 2022-01-20 23:52:29 +0000 | [diff] [blame] | 311 | * limited axes imu event data |
| 312 | */ |
| 313 | typedef struct { |
| 314 | union { |
| 315 | float calib[3]; |
| 316 | struct { |
| 317 | float x; |
| 318 | float y; |
| 319 | float z; |
| 320 | }; |
| 321 | }; |
| 322 | union { |
| 323 | float supported[3]; |
| 324 | struct { |
| 325 | float x_supported; |
| 326 | float y_supported; |
| 327 | float z_supported; |
| 328 | }; |
| 329 | }; |
| 330 | } limited_axes_imu_event_t; |
| 331 | |
| 332 | /** |
| 333 | * limited axes uncalibrated imu event data |
| 334 | */ |
| 335 | typedef struct { |
| 336 | union { |
| 337 | float uncalib[3]; |
| 338 | struct { |
| 339 | float x_uncalib; |
| 340 | float y_uncalib; |
| 341 | float z_uncalib; |
| 342 | }; |
| 343 | }; |
| 344 | union { |
| 345 | float bias[3]; |
| 346 | struct { |
| 347 | float x_bias; |
| 348 | float y_bias; |
| 349 | float z_bias; |
| 350 | }; |
| 351 | }; |
| 352 | union { |
| 353 | float supported[3]; |
| 354 | struct { |
| 355 | float x_supported; |
| 356 | float y_supported; |
| 357 | float z_supported; |
| 358 | }; |
| 359 | }; |
| 360 | } limited_axes_imu_uncalibrated_event_t; |
| 361 | |
| 362 | /** |
Tyler Trephan | 3d9af7c | 2022-01-21 00:04:35 +0000 | [diff] [blame] | 363 | * Heading event data |
| 364 | */ |
| 365 | typedef struct { |
| 366 | float heading; |
| 367 | float accuracy; |
| 368 | } heading_event_t; |
| 369 | |
| 370 | /** |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 371 | * Union of the various types of sensor data |
| 372 | * that can be returned. |
| 373 | */ |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 374 | typedef struct sensors_event_t { |
| 375 | /* must be sizeof(struct sensors_event_t) */ |
| 376 | int32_t version; |
| 377 | |
| 378 | /* sensor identifier */ |
| 379 | int32_t sensor; |
| 380 | |
| 381 | /* sensor type */ |
| 382 | int32_t type; |
| 383 | |
| 384 | /* reserved */ |
| 385 | int32_t reserved0; |
| 386 | |
| 387 | /* time is in nanosecond */ |
| 388 | int64_t timestamp; |
| 389 | |
| 390 | union { |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 391 | union { |
| 392 | float data[16]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 393 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 394 | /* acceleration values are in meter per second per second (m/s^2) */ |
| 395 | sensors_vec_t acceleration; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 396 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 397 | /* magnetic vector values are in micro-Tesla (uT) */ |
| 398 | sensors_vec_t magnetic; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 399 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 400 | /* orientation values are in degrees */ |
| 401 | sensors_vec_t orientation; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 402 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 403 | /* gyroscope values are in rad/s */ |
| 404 | sensors_vec_t gyro; |
Makarand Karvekar | 3120b58 | 2010-08-11 15:10:10 -0700 | [diff] [blame] | 405 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 406 | /* temperature is in degrees centigrade (Celsius) */ |
| 407 | float temperature; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 408 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 409 | /* distance in centimeters */ |
| 410 | float distance; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 411 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 412 | /* light in SI lux units */ |
| 413 | float light; |
Mathias Agopian | 1832f55 | 2010-07-29 15:22:30 -0700 | [diff] [blame] | 414 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 415 | /* pressure in hectopascal (hPa) */ |
| 416 | float pressure; |
Urs Fleisch | d2ed15a | 2010-12-29 17:00:33 +0100 | [diff] [blame] | 417 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 418 | /* relative humidity in percent */ |
| 419 | float relative_humidity; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 420 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 421 | /* uncalibrated gyroscope values are in rad/s */ |
| 422 | uncalibrated_event_t uncalibrated_gyro; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 423 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 424 | /* uncalibrated magnetometer values are in micro-Teslas */ |
| 425 | uncalibrated_event_t uncalibrated_magnetic; |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 426 | |
Ashutosh Joshi | d1e2562 | 2017-01-10 18:33:53 -0800 | [diff] [blame] | 427 | /* uncalibrated accelerometer values are in meter per second per second (m/s^2) */ |
| 428 | uncalibrated_event_t uncalibrated_accelerometer; |
| 429 | |
Etienne Le Grand | 7b36158 | 2014-05-16 11:08:28 -0700 | [diff] [blame] | 430 | /* heart rate data containing value in bpm and status */ |
| 431 | heart_rate_event_t heart_rate; |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 432 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 433 | /* this is a special event. see SENSOR_TYPE_META_DATA above. |
| 434 | * sensors_meta_data_event_t events are all reported with a type of |
| 435 | * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero. |
| 436 | */ |
| 437 | meta_data_event_t meta_data; |
Peng Xu | e641ba9 | 2016-01-20 00:27:21 -0800 | [diff] [blame] | 438 | |
| 439 | /* dynamic sensor meta event. See SENSOR_TYPE_DYNAMIC_SENSOR_META type for details */ |
| 440 | dynamic_sensor_meta_event_t dynamic_sensor_meta; |
Peng Xu | 0743a5c | 2016-01-21 17:30:02 -0800 | [diff] [blame] | 441 | |
| 442 | /* |
| 443 | * special additional sensor information frame, see |
| 444 | * SENSOR_TYPE_ADDITIONAL_INFO for details. |
| 445 | */ |
| 446 | additional_info_event_t additional_info; |
Brian Duddie | 373a1b9 | 2022-01-19 16:06:13 -0800 | [diff] [blame] | 447 | |
| 448 | /* vector describing head orientation (added for legacy code support only) */ |
| 449 | head_tracker_event_t head_tracker; |
Tyler Trephan | 6515145 | 2022-01-20 23:52:29 +0000 | [diff] [blame] | 450 | |
| 451 | /* |
| 452 | * limited axes imu event, See |
| 453 | * SENSOR_TYPE_GYROSCOPE_LIMITED_AXES and |
| 454 | * SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES for details. |
| 455 | */ |
| 456 | limited_axes_imu_event_t limited_axes_imu; |
| 457 | |
| 458 | /* |
| 459 | * limited axes imu uncalibrated event, See |
| 460 | * SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED and |
| 461 | * SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED for details. |
| 462 | */ |
| 463 | limited_axes_imu_uncalibrated_event_t limited_axes_imu_uncalibrated; |
Tyler Trephan | 3d9af7c | 2022-01-21 00:04:35 +0000 | [diff] [blame] | 464 | |
| 465 | /* heading data containing value in degrees and its accuracy */ |
| 466 | heading_event_t heading; |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 467 | }; |
Etienne Le Grand | ca85814 | 2013-02-26 19:17:20 -0800 | [diff] [blame] | 468 | |
Mathias Agopian | 27e1668 | 2013-07-08 14:00:54 -0700 | [diff] [blame] | 469 | union { |
| 470 | uint64_t data[8]; |
| 471 | |
| 472 | /* step-counter */ |
| 473 | uint64_t step_counter; |
| 474 | } u64; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 475 | }; |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 476 | |
| 477 | /* Reserved flags for internal use. Set to zero. */ |
| 478 | uint32_t flags; |
| 479 | |
| 480 | uint32_t reserved1[3]; |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 481 | } sensors_event_t; |
| 482 | |
| 483 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 484 | /* see SENSOR_TYPE_META_DATA */ |
| 485 | typedef sensors_event_t sensors_meta_data_event_t; |
| 486 | |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 487 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 488 | /** |
| 489 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 490 | * and the fields of this data structure must begin with hw_module_t |
| 491 | * followed by module specific information. |
| 492 | */ |
| 493 | struct sensors_module_t { |
| 494 | struct hw_module_t common; |
| 495 | |
| 496 | /** |
| 497 | * Enumerate all available sensors. The list is returned in "list". |
Colin Cross | 867e1e3 | 2016-10-06 16:44:46 -0700 | [diff] [blame] | 498 | * return number of sensors in the list |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 499 | */ |
| 500 | int (*get_sensors_list)(struct sensors_module_t* module, |
| 501 | struct sensor_t const** list); |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * Place the module in a specific mode. The following modes are defined |
| 505 | * |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 506 | * 0 - Normal operation. Default state of the module. |
Peng Xu | 0743a5c | 2016-01-21 17:30:02 -0800 | [diff] [blame] | 507 | * 1 - Loopback mode. Data is injected for the supported |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 508 | * sensors by the sensor service in this mode. |
Colin Cross | 867e1e3 | 2016-10-06 16:44:46 -0700 | [diff] [blame] | 509 | * return 0 on success |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 510 | * -EINVAL if requested mode is not supported |
Aravind Akella | c7f5413 | 2015-06-22 18:26:54 -0700 | [diff] [blame] | 511 | * -EPERM if operation is not allowed |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 512 | */ |
| 513 | int (*set_operation_mode)(unsigned int mode); |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 514 | }; |
| 515 | |
| 516 | struct sensor_t { |
Mathias Agopian | 1144bea | 2013-01-29 15:52:10 -0800 | [diff] [blame] | 517 | |
| 518 | /* Name of this sensor. |
| 519 | * All sensors of the same "type" must have a different "name". |
| 520 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 521 | const char* name; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 522 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 523 | /* vendor of the hardware part */ |
| 524 | const char* vendor; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 525 | |
Mathias Agopian | e9eaf37 | 2011-11-07 21:32:34 -0800 | [diff] [blame] | 526 | /* version of the hardware part + driver. The value of this field |
| 527 | * must increase when the driver is updated in a way that changes the |
| 528 | * output of this sensor. This is important for fused sensors when the |
| 529 | * fusion algorithm is updated. |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 530 | */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 531 | int version; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 532 | |
| 533 | /* handle that identifies this sensors. This handle is used to reference |
| 534 | * this sensor throughout the HAL API. |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 535 | */ |
| 536 | int handle; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 537 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 538 | /* this sensor's type. */ |
| 539 | int type; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 540 | |
| 541 | /* maximum range of this sensor's value in SI units */ |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 542 | float maxRange; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 543 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 544 | /* smallest difference between two values reported by this sensor */ |
| 545 | float resolution; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 546 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 547 | /* rough estimate of this sensor's power consumption in mA */ |
| 548 | float power; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 549 | |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 550 | /* this value depends on the reporting mode: |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 551 | * |
| 552 | * continuous: minimum sample period allowed in microseconds |
| 553 | * on-change : 0 |
| 554 | * one-shot :-1 |
| 555 | * special : 0, unless otherwise noted |
| 556 | */ |
Mathias Agopian | 1511e20 | 2010-07-29 15:33:22 -0700 | [diff] [blame] | 557 | int32_t minDelay; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 558 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 559 | /* number of events reserved for this sensor in the batch mode FIFO. |
| 560 | * If there is a dedicated FIFO for this sensor, then this is the |
| 561 | * size of this FIFO. If the FIFO is shared with other sensors, |
| 562 | * this is the size reserved for that sensor and it can be zero. |
| 563 | */ |
| 564 | uint32_t fifoReservedEventCount; |
| 565 | |
| 566 | /* maximum number of events of this sensor that could be batched. |
| 567 | * This is especially relevant when the FIFO is shared between |
| 568 | * several sensors; this value is then set to the size of that FIFO. |
| 569 | */ |
| 570 | uint32_t fifoMaxEventCount; |
| 571 | |
Peng Xu | 95f79b1 | 2017-01-11 14:16:15 -0800 | [diff] [blame] | 572 | /* type of this sensor as a string. |
| 573 | * |
| 574 | * If type is OEM specific or sensor manufacturer specific type |
| 575 | * (>=SENSOR_TYPE_DEVICE_PRIVATE_BASE), this string must be defined with reserved domain of |
| 576 | * vendor/OEM as a prefix, e.g. com.google.glass.onheaddetector |
| 577 | * |
| 578 | * For sensors of Android defined types, Android framework will override this value. It is ok to |
| 579 | * leave it pointing to an empty string. |
Aravind Akella | 477fbd5 | 2014-04-07 22:46:01 +0000 | [diff] [blame] | 580 | */ |
| 581 | const char* stringType; |
| 582 | |
| 583 | /* permission required to see this sensor, register to it and receive data. |
| 584 | * Set to "" if no permission is required. Some sensor types like the |
| 585 | * heart rate monitor have a mandatory require_permission. |
| 586 | * For sensors that always require a specific permission, like the heart |
| 587 | * rate monitor, the android framework might overwrite this string |
| 588 | * automatically. |
| 589 | */ |
| 590 | const char* requiredPermission; |
| 591 | |
Aravind Akella | 110d2f2 | 2014-09-04 15:36:31 -0700 | [diff] [blame] | 592 | /* This value is defined only for continuous mode and on-change sensors. It is the delay between |
| 593 | * two sensor events corresponding to the lowest frequency that this sensor supports. When lower |
| 594 | * frequencies are requested through batch()/setDelay() the events will be generated at this |
| 595 | * frequency instead. It can be used by the framework or applications to estimate when the batch |
| 596 | * FIFO may be full. |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 597 | * |
| 598 | * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds. |
Aravind Akella | 110d2f2 | 2014-09-04 15:36:31 -0700 | [diff] [blame] | 599 | * continuous, on-change: maximum sampling period allowed in microseconds. |
| 600 | * one-shot, special : 0 |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 601 | * 2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit |
| 602 | * on 64 bit architectures only for binary compatibility reasons. |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 603 | * Availability: SENSORS_DEVICE_API_VERSION_1_3 |
| 604 | */ |
| 605 | #ifdef __LP64__ |
| 606 | int64_t maxDelay; |
| 607 | #else |
| 608 | int32_t maxDelay; |
| 609 | #endif |
| 610 | |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 611 | /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here. |
| 612 | * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons. |
| 613 | * Availability: SENSORS_DEVICE_API_VERSION_1_3 |
| 614 | */ |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 615 | #ifdef __LP64__ |
| 616 | uint64_t flags; |
| 617 | #else |
| 618 | uint32_t flags; |
| 619 | #endif |
| 620 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 621 | /* reserved fields, must be zero */ |
Aravind Akella | 6242f32 | 2014-02-28 18:46:19 -0800 | [diff] [blame] | 622 | void* reserved[2]; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 623 | }; |
| 624 | |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame] | 625 | /** |
| 626 | * Shared memory information for a direct channel |
| 627 | */ |
| 628 | struct sensors_direct_mem_t { |
| 629 | int type; // enum SENSOR_DIRECT_MEM_... |
| 630 | int format; // enum SENSOR_DIRECT_FMT_... |
| 631 | size_t size; // size of the memory region, in bytes |
| 632 | const struct native_handle *handle; // shared memory handle, which is interpreted differently |
| 633 | // depending on type |
| 634 | }; |
| 635 | |
| 636 | /** |
| 637 | * Direct channel report configuration |
| 638 | */ |
| 639 | struct sensors_direct_cfg_t { |
| 640 | int rate_level; // enum SENSOR_DIRECT_RATE_... |
| 641 | }; |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 642 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 643 | /* |
| 644 | * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1 |
| 645 | * and is present for backward binary and source compatibility. |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 646 | * See the Sensors HAL interface section for complete descriptions of the |
| 647 | * following functions: |
| 648 | * http://source.android.com/devices/sensors/index.html#hal |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 649 | */ |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 650 | struct sensors_poll_device_t { |
| 651 | struct hw_device_t common; |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 652 | int (*activate)(struct sensors_poll_device_t *dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 653 | int sensor_handle, int enabled); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 654 | int (*setDelay)(struct sensors_poll_device_t *dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 655 | int sensor_handle, int64_t sampling_period_ns); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 656 | int (*poll)(struct sensors_poll_device_t *dev, |
Mathias Agopian | cdefccd | 2010-07-15 18:29:03 -0700 | [diff] [blame] | 657 | sensors_event_t* data, int count); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 658 | }; |
| 659 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 660 | /* |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 661 | * struct sensors_poll_device_1 is used in HAL versions >= SENSORS_DEVICE_API_VERSION_1_0 |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 662 | */ |
| 663 | typedef struct sensors_poll_device_1 { |
| 664 | union { |
| 665 | /* sensors_poll_device_1 is compatible with sensors_poll_device_t, |
| 666 | * and can be down-cast to it |
| 667 | */ |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 668 | struct sensors_poll_device_t v0; |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 669 | |
| 670 | struct { |
| 671 | struct hw_device_t common; |
| 672 | |
Peng Xu | aaeeaa4 | 2016-10-05 14:56:54 -0700 | [diff] [blame] | 673 | /* Activate/de-activate one sensor. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 674 | * |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 675 | * sensor_handle is the handle of the sensor to change. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 676 | * enabled set to 1 to enable, or 0 to disable the sensor. |
| 677 | * |
Aniroop Mathur | 443a4ac | 2017-07-10 22:35:47 +0530 | [diff] [blame] | 678 | * Before sensor activation, existing sensor events that have not |
| 679 | * been picked up by poll() should be abandoned so that application |
| 680 | * upon new activation request will not get stale events. |
| 681 | * (events that are generated during latter activation or during |
| 682 | * data injection mode after sensor deactivation) |
Peng Xu | aaeeaa4 | 2016-10-05 14:56:54 -0700 | [diff] [blame] | 683 | * |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 684 | * Return 0 on success, negative errno code otherwise. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 685 | */ |
| 686 | int (*activate)(struct sensors_poll_device_t *dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 687 | int sensor_handle, int enabled); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 688 | |
| 689 | /** |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 690 | * Set the events's period in nanoseconds for a given sensor. |
| 691 | * If sampling_period_ns > max_delay it will be truncated to |
| 692 | * max_delay and if sampling_period_ns < min_delay it will be |
| 693 | * replaced by min_delay. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 694 | */ |
| 695 | int (*setDelay)(struct sensors_poll_device_t *dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 696 | int sensor_handle, int64_t sampling_period_ns); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 697 | |
| 698 | /** |
Peng Xu | 355e3f6 | 2016-07-19 15:11:53 -0700 | [diff] [blame] | 699 | * Write an array of sensor_event_t to data. The size of the |
| 700 | * available buffer is specified by count. Returns number of |
| 701 | * valid sensor_event_t. |
| 702 | * |
| 703 | * This function should block if there is no sensor event |
| 704 | * available when being called. Thus, return value should always be |
| 705 | * positive. |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 706 | */ |
| 707 | int (*poll)(struct sensors_poll_device_t *dev, |
| 708 | sensors_event_t* data, int count); |
| 709 | }; |
| 710 | }; |
| 711 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 712 | |
| 713 | /* |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 714 | * Sets a sensor’s parameters, including sampling frequency and maximum |
| 715 | * report latency. This function can be called while the sensor is |
| 716 | * activated, in which case it must not cause any sensor measurements to |
| 717 | * be lost: transitioning from one sampling rate to the other cannot cause |
| 718 | * lost events, nor can transitioning from a high maximum report latency to |
| 719 | * a low maximum report latency. |
Clay Murphy | 8db1fb4 | 2013-12-19 09:58:28 -0800 | [diff] [blame] | 720 | * See the Batching sensor results page for details: |
| 721 | * http://source.android.com/devices/sensors/batching.html |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 722 | */ |
| 723 | int (*batch)(struct sensors_poll_device_1* dev, |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 724 | int sensor_handle, int flags, int64_t sampling_period_ns, |
| 725 | int64_t max_report_latency_ns); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 726 | |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 727 | /* |
| 728 | * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t) |
| 729 | * to the end of the "batch mode" FIFO for the specified sensor and flushes |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 730 | * the FIFO. |
| 731 | * If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero), |
Aravind Akella | c841efd | 2014-06-03 19:21:35 -0700 | [diff] [blame] | 732 | * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 733 | * event stream. This applies to all sensors other than one-shot sensors. |
| 734 | * If the sensor is a one-shot sensor, flush must return -EINVAL and not generate |
| 735 | * any flush complete metadata. |
Aravind Akella | a7f2cda | 2014-08-21 16:31:14 -0700 | [diff] [blame] | 736 | * If the sensor is not active at the time flush() is called, flush() should return |
| 737 | * -EINVAL. |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 738 | */ |
Etienne Le Grand | 772d85a | 2014-08-19 14:30:19 -0700 | [diff] [blame] | 739 | int (*flush)(struct sensors_poll_device_1* dev, int sensor_handle); |
Mathias Agopian | 16671c5 | 2013-07-24 21:07:40 -0700 | [diff] [blame] | 740 | |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 741 | /* |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 742 | * Inject a single sensor sample to be to this device. |
| 743 | * data points to the sensor event to be injected |
Colin Cross | 867e1e3 | 2016-10-06 16:44:46 -0700 | [diff] [blame] | 744 | * return 0 on success |
Aravind Akella | c7f5413 | 2015-06-22 18:26:54 -0700 | [diff] [blame] | 745 | * -EPERM if operation is not allowed |
Ashutosh Joshi | 050f2e4 | 2015-04-15 13:56:53 -0700 | [diff] [blame] | 746 | * -EINVAL if sensor event cannot be injected |
Ashutosh Joshi | 6507f50 | 2015-04-03 16:22:32 -0700 | [diff] [blame] | 747 | */ |
| 748 | int (*inject_sensor_data)(struct sensors_poll_device_1 *dev, const sensors_event_t *data); |
| 749 | |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame] | 750 | /* |
| 751 | * Register/unregister direct report channel. |
| 752 | * |
| 753 | * A HAL declares support for direct report by setting non-NULL values for both |
| 754 | * register_direct_channel and config_direct_report. |
| 755 | * |
| 756 | * This function has two operation modes: |
| 757 | * |
| 758 | * Register: mem != NULL, register a channel using supplied shared memory information. By the |
| 759 | * time this function returns, sensors must finish initializing shared memory content |
| 760 | * (format dependent, see SENSOR_DIRECT_FMT_*). |
| 761 | * Parameters: |
| 762 | * mem points to a valid struct sensors_direct_mem_t. |
| 763 | * channel_handle is ignored. |
| 764 | * Return value: |
Peng Xu | f144435 | 2017-01-17 14:53:16 -0800 | [diff] [blame] | 765 | * A handle of channel (>0, <INT32_MAX) when success, which later can be referred in |
| 766 | * unregister or config_direct_report call, or error code (<0) when failed |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame] | 767 | * Unregister: mem == NULL, unregister a previously registered channel. |
| 768 | * Parameters: |
| 769 | * mem set to NULL |
| 770 | * channel_handle contains handle of channel to be unregistered |
| 771 | * Return value: |
| 772 | * 0, even if the channel_handle is invalid, in which case it will be a no-op. |
| 773 | */ |
| 774 | int (*register_direct_channel)(struct sensors_poll_device_1 *dev, |
| 775 | const struct sensors_direct_mem_t* mem, int channel_handle); |
| 776 | |
| 777 | /* |
| 778 | * Configure direct sensor event report in direct channel. |
| 779 | * |
| 780 | * Start, modify rate or stop direct report of a sensor in a certain direct channel. A special |
| 781 | * case is setting sensor handle -1 to stop means to stop all active sensor report on the |
| 782 | * channel specified. |
| 783 | * |
| 784 | * A HAL declares support for direct report by setting non-NULL values for both |
| 785 | * register_direct_channel and config_direct_report. |
| 786 | * |
| 787 | * Parameters: |
| 788 | * sensor_handle sensor to be configured. The sensor has to support direct report |
| 789 | * mode by setting flags of sensor_t. Also, direct report mode is only |
| 790 | * defined for continuous reporting mode sensors. |
| 791 | * channel_handle channel handle to be configured. |
| 792 | * config direct report parameters, see sensor_direct_cfg_t. |
| 793 | * Return value: |
| 794 | * - when sensor is started or sensor rate level is changed: return positive identifier of |
| 795 | * sensor in specified channel if successful, otherwise return negative error code. |
| 796 | * - when sensor is stopped: return 0 for success or negative error code for failure. |
| 797 | */ |
| 798 | int (*config_direct_report)(struct sensors_poll_device_1 *dev, |
| 799 | int sensor_handle, int channel_handle, const struct sensors_direct_cfg_t *config); |
| 800 | |
| 801 | /* |
Peng Xu | bed42d4 | 2017-04-06 17:52:29 -0700 | [diff] [blame] | 802 | * Reserved for future use, must be zero. |
Peng Xu | 08a4dd9 | 2016-11-03 11:56:27 -0700 | [diff] [blame] | 803 | */ |
| 804 | void (*reserved_procs[5])(void); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 805 | |
| 806 | } sensors_poll_device_1_t; |
| 807 | |
| 808 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 809 | /** convenience API for opening and closing a device */ |
| 810 | |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 811 | static inline int sensors_open(const struct hw_module_t* module, |
| 812 | struct sensors_poll_device_t** device) { |
| 813 | return module->methods->open(module, |
Colin Cross | cc8d9f9 | 2016-10-06 16:44:23 -0700 | [diff] [blame] | 814 | SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device)); |
Mathias Agopian | b1e212e | 2010-07-08 16:44:54 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | static inline int sensors_close(struct sensors_poll_device_t* device) { |
| 818 | return device->common.close(&device->common); |
| 819 | } |
| 820 | |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 821 | static inline int sensors_open_1(const struct hw_module_t* module, |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 822 | sensors_poll_device_1_t** device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 823 | return module->methods->open(module, |
Colin Cross | cc8d9f9 | 2016-10-06 16:44:23 -0700 | [diff] [blame] | 824 | SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device)); |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 825 | } |
| 826 | |
Andrew Hsieh | 1082c0b | 2012-12-11 20:51:41 -0800 | [diff] [blame] | 827 | static inline int sensors_close_1(sensors_poll_device_1_t* device) { |
Mathias Agopian | a455772 | 2012-11-28 17:21:55 -0800 | [diff] [blame] | 828 | return device->common.close(&device->common); |
| 829 | } |
| 830 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 831 | __END_DECLS |
| 832 | |
The Android Open Source Project | f53ebec | 2009-03-03 19:32:14 -0800 | [diff] [blame] | 833 | #endif // ANDROID_SENSORS_INTERFACE_H |