一 背景
1.需求
陀螺仪硬件并非接在android cpu上,所以不存在陀螺仪驱动,而陀螺仪数据是通过用户空间的一个c程序传过来。
2.思路
修改陀螺仪hal层,在hal层构建socket客户端,在数据源的c程序上构建socket服务端。一旦有数据,c程序通过socket发送数据到陀螺仪hal层,并上报。
二 步骤
1.把device/samsung/crespo/libsensors目录拷贝到hardware/libhardware/modules目录下
2.修改sensors.cpp文件下的传感器数组定义。
因只用到陀螺仪传感器,把其他传感器定义删掉
static const struct sensor_t sSensorList[] = {
/*
{ "KR3DM 3-axis Accelerometer",
"STMicroelectronics",
1, SENSORS_ACCELERATION_HANDLE,
SENSOR_TYPE_ACCELEROMETER, RANGE_A, CONVERT_A, 0.23f, 20000, { } },
{ "AK8973 3-axis Magnetic field sensor",
"Asahi Kasei Microdevices",
1, SENSORS_MAGNETIC_FIELD_HANDLE,
SENSOR_TYPE_MAGNETIC_FIELD, 2000.0f, CONVERT_M, 6.8f, 16667, { } },
{ "AK8973 Orientation sensor",
"Asahi Kasei Microdevices",
1, SENSORS_ORIENTATION_HANDLE,
SENSOR_TYPE_ORIENTATION, 360.0f, CONVERT_O, 7.8f, 16667, { } },
{ "GP2A Light sensor",
"Sharp",
1, SENSORS_LIGHT_HANDLE,
SENSOR_TYPE_LIGHT, 3000.0f, 1.0f, 0.75f, 0, { } },
{ "GP2A Proximity sensor",
"Sharp",
1, SENSORS_PROXIMITY_HANDLE,
SENSOR_TYPE_PROXIMITY, 5.0f, 5.0f, 0.75f, 0, { } },
*/
{ "K3G Gyroscope sensor",
"STMicroelectronics",
1, SENSORS_GYROSCOPE_HANDLE,
SENSOR_TYPE_GYROSCOPE, RANGE_GYRO, CONVERT_GYRO, 6.1f, 1190, { } },
};
3.修改sensors.cpp的sensors_poll_context_t结构体,删除其他的传感器定义
struct sensors_poll_context_t {
struct sensors_poll_device_t device; // must be first
sensors_poll_context_t();
~sensors_poll_context_t();
int activate(int handle, int enabled);
int setDelay(int handle, int64_t ns);
int pollEvents(sensors_event_t* data, int count);
private:
enum {
//light = 0,
//proximity = 1,
//akm = 2,
//gyro = 3,
gyro = 0,
numSensorDrivers,
numFds,
};
static const size_t wake = numFds - 1; //wake = 1
static const char WAKE_MESSAGE = 'W';
struct pollfd mPollFds[numFds];//2
int mWritePipeFd;
SensorBase* mSensor