sensors.h revision 1461f28f503d75c6eda29ec9bbd5db33b44f65fe
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)
3556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
36f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
37f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * The id of this module
38f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
39f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HARDWARE_MODULE_ID "sensors"
40f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
41f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
42f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Name of the sensors device to open
43f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
44b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian#define SENSORS_HARDWARE_POLL       "poll"
45f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
46f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
47f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
48f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * A Handle identifies a given sensors. The handle is used to activate
49f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * and/or deactivate sensors.
50f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * In this version of the API there can only be 256 handles.
51f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
52f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HANDLE_BASE             0
53f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HANDLE_BITS             8
54f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HANDLE_COUNT            (1<<SENSORS_HANDLE_BITS)
55f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
56f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
57a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/* attributes queriable with query() */
58a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopianenum {
59a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    /*
60a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * Availability: SENSORS_DEVICE_API_VERSION_1_0
61a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * return the maximum number of events that can be returned
62a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * in a single call to (*poll)(). This value is used by the
63a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * framework to adequately dimension the buffer passed to
64a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * (*poll)(), note that (*poll)() still needs to pay attention to
65a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * the count parameter passed to it, it cannot blindly expect that
66a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * this value will be used for all calls to (*poll)().
67a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
68a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * Generally this value should be set to match the sum of the internal
69a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * FIFOs of all available sensors.
70a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     */
71a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    SENSORS_QUERY_MAX_EVENTS_BATCH_COUNT     = 0
72a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian};
73a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
74a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
75a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * flags for (*batch)()
76a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Availability: SENSORS_DEVICE_API_VERSION_1_0
77a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * see (*batch)() documentation for details
78a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */
79a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopianenum {
80a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    SENSORS_BATCH_DRY_RUN               = 0x00000001,
81a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    SENSORS_BATCH_WAKE_UPON_FIFO_FULL   = 0x00000002
82a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian};
83a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
84f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
8556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Definition of the axis used by the sensor HAL API
86f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
87f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * This API is relative to the screen of the device in its default orientation,
88f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * that is, if the device can be used in portrait or landscape, this API
89f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * is only relative to the NATURAL orientation of the screen. In other words,
90f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * the axis are not swapped when the device's screen orientation changes.
91f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Higher level services /may/ perform this transformation.
92f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
93f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *   x<0         x>0
94f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *                ^
95f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *                |
96f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    +-----------+-->  y>0
97f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |
98f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |
99f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |
100f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |   / z<0
101f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |  /
102f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           | /
103f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    O-----------+/
104f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |[]  [ ]  []/
105f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    +----------/+     y<0
106f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *              /
107f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *             /
108f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *           |/ z>0 (toward the sky)
109f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
110f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    O: Origin (x=0,y=0,z=0)
111f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
11256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
11356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
114a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
115a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Interaction with suspend mode
116a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
117a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Unless otherwise noted, an enabled sensor shall not prevent the
118a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * SoC to go into suspend mode. It is the responsibility of applications
119a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * to keep a partial wake-lock should they wish to receive sensor
120a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * events while the screen is off. While in suspend mode, and unless
121a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * otherwise noted, enabled sensors' events are lost.
122a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
123a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Note that conceptually, the sensor itself is not de-activated while in
124a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * suspend mode -- it's just that the data it returns are lost. As soon as
125a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * the SoC gets out of suspend mode, operations resume as usual. Of course,
126a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * in practice sensors shall be disabled while in suspend mode to
127a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * save power, unless batch mode is active, in which case they must
128a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * continue fill their internal FIFO (see the documentation of batch() to
129a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * learn how suspend interacts with batch mode).
130a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
131a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * In batch mode and only when the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is
1321144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * set and supported, the specified sensor must be able to wake-up the SoC and
1331144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * be able to buffer at least 10 seconds worth of the requested sensor events.
134a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
135a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * There are notable exceptions to this behavior, which are sensor-dependent
136a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * (see sensor types definitions below)
137a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
138a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
139a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The sensor type documentation below specifies the wake-up behavior of
140a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * each sensor:
141a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *   wake-up: yes     this sensor must wake-up the SoC to deliver events
142a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *   wake-up: no      this sensor shall not wake-up the SoC, events are dropped
143a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
144a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */
145a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
146a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
147a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Sensor type
148a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
149a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Each sensor has a type which defines what this sensor measures and how
150a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * measures are reported. All types are defined below.
151a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */
152a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
153a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
154a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Sensor fusion and virtual sensors
155a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
156a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Many sensor types are or can be implemented as virtual sensors from
157a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * physical sensors on the device. For instance the rotation vector sensor,
1582f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian * orientation sensor, step-detector, step-counter, etc...
159a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
160a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * From the point of view of this API these virtual sensors MUST appear as
161a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * real, individual sensors. It is the responsibility of the driver and HAL
162a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * to make sure this is the case.
163a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
164a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * In particular, all sensors must be able to function concurrently.
165a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * For example, if defining both an accelerometer and a step counter,
166a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * then both must be able to work concurrently.
167a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */
168a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
169a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
170a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Trigger modes
171a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
172a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Sensors can report events in different ways called trigger modes,
173a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * each sensor type has one and only one trigger mode associated to it.
174a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * Currently there are four trigger modes defined:
175a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
176a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * continuous: events are reported at a constant rate defined by setDelay().
177a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *             eg: accelerometers, gyroscopes.
178a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * on-change:  events are reported only if the sensor's value has changed.
179a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *             setDelay() is used to set a lower limit to the reporting
180a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *             period (minimum time between two events).
181a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *             The HAL must return an event immediately when an on-change
182a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *             sensor is activated.
183a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *             eg: proximity, light sensors
184ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * one-shot:   upon detection of an event, the sensor deactivates itself and
185ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *             then sends a single event. Order matters to avoid race
186ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *             conditions. No other event is sent until the sensor get
187ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *             reactivated. setDelay() is ignored.
188a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *             eg: significant motion sensor
189a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * special:    see details in the sensor type specification below
190a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
191a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */
19256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
19356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
19456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_ACCELEROMETER
195a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
196a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
19756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
19856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  All values are in SI units (m/s^2) and measure the acceleration of the
19956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  device minus the force of gravity.
20056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
20156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  Acceleration sensors return sensor events for all 3 axes at a constant
20256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  rate defined by setDelay().
20356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
20456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  x: Acceleration on the x-axis
20556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  y: Acceleration on the y-axis
20656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  z: Acceleration on the z-axis
20756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
20856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Note that the readings from the accelerometer include the acceleration
20956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * due to gravity (which is opposite to the direction of the gravity vector).
21056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
21156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  Examples:
21256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    The norm of <x, y, z>  should be close to 0 when in free fall.
21356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
21456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    When the device lies flat on a table and is pushed on its left side
21556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    toward the right, the x acceleration value is positive.
21656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
21756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    When the device lies flat on a table, the acceleration value is +9.81,
21856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    which correspond to the acceleration of the device (0 m/s^2) minus the
21956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    force of gravity (-9.81 m/s^2).
22056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
22156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    When the device lies flat on a table and is pushed toward the sky, the
22256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    acceleration value is greater than +9.81, which correspond to the
22356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    acceleration of the device (+A m/s^2) minus the force of
22456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    gravity (-9.81 m/s^2).
22556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
22656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_ACCELEROMETER                    (1)
22756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
22856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
22956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_GEOMAGNETIC_FIELD
230a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
231a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
232f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
23356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  All values are in micro-Tesla (uT) and measure the geomagnetic
23456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  field in the X, Y and Z axis.
23556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
23656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  Returned values include calibration mechanisms such that the vector is
23756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  aligned with the magnetic declination and heading of the earth's
23856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  geomagnetic field.
23956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
24056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  Magnetic Field sensors return sensor events for all 3 axes at a constant
24156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  rate defined by setDelay().
24256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
24356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GEOMAGNETIC_FIELD                (2)
24456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_MAGNETIC_FIELD  SENSOR_TYPE_GEOMAGNETIC_FIELD
24556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
24656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
247e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_ORIENTATION
248a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
249a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
250f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
251f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * All values are angles in degrees.
252f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
25366a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * Orientation sensors return sensor events for all 3 axes at a constant
25466a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * rate defined by setDelay().
25566a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *
256f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * azimuth: angle between the magnetic north direction and the Y axis, around
257f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  the Z axis (0<=azimuth<360).
258f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *      0=North, 90=East, 180=South, 270=West
259f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
260f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when
261f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  the z-axis moves toward the y-axis.
262f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
263f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * roll: Rotation around Y axis (-90<=roll<=90), with positive values when
26419ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *  the x-axis moves towards the z-axis.
26519ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
26619ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * Note: For historical reasons the roll angle is positive in the clockwise
26719ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *  direction (mathematically speaking, it should be positive in the
26819ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *  counter-clockwise direction):
26919ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
27019ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *                Z
27119ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *                ^
27219ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *  (+roll)  .--> |
27319ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *          /     |
27419ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *         |      |  roll: rotation around Y axis
27519ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *     X <-------(.)
27619ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *                 Y
27719ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *       note that +Y == -roll
27819ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
27919ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
28019ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
281f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Note: This definition is different from yaw, pitch and roll used in aviation
282f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  where the X axis is along the long side of the plane (tail to nose).
28356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
28456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_ORIENTATION                      (3)
28556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
28656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
287e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_GYROSCOPE
288a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
289a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
290e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian *
291b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell *  All values are in radians/second and measure the rate of rotation
292b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell *  around the X, Y and Z axis.  The coordinate system is the same as is
293c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian *  used for the acceleration sensor. Rotation is positive in the
294c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian *  counter-clockwise direction (right-hand rule). That is, an observer
295c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian *  looking from some positive location on the x, y or z axis at a device
296c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian *  positioned on the origin would report positive rotation if the device
297c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian *  appeared to be rotating counter clockwise. Note that this is the
298c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian *  standard mathematical definition of positive rotation and does not agree
299c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian *  with the definition of roll given earlier.
300c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian *  The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
301b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell *
30256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  automatic gyro-drift compensation is allowed but not required.
30356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
30456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GYROSCOPE                        (4)
30556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
30656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
307e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_LIGHT
308a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change
309a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
310a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood *
311a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * The light sensor value is returned in SI lux units.
31256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
31356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_LIGHT                            (5)
31456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
31556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
316e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_PRESSURE
317a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
318a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
3191832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian *
320e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
32156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
32256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_PRESSURE                         (6)
32356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
32456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/* SENSOR_TYPE_TEMPERATURE is deprecated in the HAL */
32556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_TEMPERATURE                      (7)
32656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
32756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
32856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_PROXIMITY
329a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change
330a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: yes
3311832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian *
33256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * The distance value is measured in centimeters.  Note that some proximity
33356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * sensors only support a binary "close" or "far" measurement.  In this case,
33456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * the sensor should report its maxRange value in the "far" state and a value
33556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * less than maxRange in the "near" state.
33656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
33756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_PROXIMITY                        (8)
33856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
33956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
340e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_GRAVITY
341a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
342a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
3433120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar *
344e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * A gravity output indicates the direction of and magnitude of gravity in
345e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * the devices's coordinates.  On Earth, the magnitude is 9.8 m/s^2.
346e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * Units are m/s^2.  The coordinate system is the same as is used for the
347e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * acceleration sensor. When the device is at rest, the output of the
348e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * gravity sensor should be identical to that of the accelerometer.
34956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
35056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GRAVITY                          (9)
35156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
35256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
353e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_LINEAR_ACCELERATION
354a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
355a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
3563120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar *
357e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * Indicates the linear acceleration of the device in device coordinates,
358e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * not including gravity.
359b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell *
36056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * The output is conceptually:
36156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *    output of TYPE_ACCELERATION - output of TYPE_GRAVITY
36242b743c85597e982ff1122b972862396f131db34Mathias Agopian *
36356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Readings on all axes should be close to 0 when device lies on a table.
36456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Units are m/s^2.
36556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * The coordinate system is the same as is used for the acceleration sensor.
36656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
36756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_LINEAR_ACCELERATION             (10)
36856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
36956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
37056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
371e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_ROTATION_VECTOR
372a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
373a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
37442b743c85597e982ff1122b972862396f131db34Mathias Agopian *
375b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * A rotation vector represents the orientation of the device as a combination
376b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * of an angle and an axis, in which the device has rotated through an angle
377b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * theta around an axis <x, y, z>. The three elements of the rotation vector
378b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * are <x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>, such that the magnitude
379b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * of the rotation vector is equal to sin(theta/2), and the direction of the
380b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * rotation vector is equal to the direction of the axis of rotation. The three
381b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * elements of the rotation vector are equal to the last three components of a
382ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * unit quaternion
383ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *   <cos(theta/2), x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>.
384ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * Elements of the rotation vector are unitless.  The x, y, and z axis are
385ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * defined in the same way as for the acceleration sensor.
38642b743c85597e982ff1122b972862396f131db34Mathias Agopian *
387d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * The reference coordinate system is defined as a direct orthonormal basis,
388d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * where:
389d93ff971bd507e92ac81c149079906d2123795afMathias Agopian *
390d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * - X is defined as the vector product Y.Z (It is tangential to
391d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * the ground at the device's current location and roughly points East).
392d93ff971bd507e92ac81c149079906d2123795afMathias Agopian *
393d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * - Y is tangential to the ground at the device's current location and
394d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * points towards the magnetic North Pole.
395d93ff971bd507e92ac81c149079906d2123795afMathias Agopian *
396d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * - Z points towards the sky and is perpendicular to the ground.
397d93ff971bd507e92ac81c149079906d2123795afMathias Agopian *
398d93ff971bd507e92ac81c149079906d2123795afMathias Agopian *
39942b743c85597e982ff1122b972862396f131db34Mathias Agopian * The rotation-vector is stored as:
40042b743c85597e982ff1122b972862396f131db34Mathias Agopian *
40142b743c85597e982ff1122b972862396f131db34Mathias Agopian *   sensors_event_t.data[0] = x*sin(theta/2)
40242b743c85597e982ff1122b972862396f131db34Mathias Agopian *   sensors_event_t.data[1] = y*sin(theta/2)
40342b743c85597e982ff1122b972862396f131db34Mathias Agopian *   sensors_event_t.data[2] = z*sin(theta/2)
404ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
405ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * In addition, this sensor reports an estimated heading accuracy.
406ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *   sensors_event_t.data[3] = estimated_accuracy (in radians)
407ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * The heading error must be less than estimated_accuracy 95% of the time
408ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
409ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * This sensor must use a gyroscope and an accelerometer as main orientation
410ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * change input.
411ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
412ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * This sensor can also include magnetometer input to make up for gyro drift,
413ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * but it cannot be implemented using only a magnetometer.
41456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
41556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_ROTATION_VECTOR                 (11)
41656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
41756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
418e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_RELATIVE_HUMIDITY
419a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change
420a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
421d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch *
422d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch * A relative humidity sensor measures relative ambient air humidity and
423d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch * returns a value in percent.
42456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
42556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_RELATIVE_HUMIDITY               (12)
42656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
42756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
428e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian * SENSOR_TYPE_AMBIENT_TEMPERATURE
429a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change
430a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
43154f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian *
43254f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * The ambient (room) temperature in degree Celsius.
43356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
43456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_AMBIENT_TEMPERATURE             (13)
43556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
43656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
43756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
438a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
439a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
44056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
441ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
442ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  reported separately instead of being included in the measurement.
443ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  Factory calibration and temperature compensation should still be applied to
444ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  the "uncalibrated" measurement.
445ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  Separating away the hard iron calibration estimation allows the system to
446ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  better recover from bad hard iron estimation.
44754f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian *
448ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  All values are in micro-Tesla (uT) and measure the ambient magnetic
449ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  field in the X, Y and Z axis. Assumptions that the the magnetic field
450ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  is due to the Earth's poles should be avoided.
451ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
452ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  The uncalibrated_magnetic event contains
453ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  - 3 fields for uncalibrated measurement: x_uncalib, y_uncalib, z_uncalib.
454ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    Each is a component of the measured magnetic field, with soft iron
455ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    and temperature compensation applied, but not hard iron calibration.
456ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    These values should be continuous (no re-calibration should cause a jump).
457ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  - 3 fields for hard iron bias estimates: x_bias, y_bias, z_bias.
458ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    Each field is a component of the estimated hard iron calibration.
459ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    They represent the offsets to apply to the uncalibrated readings to obtain
460ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    calibrated readings (x_calibrated = x_uncalib + x_bias)
461ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    These values are expected to jump as soon as the estimate of the hard iron
462ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    changes.
4631144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *
4641144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  If this sensor is present, then the corresponding
4651144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  SENSOR_TYPE_MAGNETIC_FIELD must be present and both must return the
4661144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  same sensor_t::name and sensor_t::vendor.
467ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
468ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * See SENSOR_TYPE_MAGNETIC_FIELD for more information
469f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
47056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED     (14)
471b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell
47256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
47356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_GAME_ROTATION_VECTOR
474a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
475a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
47656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
477ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
478ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  field. Therefore the Y axis doesn't point north, but instead to some other
479ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  reference. That reference is allowed to drift by the same order of
480ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  magnitude than the gyroscope drift around the Z axis.
48156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
482ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  This sensor does not report an estimated heading accuracy:
483ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    sensors_event_t.data[3] is reserved and should be set to 0
484ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
485ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  In the ideal case, a phone rotated and returning to the same real-world
486ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  orientation should report the same game rotation vector
487ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  (without using the earth's geomagnetic field).
488ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
489ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  This sensor must be based on a gyroscope. It cannot be implemented using
490ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  a magnetometer.
49156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
49256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * see SENSOR_TYPE_ROTATION_VECTOR for more details
49356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
49456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GAME_ROTATION_VECTOR            (15)
49556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
49656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/*
49756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
498a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: continuous
499a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
50056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
50156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  All values are in radians/second and measure the rate of rotation
5021144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  around the X, Y and Z axis. An estimation of the drift on each axis is
5031144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  reported as well.
5041144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *
5051144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  No gyro-drift compensation shall be performed.
5061144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  Factory calibration and temperature compensation should still be applied
5071144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  to the rate of rotation (angular speeds).
5081144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *
5091144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  The coordinate system is the same as is
51056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  used for the acceleration sensor. Rotation is positive in the
51156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  counter-clockwise direction (right-hand rule). That is, an observer
51256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  looking from some positive location on the x, y or z axis at a device
51356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  positioned on the origin would report positive rotation if the device
51456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  appeared to be rotating counter clockwise. Note that this is the
51556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  standard mathematical definition of positive rotation and does not agree
51656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  with the definition of roll given earlier.
51756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *  The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
51856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian *
519ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  Content of an uncalibrated_gyro event: (units are rad/sec)
520ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *   x_uncalib : angular speed (w/o drift compensation) around the X axis
521ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *   y_uncalib : angular speed (w/o drift compensation) around the Y axis
522ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *   z_uncalib : angular speed (w/o drift compensation) around the Z axis
523ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *   x_bias : estimated drift around X axis in rad/s
524ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *   y_bias : estimated drift around Y axis in rad/s
525ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *   z_bias : estimated drift around Z axis in rad/s
5261144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *
5271144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  IMPLEMENTATION NOTES:
5281144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *
5291144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  If the implementation is not able to estimate the drift, then this
5301144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  sensor MUST NOT be reported by this HAL. Instead, the regular
5311144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  SENSOR_TYPE_GYROSCOPE is used without drift compensation.
5321144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *
5331144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  If this sensor is present, then the corresponding
5341144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  SENSOR_TYPE_GYROSCOPE must be present and both must return the
5351144bea332fb24789712062bb35fe762f2f17505Mathias Agopian *  same sensor_t::name and sensor_t::vendor.
53656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
53756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED          (16)
53856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
539a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
540a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
541a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * SENSOR_TYPE_SIGNIFICANT_MOTION
542a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: one-shot
543a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: yes
544a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
545a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * A sensor of this type triggers an event each time significant motion
546a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * is detected and automatically disables itself.
547a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The only allowed value to return is 1.0.
548a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
5491461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * A significant motion is a motion that might lead to a change in the user
5501461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * location.
5511461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * Examples of such motions are:
5521461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *   walking, biking, sitting in a moving car, coach or train.
5531461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * Examples of situations that should not trigger significant motion:
5541461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * - phone in pocket and person is not moving
5551461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * - phone is on a table, even if the table shakes a bit due to nearby traffic
5561461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *   or washing machine
5571461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *
5581461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand * A note on false positive / false negative / power consumption tradeoff
5591461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *  - The goal of this sensor is to save power.
5601461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *  - Triggering an event when the user is not moving (false positive) is costly
5611461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *    in terms of power, so it should be avoided.
5621461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *  - Not triggering an event when the user is moving (false negative) is
5631461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *  - acceptable as long as it is not done repeatedly. If the user has been
5641461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *    walking for 10 seconds, not triggering an event within those 10 seconds
5651461f28f503d75c6eda29ec9bbd5db33b44f65feEtienne Le Grand *    is not acceptable.
566a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
567a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  IMPORTANT NOTE: this sensor type is very different from other types
568a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  in that it must work when the screen is off without the need of
569a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  holding a partial wake-lock and MUST allow the SoC to go into suspend.
570a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  When significant motion is detected, the sensor must awaken the SoC and
571a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  the event be reported.
572a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
573a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  If a particular hardware cannot support this mode of operation then this
574a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
575a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  to "emulate" this sensor in the HAL.
576a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
577a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  The whole point of this sensor type is to save power by keeping the
578a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  SoC in suspend mode when the device is at rest.
579a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
580a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  When the sensor is not activated, it must also be deactivated in the
581a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  hardware: it must not wake up the SoC anymore, even in case of
582a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  significant motion.
583a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
584a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  setDelay() has no effect and is ignored.
585a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  Once a "significant motion" event is returned, a sensor of this type
586a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  must disables itself automatically, as if activate(..., 0) had been called.
587a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */
588a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
589a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian#define SENSOR_TYPE_SIGNIFICANT_MOTION              (17)
590a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
591a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
592a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
5932f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian * SENSOR_TYPE_STEP_DETECTOR
594a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: special
595a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
596a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
597a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * A sensor of this type triggers an event each time a step is taken
598a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * by the user. The only allowed value to return is 1.0 and an event is
599a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * generated for each step. Like with any other event, the timestamp
600a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * indicates when the event (here the step) occurred, this corresponds to when
601a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * the foot hit the ground, generating a high variation in acceleration.
602a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
603a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * While this sensor operates, it shall not disrupt any other sensors, in
604a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * particular, but not limited to, the accelerometer; which might very well
605a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * be in use as well.
606a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
607a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * This sensor must be low power. That is, if the step detection cannot be
608a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * done in hardware, this sensor should not be defined. Also, when the
6092f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian * step detector is activated and the accelerometer is not, only steps should
610a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger interrupts (not accelerometer data).
611a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
612a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * setDelay() has no impact on this sensor type
613a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */
614a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
6152f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian#define SENSOR_TYPE_STEP_DETECTOR                   (18)
616a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
617a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
618a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
619a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * SENSOR_TYPE_STEP_COUNTER
620a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger-mode: on-change
621a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * wake-up sensor: no
622a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
623a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * A sensor of this type returns the number of steps taken by the user since
6241144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * the last reboot while activated. The value is returned as a uint64_t and is
6251144bea332fb24789712062bb35fe762f2f17505Mathias Agopian * reset to zero only on a system reboot.
626a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
627a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * The timestamp of the event is set to the time when the first step
628a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * for that event was taken.
6292f276f555064a77fa449a3ac21aa06ea3c1b45caMathias Agopian * See SENSOR_TYPE_STEP_DETECTOR for the signification of the time of a step.
630a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
631a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  The minimum size of the hardware's internal counter shall be 16 bits
632a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  (this restriction is here to avoid too frequent wake-ups when the
633a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  delay is very large).
634a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
635a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  IMPORTANT NOTE: this sensor type is different from other types
636a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  in that it must work when the screen is off without the need of
637a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  holding a partial wake-lock and MUST allow the SoC to go into suspend.
638a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  Unlike other sensors, while in suspend mode this sensor must stay active,
639a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  no events are reported during that time but, steps continue to be
640a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  accounted for; an event will be reported as soon as the SoC resumes if
641a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  the timeout has expired.
642a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
643a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *    In other words, when the screen is off and the device allowed to
644a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *    go into suspend mode, we don't want to be woken up, regardless of the
645a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *    setDelay() value, but the steps shall continue to be counted.
646a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
647a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *    The driver must however ensure that the internal step count never
648a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *    overflows. It is allowed in this situation to wake the SoC up so the
649a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *    driver can do the counter maintenance.
650a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
651a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  While this sensor operates, it shall not disrupt any other sensors, in
652a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  particular, but not limited to, the accelerometer; which might very well
653a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  be in use as well.
654a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
655a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  If a particular hardware cannot support these modes of operation then this
656a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  sensor type MUST NOT be reported by the HAL. ie: it is not acceptable
657a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  to "emulate" this sensor in the HAL.
658a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
659a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * This sensor must be low power. That is, if the step detection cannot be
660a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * done in hardware, this sensor should not be defined. Also, when the
661a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * step counter is activated and the accelerometer is not, only steps should
662a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * trigger interrupts (not accelerometer data).
663a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *
664a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  The whole point of this sensor type is to save power by keeping the
665a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian *  SoC in suspend mode when the device is at rest.
666a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */
667a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
668a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian#define SENSOR_TYPE_STEP_COUNTER                    (19)
669a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
670ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand/*
671ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
672ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * trigger-mode: continuous
673ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * wake-up sensor: no
674ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
675ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
676ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  of using a gyroscope.
677ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
678ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  This sensor must be based on a magnetometer. It cannot be implemented using
679ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  a gyroscope, and gyroscope input cannot be used by this sensor.
680ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
681ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  Just like SENSOR_TYPE_ROTATION_VECTOR, this sensor reports an estimated
682ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  heading accuracy:
683ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *    sensors_event_t.data[3] = estimated_accuracy (in radians)
684ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *  The heading error must be less than estimated_accuracy 95% of the time
685ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand *
686ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * see SENSOR_TYPE_ROTATION_VECTOR for more details
687ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand */
688ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR            (20)
689a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
69056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/**
69156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * Values returned by the accelerometer in various locations in the universe.
69256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * all values are in SI units (m/s^2)
69356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
69456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define GRAVITY_SUN             (275.0f)
69556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define GRAVITY_EARTH           (9.80665f)
69656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
69756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/** Maximum magnetic field on Earth's surface */
69856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define MAGNETIC_FIELD_EARTH_MAX    (60.0f)
69956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
70056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/** Minimum magnetic field on Earth's surface */
70156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define MAGNETIC_FIELD_EARTH_MIN    (30.0f)
70256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
70356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
70456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/**
70556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * status of orientation sensor
70656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
70756f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
70856f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_STATUS_UNRELIABLE        0
70956f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_STATUS_ACCURACY_LOW      1
71056f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_STATUS_ACCURACY_MEDIUM   2
71156f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian#define SENSOR_STATUS_ACCURACY_HIGH     3
71256f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
71356f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian
71456f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian/**
71556f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian * sensor event data
71656f66ccfb4915b03da4b470916bb2c59bed97216Mathias Agopian */
717f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projecttypedef struct {
718f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    union {
719f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        float v[3];
720f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        struct {
721f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float x;
722f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float y;
723f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float z;
724f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        };
725f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        struct {
726f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float azimuth;
727f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float pitch;
728f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float roll;
729f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        };
730f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    };
731f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int8_t status;
732f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    uint8_t reserved[3];
733f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project} sensors_vec_t;
734f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
735f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
736ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand * uncalibrated gyroscope and magnetometer event data
737ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand */
738ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grandtypedef struct {
739ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand  float x_uncalib;
740ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand  float y_uncalib;
741ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand  float z_uncalib;
742ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand  float x_bias;
743ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand  float y_bias;
744ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand  float z_bias;
745ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand} uncalibrated_event_t;
746ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand
747ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand/**
748f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Union of the various types of sensor data
749f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * that can be returned.
750f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
751cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopiantypedef struct sensors_event_t {
752cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* must be sizeof(struct sensors_event_t) */
753cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int32_t version;
754cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
755cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* sensor identifier */
756cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int32_t sensor;
757cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
758cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* sensor type */
759cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int32_t type;
760cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
761cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* reserved */
762cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int32_t reserved0;
763cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
764cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* time is in nanosecond */
765cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int64_t timestamp;
766cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
767cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    union {
768cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        float           data[16];
769cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
770cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* acceleration values are in meter per second per second (m/s^2) */
771296cf93d10b2a7627c772940c9445097d4c341e9Jeff Brown        sensors_vec_t   acceleration;
772cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
773cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* magnetic vector values are in micro-Tesla (uT) */
774cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        sensors_vec_t   magnetic;
775cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
776cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* orientation values are in degrees */
777cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        sensors_vec_t   orientation;
778cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
779c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian        /* gyroscope values are in rad/s */
780296cf93d10b2a7627c772940c9445097d4c341e9Jeff Brown        sensors_vec_t   gyro;
7813120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar
782cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* temperature is in degrees centigrade (Celsius) */
783cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        float           temperature;
784cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
785cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* distance in centimeters */
786cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        float           distance;
787cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
788cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* light in SI lux units */
789cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        float           light;
7901832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian
7911832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian        /* pressure in hectopascal (hPa) */
7921832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian        float           pressure;
793d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch
794d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch        /* relative humidity in percent */
795d2ed15a6b81a9a2fd95c1a565f72796869545115Urs Fleisch        float           relative_humidity;
796a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
797a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian        /* step-counter */
798a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian        uint64_t        step_counter;
799ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand
800ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand        /* uncalibrated gyroscope values are in rad/s */
801ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand        uncalibrated_event_t uncalibrated_gyro;
802ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand
803ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand        /* uncalibrated magnetometer values are in micro-Teslas */
804ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand        uncalibrated_event_t uncalibrated_magnetic;
805cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    };
806cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    uint32_t        reserved1[4];
807cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian} sensors_event_t;
808cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
809cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
810cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
811f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensor_t;
812f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
813f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
814f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
815f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * and the fields of this data structure must begin with hw_module_t
816f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * followed by module specific information.
817f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
818f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensors_module_t {
819f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    struct hw_module_t common;
820f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
821f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /**
822f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     * Enumerate all available sensors. The list is returned in "list".
823f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     * @return number of sensors in the list
824f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     */
825f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int (*get_sensors_list)(struct sensors_module_t* module,
826f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            struct sensor_t const** list);
827f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project};
828f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
829f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensor_t {
8301144bea332fb24789712062bb35fe762f2f17505Mathias Agopian
8311144bea332fb24789712062bb35fe762f2f17505Mathias Agopian    /* Name of this sensor.
8321144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * All sensors of the same "type" must have a different "name".
8331144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     */
834f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    const char*     name;
835a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
836f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* vendor of the hardware part */
837f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    const char*     vendor;
838a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
839e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian    /* version of the hardware part + driver. The value of this field
840e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian     * must increase when the driver is updated in a way that changes the
841e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian     * output of this sensor. This is important for fused sensors when the
842e9eaf3721dd715901d669df6488b1ecd63b1e634Mathias Agopian     * fusion algorithm is updated.
843f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     */
844f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int             version;
845a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
846a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    /* handle that identifies this sensors. This handle is used to reference
847a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * this sensor throughout the HAL API.
848f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     */
849f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int             handle;
850a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
851f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* this sensor's type. */
852f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int             type;
853a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
854a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    /* maximum range of this sensor's value in SI units */
855f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    float           maxRange;
856a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
857f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* smallest difference between two values reported by this sensor */
858f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    float           resolution;
859a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
860f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* rough estimate of this sensor's power consumption in mA */
861f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    float           power;
862a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
863a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    /* this value depends on the trigger mode:
864a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
865a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *   continuous: minimum sample period allowed in microseconds
866a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *   on-change : 0
867a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *   one-shot  :-1
868a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *   special   : 0, unless otherwise noted
869a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     */
8701511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian    int32_t         minDelay;
871a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
872f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* reserved fields, must be zero */
8731511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian    void*           reserved[8];
874f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project};
875f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
876f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
877a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
878a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * sensors_poll_device_t is used with SENSORS_DEVICE_API_VERSION_0_1
879a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * and is present for backward binary and source compatibility.
880a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * (see documentation of the hooks in struct sensors_poll_device_1 below)
881f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
882b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstruct sensors_poll_device_t {
883b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    struct hw_device_t common;
884b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    int (*activate)(struct sensors_poll_device_t *dev,
885b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian            int handle, int enabled);
886a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    int (*setDelay)(struct sensors_poll_device_t *dev,
887a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            int handle, int64_t ns);
888a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    int (*poll)(struct sensors_poll_device_t *dev,
889a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            sensors_event_t* data, int count);
890a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian};
891b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
892a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian/*
893a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian * struct sensors_poll_device_1 is used with SENSORS_DEVICE_API_VERSION_1_0
894a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian */
895a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopiantypedef struct sensors_poll_device_1 {
896a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    union {
897a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian        /* sensors_poll_device_1 is compatible with sensors_poll_device_t,
898a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian         * and can be down-cast to it
899a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian         */
9001082c0b54c21c220e975f1c714e41f9183b366d1Andrew Hsieh        struct sensors_poll_device_t v0;
901a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
902a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian        struct {
903a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            struct hw_device_t common;
904a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
905a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            /* Activate/de-activate one sensor.
906a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
907a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * handle is the handle of the sensor to change.
908a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * enabled set to 1 to enable, or 0 to disable the sensor.
909a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
910a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * unless otherwise noted in the sensor types definitions, an
911a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * activated sensor never prevents the SoC to go into suspend
912a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * mode; that is, the HAL shall not hold a partial wake-lock on
913a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * behalf of applications.
914a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
915a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * one-shot sensors de-activate themselves automatically upon
916a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * receiving an event and they must still accept to be deactivated
917a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * through a call to activate(..., ..., 0).
918a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
919a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * if "enabled" is true and the sensor is already activated, this
920a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * function is a no-op and succeeds.
921a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
922a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * if "enabled" is false and the sensor is already de-activated,
923a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * this function is a no-op and succeeds.
924a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
925a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * return 0 on success, negative errno code otherwise
926a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             */
927a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            int (*activate)(struct sensors_poll_device_t *dev,
928a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian                    int handle, int enabled);
929a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
930a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            /**
9311144bea332fb24789712062bb35fe762f2f17505Mathias Agopian             * Set the events's period in nanoseconds for a given sensor.
932a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
9331144bea332fb24789712062bb35fe762f2f17505Mathias Agopian             * What the period_ns parameter means depends on the specified
934a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * sensor's trigger mode:
935a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
936a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * continuous: setDelay() sets the sampling rate.
937a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * on-change: setDelay() limits the delivery rate of events
938a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * one-shot: setDelay() is ignored. it has no effect.
939a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * special: see specific sensor type definitions
940a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
941a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * For continuous and on-change sensors, if the requested value is
942a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * less than sensor_t::minDelay, then it's silently clamped to
943a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * sensor_t::minDelay unless sensor_t::minDelay is 0, in which
944a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * case it is clamped to >= 1ms.
945a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
946a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * @return 0 if successful, < 0 on error
947a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             */
948a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            int (*setDelay)(struct sensors_poll_device_t *dev,
9491144bea332fb24789712062bb35fe762f2f17505Mathias Agopian                    int handle, int64_t period_ns);
950a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
951a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            /**
952a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * Returns an array of sensor data.
953a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * This function must block until events are available.
954a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
955a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * return the number of events read on success, or -errno in case
956a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * of an error.
957a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
958a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * The number of events returned in data must be less or equal
959a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * to SENSORS_QUERY_MAX_EVENTS_BATCH_COUNT.
960a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             *
961a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             * This function shall never return 0 (no event).
962a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian             */
963a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            int (*poll)(struct sensors_poll_device_t *dev,
964a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian                    sensors_event_t* data, int count);
965a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian        };
966a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    };
967a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
968a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    /*
969a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * Used to retrieve information about the sensor HAL
970b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     *
971a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * Returns 0 on success or -errno on error.
972b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     */
973a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    int (*query)(struct sensors_poll_device_1* dev, int what, int* value);
974b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
975a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
976a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    /*
9771144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * Enables batch mode for the given sensor and sets the delay between events
978a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
979a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * A timeout value of zero disables batch mode for the given sensor.
980a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
9811144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * The period_ns parameter is equivalent to calling setDelay() -- this
9821144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * function both enables or disables the batch mode AND sets the events's
9831144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * period in nanosecond. See setDelay() above for a detailed explanation of
9841144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * the period_ns parameter.
9851144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *
986a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * While in batch mode sensor events are reported in batches at least
987a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * every "timeout" nanosecond; that is all events since the previous batch
988a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * are recorded and returned all at once. Batches can be interleaved and
989a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * split, and as usual events of the same sensor type are time-ordered.
990a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
991a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * setDelay() is not affected and it behaves as usual.
992a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
993a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * Each event has a timestamp associated with it, the timestamp
994a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * must be accurate and correspond to the time at which the event
995a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * physically happened.
996a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
997a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * If internal h/w FIFOs fill-up before the timeout, then events are
9981144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * reported at that point. No event shall be dropped or lost.
9991144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *
10001144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *
10011144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * INTERACTION WITH SUSPEND MODE:
10021144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * ------------------------------
1003a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1004a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * By default batch mode doesn't significantly change the interaction with
1005a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * suspend mode, that is, sensors must continue to allow the SoC to
1006a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * go into suspend mode and sensors must stay active to fill their
1007a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * internal FIFO, in this mode, when the FIFO fills-up, it shall wrap
1008a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * around (basically behave like a circular buffer, overwriting events).
1009a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * As soon as the SoC comes out of suspend mode, a batch is produced with
1010a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * as much as the recent history as possible, and batch operation
1011a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * resumes as usual.
1012a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1013a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * The behavior described above allows applications to record the recent
1014a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * history of a set of sensor while keeping the SoC into suspend. It
1015a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * also allows the hardware to not have to rely on a wake-up interrupt line.
1016a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1017a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * There are cases however where an application cannot afford to lose
1018a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * any events, even when the device goes into suspend mode. The behavior
1019a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * specified above can be altered by setting the
1020a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * SENSORS_BATCH_WAKE_UPON_FIFO_FULL flag. If this flag is set, the SoC
1021a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * must be woken up from suspend and a batch must be returned before
1022a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * the FIFO fills-up. Enough head room must be allocated in the FIFO to allow
1023a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * the device to entirely come out of suspend (which might take a while and
1024a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * is device dependent) such that no event are lost.
1025a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1026a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *   If the hardware cannot support this mode, or, if the physical
1027a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *   FIFO is so small that the device would never be allowed to go into
10281144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *   suspend for at least 10 seconds, then this function MUST fail when
10291144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *   the flag SENSORS_BATCH_WAKE_UPON_FIFO_FULL is set, regardless of
10301144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *   the value of the timeout parameter.
1031a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
10321144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * DRY RUN:
10331144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * --------
1034a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1035a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * If the flag SENSORS_BATCH_DRY_RUN is set, this function returns
10361144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * without modifying the batch mode or the event period and has no side
10371144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * effects, but returns errors as usual (as it would if this flag was
10381144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * not set). This flag is used to check if batch mode is available for a
10391144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * given configuration -- in particular for a given sensor at a given rate.
10401144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *
1041a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1042a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * Return values:
10431144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * --------------
10441144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *
10451144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * Because sensors must be independent, the return value must not depend
10461144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * on the state of the system (whether another sensor is on or not),
10471144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * nor on whether the flag SENSORS_BATCH_DRY_RUN is set (in other words,
10481144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * if a batch call with SENSORS_BATCH_DRY_RUN is successful,
10491144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * the same call without SENSORS_BATCH_DRY_RUN must succeed as well).
1050a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1051a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * If successful, 0 is returned.
1052a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * If the specified sensor doesn't support batch mode, -EINVAL is returned.
1053a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * If the specified sensor's trigger-mode is one-shot, -EINVAL is returned.
1054a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * If any of the constraint above cannot be satisfied, -EINVAL is returned.
1055a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
10561144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * Note: the timeout parameter, when > 0, has no impact on whether this
10571144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *       function succeeds or fails.
10581144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     *
1059a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * If timeout is set to 0, this function must succeed.
1060a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1061a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1062a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * IMPLEMENTATION NOTES:
10631144bea332fb24789712062bb35fe762f2f17505Mathias Agopian     * ---------------------
1064b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     *
1065a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * batch mode, if supported, should happen at the hardware level,
1066a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * typically using hardware FIFOs. In particular, it SHALL NOT be
1067a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * implemented in the HAL, as this would be counter productive.
1068a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * The goal here is to save significant amounts of power.
1069a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     *
1070a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * batch mode can be enabled or disabled at any time, in particular
1071a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * while the specified sensor is already enabled and this shall not
1072a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian     * result in the loss of events.
1073b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     *
1074ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * COMPARATIVE IMPORTANCE OF BATCHING FOR DIFFERENT SENSORS:
1075ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * ---------------------------------------------------------
1076ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *
1077ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * On platforms on which hardware fifo size is limited, the system designers
1078ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * might have to choose how much fifo to reserve for each sensor. To help
1079ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * with this choice, Here is a list of applications made possible when
1080ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * batching is implemented on the different sensors.
1081ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *
1082ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * High value: Low power pedestrian dead reckoning
1083ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Target batching time: 20 seconds to 1 minute
1084ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Sensors to batch:
1085ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *    - Step detector
1086ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *    - Rotation vector or game rotation vector at 5Hz
1087ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Gives us step and heading while letting the AP go to Suspend.
1088ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *
1089ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * High value: Medium power activity/gesture recognition
1090ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Target batching time: 3 seconds
1091ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Sensors to batch: accelerometer between 20Hz and 50Hz
1092ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Allows recognizing arbitrary activities and gestures without having
1093ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   to keep the AP fully awake while the data is collected.
1094ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *
1095ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * Medium-high value: Interrupt load reduction
1096ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Target batching time: < 1 second
1097ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Sensors to batch: any high frequency sensor.
1098ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   If the gyroscope is set at 800Hz, even batching just 10 gyro events can
1099ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   reduce the number of interrupts from 800/second to 80/second.
1100ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *
1101ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * Medium value: Continuous low frequency data collection
1102ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Target batching time: > 1 minute
1103ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Sensors to batch: barometer, humidity sensor, other low frequency
1104ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *     sensors.
1105ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Allows creating monitoring applications at low power.
1106ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *
1107ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     * Medium value: Continuous full-sensors collection
1108ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Target batching time: > 1 minute
1109ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Sensors to batch: all, at high frequencies
1110ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   Allows full collection of sensor data while leaving the AP in
1111ca8581433b778c60b074839baa6c3f2233c09614Etienne Le Grand     *   suspend mode. Only to consider if fifo space is not an issue.
1112b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     */
1113a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    int (*batch)(struct sensors_poll_device_1* dev,
11141144bea332fb24789712062bb35fe762f2f17505Mathias Agopian            int handle, int flags, int64_t period_ns, int64_t timeout);
1115a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
1116a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    void (*reserved_procs[8])(void);
1117a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
1118a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian} sensors_poll_device_1_t;
1119a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
1120a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
1121b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
1122f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** convenience API for opening and closing a device */
1123f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
1124b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstatic inline int sensors_open(const struct hw_module_t* module,
1125b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian        struct sensors_poll_device_t** device) {
1126b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    return module->methods->open(module,
1127b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian            SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1128b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian}
1129b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
1130b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstatic inline int sensors_close(struct sensors_poll_device_t* device) {
1131b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    return device->common.close(&device->common);
1132b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian}
1133b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
1134a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopianstatic inline int sensors_open_1(const struct hw_module_t* module,
11351082c0b54c21c220e975f1c714e41f9183b366d1Andrew Hsieh        sensors_poll_device_1_t** device) {
1136a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    return module->methods->open(module,
1137a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian            SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
1138a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian}
1139a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
11401082c0b54c21c220e975f1c714e41f9183b366d1Andrew Hsiehstatic inline int sensors_close_1(sensors_poll_device_1_t* device) {
1141a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian    return device->common.close(&device->common);
1142a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian}
1143a455772cb30cb8fed26b12f61a6d78c9b689e640Mathias Agopian
1144f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project__END_DECLS
1145f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
1146f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#endif  // ANDROID_SENSORS_INTERFACE_H
1147