示例#1
0
BatchSensor::BatchSensor()
    : SensorBase("/dev/m_batch_misc", "m_batch_input"),//BATCH_INPUTDEV_NAME
      mEnabled(0),
      mInputReader(128),//temp value for 128
      mHasPendingEvent(false)
{
        int handle=0;
        mPendingEvent.version = sizeof(sensors_event_t);
        mPendingEvent.sensor = 0;
        mPendingEvent.type = SENSOR_TYPE_META_DATA;
        memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
        mEnabledTime =0;

        mPendingEvent.timestamp =0;
        mdata_fd = FindDataFd();
        if (mdata_fd >= 0) {
        strcpy(input_sysfs_path, "/sys/class/misc/m_batch_misc/");
        input_sysfs_path_len = strlen(input_sysfs_path);
        }
    char datapath[64]={"/sys/class/misc/m_batch_misc/batchactive"};
    int fd = open(datapath, O_RDWR);
    char buf[64];
    int len;

    for(int i=0;i<ID_SENSOR_MAX_HANDLE;i++)
    {
        flushSensorReq[i] = 0;
    }

    if (fd >= 0)
    {
        for(int i=0; i<numSensors;i++)
        {
            lseek(fd,0,SEEK_SET);
            sprintf(buf, "%d,%d", i, 2);//write 2 means notify driver I want to read whitch handle
            write(fd, buf, strlen(buf)+1);
            lseek(fd,0,SEEK_SET);
            len = read(fd,buf,sizeof(buf)-1);
            if(len<=0)
            {
                ALOGD("read div err, i = %d, len = %d", i, len);
            }
            else
            {
                buf[len] = '\0';
                sscanf(buf, "%d", &mDataDiv[i]);
                ALOGD("read div buf(%s)", datapath);
                ALOGD("fwq!!mdiv[%d] %d",i,mDataDiv[i] );
            }
        }

        close(fd);
    }
    open_device();
    ALOGD("batch misc path =%s", input_sysfs_path);

}
示例#2
0
PedometerSensor::PedometerSensor()
    : SensorBase(NULL, "m_pdr_input"),//PDR_INPUTDEV_NAME
      mEnabled(0),
      mInputReader(32)
{
    mPendingEvent.version = sizeof(sensors_event_t);
    mPendingEvent.sensor = ID_PEDOMETER;
    mPendingEvent.type = SENSOR_TYPE_PEDOMETER;
    memset(mPendingEvent.data, 0x00, sizeof(mPendingEvent.data));
	mEnabledTime =0;
	mDataDiv = 1;
	mPendingEvent.timestamp =0;
	input_sysfs_path_len = 0;
	memset(input_sysfs_path, 0, PATH_MAX);

    mdata_fd = FindDataFd();
    if (mdata_fd >= 0) {
        strcpy(input_sysfs_path, "/sys/class/misc/m_pdr_misc/");
        input_sysfs_path_len = strlen(input_sysfs_path);
    }
	ALOGD("pdr misc path =%s", input_sysfs_path);

	char datapath[64]={"/sys/class/misc/m_pdr_misc/pdractive"};
	int fd = open(datapath, O_RDWR);
	char buf[64];
	int len;
    if (fd >= 0)
    {
        len = read(fd,buf,sizeof(buf)-1);
        if(len<=0)
        {
            ALOGD("read div err buf(%s)",buf );
        }
        else
        {
            buf[len] = '\0';
            sscanf(buf, "%d", &mDataDiv);
            ALOGD("read div buf(%s)", datapath);
            ALOGD("mdiv %d",mDataDiv );
        }
        close(fd);
    }
    else
    {
        ALOGE("open pdr misc path %s fail ", datapath);
    }
}