示例#1
0
static int enable_disable_cm(struct sensors_control_context_t *dev,
                             uint32_t active, uint32_t sensors, uint32_t mask)
{
    int rc = 0;
    uint32_t now_active_cm_sensors;
    int fd = open_cm(dev);

    if (fd < 0) {
        LOGE("Couldn't open %s (%s)", CM_DEVICE_NAME, strerror(errno));
        return 0;
    }

    LOGV("(before) cm sensors = %08x, real = %08x",
         sensors, read_cm_sensors_state(fd));

    if (mask & SENSORS_CM_PROXIMITY) {
        int flags = (sensors & SENSORS_CM_PROXIMITY) ? 1 : 0;
        rc = ioctl(fd, CAPELLA_CM3602_IOCTL_ENABLE, &flags);
        if (rc < 0)
            LOGE("CAPELLA_CM3602_IOCTL_ENABLE error (%s)", strerror(errno));
    }

    now_active_cm_sensors = read_cm_sensors_state(fd);

    LOGV("(after) cm sensors = %08x, real = %08x",
         sensors, now_active_cm_sensors);

    return now_active_cm_sensors;
}
static int enable_disable_cm(struct sensors_control_context_t *dev,
                             uint32_t active, uint32_t sensors, uint32_t mask)
{
    int rc = 0;
    uint32_t now_active_cm_sensors;
    int fd = open_cm(dev);

    if (fd < 0) {
        LOGE("Couldn't open %s (%s)", CM_DEVICE_NAME, strerror(errno));
        return 0;
    }

    LOGV("(before) cm sensors = %08x, real = %08x",
         sensors, read_cm_sensors_state(fd,0));
         
    int flags = 0;
    if (mask & SENSORS_CM_PROXIMITY) {
        flags = (sensors & SENSORS_CM_PROXIMITY) ? 1 : 0;
        
        if(flags == 1) {
        uint16_t mode = 1;
        rc = ioctl(fd, P_IOC_POWERUP_SET_MODE, &mode);
        if (rc < 0)
            LOGE("P_IOC_POWERUP_SET_MODE error (%s)", strerror(errno));
        } 
        else {
        rc = ioctl(fd, P_IOC_SHUTDOWN);
        if (rc < 0)
            LOGE("P_IOC_POWERUP_SET_MODE error (%s)", strerror(errno));
        }
    }

    now_active_cm_sensors = read_cm_sensors_state(fd,flags);

    LOGV("(after) cm sensors = %08x, real = %08x",
         sensors, now_active_cm_sensors);

    return now_active_cm_sensors;
}