};
SortedVector< wp > getActiveConnections() const; DefaultKeyedVector getActiveVirtualSensors() const; String8 getSensorName(int handle) const;
void recordLastValue(sensors_event_t const * buffer, size_t count); static void sortEventBuffer(sensors_event_t* buffer, size_t count); void registerSensor(SensorInterface* sensor); void registerVirtualSensor(SensorInterface* sensor); // constants
Vector mSensorList; // Sensor列表
Vector mUserSensorList; //与mSensorList一样
DefaultKeyedVector mSensorMap; //其成员为HardwareSensor Vector mVirtualSensorList; //其成员为HardwareSensor status_t mInitCheck; // protected by mLock mutable Mutex mLock;
DefaultKeyedVector mActiveSensors; //成员为SensorRecord
DefaultKeyedVector mActiveVirtualSensors; //成员为HardwareSensor SortedVector< wp > mActiveConnections;
// The size of this vector is constant, only the items are mutable KeyedVector mLastEventSeen; public:
static char const* getServiceName() { return \void cleanupConnection(SensorEventConnection* connection);
/*
1) 调用HardwareSensor::activate,即SensorDevice::activate 2) 然后创建SensorRecord并增加到列表mActiveSensors 3) 把此HardwareSensor增加到连接的mSensorInfo 4) 把此连接增加到mActiveConnections中 */
status_t enable(const sp& connection, int handle); /*
1) 把此sensor从连接的mSensorInfo中删除 2) 把此连接从mActiveConnections中删除
3) 调用HardwareSensor::activate,即SensorDevice::activate */
status_t disable(const sp& connection, int handle); /*
1)调用HardwareSensor::setDelay,即SensorDevice::setDelay */
status_t setEventRate(const sp& connection, int handle, nsecs_t ns); }
2.5 SensorDevice.cpp
SensorDevice封装了对SensorHAL层代码的调用,主要包含以下功能: 1) 获取sensor列表(getSensorList) 2) 获取sensor事件(poll)
3) Enable或Disable sensor (activate) 4) 设置delay时间
[cpp]
view plaincopyclass SensorDevice : public Singleton { friend class Singleton;
struct sensors_poll_device_t* mSensorDevice; // sensor设备 struct sensors_module_t* mSensorModule;
mutable Mutex mLock; // protect mActivationCount[].rates // fixed-size array after construction struct Info { Info() : delay(0) { } KeyedVector rates; nsecs_t delay;
status_t setDelayForIdent(void* ident, int64_t ns); nsecs_t selectDelay(); };
DefaultKeyedVector mActivationCount; /*
1) 调用hw_get_module(SENSORS_HARDWARE_MODULE_ID,..)获取sensors_module_t, 并保存在mSensorModule中
2) 调用mSensorModule->common->methods->open,以返回sensors_poll_device_t, 并保存在mSensorDevice中
3) 调用mSensorModule->get_sensors_list所有可访问的sensor_t 4) 调用mSensorDevice->activate激活所有的sensor */
SensorDevice();
public:
// 调用mSensorModule->get_sensors_list实现 ssize_t getSensorList(sensor_t const** list); status_t initCheck() const; // 调用mSensorDevice->poll实现
ssize_t poll(sensors_event_t* buffer, size_t count); // 调用mSensorDevice->activate实现
status_t activate(void* ident, int handle, int enabled); // 调用mSensorDevice->setDelay实现
status_t setDelay(void* ident, int handle, int64_t ns); void dump(String8& result, char* buffer, size_t SIZE); };
2.6 Sensor HAL
定义:/hardware/libhardware/include/hardware/sensors.h 实现:/hardware/mychip/sensor/st/sensors.c 2.6.1 struct sensors_poll_device_t 定义 [cpp]
view plaincopystruct sensors_poll_device_t { struct hw_device_t common;
// Activate/deactivate one sensor.
int (*activate)(struct sensors_poll_device_t *dev, int handle, int enabled);
// Set the delay between sensor events in nanoseconds for a given sensor. int (*setDelay)(struct sensors_poll_device_t *dev,
int handle, int64_t ns);
// Returns an array of sensor data.
int (*poll)(struct sensors_poll_device_t *dev, sensors_event_t* data, int count); };
2.6.2 struct sensors_module_t 定义 [cpp]
view plaincopystruct sensors_module_t { struct hw_module_t common; /**
* Enumerate all available sensors. The list is returned in \* @return number of sensors in the list */
int (*get_sensors_list)(struct sensors_module_t* module, struct sensor_t const** list); };
2.6.3 struct sensor_t 定义 [cpp]
view plaincopystruct sensor_t { /* name of this sensors */ const char* name;
/* vendor of the hardware part */ const char* vendor;
/* version of the hardware part + driver. The value of this field