hi all,
    I refered to the sensors_qemu.c and the htc_sensors.c to write own
sensor hardware module.
    but mine doesn't work well...
    it always stuck inside the while(1) in the data__poll() {...} can't get
out...
    below is part of my data__poll()

    SensorData*  data = (void*)dev;
    int i, fds[MAX_NUM_SENSORS];
    uint32_t new_sensors = 0;

    /* the pick_sensor(...) is same as the sensors_qemu.c */
    if (data->pendingSensors) {
        return pick_sensor(data, values);
    }

    for (i = 0; i < MAX_NUM_SENSORS; i++) fds[i] = data->event_fds[i];
    while (1) {
int ret, val;
list302dl_data lis_data;
char magnetic_data[5];

                if (gactive_sensors | ID_TEMPERATURE) {
                    ret = ioctl(fds[ID_TEMPERATURE],
SCP1000_READ_TEMPERATURE, &val);
                    if (ret >= 0) {
                        new_sensors |= ID_TEMPERATURE;
data->sensors[ID_TEMPERATURE].temperature = (float)val / 20.0;
                    } else {
                        data->sensors[ID_TEMPERATURE].temperature = 0;
                    }
                }
                ...other sensor type

                if (android_atomic_swap(0x0, &gwake) == 0x1) {
return 0x7FFFFFFF;
}

                if (new_sensors) {
data->pendingSensors = new_sensors;
                        int64_t t = data__now_ns();
                        while (new_sensors) {
                         uint32_t i = 31 - __builtin_clz(new_sensors);
                         new_sensors &= ~(1<<i);
                    data->sensors[i].time = t;
                       }
                       return pick_sensor(data, values);
}
    }

    and, below is my control_wake function
    static int
    control__wake(struct sensors_control_device_t *dev)
    {
        android_atomic_write(0x1, &gwake);
        return 0;
    }

    and, below is my control__open_data_source function
    static native_handle_t*
    control__open_data_source(struct sensors_control_device_t *dev)
    {
        SensorControl*  ctl = (void*)dev;
        native_handle_t* handle;

        handle = native_handle_create(MAX_NUM_SENSORS, 0);
        handle->data[ID_TEMPERATURE] = open(SCP1000D11PATH, O_RDONLY);
        handle->data[ID_PRESSURE] = handle->data[0];
        handle->data[ID_MAGNETIC_FIELD] = open(AKMPATH, O_RDONLY);
        handle->data[ID_ACCELERATION] = open(GSENSORPATH, O_RDONLY);

        return handle;
    }

    I need some advance, please ~ thanks.
-- 
Regards
Y-C Wang

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: http://groups.google.com/group/android-porting

Reply via email to