分享

sensor

 dwlinux_gs 2014-07-19

首先看下sensor的hal层头文件:hardware\libhardware\include\hardware


  1. typedef struct {  
  2.     union {  
  3.         float v[3];  
  4.         struct {  
  5.             float x;  
  6.             float y;  
  7.             float z;  
  8.         };  
  9.         struct {  
  10.             float azimuth;  
  11.             float pitch;  
  12.             float roll;  
  13.         };  
  14.     };  
  15.     int8_t status;  
  16.     uint8_t reserved[3];  
  17. } sensors_vec_t;  
  18.   
  19. /** 
  20.  * Union of the various types of sensor data 
  21.  * that can be returned. 
  22.  */  
  23. typedef struct sensors_event_t {  
  24.     /* must be sizeof(struct sensors_event_t) */  
  25.     int32_t version;  
  26.   
  27.     /* sensor identifier */  
  28.     int32_t sensor;  
  29.   
  30.     /* sensor type */  
  31.     int32_t type;  
  32.   
  33.     /* reserved */  
  34.     int32_t reserved0;  
  35.   
  36.     /* time is in nanosecond */  
  37.     int64_t timestamp;  
  38.   
  39.     union {  
  40.         float           data[16];  
  41.   
  42.         /* acceleration values are in meter per second per second (m/s^2) */  
  43.         sensors_vec_t   acceleration;  
  44.   
  45.         /* magnetic vector values are in micro-Tesla (uT) */  
  46.         sensors_vec_t   magnetic;  
  47.   
  48.         /* orientation values are in degrees */  
  49.         sensors_vec_t   orientation;  
  50.   
  51.         /* gyroscope values are in rad/s */  
  52.         sensors_vec_t   gyro;  
  53.   
  54.         /* temperature is in degrees centigrade (Celsius) */  
  55.         float           temperature;  
  56.   
  57.         /* distance in centimeters */  
  58.         float           distance;  
  59.   
  60.         /* light in SI lux units */  
  61.         float           light;  
  62.   
  63.         /* pressure in hectopascal (hPa) */  
  64.         float           pressure;  
  65.   
  66.         /* relative humidity in percent */  
  67.         float           relative_humidity;  
  68.     };  
  69.     uint32_t        reserved1[4];  
  70. } sensors_event_t;  
  71.   
  72.   
  73.   
  74. struct sensor_t;  
  75.   
  76. /** 
  77.  * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 
  78.  * and the fields of this data structure must begin with hw_module_t 
  79.  * followed by module specific information. 
  80.  */  
  81. struct sensors_module_t {  
  82.     struct hw_module_t common;  
  83.   
  84.     /** 
  85.      * Enumerate all available sensors. The list is returned in "list". 
  86.      * @return number of sensors in the list 
  87.      */  
  88.     int (*get_sensors_list)(struct sensors_module_t* module,  
  89.             struct sensor_t const** list);  
  90. };  
  91.   
  92. struct sensor_t {  
  93.     /* name of this sensors */  
  94.     const char*     name;  
  95.     /* vendor of the hardware part */  
  96.     const char*     vendor;  
  97.     /* version of the hardware part + driver. The value of this field 
  98.      * must increase when the driver is updated in a way that changes the 
  99.      * output of this sensor. This is important for fused sensors when the 
  100.      * fusion algorithm is updated. 
  101.      */      
  102.     int             version;  
  103.     /* handle that identifies this sensors. This handle is used to activate 
  104.      * and deactivate this sensor. The value of the handle must be 8 bits 
  105.      * in this version of the API.  
  106.      */  
  107.     int             handle;  
  108.     /* this sensor's type. */  
  109.     int             type;  
  110.     /* maximaum range of this sensor's value in SI units */  
  111.     float           maxRange;  
  112.     /* smallest difference between two values reported by this sensor */  
  113.     float           resolution;  
  114.     /* rough estimate of this sensor's power consumption in mA */  
  115.     float           power;  
  116.     /* minimum delay allowed between events in microseconds. A value of zero 
  117.      * means that this sensor doesn't report events at a constant rate, but 
  118.      * rather only when a new data is available */  
  119.     int32_t         minDelay;  
  120.     /* reserved fields, must be zero */  
  121.     void*           reserved[8];  
  122. };  
  123.   
  124.   
  125. /** 
  126.  * Every device data structure must begin with hw_device_t 
  127.  * followed by module specific public methods and attributes. 
  128.  */  
  129. struct sensors_poll_device_t {  
  130.     struct hw_device_t common;  
  131.   
  132.     /** Activate/deactivate one sensor. 
  133.      * 
  134.      * @param handle is the handle of the sensor to change. 
  135.      * @param enabled set to 1 to enable, or 0 to disable the sensor. 
  136.      * 
  137.      * @return 0 on success, negative errno code otherwise 
  138.      */  
  139.     int (*activate)(struct sensors_poll_device_t *dev,  
  140.             int handle, int enabled);  
  141.   
  142.     /** 
  143.      * Set the delay between sensor events in nanoseconds for a given sensor. 
  144.      * 
  145.      * If the requested value is less than sensor_t::minDelay, then it's 
  146.      * silently clamped to sensor_t::minDelay unless sensor_t::minDelay is 
  147.      * 0, in which case it is clamped to >= 1ms. 
  148.      * 
  149.      * @return 0 if successful, < 0 on error 
  150.      */  
  151.     int (*setDelay)(struct sensors_poll_device_t *dev,  
  152.             int handle, int64_t ns);  
  153.   
  154.     /** 
  155.      * Returns an array of sensor data. 
  156.      * This function must block until events are available. 
  157.      * 
  158.      * @return the number of events read on success, or -errno in case of an error. 
  159.      * This function should never return 0 (no event). 
  160.      * 
  161.      */  
  162.     int (*poll)(struct sensors_poll_device_t *dev,  
  163.             sensors_event_t* data, int count);  
  164. };  
  165.   
  166. /** convenience API for opening and closing a device */  
  167.   
  168. static inline int sensors_open(const struct hw_module_t* module,  
  169.         struct sensors_poll_device_t** device) {  
  170.     return module->methods->open(module,  
  171.             SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);  
  172. }  
  173.   
  174. static inline int sensors_close(struct sensors_poll_device_t* device) {  
  175.     return device->common.close(&device->common);  
  176. }  
  177.   
  178. __END_DECLS  



主要包括sensors_vec_t、sensors_event_t、sensors_module_t、sensor_t、sensors_poll_device_t几个结构


sensors_vec_t主要是上传的数据,里面包括一个union结构,包含各种上传数据的一个数据封装,都是三个float


sensors_event_t主要是以一个事件的形式上传从sensor获取的数据,里面也有一个union,包含的是各种各样的传感器的数据,其中type是sensor的类型,sensor是一个标识


sensors_module_t是hw_module_t的一个封装,提供一个get_sensors_list获取该平台可提供的所有sensor


sensor_t用来描述一个sensor


sensors_poll_device_t是hw_device_t的一个封装。提供了3个方法activate、setDelay、poll


activate用来启动和停止sensor


setDelay用来设置延时


poll用来监听sensor上是否有数据





    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多