blob: 19fd72c2eb2a8ab2512642b15d7e71197f7dd4fe [file] [log] [blame]
The Android Open Source Projectd6054a32008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _HARDWARE_SENSORS_H
18#define _HARDWARE_SENSORS_H
19
20#include <stdint.h>
21
22#if __cplusplus
23extern "C" {
24#endif
25
26/**
27 * Sensor IDs must be a power of two and
28 * must match values in SensorManager.java
29 */
30
31#define SENSORS_ORIENTATION 0x00000001
32#define SENSORS_ACCELERATION 0x00000002
33#define SENSORS_TEMPERATURE 0x00000004
34#define SENSORS_MAGNETIC_FIELD 0x00000008
35#define SENSORS_LIGHT 0x00000010
36#define SENSORS_PROXIMITY 0x00000020
37#define SENSORS_TRICORDER 0x00000040
38#define SENSORS_ORIENTATION_RAW 0x00000080
39#define SENSORS_MASK 0x000000FF
40
41/**
42 * Values returned by the accelerometer in various locations in the universe.
43 * all values are in SI units (m/s^2)
44 */
45
46#define GRAVITY_SUN (275.0f)
47#define GRAVITY_MERCURY (3.70f)
48#define GRAVITY_VENUS (8.87f)
49#define GRAVITY_EARTH (9.80665f)
50#define GRAVITY_MOON (1.6f)
51#define GRAVITY_MARS (3.71f)
52#define GRAVITY_JUPITER (23.12f)
53#define GRAVITY_SATURN (8.96f)
54#define GRAVITY_URANUS (8.69f)
55#define GRAVITY_NEPTUN (11.0f)
56#define GRAVITY_PLUTO (0.6f)
57#define GRAVITY_DEATH_STAR_I (0.000000353036145f)
58#define GRAVITY_THE_ISLAND (4.815162342f)
59
60/** Maximum magnetic field on Earth's surface */
61#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
62
63/** Minimum magnetic field on Earth's surface */
64#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
65
66/**
67 * Various luminance values during the day (lux)
68 */
69
70#define LIGHT_SUNLIGHT_MAX (120000.0f)
71#define LIGHT_SUNLIGHT (110000.0f)
72#define LIGHT_SHADE (20000.0f)
73#define LIGHT_OVERCAST (10000.0f)
74#define LIGHT_SUNRISE (400.0f)
75#define LIGHT_CLOUDY (100.0f)
76
77/*
78 * Various luminance values during the night (lux)
79 */
80
81#define LIGHT_FULLMOON (0.25f)
82#define LIGHT_NO_MOON (0.001f)
83
84/**
85 * status of each sensor
86 */
87
88#define SENSOR_STATUS_UNRELIABLE 0
89#define SENSOR_STATUS_ACCURACY_LOW 1
90#define SENSOR_STATUS_ACCURACY_MEDIUM 2
91#define SENSOR_STATUS_ACCURACY_HIGH 3
92
93/**
94 * Definition of the axis
95 *
96 * This API is relative to the screen of the device in its default orientation,
97 * that is, if the device can be used in portrait or landscape, this API
98 * is only relative to the NATURAL orientation of the screen. In other words,
99 * the axis are not swapped when the device's screen orientation changes.
100 * Higher level services /may/ perform this transformation.
101 *
102 * -x +x
103 * ^
104 * |
105 * +-----------+--> +y
106 * | |
107 * | |
108 * | |
109 * | | / -z
110 * | | /
111 * | | /
112 * +-----------+/
113 * | o O o /
114 * +----------/+ -y
115 * /
116 * /
117 * |/ +z
118 *
119 */
120typedef struct {
121 union {
122 float v[3];
123 struct {
124 float x;
125 float y;
126 float z;
127 };
128 struct {
129 float yaw;
130 float pitch;
131 float roll;
132 };
133 };
134 int8_t status;
135 uint8_t reserved[3];
136} sensors_vec_t;
137
138/**
139 * Union of the various types of sensor data
140 * that can be returned.
141 */
142typedef struct {
143 /* sensor identifier */
144 int sensor;
145
146 union {
147 /* x,y,z values of the given sensor */
148 sensors_vec_t vector;
149
150 /* orientation values are in degres */
151 sensors_vec_t orientation;
152
153 /* acceleration values are in meter per second per second (m/s^2) */
154 sensors_vec_t acceleration;
155
156 /* magnetic vector values are in micro-Tesla (uT) */
157 sensors_vec_t magnetic;
158
159 /* temperature is in degres C */
160 float temperature;
161 };
162
163 /* time is in nanosecond */
164 int64_t time;
165
166 uint32_t reserved;
167} sensors_data_t;
168
169/**
170 * Initialize the module. This is the first entry point
171 * called and typically initializes the hardware.
172 *
173 * @return bit map of available sensors defined by
174 * the constants SENSORS_XXXX.
175 */
176uint32_t sensors_control_init();
177
178/**
179 * Returns the fd which will be the parameter to
180 * sensors_data_open. The caller takes ownership
181 * of this fd.
182 *
183 * @return a fd if successful, < 0 on error
184 */
185int sensors_control_open();
186
187/** Activate/deactiveate one or more of the sensors.
188 *
189 * @param sensors is a bitmask of the sensors to change.
190 * @param mask is a bitmask for enabling/disabling sensors.
191 *
192 * @return bitmask of SENSORS_XXXX indicating which sensors are enabled
193 */
194uint32_t sensors_control_activate(uint32_t sensors, uint32_t mask);
195
196/**
197 * Set the delay between sensor events in ms
198 *
199 * @return 0 if successful, < 0 on error
200 */
201int sensors_control_delay(int32_t ms);
202
203/**
204 * Prepare to read sensor data.
205 *
206 * This routiune does NOT take ownership of the fd
207 * and must not close it. Typcially this routine would
208 * use a duplicate of the fd parameter.
209 *
210 * @param fd from sensors_control_open.
211 *
212 * @return 0 if successful, < 0 on error
213 */
214int sensors_data_open(int fd);
215
216/**
217 * Caller has completed using the sensor data.
218 * The caller will not be blocked in sensors_data_poll
219 * when this routine is called.
220 *
221 * @return 0 if successful, < 0 on error
222 */
223int sensors_data_close();
224
225/**
226 * Return sensor data for one of the enabled sensors.
227 *
228 * @return SENSOR_XXXX for the returned data, -1 on error
229 * */
230int sensors_data_poll(sensors_data_t* data, uint32_t sensors_of_interest);
231
232/**
233 * @return bit map of available sensors defined by
234 * the constants SENSORS_XXXX.
235 */
236uint32_t sensors_data_get_sensors();
237
238
239#if __cplusplus
240} // extern "C"
241#endif
242
243#endif // _HARDWARE_SENSORS_H