sensors.h revision 1832f55760fff86d00b5d808b3da8f1e55a889e5
1f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/*
2f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Copyright (C) 2008 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
29f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
30f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * The id of this module
31f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
32f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HARDWARE_MODULE_ID "sensors"
33f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
34f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
35f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Name of the sensors device to open
36f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
37b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian#define SENSORS_HARDWARE_POLL       "poll"
38f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
39f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
40f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
41f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * A Handle identifies a given sensors. The handle is used to activate
42f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * and/or deactivate sensors.
43f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * In this version of the API there can only be 256 handles.
44f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
45f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HANDLE_BASE             0
46f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HANDLE_BITS             8
47f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSORS_HANDLE_COUNT            (1<<SENSORS_HANDLE_BITS)
48f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
49f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
50f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
51f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Sensor types
52f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
53f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_TYPE_ACCELEROMETER       1
54f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_TYPE_MAGNETIC_FIELD      2
55f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_TYPE_ORIENTATION         3
56f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_TYPE_GYROSCOPE           4
57f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_TYPE_LIGHT               5
58f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_TYPE_PRESSURE            6
59f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_TYPE_TEMPERATURE         7
60f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_TYPE_PROXIMITY           8
61f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
62f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
63f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Values returned by the accelerometer in various locations in the universe.
64f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * all values are in SI units (m/s^2)
65f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
66f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
67f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define GRAVITY_SUN             (275.0f)
68f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define GRAVITY_EARTH           (9.80665f)
69f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
70f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** Maximum magnetic field on Earth's surface */
71f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define MAGNETIC_FIELD_EARTH_MAX    (60.0f)
72f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
73f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** Minimum magnetic field on Earth's surface */
74f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define MAGNETIC_FIELD_EARTH_MIN    (30.0f)
75f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
76f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
77f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
78f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * status of each sensor
79f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
80f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
81f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_STATUS_UNRELIABLE        0
82f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_STATUS_ACCURACY_LOW      1
83f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_STATUS_ACCURACY_MEDIUM   2
84f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_STATUS_ACCURACY_HIGH     3
85f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
86f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
87f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Definition of the axis
88f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * ----------------------
89f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
90f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * This API is relative to the screen of the device in its default orientation,
91f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * that is, if the device can be used in portrait or landscape, this API
92f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * is only relative to the NATURAL orientation of the screen. In other words,
93f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * the axis are not swapped when the device's screen orientation changes.
94f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Higher level services /may/ perform this transformation.
95f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
96f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *   x<0         x>0
97f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *                ^
98f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *                |
99f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    +-----------+-->  y>0
100f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |
101f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |
102f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |
103f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |   / z<0
104f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           |  /
105f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |           | /
106f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    O-----------+/
107f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    |[]  [ ]  []/
108f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    +----------/+     y<0
109f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *              /
110f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *             /
111f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *           |/ z>0 (toward the sky)
112f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
113f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    O: Origin (x=0,y=0,z=0)
114f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
115f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
116f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Orientation
117f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * -----------
118f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
119f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * All values are angles in degrees.
120f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
12166a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * Orientation sensors return sensor events for all 3 axes at a constant
12266a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * rate defined by setDelay().
12366a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *
124f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * azimuth: angle between the magnetic north direction and the Y axis, around
125f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  the Z axis (0<=azimuth<360).
126f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *      0=North, 90=East, 180=South, 270=West
127f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
128f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when
129f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  the z-axis moves toward the y-axis.
130f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
131f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * roll: Rotation around Y axis (-90<=roll<=90), with positive values when
13219ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *  the x-axis moves towards the z-axis.
13319ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
13419ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * Note: For historical reasons the roll angle is positive in the clockwise
13519ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *  direction (mathematically speaking, it should be positive in the
13619ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *  counter-clockwise direction):
13719ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
13819ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *                Z
13919ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *                ^
14019ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *  (+roll)  .--> |
14119ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *          /     |
14219ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *         |      |  roll: rotation around Y axis
14319ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *     X <-------(.)
14419ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *                 Y
14519ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *       note that +Y == -roll
14619ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
14719ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
14819ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian *
149f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Note: This definition is different from yaw, pitch and roll used in aviation
150f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  where the X axis is along the long side of the plane (tail to nose).
151f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
152f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
153f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Acceleration
154f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * ------------
155f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
156f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  All values are in SI units (m/s^2) and measure the acceleration of the
157f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  device minus the force of gravity.
158f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
15966a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *  Acceleration sensors return sensor events for all 3 axes at a constant
16066a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *  rate defined by setDelay().
16166a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *
162f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  x: Acceleration minus Gx on the x-axis
163f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  y: Acceleration minus Gy on the y-axis
164f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  z: Acceleration minus Gz on the z-axis
165f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
166f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  Examples:
167f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    When the device lies flat on a table and is pushed on its left side
168f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    toward the right, the x acceleration value is positive.
169f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
170f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    When the device lies flat on a table, the acceleration value is +9.81,
171f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    which correspond to the acceleration of the device (0 m/s^2) minus the
172f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    force of gravity (-9.81 m/s^2).
173f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
174f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    When the device lies flat on a table and is pushed toward the sky, the
175f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    acceleration value is greater than +9.81, which correspond to the
176f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    acceleration of the device (+A m/s^2) minus the force of
177f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *    gravity (-9.81 m/s^2).
178f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
179f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
180f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Magnetic Field
181f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * --------------
182f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *
183f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  All values are in micro-Tesla (uT) and measure the ambient magnetic
184f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project *  field in the X, Y and Z axis.
185a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood *
18666a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *  Magnetic Field sensors return sensor events for all 3 axes at a constant
18766a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *  rate defined by setDelay().
18866a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *
189a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * Proximity
190a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * ---------
191a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood *
192a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * The distance value is measured in centimeters.  Note that some proximity
193a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * sensors only support a binary "close" or "far" measurement.  In this case,
194a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * the sensor should report its maxRange value in the "far" state and a value
195a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * less than maxRange in the "near" state.
196a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood *
197478994a758e48b0de7f56f3de0678d5c2b6a4b61Mathias Agopian * Proximity sensors report a value only when it changes and each time the
198478994a758e48b0de7f56f3de0678d5c2b6a4b61Mathias Agopian * sensor is enabled. setDelay() is ignored.
19966a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *
200a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * Light
201a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * -----
202a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood *
203a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * The light sensor value is returned in SI lux units.
204a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood *
205478994a758e48b0de7f56f3de0678d5c2b6a4b61Mathias Agopian * Light sensors report a value only when it changes and each time the
206478994a758e48b0de7f56f3de0678d5c2b6a4b61Mathias Agopian * sensor is enabled. setDelay() is ignored.
20766a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian *
2081832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * Pressure
2091832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * --------
2101832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian *
2111832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * The pressure sensor value is returned in hectopascal (hPa)
2121832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian *
2131832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * Pressure sensors report events at a constant rate defined by setDelay().
2141832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian *
215f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
216f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projecttypedef struct {
217f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    union {
218f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        float v[3];
219f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        struct {
220f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float x;
221f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float y;
222f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float z;
223f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        };
224f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        struct {
225f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float azimuth;
226f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float pitch;
227f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            float roll;
228f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project        };
229f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    };
230f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int8_t status;
231f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    uint8_t reserved[3];
232f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project} sensors_vec_t;
233f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
234f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
235f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Union of the various types of sensor data
236f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * that can be returned.
237f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
238cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopiantypedef struct sensors_event_t {
239cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* must be sizeof(struct sensors_event_t) */
240cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int32_t version;
241cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
242cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* sensor identifier */
243cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int32_t sensor;
244cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
245cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* sensor type */
246cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int32_t type;
247cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
248cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* reserved */
249cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int32_t reserved0;
250cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
251cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    /* time is in nanosecond */
252cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    int64_t timestamp;
253cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
254cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    union {
255cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        float           data[16];
256cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
257cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* acceleration values are in meter per second per second (m/s^2) */
258cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        sensors_vec_t   acceleration;
259cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
260cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* magnetic vector values are in micro-Tesla (uT) */
261cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        sensors_vec_t   magnetic;
262cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
263cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* orientation values are in degrees */
264cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        sensors_vec_t   orientation;
265cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
266cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* temperature is in degrees centigrade (Celsius) */
267cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        float           temperature;
268cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
269cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* distance in centimeters */
270cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        float           distance;
271cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
272cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        /* light in SI lux units */
273cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian        float           light;
2741832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian
2751832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian        /* pressure in hectopascal (hPa) */
2761832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian        float           pressure;
277cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    };
278cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian    uint32_t        reserved1[4];
279cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian} sensors_event_t;
280cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
281cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
282cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian
283f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensor_t;
284f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
285f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
286f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
287f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * and the fields of this data structure must begin with hw_module_t
288f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * followed by module specific information.
289f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
290f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensors_module_t {
291f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    struct hw_module_t common;
292f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
293f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /**
294f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     * Enumerate all available sensors. The list is returned in "list".
295f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     * @return number of sensors in the list
296f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     */
297f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int (*get_sensors_list)(struct sensors_module_t* module,
298f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project            struct sensor_t const** list);
299f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project};
300f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
301f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensor_t {
302f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* name of this sensors */
303f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    const char*     name;
304f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* vendor of the hardware part */
305f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    const char*     vendor;
306f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* version of the hardware part + driver. The value of this field is
307b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     * left to the implementation and doesn't have to be monotonically
308f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     * increasing.
309f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     */
310f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int             version;
311f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* handle that identifies this sensors. This handle is used to activate
312f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     * and deactivate this sensor. The value of the handle must be 8 bits
313f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     * in this version of the API.
314f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project     */
315f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int             handle;
316f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* this sensor's type. */
317f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    int             type;
318f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* maximaum range of this sensor's value in SI units */
319f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    float           maxRange;
320f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* smallest difference between two values reported by this sensor */
321f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    float           resolution;
322f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* rough estimate of this sensor's power consumption in mA */
323f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    float           power;
324f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    /* reserved fields, must be zero */
325f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project    void*           reserved[9];
326f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project};
327f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
328f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
329f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/**
330f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Every device data structure must begin with hw_device_t
331f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * followed by module specific public methods and attributes.
332f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */
333b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstruct sensors_poll_device_t {
334b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    struct hw_device_t common;
335b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
336b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    /** Activate/deactivate one sensor.
337b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     *
338b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     * @param handle is the handle of the sensor to change.
339b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     * @param enabled set to 1 to enable, or 0 to disable the sensor.
340b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     *
341b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     * @return 0 on success, negative errno code otherwise
342b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     */
343b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    int (*activate)(struct sensors_poll_device_t *dev,
344b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian            int handle, int enabled);
345b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
346b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    /**
347b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     * Set the delay between sensor events in nanoseconds for a given sensor
348b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     *
349b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     * @return 0 if successful, < 0 on error
350b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     */
351b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    int (*setDelay)(struct sensors_poll_device_t *dev,
352b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian            int handle, int64_t ns);
353b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
354b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    /**
355b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     * Returns an array of sensor data.
356b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     *
357b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     * @return the number of events read on success, or -errno in case of an error.
358b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     *
359b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian     */
360b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    int (*poll)(struct sensors_poll_device_t *dev,
361cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian            sensors_event_t* data, int count);
362b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian};
363b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
364f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** convenience API for opening and closing a device */
365f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
366b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstatic inline int sensors_open(const struct hw_module_t* module,
367b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian        struct sensors_poll_device_t** device) {
368b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    return module->methods->open(module,
369b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian            SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
370b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian}
371b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
372b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstatic inline int sensors_close(struct sensors_poll_device_t* device) {
373b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian    return device->common.close(&device->common);
374b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian}
375b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian
376f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project__END_DECLS
377f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project
37898c5309047d2eedfe93ac42243f9750cfeb3517eMathias Agopian#include <hardware/sensors_deprecated.h>
37998c5309047d2eedfe93ac42243f9750cfeb3517eMathias Agopian
380f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#endif  // ANDROID_SENSORS_INTERFACE_H
381