Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

phh
Saturday, January 2nd, 2010 at 1:31:57pm MST 

  1. /*
  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 ANDROID_SENSORS_INTERFACE_H
  18. #define ANDROID_SENSORS_INTERFACE_H
  19.  
  20. #include <stdint.h>
  21. #include <sys/cdefs.h>
  22. #include <sys/types.h>
  23.  
  24. #include <hardware/hardware.h>
  25. #include <cutils/native_handle.h>
  26.  
  27. __BEGIN_DECLS
  28.  
  29. /**
  30.  * The id of this module
  31.  */
  32. #define SENSORS_HARDWARE_MODULE_ID "sensors"
  33.  
  34. /**
  35.  * Name of the sensors device to open
  36.  */
  37. #define SENSORS_HARDWARE_CONTROL    "control"
  38. #define SENSORS_HARDWARE_DATA       "data"
  39.  
  40. /**
  41.  * Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
  42.  * A Handle identifies a given sensors. The handle is used to activate
  43.  * and/or deactivate sensors.
  44.  * In this version of the API there can only be 256 handles.
  45.  */
  46. #define SENSORS_HANDLE_BASE             0
  47. #define SENSORS_HANDLE_BITS             8
  48. #define SENSORS_HANDLE_COUNT            (1<<SENSORS_HANDLE_BITS)
  49.  
  50.  
  51. /**
  52.  * Sensor types
  53.  */
  54. #define SENSOR_TYPE_ACCELEROMETER       1
  55. #define SENSOR_TYPE_MAGNETIC_FIELD      2
  56. #define SENSOR_TYPE_ORIENTATION         3
  57. #define SENSOR_TYPE_GYROSCOPE           4
  58. #define SENSOR_TYPE_LIGHT               5
  59. #define SENSOR_TYPE_PRESSURE            6
  60. #define SENSOR_TYPE_TEMPERATURE         7
  61. #define SENSOR_TYPE_PROXIMITY           8
  62.  
  63. /**
  64.  * Values returned by the accelerometer in various locations in the universe.
  65.  * all values are in SI units (m/s^2)
  66.  */
  67.  
  68. #define GRAVITY_SUN             (275.0f)
  69. #define GRAVITY_MERCURY         (3.70f)
  70. #define GRAVITY_VENUS           (8.87f)
  71. #define GRAVITY_EARTH           (9.80665f)
  72. #define GRAVITY_MOON            (1.6f)
  73. #define GRAVITY_MARS            (3.71f)
  74. #define GRAVITY_JUPITER         (23.12f)
  75. #define GRAVITY_SATURN          (8.96f)
  76. #define GRAVITY_URANUS          (8.69f)
  77. #define GRAVITY_NEPTUNE         (11.0f)
  78. #define GRAVITY_PLUTO           (0.6f)
  79. #define GRAVITY_DEATH_STAR_I    (0.000000353036145f)
  80. #define GRAVITY_THE_ISLAND      (4.815162342f)
  81.  
  82. /** Maximum magnetic field on Earth's surface */
  83. #define MAGNETIC_FIELD_EARTH_MAX    (60.0f)
  84.  
  85. /** Minimum magnetic field on Earth's surface */
  86. #define MAGNETIC_FIELD_EARTH_MIN    (30.0f)
  87.  
  88.  
  89. /**
  90.  * status of each sensor
  91.  */
  92.  
  93. #define SENSOR_STATUS_UNRELIABLE        0
  94. #define SENSOR_STATUS_ACCURACY_LOW      1
  95. #define SENSOR_STATUS_ACCURACY_MEDIUM   2
  96. #define SENSOR_STATUS_ACCURACY_HIGH     3
  97.  
  98. /**
  99.  * Definition of the axis
  100.  * ----------------------
  101.  *
  102.  * This API is relative to the screen of the device in its default orientation,
  103.  * that is, if the device can be used in portrait or landscape, this API
  104.  * is only relative to the NATURAL orientation of the screen. In other words,
  105.  * the axis are not swapped when the device's screen orientation changes.
  106.  * Higher level services /may/ perform this transformation.
  107.  *
  108.  *   x<0         x>0
  109.  *                ^
  110.  *                |
  111.  *    +-----------+-->  y>0
  112.  *    |           |
  113.  *    |           |
  114.  *    |           |
  115.  *    |           |   / z<0
  116.  *    |           |  /
  117.  *    |           | /
  118.  *    O-----------+/
  119.  *    |[]  [ ]  []/
  120.  *    +----------/+     y<0
  121.  *              /
  122.  *             /
  123.  *           |/ z>0 (toward the sky)
  124.  *
  125.  *    O: Origin (x=0,y=0,z=0)
  126.  *
  127.  *
  128.  * Orientation
  129.  * -----------
  130.  *
  131.  * All values are angles in degrees.
  132.  *
  133.  * azimuth: angle between the magnetic north direction and the Y axis, around
  134.  *  the Z axis (0<=azimuth<360).
  135.  *      0=North, 90=East, 180=South, 270=West
  136.  *
  137.  * pitch: Rotation around X axis (-180<=pitch<=180), with positive values when
  138.  *  the z-axis moves toward the y-axis.
  139.  *
  140.  * roll: Rotation around Y axis (-90<=roll<=90), with positive values when
  141.  *  the x-axis moves AWAY from the z-axis.
  142.  *
  143.  * Note: This definition is different from yaw, pitch and roll used in aviation
  144.  *  where the X axis is along the long side of the plane (tail to nose).
  145.  * 
  146.  * 
  147.  * Acceleration
  148.  * ------------
  149.  *
  150.  *  All values are in SI units (m/s^2) and measure the acceleration of the
  151.  *  device minus the force of gravity.
  152.  * 
  153.  *  x: Acceleration minus Gx on the x-axis
  154.  *  y: Acceleration minus Gy on the y-axis
  155.  *  z: Acceleration minus Gz on the z-axis
  156.  * 
  157.  *  Examples:
  158.  *    When the device lies flat on a table and is pushed on its left side
  159.  *    toward the right, the x acceleration value is positive.
  160.  *   
  161.  *    When the device lies flat on a table, the acceleration value is +9.81,
  162.  *    which correspond to the acceleration of the device (0 m/s^2) minus the
  163.  *    force of gravity (-9.81 m/s^2).
  164.  *   
  165.  *    When the device lies flat on a table and is pushed toward the sky, the
  166.  *    acceleration value is greater than +9.81, which correspond to the
  167.  *    acceleration of the device (+A m/s^2) minus the force of
  168.  *    gravity (-9.81 m/s^2).
  169.  *   
  170.  *   
  171.  * Magnetic Field
  172.  * --------------
  173.  *
  174.  *  All values are in micro-Tesla (uT) and measure the ambient magnetic
  175.  *  field in the X, Y and Z axis.
  176.  *
  177.  * Proximity
  178.  * ---------
  179.  *
  180.  * The distance value is measured in centimeters.  Note that some proximity
  181.  * sensors only support a binary "close" or "far" measurement.  In this case,
  182.  * the sensor should report its maxRange value in the "far" state and a value
  183.  * less than maxRange in the "near" state.
  184.  *
  185.  * Light
  186.  * -----
  187.  *
  188.  * The light sensor value is returned in SI lux units.
  189.  *
  190.  */
  191. typedef struct {
  192.     union {
  193.         float v[3];
  194.         struct {
  195.             float x;
  196.             float y;
  197.             float z;
  198.         };
  199.         struct {
  200.             float azimuth;
  201.             float pitch;
  202.             float roll;
  203.         };
  204.     };
  205.     int8_t status;
  206.     uint8_t reserved[3];
  207. } sensors_vec_t;
  208.  
  209. /**
  210.  * Union of the various types of sensor data
  211.  * that can be returned.
  212.  */
  213. typedef struct {
  214.     /* sensor identifier */
  215.     int             sensor;
  216.  
  217.     union {
  218.         /* x,y,z values of the given sensor */
  219.         sensors_vec_t   vector;
  220.  
  221.         /* orientation values are in degrees */
  222.         sensors_vec_t   orientation;
  223.  
  224.         /* acceleration values are in meter per second per second (m/s^2) */
  225.         sensors_vec_t   acceleration;
  226.  
  227.         /* magnetic vector values are in micro-Tesla (uT) */
  228.         sensors_vec_t   magnetic;
  229.  
  230.         /* temperature is in degrees centigrade (Celsius) */
  231.         float           temperature;
  232.  
  233.         /* distance in centimeters */
  234.         float           distance;
  235.  
  236.         /* light in SI lux units */
  237.         float           light;
  238.     };
  239.  
  240.     /* time is in nanosecond */
  241.     int64_t         time;
  242.  
  243.     uint32_t        reserved;
  244. } sensors_data_t;
  245.  
  246.  
  247. struct sensor_t;
  248.  
  249. /**
  250.  * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
  251.  * and the fields of this data structure must begin with hw_module_t
  252.  * followed by module specific information.
  253.  */
  254. struct sensors_module_t {
  255.     struct hw_module_t common;
  256.  
  257.     /**
  258.      * Enumerate all available sensors. The list is returned in "list".
  259.      * @return number of sensors in the list
  260.      */
  261.     int (*get_sensors_list)(struct sensors_module_t* module,
  262.             struct sensor_t const** list);
  263. };
  264.  
  265. struct sensor_t {
  266.     /* name of this sensors */
  267.     const char*     name;
  268.     /* vendor of the hardware part */
  269.     const char*     vendor;
  270.     /* version of the hardware part + driver. The value of this field is
  271.      * left to the implementation and doesn't have to be monotonicaly
  272.      * increasing.
  273.      */   
  274.     int             version;
  275.     /* handle that identifies this sensors. This handle is used to activate
  276.      * and deactivate this sensor. The value of the handle must be 8 bits
  277.      * in this version of the API.
  278.      */
  279.     int             handle;
  280.     /* this sensor's type. */
  281.     int             type;
  282.     /* maximaum range of this sensor's value in SI units */
  283.     float           maxRange;
  284.     /* smallest difference between two values reported by this sensor */
  285.     float           resolution;
  286.     /* rough estimate of this sensor's power consumption in mA */
  287.     float           power;
  288.     /* reserved fields, must be zero */
  289.     void*           reserved[9];
  290. };
  291.  
  292.  
  293. /**
  294.  * Every device data structure must begin with hw_device_t
  295.  * followed by module specific public methods and attributes.
  296.  */
  297. struct sensors_control_device_t {
  298.     struct hw_device_t common;
  299.    
  300.     /**
  301.      * Returns a native_handle_t, which will be the parameter to
  302.      * sensors_data_device_t::open_data().
  303.      * The caller takes ownership of this handle. This is intended to be
  304.      * passed cross processes.
  305.      *
  306.      * @return a native_handle_t if successful, NULL on error
  307.      */
  308.     native_handle_t* (*open_data_source)(struct sensors_control_device_t *dev);
  309.  
  310.     /**
  311.      * Releases any resources that were created by open_data_source.
  312.      * This call is optional and can be NULL if not implemented
  313.      * by the sensor HAL.
  314.      *
  315.      * @return 0 if successful, < 0 on error
  316.      */
  317.     int (*close_data_source)(struct sensors_control_device_t *dev);
  318.  
  319.     /** Activate/deactivate one sensor.
  320.      *
  321.      * @param handle is the handle of the sensor to change.
  322.      * @param enabled set to 1 to enable, or 0 to disable the sensor.
  323.      *
  324.      * @return 0 on success, negative errno code otherwise
  325.      */
  326.     int (*activate)(struct sensors_control_device_t *dev,
  327.             int handle, int enabled);
  328.    
  329.     /**
  330.      * Set the delay between sensor events in ms
  331.      *
  332.      * @return 0 if successful, < 0 on error
  333.      */
  334.     int (*set_delay)(struct sensors_control_device_t *dev, int32_t ms);
  335.  
  336.     /**
  337.      * Causes sensors_data_device_t.poll() to return -EWOULDBLOCK immediately.
  338.      */
  339.     int (*wake)(struct sensors_control_device_t *dev);
  340. };
  341.  
  342. struct sensors_data_device_t {
  343.     struct hw_device_t common;
  344.  
  345.     /**
  346.      * Prepare to read sensor data.
  347.      *
  348.      * This routine does NOT take ownership of the handle
  349.      * and must not close it. Typically this routine would
  350.      * use a duplicate of the nh parameter.
  351.      *
  352.      * @param nh from sensors_control_open.
  353.      *
  354.      * @return 0 if successful, < 0 on error
  355.      */
  356.     int (*data_open)(struct sensors_data_device_t *dev, native_handle_t* nh);
  357.    
  358.     /**
  359.      * Caller has completed using the sensor data.
  360.      * The caller will not be blocked in sensors_data_poll
  361.      * when this routine is called.
  362.      *
  363.      * @return 0 if successful, < 0 on error
  364.      */
  365.     int (*data_close)(struct sensors_data_device_t *dev);
  366.    
  367.     /**
  368.      * Return sensor data for one of the enabled sensors.
  369.      *
  370.      * @return sensor handle for the returned data, 0x7FFFFFFF when
  371.      * sensors_control_device_t.wake() is called and -errno on error
  372.      * 
  373.      */
  374.     int (*poll)(struct sensors_data_device_t *dev,
  375.             sensors_data_t* data);
  376. };
  377.  
  378.  
  379. /** convenience API for opening and closing a device */
  380.  
  381. static inline int sensors_control_open(const struct hw_module_t* module,
  382.         struct sensors_control_device_t** device) {
  383.     return module->methods->open(module,
  384.             SENSORS_HARDWARE_CONTROL, (struct hw_device_t**)device);
  385. }
  386.  
  387. static inline int sensors_control_close(struct sensors_control_device_t* device) {
  388.     return device->common.close(&device->common);
  389. }
  390.  
  391. static inline int sensors_data_open(const struct hw_module_t* module,
  392.         struct sensors_data_device_t** device) {
  393.     return module->methods->open(module,
  394.             SENSORS_HARDWARE_DATA, (struct hw_device_t**)device);
  395. }
  396.  
  397. static inline int sensors_data_close(struct sensors_data_device_t* device) {
  398.     return device->common.close(&device->common);
  399. }
  400.  
  401.  
  402. __END_DECLS
  403.  
  404. #endif  // ANDROID_SENSORS_INTERFACE_H

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
worth-right