sensors.h revision d93ff971bd507e92ac81c149079906d2123795af
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 5954f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian#define SENSOR_TYPE_TEMPERATURE 7 // deprecated 60f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_TYPE_PROXIMITY 8 61b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell#define SENSOR_TYPE_GRAVITY 9 62b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell#define SENSOR_TYPE_LINEAR_ACCELERATION 10 63b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell#define SENSOR_TYPE_ROTATION_VECTOR 11 6454f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian#define SENSOR_TYPE_AMBIENT_TEMPERATURE 13 65f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 66f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 67f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Values returned by the accelerometer in various locations in the universe. 68f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * all values are in SI units (m/s^2) 69f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 70f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 71f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define GRAVITY_SUN (275.0f) 72f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define GRAVITY_EARTH (9.80665f) 73f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 74f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** Maximum magnetic field on Earth's surface */ 75f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define MAGNETIC_FIELD_EARTH_MAX (60.0f) 76f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 77f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** Minimum magnetic field on Earth's surface */ 78f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define MAGNETIC_FIELD_EARTH_MIN (30.0f) 79f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 80f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 81f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 82f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * status of each sensor 83f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 84f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 85f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_STATUS_UNRELIABLE 0 86f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_STATUS_ACCURACY_LOW 1 87f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_STATUS_ACCURACY_MEDIUM 2 88f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#define SENSOR_STATUS_ACCURACY_HIGH 3 89f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 90f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 91f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Definition of the axis 92f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * ---------------------- 93f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 94f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * This API is relative to the screen of the device in its default orientation, 95f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * that is, if the device can be used in portrait or landscape, this API 96f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * is only relative to the NATURAL orientation of the screen. In other words, 97f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * the axis are not swapped when the device's screen orientation changes. 98f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Higher level services /may/ perform this transformation. 99f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 100f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * x<0 x>0 101f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * ^ 102f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | 103f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * +-----------+--> y>0 104f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | 105f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | 106f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | 107f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | / z<0 108f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | / 109f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * | | / 110f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * O-----------+/ 111f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * |[] [ ] []/ 112f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * +----------/+ y<0 113f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * / 114f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * / 115f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * |/ z>0 (toward the sky) 116f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 117f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * O: Origin (x=0,y=0,z=0) 118f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 119f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 120f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Orientation 121f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * ----------- 122f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 123f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * All values are angles in degrees. 124f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 12566a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * Orientation sensors return sensor events for all 3 axes at a constant 12666a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * rate defined by setDelay(). 12766a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * 128f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * azimuth: angle between the magnetic north direction and the Y axis, around 129f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * the Z axis (0<=azimuth<360). 130f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 0=North, 90=East, 180=South, 270=West 131f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 132f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when 133f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * the z-axis moves toward the y-axis. 134f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 135f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * roll: Rotation around Y axis (-90<=roll<=90), with positive values when 13619ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * the x-axis moves towards the z-axis. 13719ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 13819ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * Note: For historical reasons the roll angle is positive in the clockwise 13919ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * direction (mathematically speaking, it should be positive in the 14019ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * counter-clockwise direction): 14119ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 14219ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * Z 14319ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * ^ 14419ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * (+roll) .--> | 14519ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * / | 14619ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * | | roll: rotation around Y axis 14719ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * X <-------(.) 14819ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * Y 14919ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * note that +Y == -roll 15019ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 15119ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 15219ea59f86521c1b3ef72999e3cccc47b48c445adMathias Agopian * 153f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Note: This definition is different from yaw, pitch and roll used in aviation 154f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * where the X axis is along the long side of the plane (tail to nose). 155f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 156f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 157f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Acceleration 158f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * ------------ 159f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 160f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * All values are in SI units (m/s^2) and measure the acceleration of the 161f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * device minus the force of gravity. 162f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 16366a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * Acceleration sensors return sensor events for all 3 axes at a constant 16466a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * rate defined by setDelay(). 16566a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * 166f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * x: Acceleration minus Gx on the x-axis 167f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * y: Acceleration minus Gy on the y-axis 168f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * z: Acceleration minus Gz on the z-axis 169f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 170f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Examples: 171f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * When the device lies flat on a table and is pushed on its left side 172f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * toward the right, the x acceleration value is positive. 173f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 174f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * When the device lies flat on a table, the acceleration value is +9.81, 175f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * which correspond to the acceleration of the device (0 m/s^2) minus the 176f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * force of gravity (-9.81 m/s^2). 177f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 178f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * When the device lies flat on a table and is pushed toward the sky, the 179f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * acceleration value is greater than +9.81, which correspond to the 180f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * acceleration of the device (+A m/s^2) minus the force of 181f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * gravity (-9.81 m/s^2). 182f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 183f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 184f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Magnetic Field 185f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * -------------- 186f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * 187f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * All values are in micro-Tesla (uT) and measure the ambient magnetic 188f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * field in the X, Y and Z axis. 189a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * 19066a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * Magnetic Field sensors return sensor events for all 3 axes at a constant 19166a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * rate defined by setDelay(). 19266a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * 193b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * Gyroscope 194b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * --------- 195b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * All values are in radians/second and measure the rate of rotation 196b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * around the X, Y and Z axis. The coordinate system is the same as is 197c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * used for the acceleration sensor. Rotation is positive in the 198c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * counter-clockwise direction (right-hand rule). That is, an observer 199c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * looking from some positive location on the x, y or z axis at a device 200c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * positioned on the origin would report positive rotation if the device 201c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * appeared to be rotating counter clockwise. Note that this is the 202c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * standard mathematical definition of positive rotation and does not agree 203c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * with the definition of roll given earlier. 204c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian * The range should at least be 17.45 rad/s (ie: ~1000 deg/s). 205b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * 206a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * Proximity 207a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * --------- 208a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * 209a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * The distance value is measured in centimeters. Note that some proximity 210a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * sensors only support a binary "close" or "far" measurement. In this case, 211a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * the sensor should report its maxRange value in the "far" state and a value 212a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * less than maxRange in the "near" state. 213a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * 214478994a758e48b0de7f56f3de0678d5c2b6a4b61Mathias Agopian * Proximity sensors report a value only when it changes and each time the 215478994a758e48b0de7f56f3de0678d5c2b6a4b61Mathias Agopian * sensor is enabled. setDelay() is ignored. 21666a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * 217a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * Light 218a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * ----- 219a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * 220a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * The light sensor value is returned in SI lux units. 221a2414316075dde4ca5c1393c662f224b36dd3fdcMike Lockwood * 222478994a758e48b0de7f56f3de0678d5c2b6a4b61Mathias Agopian * Light sensors report a value only when it changes and each time the 223478994a758e48b0de7f56f3de0678d5c2b6a4b61Mathias Agopian * sensor is enabled. setDelay() is ignored. 22466a4095ca0ecfe89b10abe5402617450f57759cdMathias Agopian * 2251832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * Pressure 2261832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * -------- 2271832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * 2281832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * The pressure sensor value is returned in hectopascal (hPa) 2291832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * 2301832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * Pressure sensors report events at a constant rate defined by setDelay(). 2311832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian * 2323120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar * Gyro 2333120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar * -------- 2343120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar * 2353120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar * The gyroscope sensor values are returned in degrees per second (dps) 2363120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar * 2373120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar * Gyroscope sensor report events at a constant rate defined by setDelay(). 2383120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar * 239b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * Gravity 240b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * ------- 241b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * A gravity output indicates the direction of and magnitude of gravity in the devices's 242b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * coordinates. On Earth, the magnitude is 9.8. Units are m/s^2. The coordinate system 243b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * is the same as is used for the acceleration sensor. 24442b743c85597e982ff1122b972862396f131db34Mathias Agopian * When the device is at rest, the output of the gravity sensor should be identical 24542b743c85597e982ff1122b972862396f131db34Mathias Agopian * to that of the accelerometer. 246b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * 247b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * Linear Acceleration 248b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * ------------------- 249b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * Indicates the linear acceleration of the device in device coordinates, not including gravity. 250b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * This output is essentially Acceleration - Gravity. Units are m/s^2. The coordinate system is 251b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * the same as is used for the acceleration sensor. 25242b743c85597e982ff1122b972862396f131db34Mathias Agopian * The output of the accelerometer, gravity and linear-acceleration sensors must obey the 25342b743c85597e982ff1122b972862396f131db34Mathias Agopian * following relation: 25442b743c85597e982ff1122b972862396f131db34Mathias Agopian * 25542b743c85597e982ff1122b972862396f131db34Mathias Agopian * acceleration = gravity + linear-acceleration 25642b743c85597e982ff1122b972862396f131db34Mathias Agopian * 257b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * 258b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * Rotation Vector 259b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * --------------- 260b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * A rotation vector represents the orientation of the device as a combination 261b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * of an angle and an axis, in which the device has rotated through an angle 262b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * theta around an axis <x, y, z>. The three elements of the rotation vector 263b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * are <x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>, such that the magnitude 264b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * of the rotation vector is equal to sin(theta/2), and the direction of the 265b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * rotation vector is equal to the direction of the axis of rotation. The three 266b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * elements of the rotation vector are equal to the last three components of a 267b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * unit quaternion <cos(theta/2), x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>. 268b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * Elements of the rotation vector are unitless. The x, y, and z axis are defined 269b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell * in the same was as for the acceleration sensor. 27042b743c85597e982ff1122b972862396f131db34Mathias Agopian * 271d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * The reference coordinate system is defined as a direct orthonormal basis, 272d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * where: 273d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * 274d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * - X is defined as the vector product Y.Z (It is tangential to 275d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * the ground at the device's current location and roughly points East). 276d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * 277d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * - Y is tangential to the ground at the device's current location and 278d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * points towards the magnetic North Pole. 279d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * 280d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * - Z points towards the sky and is perpendicular to the ground. 281d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * 282d93ff971bd507e92ac81c149079906d2123795afMathias Agopian * 28342b743c85597e982ff1122b972862396f131db34Mathias Agopian * The rotation-vector is stored as: 28442b743c85597e982ff1122b972862396f131db34Mathias Agopian * 28542b743c85597e982ff1122b972862396f131db34Mathias Agopian * sensors_event_t.data[0] = x*sin(theta/2) 28642b743c85597e982ff1122b972862396f131db34Mathias Agopian * sensors_event_t.data[1] = y*sin(theta/2) 28742b743c85597e982ff1122b972862396f131db34Mathias Agopian * sensors_event_t.data[2] = z*sin(theta/2) 28842b743c85597e982ff1122b972862396f131db34Mathias Agopian * sensors_event_t.data[3] = cos(theta/2) 28942b743c85597e982ff1122b972862396f131db34Mathias Agopian * 29054f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * Ambient Temperature 29154f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * ------------------- 29254f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * 29354f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * The ambient (room) temperature in degree Celsius. 29454f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * 29554f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * Temperature sensors report a value only when it changes and each time the 29654f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * sensor is enabled. setDelay() is ignored. 29754f9dd032dfbd336ca90e3b44047373f0297c3a5Mathias Agopian * 298f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 299b01a043df41e987321f6c01930ac306befb1d3dcKevin Powell 300f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projecttypedef struct { 301f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project union { 302f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float v[3]; 303f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project struct { 304f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float x; 305f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float y; 306f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float z; 307f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project }; 308f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project struct { 309f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float azimuth; 310f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float pitch; 311f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float roll; 312f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project }; 313f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project }; 314f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int8_t status; 315f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project uint8_t reserved[3]; 316f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project} sensors_vec_t; 317f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 318f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 319f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Union of the various types of sensor data 320f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * that can be returned. 321f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 322cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopiantypedef struct sensors_event_t { 323cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* must be sizeof(struct sensors_event_t) */ 324cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int32_t version; 325cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 326cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* sensor identifier */ 327cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int32_t sensor; 328cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 329cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* sensor type */ 330cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int32_t type; 331cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 332cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* reserved */ 333cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int32_t reserved0; 334cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 335cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* time is in nanosecond */ 336cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian int64_t timestamp; 337cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 338cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian union { 339cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian float data[16]; 340cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 341cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* acceleration values are in meter per second per second (m/s^2) */ 342cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian sensors_vec_t acceleration; 343cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 344cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* magnetic vector values are in micro-Tesla (uT) */ 345cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian sensors_vec_t magnetic; 346cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 347cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* orientation values are in degrees */ 348cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian sensors_vec_t orientation; 349cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 350c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian /* gyroscope values are in rad/s */ 351c04e5f68905127ae4c1a0c17d225db9cebe66a07Mathias Agopian sensors_vec_t gyro; 3523120b58768ff6aad5ad169b9c18f962ef6abb3c5Makarand Karvekar 353cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* temperature is in degrees centigrade (Celsius) */ 354cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian float temperature; 355cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 356cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* distance in centimeters */ 357cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian float distance; 358cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 359cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian /* light in SI lux units */ 360cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian float light; 3611832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian 3621832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian /* pressure in hectopascal (hPa) */ 3631832f55760fff86d00b5d808b3da8f1e55a889e5Mathias Agopian float pressure; 364cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian }; 365cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian uint32_t reserved1[4]; 366cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian} sensors_event_t; 367cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 368cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 369cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian 370f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensor_t; 371f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 372f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 373f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 374f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * and the fields of this data structure must begin with hw_module_t 375f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * followed by module specific information. 376f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 377f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensors_module_t { 378f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project struct hw_module_t common; 379f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 380f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /** 381f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Enumerate all available sensors. The list is returned in "list". 382f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * @return number of sensors in the list 383f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 384f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int (*get_sensors_list)(struct sensors_module_t* module, 385f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project struct sensor_t const** list); 386f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project}; 387f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 388f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Projectstruct sensor_t { 389f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* name of this sensors */ 390f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project const char* name; 391f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* vendor of the hardware part */ 392f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project const char* vendor; 393f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* version of the hardware part + driver. The value of this field is 394b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * left to the implementation and doesn't have to be monotonically 395f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * increasing. 396f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 397f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int version; 398f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* handle that identifies this sensors. This handle is used to activate 399f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * and deactivate this sensor. The value of the handle must be 8 bits 400f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * in this version of the API. 401f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 402f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int handle; 403f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* this sensor's type. */ 404f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project int type; 405f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* maximaum range of this sensor's value in SI units */ 406f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float maxRange; 407f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* smallest difference between two values reported by this sensor */ 408f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float resolution; 409f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* rough estimate of this sensor's power consumption in mA */ 410f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project float power; 4111511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian /* minimum delay allowed between events in microseconds. A value of zero 4121511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian * means that this sensor doesn't report events at a constant rate, but 4131511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian * rather only when a new data is available */ 4141511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian int32_t minDelay; 415f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project /* reserved fields, must be zero */ 4161511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian void* reserved[8]; 417f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project}; 418f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 419f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 420f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** 421f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * Every device data structure must begin with hw_device_t 422f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project * followed by module specific public methods and attributes. 423f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project */ 424b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstruct sensors_poll_device_t { 425b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian struct hw_device_t common; 426b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 427b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian /** Activate/deactivate one sensor. 428b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * 429b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * @param handle is the handle of the sensor to change. 430b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * @param enabled set to 1 to enable, or 0 to disable the sensor. 431b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * 432b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * @return 0 on success, negative errno code otherwise 433b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian */ 434b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian int (*activate)(struct sensors_poll_device_t *dev, 435b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian int handle, int enabled); 436b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 437b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian /** 4381511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian * Set the delay between sensor events in nanoseconds for a given sensor. 4391511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian * It is an error to set a delay inferior to the value defined by 4401511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian * sensor_t::minDelay. If sensor_t::minDelay is zero, setDelay() is 4411511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian * ignored and returns 0. 442b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * 443b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * @return 0 if successful, < 0 on error 444b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian */ 445b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian int (*setDelay)(struct sensors_poll_device_t *dev, 446b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian int handle, int64_t ns); 447b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 448b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian /** 449b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * Returns an array of sensor data. 4501511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian * This function must block until events are available. 451b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * 452b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * @return the number of events read on success, or -errno in case of an error. 4531511e20fbbdfe7bf30b9de73f06fc981eb494f09Mathias Agopian * This function should never return 0 (no event). 454b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian * 455b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian */ 456b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian int (*poll)(struct sensors_poll_device_t *dev, 457cdefccdba52337df41f577d9ebfcfd67c05708cfMathias Agopian sensors_event_t* data, int count); 458b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian}; 459b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 460f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project/** convenience API for opening and closing a device */ 461f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 462b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstatic inline int sensors_open(const struct hw_module_t* module, 463b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian struct sensors_poll_device_t** device) { 464b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian return module->methods->open(module, 465b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian SENSORS_HARDWARE_POLL, (struct hw_device_t**)device); 466b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian} 467b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 468b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopianstatic inline int sensors_close(struct sensors_poll_device_t* device) { 469b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian return device->common.close(&device->common); 470b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian} 471b1e212e7b6fce2bc5c743b05853129e19760d7a4Mathias Agopian 472f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project__END_DECLS 473f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project 474f53ebec38718ff5d6b2aff2fa62b92a75d007ca5The Android Open Source Project#endif // ANDROID_SENSORS_INTERFACE_H 475