#include <sys/types.h>
#include <hardware/hardware.h>
+#include <cutils/native_handle.h>
__BEGIN_DECLS
/**
* Name of the sensors device to open
*/
-#define SENSORS_HARDWARE_CONTROL "control"
-#define SENSORS_HARDWARE_DATA "data"
+#define SENSORS_HARDWARE_POLL "poll"
/**
* Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
#define SENSOR_TYPE_PRESSURE 6
#define SENSOR_TYPE_TEMPERATURE 7
#define SENSOR_TYPE_PROXIMITY 8
+#define SENSOR_TYPE_GRAVITY 9
+#define SENSOR_TYPE_LINEAR_ACCELERATION 10
+#define SENSOR_TYPE_ROTATION_VECTOR 11
/**
* Values returned by the accelerometer in various locations in the universe.
*/
#define GRAVITY_SUN (275.0f)
-#define GRAVITY_MERCURY (3.70f)
-#define GRAVITY_VENUS (8.87f)
#define GRAVITY_EARTH (9.80665f)
-#define GRAVITY_MOON (1.6f)
-#define GRAVITY_MARS (3.71f)
-#define GRAVITY_JUPITER (23.12f)
-#define GRAVITY_SATURN (8.96f)
-#define GRAVITY_URANUS (8.69f)
-#define GRAVITY_NEPTUNE (11.0f)
-#define GRAVITY_PLUTO (0.6f)
-#define GRAVITY_DEATH_STAR_I (0.000000353036145f)
-#define GRAVITY_THE_ISLAND (4.815162342f)
/** Maximum magnetic field on Earth's surface */
#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
*
* All values are angles in degrees.
*
+ * Orientation sensors return sensor events for all 3 axes at a constant
+ * rate defined by setDelay().
+ *
* azimuth: angle between the magnetic north direction and the Y axis, around
* the Z axis (0<=azimuth<360).
* 0=North, 90=East, 180=South, 270=West
* the z-axis moves toward the y-axis.
*
* roll: Rotation around Y axis (-90<=roll<=90), with positive values when
- * the z-axis moves AWAY from the x-axis.
- *
+ * the x-axis moves towards the z-axis.
+ *
+ * Note: For historical reasons the roll angle is positive in the clockwise
+ * direction (mathematically speaking, it should be positive in the
+ * counter-clockwise direction):
+ *
+ * Z
+ * ^
+ * (+roll) .--> |
+ * / |
+ * | | roll: rotation around Y axis
+ * X <-------(.)
+ * Y
+ * note that +Y == -roll
+ *
+ *
+ *
* Note: This definition is different from yaw, pitch and roll used in aviation
* where the X axis is along the long side of the plane (tail to nose).
*
* All values are in SI units (m/s^2) and measure the acceleration of the
* device minus the force of gravity.
*
+ * Acceleration sensors return sensor events for all 3 axes at a constant
+ * rate defined by setDelay().
+ *
* x: Acceleration minus Gx on the x-axis
* y: Acceleration minus Gy on the y-axis
* z: Acceleration minus Gz on the z-axis
*
* All values are in micro-Tesla (uT) and measure the ambient magnetic
* field in the X, Y and Z axis.
- *
+ *
+ * Magnetic Field sensors return sensor events for all 3 axes at a constant
+ * rate defined by setDelay().
+ *
+ * Gyroscope
+ * ---------
+ * All values are in radians/second and measure the rate of rotation
+ * around the X, Y and Z axis. The coordinate system is the same as is
+ * used for the acceleration sensor. Rotation is positive in the counter-clockwise
+ * direction. That is, an observer looking from some positive location on the x, y.
+ * or z axis at a device positioned on the origin would report positive rotation
+ * if the device appeared to be rotating counter clockwise. Note that this is the
+ * standard mathematical definition of positive rotation and does not agree with the
+ * definition of roll given earlier.
+ *
+ * Proximity
+ * ---------
+ *
+ * The distance value is measured in centimeters. Note that some proximity
+ * sensors only support a binary "close" or "far" measurement. In this case,
+ * the sensor should report its maxRange value in the "far" state and a value
+ * less than maxRange in the "near" state.
+ *
+ * Proximity sensors report a value only when it changes and each time the
+ * sensor is enabled. setDelay() is ignored.
+ *
+ * Light
+ * -----
+ *
+ * The light sensor value is returned in SI lux units.
+ *
+ * Light sensors report a value only when it changes and each time the
+ * sensor is enabled. setDelay() is ignored.
+ *
+ * Pressure
+ * --------
+ *
+ * The pressure sensor value is returned in hectopascal (hPa)
+ *
+ * Pressure sensors report events at a constant rate defined by setDelay().
+ *
+ * Gravity
+ * -------
+ * A gravity output indicates the direction of and magnitude of gravity in the devices's
+ * coordinates. On Earth, the magnitude is 9.8. Units are m/s^2. The coordinate system
+ * is the same as is used for the acceleration sensor.
+ *
+ * Linear Acceleration
+ * -------------------
+ * Indicates the linear acceleration of the device in device coordinates, not including gravity.
+ * This output is essentially Acceleration - Gravity. Units are m/s^2. The coordinate system is
+ * the same as is used for the acceleration sensor.
+ *
+ * Rotation Vector
+ * ---------------
+ * A rotation vector represents the orientation of the device as a combination
+ * of an angle and an axis, in which the device has rotated through an angle
+ * theta around an axis <x, y, z>. The three elements of the rotation vector
+ * are <x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>, such that the magnitude
+ * of the rotation vector is equal to sin(theta/2), and the direction of the
+ * rotation vector is equal to the direction of the axis of rotation. The three
+ * elements of the rotation vector are equal to the last three components of a
+ * unit quaternion <cos(theta/2), x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>.
+ * Elements of the rotation vector are unitless. The x, y, and z axis are defined
+ * in the same was as for the acceleration sensor.
*/
+
typedef struct {
union {
float v[3];
* Union of the various types of sensor data
* that can be returned.
*/
-typedef struct {
+typedef struct sensors_event_t {
+ /* must be sizeof(struct sensors_event_t) */
+ int32_t version;
+
/* sensor identifier */
- int sensor;
+ int32_t sensor;
- union {
- /* x,y,z values of the given sensor */
- sensors_vec_t vector;
+ /* sensor type */
+ int32_t type;
- /* orientation values are in degrees */
- sensors_vec_t orientation;
+ /* reserved */
+ int32_t reserved0;
+
+ /* time is in nanosecond */
+ int64_t timestamp;
+
+ union {
+ float data[16];
/* acceleration values are in meter per second per second (m/s^2) */
sensors_vec_t acceleration;
/* magnetic vector values are in micro-Tesla (uT) */
sensors_vec_t magnetic;
+ /* orientation values are in degrees */
+ sensors_vec_t orientation;
+
/* temperature is in degrees centigrade (Celsius) */
float temperature;
- };
- /* time is in nanosecond */
- int64_t time;
+ /* distance in centimeters */
+ float distance;
+
+ /* light in SI lux units */
+ float light;
+
+ /* pressure in hectopascal (hPa) */
+ float pressure;
+ };
+ uint32_t reserved1[4];
+} sensors_event_t;
- uint32_t reserved;
-} sensors_data_t;
struct sensor_t;
/* vendor of the hardware part */
const char* vendor;
/* version of the hardware part + driver. The value of this field is
- * left to the implementation and doesn't have to be monotonicaly
+ * left to the implementation and doesn't have to be monotonically
* increasing.
*/
int version;
float resolution;
/* rough estimate of this sensor's power consumption in mA */
float power;
+ /* minimum delay allowed between events in microseconds. A value of zero
+ * means that this sensor doesn't report events at a constant rate, but
+ * rather only when a new data is available */
+ int32_t minDelay;
/* reserved fields, must be zero */
- void* reserved[9];
+ void* reserved[8];
};
* Every device data structure must begin with hw_device_t
* followed by module specific public methods and attributes.
*/
-struct sensors_control_device_t {
+struct sensors_poll_device_t {
struct hw_device_t common;
-
- /**
- * Returns the fd which will be the parameter to
- * sensors_data_device_t::open_data().
- * The caller takes ownership of this fd. This is intended to be
- * passed cross processes.
- *
- * @return a fd if successful, < 0 on error
- */
- int (*open_data_source)(struct sensors_control_device_t *dev);
-
+
/** Activate/deactivate one sensor.
*
* @param handle is the handle of the sensor to change.
*
* @return 0 on success, negative errno code otherwise
*/
- int (*activate)(struct sensors_control_device_t *dev,
+ int (*activate)(struct sensors_poll_device_t *dev,
int handle, int enabled);
-
- /**
- * Set the delay between sensor events in ms
- *
- * @return 0 if successful, < 0 on error
- */
- int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms);
/**
- * Causes sensors_data_device_t.poll() to return -EWOULDBLOCK immediately.
- */
- int (*wake)(struct sensors_control_device_t *dev);
-};
-
-struct sensors_data_device_t {
- struct hw_device_t common;
-
- /**
- * Prepare to read sensor data.
- *
- * This routine does NOT take ownership of the fd
- * and must not close it. Typically this routine would
- * use a duplicate of the fd parameter.
- *
- * @param fd from sensors_control_open.
+ * Set the delay between sensor events in nanoseconds for a given sensor.
+ * It is an error to set a delay inferior to the value defined by
+ * sensor_t::minDelay. If sensor_t::minDelay is zero, setDelay() is
+ * ignored and returns 0.
*
* @return 0 if successful, < 0 on error
*/
- int (*data_open)(struct sensors_data_device_t *dev, int fd);
-
+ int (*setDelay)(struct sensors_poll_device_t *dev,
+ int handle, int64_t ns);
+
/**
- * Caller has completed using the sensor data.
- * The caller will not be blocked in sensors_data_poll
- * when this routine is called.
+ * Returns an array of sensor data.
+ * This function must block until events are available.
*
- * @return 0 if successful, < 0 on error
- */
- int (*data_close)(struct sensors_data_device_t *dev);
-
- /**
- * Return sensor data for one of the enabled sensors.
+ * @return the number of events read on success, or -errno in case of an error.
+ * This function should never return 0 (no event).
*
- * @return sensor handle for the returned data, 0x7FFFFFFF when
- * sensors_control_device_t.wake() is called and -errno on error
- *
*/
- int (*poll)(struct sensors_data_device_t *dev,
- sensors_data_t* data);
+ int (*poll)(struct sensors_poll_device_t *dev,
+ sensors_event_t* data, int count);
};
-
/** convenience API for opening and closing a device */
-static inline int sensors_control_open(const struct hw_module_t* module,
- struct sensors_control_device_t** device) {
- return module->methods->open(module,
- SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device);
-}
-
-static inline int sensors_control_close(struct sensors_control_device_t* device) {
- return device->common.close(&device->common);
-}
-
-static inline int sensors_data_open(const struct hw_module_t* module,
- struct sensors_data_device_t** device) {
- return module->methods->open(module,
- SENSORS_HARDWARE_DATA, (struct hw_device_t**)device);
+static inline int sensors_open(const struct hw_module_t* module,
+ struct sensors_poll_device_t** device) {
+ return module->methods->open(module,
+ SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
}
-static inline int sensors_data_close(struct sensors_data_device_t* device) {
+static inline int sensors_close(struct sensors_poll_device_t* device) {
return device->common.close(&device->common);
}
-
__END_DECLS
+#include <hardware/sensors_deprecated.h>
+
#endif // ANDROID_SENSORS_INTERFACE_H