sensors.h revision 1599ec675579eaf8f8e7f79fc03648b9d838f475
1f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/* 2a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Copyright (C) 2012 The Android Open Source Project 3f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 4f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 5f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * you may not use this file except in compliance with the License. 6f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * You may obtain a copy of the License at 7f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 8f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 9f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 10f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 12f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * See the License for the specific language governing permissions and 14f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * limitations under the License. 15f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 16f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 17f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#ifndef ANDROID_SENSORS_INTERFACE_H 18f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define ANDROID_SENSORS_INTERFACE_H 19f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 20f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#include <stdint.h> 21f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#include <sys/cdefs.h> 22f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#include <sys/types.h> 23f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 24f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#include <hardware/hardware.h> 2521b652f933b21aa37bd73364b486347fcc333d5cMike Lockwood#include <cutils/native_handle.h> 26f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 27f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project__BEGIN_DECLS 28f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 2956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*****************************************************************************/ 3056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 3156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSORS_HEADER_VERSION 1 3256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSORS_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) 3356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSORS_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION_2(0, 1, SENSORS_HEADER_VERSION) 34a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian#define SENSORS_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION_2(1, 0, SENSORS_HEADER_VERSION) 3516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian#define SENSORS_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION_2(1, 1, SENSORS_HEADER_VERSION) 3656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 37f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 38f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * The id of this module 39f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 40f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HARDWARE_MODULE_ID "sensors" 41f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 42f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 43f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Name of the sensors device to open 44f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 45b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian#define SENSORS_HARDWARE_POLL "poll" 46f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 47f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 48f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Handles must be higher than SENSORS_HANDLE_BASE and must be unique. 49f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * A Handle identifies a given sensors. The handle is used to activate 50f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * and/or deactivate sensors. 51f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * In this version of the API there can only be 256 handles. 52f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 53f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HANDLE_BASE 0 54f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HANDLE_BITS 8 55f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS) 56f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 57f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 58a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 59a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * flags for (*batch)() 60a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Availability: SENSORS_DEVICE_API_VERSION_1_0 61a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * see (*batch)() documentation for details 62a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 63a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopianenum { 64a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian SENSORS_BATCH_DRY_RUN = 0x00000001, 65a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian SENSORS_BATCH_WAKE_UPON_FIFO_FULL = 0x00000002 66a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian}; 67a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 6816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian/* 6916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * what field for meta_data_event_t 7016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian */ 7116671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopianenum { 7216671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian /* a previous flush operation has completed */ 73af32a8d59463ddf67154cb432da232cfb185e6bcMathias Agopian META_DATA_FLUSH_COMPLETE = 1, 74af32a8d59463ddf67154cb432da232cfb185e6bcMathias Agopian META_DATA_VERSION /* always last, leave auto-assigned */ 7516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian}; 7616671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian 77f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 7856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Definition of the axis used by the sensor HAL API 79f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 80f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * This API is relative to the screen of the device in its default orientation, 81f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * that is, if the device can be used in portrait or landscape, this API 82f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * is only relative to the NATURAL orientation of the screen. In other words, 83f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * the axis are not swapped when the device's screen orientation changes. 84f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Higher level services /may/ perform this transformation. 85f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 86f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * x<0 x>0 87f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * ^ 88f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | 89f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * +-----------+--> y>0 90f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | 91f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | 92f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | 93f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | / z<0 94f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | / 95f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | / 96f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * O-----------+/ 97f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * |[] [ ] []/ 98f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * +----------/+ y<0 99f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * / 100f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * / 101f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * |/ z>0 (toward the sky) 102f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 103f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * O: Origin (x=0,y=0,z=0) 104f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 10556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 10656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 107a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 108a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Interaction with suspend mode 109a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 110a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Unless otherwise noted, an enabled sensor shall not prevent the 111a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * SoC to go into suspend mode. It is the responsibility of applications 112a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * to keep a partial wake-lock should they wish to receive sensor 113a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * events while the screen is off. While in suspend mode, and unless 11428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * otherwise noted (batch mode, sensor particularities, ...), enabled sensors' 11528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * events are lost. 116a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 117a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Note that conceptually, the sensor itself is not de-activated while in 118a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * suspend mode -- it's just that the data it returns are lost. As soon as 119a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * the SoC gets out of suspend mode, operations resume as usual. Of course, 120a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * in practice sensors shall be disabled while in suspend mode to 121a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * save power, unless batch mode is active, in which case they must 122a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * continue fill their internal FIFO (see the documentation of batch() to 123a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * learn how suspend interacts with batch mode). 124a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 12528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * In batch mode, and only when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is 1261144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * set and supported, the specified sensor must be able to wake-up the SoC and 1271144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * be able to buffer at least 10 seconds worth of the requested sensor events. 128a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 129a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * There are notable exceptions to this behavior, which are sensor-dependent 130a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * (see sensor types definitions below) 131a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 132a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 133a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The sensor type documentation below specifies the wake-up behavior of 134a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * each sensor: 135a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up: yes this sensor must wake-up the SoC to deliver events 136a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up: no this sensor shall not wake-up the SoC, events are dropped 137a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 138a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 139a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 140a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 141a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Sensor type 142a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 143a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Each sensor has a type which defines what this sensor measures and how 144a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * measures are reported. All types are defined below. 1451599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian * 1461599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian * Device manufacturers (OEMs) can define their own sensor types, for 1471599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian * their private use by applications or services provided by them. Such 1481599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian * sensor types are specific to an OEM and can't be exposed in the SDK. 1491599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian * These types must start at SENSOR_TYPE_DEVICE_PRIVATE_BASE. 1501599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian */ 1511599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian 1521599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian/* 1531599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian * Base for device manufacturers private sensor types. 1541599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian * These sensor types can't be exposed in the SDK. 155a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 1561599ec675579eaf8f8e7f79fc03648b9d838f475Mathias Agopian#define SENSOR_TYPE_DEVICE_PRIVATE_BASE 0x10000 157a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 158a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 159a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Sensor fusion and virtual sensors 160a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 161a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Many sensor types are or can be implemented as virtual sensors from 162a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * physical sensors on the device. For instance the rotation vector sensor, 1632f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian * orientation sensor, step-detector, step-counter, etc... 164a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 165a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * From the point of view of this API these virtual sensors MUST appear as 166a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * real, individual sensors. It is the responsibility of the driver and HAL 167a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * to make sure this is the case. 168a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 169a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * In particular, all sensors must be able to function concurrently. 170a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * For example, if defining both an accelerometer and a step counter, 171a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * then both must be able to work concurrently. 172a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 173a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 174a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 175a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Trigger modes 176a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 177a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Sensors can report events in different ways called trigger modes, 178a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * each sensor type has one and only one trigger mode associated to it. 179a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Currently there are four trigger modes defined: 180a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 181a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * continuous: events are reported at a constant rate defined by setDelay(). 182a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * eg: accelerometers, gyroscopes. 183a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * on-change: events are reported only if the sensor's value has changed. 184a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * setDelay() is used to set a lower limit to the reporting 185a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * period (minimum time between two events). 186a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The HAL must return an event immediately when an on-change 187a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * sensor is activated. 188a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * eg: proximity, light sensors 189ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * one-shot: upon detection of an event, the sensor deactivates itself and 190ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * then sends a single event. Order matters to avoid race 191ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * conditions. No other event is sent until the sensor get 192ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * reactivated. setDelay() is ignored. 193a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * eg: significant motion sensor 194a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * special: see details in the sensor type specification below 195a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 196a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 19756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 19816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian 19916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian/* 20016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * SENSOR_TYPE_META_DATA 20116671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * trigger-mode: n/a 20216671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * wake-up sensor: n/a 20316671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 20416671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)() 20516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 20616671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * SENSOR_TYPE_META_DATA is a special token used to populate the 20716671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * sensors_meta_data_event structure. It doesn't correspond to a physical 20816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * sensor. sensors_meta_data_event are special, they exist only inside 20916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * the HAL and are generated spontaneously, as opposed to be related to 21016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * a physical sensor. 21116671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 212af32a8d59463ddf67154cb432da232cfb185e6bcMathias Agopian * sensors_meta_data_event_t.version must be META_DATA_VERSION 213af32a8d59463ddf67154cb432da232cfb185e6bcMathias Agopian * sensors_meta_data_event_t.sensor must be 0 214af32a8d59463ddf67154cb432da232cfb185e6bcMathias Agopian * sensors_meta_data_event_t.type must be SENSOR_TYPE_META_DATA 215af32a8d59463ddf67154cb432da232cfb185e6bcMathias Agopian * sensors_meta_data_event_t.reserved must be 0 216af32a8d59463ddf67154cb432da232cfb185e6bcMathias Agopian * sensors_meta_data_event_t.timestamp must be 0 21716671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 21816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * The payload is a meta_data_event_t, where: 21916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * meta_data_event_t.what can take the following values: 22016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 22116671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * META_DATA_FLUSH_COMPLETE 22216671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * This event indicates that a previous (*flush)() call has completed for the sensor 22316671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * handle specified in meta_data_event_t.sensor. 22416671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * see (*flush)() for more details 22516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 22616671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * All other values for meta_data_event_t.what are reserved and 22716671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * must not be used. 22816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 22916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian */ 23016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian#define SENSOR_TYPE_META_DATA (0) 23116671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian 23256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 23356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_ACCELEROMETER 234a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 235a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 23656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 23756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * All values are in SI units (m/s^2) and measure the acceleration of the 23856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * device minus the force of gravity. 23956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 24056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Acceleration sensors return sensor events for all 3 axes at a constant 24156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * rate defined by setDelay(). 24256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 24356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * x: Acceleration on the x-axis 24456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * y: Acceleration on the y-axis 24556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * z: Acceleration on the z-axis 24656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 24756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Note that the readings from the accelerometer include the acceleration 24856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * due to gravity (which is opposite to the direction of the gravity vector). 24956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 25056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Examples: 25156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * The norm of <x, y, z> should be close to 0 when in free fall. 25256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 25356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * When the device lies flat on a table and is pushed on its left side 25456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * toward the right, the x acceleration value is positive. 25556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 25656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * When the device lies flat on a table, the acceleration value is +9.81, 25756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * which correspond to the acceleration of the device (0 m/s^2) minus the 25856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * force of gravity (-9.81 m/s^2). 25956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 26056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * When the device lies flat on a table and is pushed toward the sky, the 26156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * acceleration value is greater than +9.81, which correspond to the 26256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * acceleration of the device (+A m/s^2) minus the force of 26356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * gravity (-9.81 m/s^2). 26456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 26556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_ACCELEROMETER (1) 26656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 26756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 26856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_GEOMAGNETIC_FIELD 269a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 270a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 271f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 27256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * All values are in micro-Tesla (uT) and measure the geomagnetic 27356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * field in the X, Y and Z axis. 27456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 27556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Returned values include calibration mechanisms such that the vector is 27656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * aligned with the magnetic declination and heading of the earth's 27756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * geomagnetic field. 27856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 27956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Magnetic Field sensors return sensor events for all 3 axes at a constant 28056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * rate defined by setDelay(). 28156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 28256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GEOMAGNETIC_FIELD (2) 28356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_MAGNETIC_FIELD SENSOR_TYPE_GEOMAGNETIC_FIELD 28456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 28556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 286e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_ORIENTATION 287a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 288a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 289f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 290f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * All values are angles in degrees. 291f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 29266a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * Orientation sensors return sensor events for all 3 axes at a constant 29366a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * rate defined by setDelay(). 29466a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * 295f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * azimuth: angle between the magnetic north direction and the Y axis, around 296f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * the Z axis (0<=azimuth<360). 297f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 0=North, 90=East, 180=South, 270=West 298f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 299f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when 300f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * the z-axis moves toward the y-axis. 301f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 302f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * roll: Rotation around Y axis (-90<=roll<=90), with positive values when 30319ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * the x-axis moves towards the z-axis. 30419ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 30519ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * Note: For historical reasons the roll angle is positive in the clockwise 30619ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * direction (mathematically speaking, it should be positive in the 30719ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * counter-clockwise direction): 30819ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 30919ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * Z 31019ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * ^ 31119ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * (+roll) .--> | 31219ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * / | 31319ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * | | roll: rotation around Y axis 31419ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * X <-------(.) 31519ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * Y 31619ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * note that +Y == -roll 31719ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 31819ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 31919ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 320f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Note: This definition is different from yaw, pitch and roll used in aviation 321f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * where the X axis is along the long side of the plane (tail to nose). 32256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 32356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_ORIENTATION (3) 32456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 32556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 326e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_GYROSCOPE 327a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 328a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 329e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * 330b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * All values are in radians/second and measure the rate of rotation 331b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * around the X, Y and Z axis. The coordinate system is the same as is 332c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * used for the acceleration sensor. Rotation is positive in the 333c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * counter-clockwise direction (right-hand rule). That is, an observer 334c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * looking from some positive location on the x, y or z axis at a device 335c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * positioned on the origin would report positive rotation if the device 336c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * appeared to be rotating counter clockwise. Note that this is the 337c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * standard mathematical definition of positive rotation and does not agree 338c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * with the definition of roll given earlier. 339c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). 340b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * 34156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * automatic gyro-drift compensation is allowed but not required. 34256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 34356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GYROSCOPE (4) 34456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 34556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 346e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_LIGHT 347a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change 348a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 349a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * 350a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * The light sensor value is returned in SI lux units. 35156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 35256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_LIGHT (5) 35356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 35456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 355e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_PRESSURE 356a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 357a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 3581832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * 359e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * The pressure sensor return the athmospheric pressure in hectopascal (hPa) 36056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 36156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_PRESSURE (6) 36256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 36356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */ 36456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_TEMPERATURE (7) 36556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 36656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 36756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_PROXIMITY 368a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change 369a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: yes 3701832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * 37156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * The distance value is measured in centimeters. Note that some proximity 37256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * sensors only support a binary "close" or "far" measurement. In this case, 37356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * the sensor should report its maxRange value in the "far" state and a value 37456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * less than maxRange in the "near" state. 37556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 37656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_PROXIMITY (8) 37756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 37856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 379e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_GRAVITY 380a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 381a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 3823120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar * 383e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * A gravity output indicates the direction of and magnitude of gravity in 384e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2. 385e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * Units are m/s^2. The coordinate system is the same as is used for the 386e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * acceleration sensor. When the device is at rest, the output of the 387e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * gravity sensor should be identical to that of the accelerometer. 38856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 38956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GRAVITY (9) 39056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 39156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 392e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_LINEAR_ACCELERATION 393a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 394a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 3953120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar * 396e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * Indicates the linear acceleration of the device in device coordinates, 397e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * not including gravity. 398b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * 39956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * The output is conceptually: 40056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * output of TYPE_ACCELERATION - output of TYPE_GRAVITY 40142b743c85597e982ff1122b972862396f131db34Mathias Agopian * 40256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Readings on all axes should be close to 0 when device lies on a table. 40356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Units are m/s^2. 40456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * The coordinate system is the same as is used for the acceleration sensor. 40556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 40656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_LINEAR_ACCELERATION (10) 40756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 40856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 40956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 410e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_ROTATION_VECTOR 411a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 412a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 41342b743c85597e982ff1122b972862396f131db34Mathias Agopian * 41428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * The rotation vector symbolizes the orientation of the device relative to the 41528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * East-North-Up coordinates frame. It is usually obtained by integration of 41628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * accelerometer, gyroscope and magnetometer readings. 417d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * 41828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * The East-North-Up coordinate system is defined as a direct orthonormal basis 41928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * where: 42028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * - X points east and is tangential to the ground. 42128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * - Y points north and is tangential to the ground. 422d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * - Z points towards the sky and is perpendicular to the ground. 423d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * 42428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * The orientation of the phone is represented by the rotation necessary to 42528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * align the East-North-Up coordinates with the phone's coordinates. That is, 42628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * applying the rotation to the world frame (X,Y,Z) would align them with the 42728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * phone coordinates (x,y,z). 428d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * 42928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * The rotation can be seen as rotating the phone by an angle theta around 43028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * an axis rot_axis to go from the reference (East-North-Up aligned) device 43128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * orientation to the current device orientation. 43242b743c85597e982ff1122b972862396f131db34Mathias Agopian * 43328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * The rotation is encoded as the 4 (reordered) components of a unit quaternion: 43428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * sensors_event_t.data[0] = rot_axis.x*sin(theta/2) 43528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * sensors_event_t.data[1] = rot_axis.y*sin(theta/2) 43628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * sensors_event_t.data[2] = rot_axis.z*sin(theta/2) 43728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * sensors_event_t.data[3] = cos(theta/2) 43828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * where 43928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * - rot_axis.x,y,z are the North-East-Up coordinates of a unit length vector 44028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * representing the rotation axis 44128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * - theta is the rotation angle 44228f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * 44328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * The quaternion must be of norm 1 (it is a unit quaternion). Failure to ensure 44428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * this will cause erratic client behaviour. 445ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 446ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * In addition, this sensor reports an estimated heading accuracy. 44728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * sensors_event_t.data[4] = estimated_accuracy (in radians) 448ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * The heading error must be less than estimated_accuracy 95% of the time 449ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 450ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * This sensor must use a gyroscope and an accelerometer as main orientation 451ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * change input. 452ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 453ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * This sensor can also include magnetometer input to make up for gyro drift, 454ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * but it cannot be implemented using only a magnetometer. 45556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 45656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_ROTATION_VECTOR (11) 45756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 45856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 459e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_RELATIVE_HUMIDITY 460a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change 461a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 462d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch * 463d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch * A relative humidity sensor measures relative ambient air humidity and 464d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch * returns a value in percent. 46556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 46656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_RELATIVE_HUMIDITY (12) 46756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 46856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 469e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_AMBIENT_TEMPERATURE 470a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change 471a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 47254f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * 47354f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * The ambient (room) temperature in degree Celsius. 47456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 47556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13) 47656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 47756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 47856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED 479a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 480a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 48156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 482ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is 483ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * reported separately instead of being included in the measurement. 484ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Factory calibration and temperature compensation should still be applied to 485ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * the "uncalibrated" measurement. 486ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Separating away the hard iron calibration estimation allows the system to 487ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * better recover from bad hard iron estimation. 48854f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * 489ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * All values are in micro-Tesla (uT) and measure the ambient magnetic 490ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * field in the X, Y and Z axis. Assumptions that the the magnetic field 491ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * is due to the Earth's poles should be avoided. 492ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 493ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * The uncalibrated_magnetic event contains 494ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * - 3 fields for uncalibrated measurement: x_uncalib, y_uncalib, z_uncalib. 495ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Each is a component of the measured magnetic field, with soft iron 496ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * and temperature compensation applied, but not hard iron calibration. 497ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * These values should be continuous (no re-calibration should cause a jump). 498ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * - 3 fields for hard iron bias estimates: x_bias, y_bias, z_bias. 499ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Each field is a component of the estimated hard iron calibration. 5007a813e844252612cd8f7fa4e391825477d8b63d0Etienne Le Grand * They represent the offsets to apply to the calibrated readings to obtain 5017a813e844252612cd8f7fa4e391825477d8b63d0Etienne Le Grand * uncalibrated readings (x_uncalib ~= x_calibrated + x_bias) 502ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * These values are expected to jump as soon as the estimate of the hard iron 5037a813e844252612cd8f7fa4e391825477d8b63d0Etienne Le Grand * changes, and they should be stable the rest of the time. 5041144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 5051144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * If this sensor is present, then the corresponding 5061144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * SENSOR_TYPE_MAGNETIC_FIELD must be present and both must return the 5071144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * same sensor_t::name and sensor_t::vendor. 508ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 509f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * Minimum filtering should be applied to this sensor. In particular, low pass 510f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * filters should be avoided. 511f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * 512ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * See SENSOR_TYPE_MAGNETIC_FIELD for more information 513f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 51456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14) 515b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell 51656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 51756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_GAME_ROTATION_VECTOR 518a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 519a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 52056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 521ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic 522ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * field. Therefore the Y axis doesn't point north, but instead to some other 523ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * reference. That reference is allowed to drift by the same order of 524ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * magnitude than the gyroscope drift around the Z axis. 52556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 526ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * This sensor does not report an estimated heading accuracy: 52728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * sensors_event_t.data[4] is reserved and should be set to 0 528ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 529ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * In the ideal case, a phone rotated and returning to the same real-world 530ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * orientation should report the same game rotation vector 531ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * (without using the earth's geomagnetic field). 532ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 533ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * This sensor must be based on a gyroscope. It cannot be implemented using 534ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * a magnetometer. 53556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 53656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * see SENSOR_TYPE_ROTATION_VECTOR for more details 53756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 53856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15) 53956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 54056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* 54156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED 542a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous 543a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 54456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 54556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * All values are in radians/second and measure the rate of rotation 5461144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * around the X, Y and Z axis. An estimation of the drift on each axis is 5471144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * reported as well. 5481144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 5491144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * No gyro-drift compensation shall be performed. 5501144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * Factory calibration and temperature compensation should still be applied 5511144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * to the rate of rotation (angular speeds). 5521144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 5531144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * The coordinate system is the same as is 55456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * used for the acceleration sensor. Rotation is positive in the 55556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * counter-clockwise direction (right-hand rule). That is, an observer 55656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * looking from some positive location on the x, y or z axis at a device 55756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * positioned on the origin would report positive rotation if the device 55856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * appeared to be rotating counter clockwise. Note that this is the 55956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * standard mathematical definition of positive rotation and does not agree 56056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * with the definition of roll given earlier. 56156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). 56256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * 563ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Content of an uncalibrated_gyro event: (units are rad/sec) 564ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * x_uncalib : angular speed (w/o drift compensation) around the X axis 565ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * y_uncalib : angular speed (w/o drift compensation) around the Y axis 566ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * z_uncalib : angular speed (w/o drift compensation) around the Z axis 567ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * x_bias : estimated drift around X axis in rad/s 568ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * y_bias : estimated drift around Y axis in rad/s 569ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * z_bias : estimated drift around Z axis in rad/s 5701144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 5711144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * IMPLEMENTATION NOTES: 5721144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 5731144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * If the implementation is not able to estimate the drift, then this 5741144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * sensor MUST NOT be reported by this HAL. Instead, the regular 5751144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * SENSOR_TYPE_GYROSCOPE is used without drift compensation. 5761144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 5771144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * If this sensor is present, then the corresponding 5781144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * SENSOR_TYPE_GYROSCOPE must be present and both must return the 5791144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * same sensor_t::name and sensor_t::vendor. 58056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 58156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16) 58256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 583a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 584a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 585a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * SENSOR_TYPE_SIGNIFICANT_MOTION 586a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: one-shot 587a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: yes 588a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 589a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * A sensor of this type triggers an event each time significant motion 590a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * is detected and automatically disables itself. 591a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The only allowed value to return is 1.0. 592a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 5931461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * A significant motion is a motion that might lead to a change in the user 5941461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * location. 5951461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * Examples of such motions are: 5961461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * walking, biking, sitting in a moving car, coach or train. 5971461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * Examples of situations that should not trigger significant motion: 5981461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * - phone in pocket and person is not moving 5991461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * - phone is on a table, even if the table shakes a bit due to nearby traffic 6001461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * or washing machine 6011461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * 6021461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * A note on false positive / false negative / power consumption tradeoff 6031461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * - The goal of this sensor is to save power. 6041461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * - Triggering an event when the user is not moving (false positive) is costly 6051461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * in terms of power, so it should be avoided. 6061461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * - Not triggering an event when the user is moving (false negative) is 6072e7d3cd8a8bc6c4d1b977d7b08da605da36c181bEtienne Le Grand * acceptable as long as it is not done repeatedly. If the user has been 6081461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * walking for 10 seconds, not triggering an event within those 10 seconds 6091461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * is not acceptable. 610a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 611a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * IMPORTANT NOTE: this sensor type is very different from other types 612a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * in that it must work when the screen is off without the need of 613a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * holding a partial wake-lock and MUST allow the SoC to go into suspend. 614a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * When significant motion is detected, the sensor must awaken the SoC and 615a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * the event be reported. 616a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 617a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * If a particular hardware cannot support this mode of operation then this 618a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable 619a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * to "emulate" this sensor in the HAL. 620a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 621a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The whole point of this sensor type is to save power by keeping the 622a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * SoC in suspend mode when the device is at rest. 623a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 624a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * When the sensor is not activated, it must also be deactivated in the 625a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * hardware: it must not wake up the SoC anymore, even in case of 626a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * significant motion. 627a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 628a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * setDelay() has no effect and is ignored. 629a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Once a "significant motion" event is returned, a sensor of this type 630a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * must disables itself automatically, as if activate(..., 0) had been called. 631a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 632a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 633a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian#define SENSOR_TYPE_SIGNIFICANT_MOTION (17) 634a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 635a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 636a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 6372f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian * SENSOR_TYPE_STEP_DETECTOR 638a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: special 639a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 640a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 641a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * A sensor of this type triggers an event each time a step is taken 642a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * by the user. The only allowed value to return is 1.0 and an event is 643a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * generated for each step. Like with any other event, the timestamp 644a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * indicates when the event (here the step) occurred, this corresponds to when 645a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * the foot hit the ground, generating a high variation in acceleration. 646a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 647a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * While this sensor operates, it shall not disrupt any other sensors, in 648a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * particular, but not limited to, the accelerometer; which might very well 649a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * be in use as well. 650a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 651a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * This sensor must be low power. That is, if the step detection cannot be 652a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * done in hardware, this sensor should not be defined. Also, when the 6532f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian * step detector is activated and the accelerometer is not, only steps should 654a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger interrupts (not accelerometer data). 655a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 656a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * setDelay() has no impact on this sensor type 657a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 658a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 6592f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian#define SENSOR_TYPE_STEP_DETECTOR (18) 660a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 661a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 662a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 663a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * SENSOR_TYPE_STEP_COUNTER 664a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change 665a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no 666a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 667a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * A sensor of this type returns the number of steps taken by the user since 6681144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * the last reboot while activated. The value is returned as a uint64_t and is 669f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * reset to zero only on a system / android reboot. 670a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 671a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The timestamp of the event is set to the time when the first step 672a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * for that event was taken. 6732f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian * See SENSOR_TYPE_STEP_DETECTOR for the signification of the time of a step. 674a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 675a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The minimum size of the hardware's internal counter shall be 16 bits 676a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * (this restriction is here to avoid too frequent wake-ups when the 677a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * delay is very large). 678a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 679a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * IMPORTANT NOTE: this sensor type is different from other types 680a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * in that it must work when the screen is off without the need of 681a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * holding a partial wake-lock and MUST allow the SoC to go into suspend. 682a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Unlike other sensors, while in suspend mode this sensor must stay active, 683a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * no events are reported during that time but, steps continue to be 684a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * accounted for; an event will be reported as soon as the SoC resumes if 685a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * the timeout has expired. 686a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 687a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * In other words, when the screen is off and the device allowed to 688a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * go into suspend mode, we don't want to be woken up, regardless of the 689a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * setDelay() value, but the steps shall continue to be counted. 690a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 691a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The driver must however ensure that the internal step count never 692a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * overflows. It is allowed in this situation to wake the SoC up so the 693a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * driver can do the counter maintenance. 694a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 695a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * While this sensor operates, it shall not disrupt any other sensors, in 696a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * particular, but not limited to, the accelerometer; which might very well 697a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * be in use as well. 698a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 699a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * If a particular hardware cannot support these modes of operation then this 700a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * sensor type MUST NOT be reported by the HAL. ie: it is not acceptable 701a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * to "emulate" this sensor in the HAL. 702a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 703a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * This sensor must be low power. That is, if the step detection cannot be 704a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * done in hardware, this sensor should not be defined. Also, when the 705a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * step counter is activated and the accelerometer is not, only steps should 706a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger interrupts (not accelerometer data). 707a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 708a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The whole point of this sensor type is to save power by keeping the 709a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * SoC in suspend mode when the device is at rest. 710a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 711a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 712a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian#define SENSOR_TYPE_STEP_COUNTER (19) 713a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 714ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand/* 715ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR 716ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * trigger-mode: continuous 717ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * wake-up sensor: no 718ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 719ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead 720ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * of using a gyroscope. 721ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 722ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * This sensor must be based on a magnetometer. It cannot be implemented using 723f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * a gyroscope, and gyroscope input cannot be used by this sensor, as the 724f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * goal of this sensor is to be low power. 725f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * The accelerometer can be (and usually is) used. 726ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 727ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Just like SENSOR_TYPE_ROTATION_VECTOR, this sensor reports an estimated 728ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * heading accuracy: 72928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * sensors_event_t.data[4] = estimated_accuracy (in radians) 730ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * The heading error must be less than estimated_accuracy 95% of the time 731ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 732ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * see SENSOR_TYPE_ROTATION_VECTOR for more details 733ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand */ 734ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20) 735a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 73656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/** 73756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Values returned by the accelerometer in various locations in the universe. 73856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * all values are in SI units (m/s^2) 73956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 74056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define GRAVITY_SUN (275.0f) 74156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define GRAVITY_EARTH (9.80665f) 74256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 74356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/** Maximum magnetic field on Earth's surface */ 74456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define MAGNETIC_FIELD_EARTH_MAX (60.0f) 74556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 74656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/** Minimum magnetic field on Earth's surface */ 74756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define MAGNETIC_FIELD_EARTH_MIN (30.0f) 74856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 74956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 75056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/** 75156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * status of orientation sensor 75256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 75356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 75456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_STATUS_UNRELIABLE 0 75556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_STATUS_ACCURACY_LOW 1 75656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_STATUS_ACCURACY_MEDIUM 2 75756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_STATUS_ACCURACY_HIGH 3 75856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 75956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian 76056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/** 76156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * sensor event data 76256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */ 763f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projecttypedef struct { 764f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project union { 765f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float v[3]; 766f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project struct { 767f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float x; 768f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float y; 769f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float z; 770f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project }; 771f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project struct { 772f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float azimuth; 773f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float pitch; 774f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float roll; 775f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project }; 776f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project }; 777f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int8_t status; 778f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project uint8_t reserved[3]; 779f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project} sensors_vec_t; 780f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 781f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 782ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * uncalibrated gyroscope and magnetometer event data 783ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand */ 784ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grandtypedef struct { 78528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand union { 78628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand float uncalib[3]; 78728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand struct { 78828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand float x_uncalib; 78928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand float y_uncalib; 79028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand float z_uncalib; 79128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand }; 79228f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand }; 79328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand union { 79428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand float bias[3]; 79528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand struct { 79628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand float x_bias; 79728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand float y_bias; 79828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand float z_bias; 79928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand }; 80028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand }; 801ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand} uncalibrated_event_t; 802ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand 80316671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopiantypedef struct meta_data_event { 80416671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian int32_t what; 80516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian int32_t sensor; 80616671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian} meta_data_event_t; 80716671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian 808ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand/** 809f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Union of the various types of sensor data 810f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * that can be returned. 811f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 812cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopiantypedef struct sensors_event_t { 813cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* must be sizeof(struct sensors_event_t) */ 814cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int32_t version; 815cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 816cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* sensor identifier */ 817cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int32_t sensor; 818cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 819cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* sensor type */ 820cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int32_t type; 821cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 822cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* reserved */ 823cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int32_t reserved0; 824cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 825cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* time is in nanosecond */ 826cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int64_t timestamp; 827cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 828cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian union { 82927e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian union { 83027e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian float data[16]; 831cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 83227e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* acceleration values are in meter per second per second (m/s^2) */ 83327e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian sensors_vec_t acceleration; 834cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 83527e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* magnetic vector values are in micro-Tesla (uT) */ 83627e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian sensors_vec_t magnetic; 837cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 83827e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* orientation values are in degrees */ 83927e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian sensors_vec_t orientation; 840cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 84127e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* gyroscope values are in rad/s */ 84227e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian sensors_vec_t gyro; 8433120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar 84427e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* temperature is in degrees centigrade (Celsius) */ 84527e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian float temperature; 846cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 84727e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* distance in centimeters */ 84827e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian float distance; 849cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 85027e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* light in SI lux units */ 85127e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian float light; 8521832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian 85327e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* pressure in hectopascal (hPa) */ 85427e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian float pressure; 855d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch 85627e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* relative humidity in percent */ 85727e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian float relative_humidity; 858a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 85927e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* uncalibrated gyroscope values are in rad/s */ 86027e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian uncalibrated_event_t uncalibrated_gyro; 861ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand 86227e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* uncalibrated magnetometer values are in micro-Teslas */ 86327e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian uncalibrated_event_t uncalibrated_magnetic; 86416671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian 86516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian /* this is a special event. see SENSOR_TYPE_META_DATA above. 86616671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * sensors_meta_data_event_t events are all reported with a type of 86716671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * SENSOR_TYPE_META_DATA. The handle is ignored and must be zero. 86816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian */ 86916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian meta_data_event_t meta_data; 87027e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian }; 87127e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian 87227e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian union { 87327e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian uint64_t data[8]; 874ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand 87527e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian /* step-counter */ 87627e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian uint64_t step_counter; 87727e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian } u64; 878cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian }; 87927e16688ec7496e72304d093a24d9c1d4fd37be5Mathias Agopian uint32_t reserved1[4]; 880cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian} sensors_event_t; 881cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 882cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 88316671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian/* see SENSOR_TYPE_META_DATA */ 88416671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopiantypedef sensors_event_t sensors_meta_data_event_t; 88516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian 886cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 887f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensor_t; 888f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 889f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 890f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 891f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * and the fields of this data structure must begin with hw_module_t 892f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * followed by module specific information. 893f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 894f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensors_module_t { 895f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project struct hw_module_t common; 896f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 897f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /** 898f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Enumerate all available sensors. The list is returned in "list". 899f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * @return number of sensors in the list 900f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 901f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int (*get_sensors_list)(struct sensors_module_t* module, 902f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project struct sensor_t const** list); 903f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project}; 904f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 905f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensor_t { 9061144bea332fb24789712062bb35fe762f2f17505Mathias Agopian 9071144bea332fb24789712062bb35fe762f2f17505Mathias Agopian /* Name of this sensor. 9081144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * All sensors of the same "type" must have a different "name". 9091144bea332fb24789712062bb35fe762f2f17505Mathias Agopian */ 910f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project const char* name; 911a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 912f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* vendor of the hardware part */ 913f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project const char* vendor; 914a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 915e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian /* version of the hardware part + driver. The value of this field 916e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * must increase when the driver is updated in a way that changes the 917e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * output of this sensor. This is important for fused sensors when the 918e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * fusion algorithm is updated. 919f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 920f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int version; 921a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 922a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian /* handle that identifies this sensors. This handle is used to reference 923a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * this sensor throughout the HAL API. 924f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 925f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int handle; 926a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 927f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* this sensor's type. */ 928f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int type; 929a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 930a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian /* maximum range of this sensor's value in SI units */ 931f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float maxRange; 932a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 933f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* smallest difference between two values reported by this sensor */ 934f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float resolution; 935a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 936f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* rough estimate of this sensor's power consumption in mA */ 937f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float power; 938a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 939a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian /* this value depends on the trigger mode: 940a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 941a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * continuous: minimum sample period allowed in microseconds 942a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * on-change : 0 943a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * one-shot :-1 944a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * special : 0, unless otherwise noted 945a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 9461511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian int32_t minDelay; 947a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 94816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian /* number of events reserved for this sensor in the batch mode FIFO. 94916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * If there is a dedicated FIFO for this sensor, then this is the 95016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * size of this FIFO. If the FIFO is shared with other sensors, 95116671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * this is the size reserved for that sensor and it can be zero. 95216671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian */ 95316671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian uint32_t fifoReservedEventCount; 95416671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian 95516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian /* maximum number of events of this sensor that could be batched. 95616671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * This is especially relevant when the FIFO is shared between 95716671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * several sensors; this value is then set to the size of that FIFO. 95816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian */ 95916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian uint32_t fifoMaxEventCount; 96016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian 961f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* reserved fields, must be zero */ 96216671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian void* reserved[6]; 963f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project}; 964f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 965f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 966a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 967a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1 968a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * and is present for backward binary and source compatibility. 969a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * (see documentation of the hooks in struct sensors_poll_device_1 below) 970f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 971b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstruct sensors_poll_device_t { 972b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian struct hw_device_t common; 973b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian int (*activate)(struct sensors_poll_device_t *dev, 974b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian int handle, int enabled); 975a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian int (*setDelay)(struct sensors_poll_device_t *dev, 976a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian int handle, int64_t ns); 977a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian int (*poll)(struct sensors_poll_device_t *dev, 978a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian sensors_event_t* data, int count); 979a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian}; 980b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 981a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* 982a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0 983a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 984a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopiantypedef struct sensors_poll_device_1 { 985a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian union { 986a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian /* sensors_poll_device_1 is compatible with sensors_poll_device_t, 987a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * and can be down-cast to it 988a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 9891082c0b54c21c220e975f1c714e41f9183b366d1Andrew Hsieh struct sensors_poll_device_t v0; 990a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 991a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian struct { 992a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian struct hw_device_t common; 993a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 994a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian /* Activate/de-activate one sensor. 995a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 996a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * handle is the handle of the sensor to change. 997a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * enabled set to 1 to enable, or 0 to disable the sensor. 998a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 999f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * if enabled is set to 1, the sensor is activated even if 1000f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * setDelay() wasn't called before. In this case, a default rate 1001f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * should be used. 1002f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * 1003a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * unless otherwise noted in the sensor types definitions, an 1004a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * activated sensor never prevents the SoC to go into suspend 1005a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * mode; that is, the HAL shall not hold a partial wake-lock on 1006a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * behalf of applications. 1007a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1008a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * one-shot sensors de-activate themselves automatically upon 1009a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * receiving an event and they must still accept to be deactivated 1010a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * through a call to activate(..., ..., 0). 1011a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1012f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * if "enabled" is 1 and the sensor is already activated, this 1013a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * function is a no-op and succeeds. 1014a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1015f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * if "enabled" is 0 and the sensor is already de-activated, 1016a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * this function is a no-op and succeeds. 1017a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1018a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * return 0 on success, negative errno code otherwise 1019a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 1020a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian int (*activate)(struct sensors_poll_device_t *dev, 1021a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian int handle, int enabled); 1022a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 1023a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian /** 10241144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * Set the events's period in nanoseconds for a given sensor. 1025a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 10261144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * What the period_ns parameter means depends on the specified 1027a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * sensor's trigger mode: 1028a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1029a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * continuous: setDelay() sets the sampling rate. 1030a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * on-change: setDelay() limits the delivery rate of events 1031a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * one-shot: setDelay() is ignored. it has no effect. 1032a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * special: see specific sensor type definitions 1033a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1034a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * For continuous and on-change sensors, if the requested value is 1035a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * less than sensor_t::minDelay, then it's silently clamped to 1036a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * sensor_t::minDelay unless sensor_t::minDelay is 0, in which 1037a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * case it is clamped to >= 1ms. 1038a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1039f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * setDelay will not be called when the sensor is in batching mode. 1040f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * In this case, batch() will be called with the new period. 1041f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * 1042a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * @return 0 if successful, < 0 on error 1043a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 1044a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian int (*setDelay)(struct sensors_poll_device_t *dev, 10451144bea332fb24789712062bb35fe762f2f17505Mathias Agopian int handle, int64_t period_ns); 1046a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 1047a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian /** 1048a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Returns an array of sensor data. 1049a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * This function must block until events are available. 1050a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1051a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * return the number of events read on success, or -errno in case 1052a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * of an error. 1053a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1054a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The number of events returned in data must be less or equal 105528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * to the "count" argument. 1056a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1057a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * This function shall never return 0 (no event). 1058a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */ 1059a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian int (*poll)(struct sensors_poll_device_t *dev, 1060a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian sensors_event_t* data, int count); 1061a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian }; 1062a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian }; 1063a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 1064a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 1065a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian /* 10661144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * Enables batch mode for the given sensor and sets the delay between events 1067a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1068a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * A timeout value of zero disables batch mode for the given sensor. 1069a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 10701144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * The period_ns parameter is equivalent to calling setDelay() -- this 10711144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * function both enables or disables the batch mode AND sets the events's 10721144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * period in nanosecond. See setDelay() above for a detailed explanation of 10731144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * the period_ns parameter. 10741144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 107528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * BATCH MODE: 107628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * ----------- 107728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * In non-batch mode, all sensor events must be reported as soon as they 107828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * are detected. For example, an accelerometer activated at 50Hz will 107928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * trigger interrupts 50 times per second. 108028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * While in batch mode, sensor events do not need to be reported as soon 108128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * as they are detected. They can be temporarily stored in batches and 108228f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * reported in batches, as long as no event is delayed by more than 108328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * "timeout" nanoseconds. That is, all events since the previous batch 108428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * are recorded and returned all at once. This allows to reduce the amount 108528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * of interrupts sent to the SoC, and allow the SoC to switch to a lower 108628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * power state (Idle) while the sensor is capturing and batching data. 1087a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1088a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * setDelay() is not affected and it behaves as usual. 1089a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1090a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Each event has a timestamp associated with it, the timestamp 1091a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * must be accurate and correspond to the time at which the event 1092a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * physically happened. 1093a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 109428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * Batching does not modify the behavior of poll(): batches from different 109528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * sensors can be interleaved and split. As usual, all events from the same 109628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * sensor are time-ordered. 109728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * 109828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * BEHAVIOUR OUTSIDE OF SUSPEND MODE: 109928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * ---------------------------------- 110028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * 110128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * When the SoC is awake (not in suspend mode), events must be reported in 110228f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * batches at least every "timeout". No event shall be dropped or lost. 1103a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * If internal h/w FIFOs fill-up before the timeout, then events are 110428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * reported at that point to ensure no event is lost. 11051144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 11061144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 110728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * NORMAL BEHAVIOR IN SUSPEND MODE: 110828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * --------------------------------- 1109a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 111028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * By default, batch mode doesn't significantly change the interaction with 111128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * suspend mode. That is, sensors must continue to allow the SoC to 1112a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * go into suspend mode and sensors must stay active to fill their 111328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * internal FIFO. In this mode, when the FIFO fills up, it shall wrap 1114a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * around (basically behave like a circular buffer, overwriting events). 1115a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * As soon as the SoC comes out of suspend mode, a batch is produced with 1116a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * as much as the recent history as possible, and batch operation 1117a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * resumes as usual. 1118a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1119a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The behavior described above allows applications to record the recent 1120a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * history of a set of sensor while keeping the SoC into suspend. It 1121a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * also allows the hardware to not have to rely on a wake-up interrupt line. 1122a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 112328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * WAKE_UPON_FIFO_FULL BEHAVIOR IN SUSPEND MODE: 112428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * ---------------------------------------------- 1125a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 112628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * There are cases, however, where an application cannot afford to lose 112728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * any events, even when the device goes into suspend mode. 112828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * For a given rate, if a sensor has the capability to store at least 10 112928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * seconds worth of events in its FIFO and is able to wake up the Soc, it 113028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * can implement an optional secondary mode: the WAKE_UPON_FIFO_FULL mode. 113128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * 113228f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * The caller will set the SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag to 113328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * activate this mode. If the sensor does not support this mode, batch() 113428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * will fail when the flag is set. 113528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * 113628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * When running with the WAKE_UPON_FIFO_FULL flag set, no events can be 113728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * lost. When the FIFO is getting full, the sensor must wake up the SoC from 113828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * suspend and return a batch before the FIFO fills-up. 113928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * Depending on the device, it might take a few miliseconds for the SoC to 114028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * entirely come out of suspend and start flushing the FIFO. Enough head 114128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * room must be allocated in the FIFO to allow the device to entirely come 114228f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * out of suspend without the FIFO overflowing (no events shall be lost). 114328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * 114428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * Implementing the WAKE_UPON_FIFO_FULL mode is optional. 114528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * If the hardware cannot support this mode, or if the physical 1146a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * FIFO is so small that the device would never be allowed to go into 11471144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * suspend for at least 10 seconds, then this function MUST fail when 11481144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of 11491144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * the value of the timeout parameter. 1150a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 115128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * 11521144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * DRY RUN: 11531144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * -------- 1154a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1155a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns 11561144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * without modifying the batch mode or the event period and has no side 11571144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * effects, but returns errors as usual (as it would if this flag was 11581144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * not set). This flag is used to check if batch mode is available for a 11591144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * given configuration -- in particular for a given sensor at a given rate. 11601144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 1161a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1162a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Return values: 11631144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * -------------- 11641144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 11651144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * Because sensors must be independent, the return value must not depend 11661144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * on the state of the system (whether another sensor is on or not), 11671144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words, 11681144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * if a batch call with SENSORS_BATCH_DRY_RUN is successful, 11691144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * the same call without SENSORS_BATCH_DRY_RUN must succeed as well). 1170a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1171f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * When timeout is not 0: 1172f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * If successful, 0 is returned. 1173f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * If the specified sensor doesn't support batch mode, return -EINVAL. 1174f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * If the specified sensor's trigger-mode is one-shot, return -EINVAL. 1175f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * If WAKE_UPON_FIFO_FULL is specified and the specified sensor's internal 1176f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * FIFO is too small to store at least 10 seconds worth of data at the 1177f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * given rate, -EINVAL is returned. Note that as stated above, this has to 1178f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * be determined at compile time, and not based on the state of the 1179f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * system. 1180f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * If some other constraints above cannot be satisfied, return -EINVAL. 1181a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 11821144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * Note: the timeout parameter, when > 0, has no impact on whether this 11831144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * function succeeds or fails. 11841144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * 1185f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * When timeout is 0: 1186f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * The caller will never set the wake_upon_fifo_full flag. 1187f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * The function must succeed, and batch mode must be deactivated. 1188f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * 1189f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * Independently of whether DRY_RUN is specified, When the call to batch() 1190f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * fails, no state should be changed. In particular, a failed call to 1191f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * batch() should not change the rate of the sensor. Example: 1192f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * setDelay(..., 10ms) 1193f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * batch(..., 20ms, ...) fails 1194f770b7a9b9315fa924de224af188c314a474eb10Etienne Le Grand * rate should stay 10ms. 1195a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1196a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 1197a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * IMPLEMENTATION NOTES: 11981144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * --------------------- 1199b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * 120028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * Batch mode, if supported, should happen at the hardware level, 1201a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * typically using hardware FIFOs. In particular, it SHALL NOT be 1202a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * implemented in the HAL, as this would be counter productive. 1203a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The goal here is to save significant amounts of power. 1204a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * 120528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * In some implementations, events from several sensors can share the 120628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * same physical FIFO. In that case, all events in the FIFO can be sent and 120728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * processed by the HAL as soon as one batch must be reported. 120828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * For example, if the following sensors are activated: 120928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * - accelerometer batched with timeout = 20s 121028f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * - gyroscope batched with timeout = 5s 121128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * then the accelerometer batches can be reported at the same time the 121228f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * gyroscope batches are reported (every 5 seconds) 121328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * 121428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * Batch mode can be enabled or disabled at any time, in particular 121528f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * while the specified sensor is already enabled, and this shall not 1216a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * result in the loss of events. 1217b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * 1218ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS: 1219ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * --------------------------------------------------------- 1220ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 1221ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * On platforms on which hardware fifo size is limited, the system designers 1222ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * might have to choose how much fifo to reserve for each sensor. To help 122328f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * with this choice, here is a list of applications made possible when 1224ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * batching is implemented on the different sensors. 1225ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 1226ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * High value: Low power pedestrian dead reckoning 1227ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Target batching time: 20 seconds to 1 minute 1228ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Sensors to batch: 1229ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * - Step detector 1230ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * - Rotation vector or game rotation vector at 5Hz 123128f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * Gives us step and heading while letting the SoC go to Suspend. 1232ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 1233ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * High value: Medium power activity/gesture recognition 1234ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Target batching time: 3 seconds 1235ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Sensors to batch: accelerometer between 20Hz and 50Hz 1236ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Allows recognizing arbitrary activities and gestures without having 123728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * to keep the SoC fully awake while the data is collected. 1238ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 1239ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Medium-high value: Interrupt load reduction 1240ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Target batching time: < 1 second 1241ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Sensors to batch: any high frequency sensor. 1242ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * If the gyroscope is set at 800Hz, even batching just 10 gyro events can 1243ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * reduce the number of interrupts from 800/second to 80/second. 1244ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 1245ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Medium value: Continuous low frequency data collection 1246ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Target batching time: > 1 minute 1247ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Sensors to batch: barometer, humidity sensor, other low frequency 1248ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * sensors. 1249ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Allows creating monitoring applications at low power. 1250ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * 1251ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Medium value: Continuous full-sensors collection 1252ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Target batching time: > 1 minute 1253ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Sensors to batch: all, at high frequencies 125428f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * Allows full collection of sensor data while leaving the SoC in 1255ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * suspend mode. Only to consider if fifo space is not an issue. 125628f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * 125728f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * In each of the cases above, if WAKE_UPON_FIFO_FULL is implemented, the 125828f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * applications might decide to let the SoC go to suspend, allowing for even 125928f04113f56a05560fc6074579ab5a4fcd424a0fEtienne Le Grand * more power savings. 1260b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian */ 1261a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian int (*batch)(struct sensors_poll_device_1* dev, 12621144bea332fb24789712062bb35fe762f2f17505Mathias Agopian int handle, int flags, int64_t period_ns, int64_t timeout); 1263a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 126416671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian /* 126516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t) 126616671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * to the end of the "batch mode" FIFO for the specified sensor and flushes 126716671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * the FIFO; those events are delivered as usual (i.e.: as if the batch 126816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * timeout had expired) and removed from the FIFO. 126916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 127016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * See the META_DATA_FLUSH_COMPLETE section for details about the 127116671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * META_DATA_FLUSH_COMPLETE event. 127216671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 127316671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * The flush happens asynchronously (i.e.: this function must return 127416671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * immediately). 127516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 127616671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * If the implementation uses a single FIFO for several sensors, that 127716671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * FIFO is flushed and the META_DATA_FLUSH_COMPLETE event is added only 127816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * for the specified sensor. 127916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 128016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * If the specified sensor wasn't in batch mode, flush succeeds and 128116671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * promptly sends a META_DATA_FLUSH_COMPLETE event for that sensor. 128216671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 128316671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * If the FIFO was empty at the time of the call, flush returns 128416671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 0 (success) and promptly sends a META_DATA_FLUSH_COMPLETE event 128516671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * for that sensor. 128616671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 128716671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * If the specified sensor wasn't enabled, flush returns -EINVAL. 128816671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * 128916671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian * return 0 on success, negative errno code otherwise. 129016671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian */ 129116671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian int (*flush)(struct sensors_poll_device_1* dev, int handle); 129216671c5519003d3be0eab34a8a78fecac9e941a3Mathias Agopian 1293a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian void (*reserved_procs[8])(void); 1294a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 1295a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian} sensors_poll_device_1_t; 1296a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 1297a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 1298b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 1299f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** convenience API for opening and closing a device */ 1300f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 1301b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstatic inline int sensors_open(const struct hw_module_t* module, 1302b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian struct sensors_poll_device_t** device) { 1303b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian return module->methods->open(module, 1304b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); 1305b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian} 1306b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 1307b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstatic inline int sensors_close(struct sensors_poll_device_t* device) { 1308b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian return device->common.close(&device->common); 1309b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian} 1310b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 1311a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopianstatic inline int sensors_open_1(const struct hw_module_t* module, 13121082c0b54c21c220e975f1c714e41f9183b366d1Andrew Hsieh sensors_poll_device_1_t** device) { 1313a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian return module->methods->open(module, 1314a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); 1315a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian} 1316a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 13171082c0b54c21c220e975f1c714e41f9183b366d1Andrew Hsiehstatic inline int sensors_close_1(sensors_poll_device_1_t* device) { 1318a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian return device->common.close(&device->common); 1319a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian} 1320a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian 1321f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project__END_DECLS 1322f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 1323f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#endif // ANDROID_SENSORS_INTERFACE_H 1324