static int sensors_control_activate(struct sensors_control_device_t *dev, int handle, int enabled) { uint32_t active = sActiveSensors; uint32_t sensor = 1 << (handle - SENSORS_HANDLE_BASE); uint32_t new_sensors = enabled ? (active | sensor) : (active & ~sensor); uint32_t changed = active ^ new_sensors; LOGD("%s active=%08x sensor=%08x new_sensors=%x changed=%x", __FUNCTION__, active, sensor, new_sensors, changed); LOGI("sensors_control_activate"); if (changed) { int fd = open_akm(); if (fd < 0) return -1; if (!active && new_sensors) { // force all sensors to be updated changed = SUPPORTED_SENSORS; } enable_disable(fd, new_sensors, changed); if(active && !new_sensors){ // close the driver close_akm(); } sActiveSensors = active = new_sensors; LOGD("sensors=%08x, real=%08x", sActiveSensors, read_sensors_state(fd)); } return 0; }
static uint32_t enable_disable_akm(struct sensors_control_context_t *dev, uint32_t active, uint32_t sensors, uint32_t mask) { uint32_t now_active_akm_sensors; int fd = open_akm(dev); if (fd < 0) return 0; LOGV("(before) akm sensors = %08x, real = %08x", sensors, read_akm_sensors_state(fd,0)); int flags = 0; #if 0 if (mask & SENSORS_AKM_ORIENTATION) { flags = (sensors & SENSORS_AKM_ORIENTATION) ? 1 : 0; flags = 1; LOGE("flags (%d)", flags); if (ioctl(fd, KXSD9_IOC_SET_MODE_AKMD2, &flags) < 0) { LOGE("KXSD9_IOC_SET_MODE_AKMD2 error (%s)", strerror(errno)); } } #endif if (mask & SENSORS_AKM_ACCELERATION) { flags = (sensors & SENSORS_AKM_ACCELERATION) ? 1 : 0; if (ioctl(fd, KXSD9_IOC_SET_MODE, &flags) < 0) { LOGE("KXSD9_IOC_SET_MODE error (%s)", strerror(errno)); } } #if 0 if (mask & SENSORS_AKM_MAGNETIC_FIELD) { flags = (sensors & KXSD9_IOC_SET_MODE) ? 1 : 0; if (ioctl(fd, KXSD9_IOC_SET_MODE, &flags) < 0) { LOGE("ECS_IOCTL_APP_SET_MVFLAG error (%s)", strerror(errno)); } } #endif now_active_akm_sensors = read_akm_sensors_state(fd,flags); LOGV("(after) akm sensors = %08x, real = %08x", sensors, now_active_akm_sensors); if (!sensors) close_akm(dev); return now_active_akm_sensors; }
static uint32_t enable_disable_akm(struct sensors_control_context_t *dev, uint32_t active, uint32_t sensors, uint32_t mask) { uint32_t now_active_akm_sensors; int fd = open_akm(dev); if (fd < 0) return 0; LOGV("(before) akm sensors = %08x, real = %08x", sensors, read_akm_sensors_state(fd)); short flags; if (mask & SENSORS_AKM_ORIENTATION) { flags = (sensors & SENSORS_AKM_ORIENTATION) ? 1 : 0; if (ioctl(fd, ECS_IOCTL_APP_SET_MFLAG, &flags) < 0) { LOGE("ECS_IOCTL_APP_SET_MFLAG error (%s)", strerror(errno)); } } if (mask & SENSORS_AKM_ACCELERATION) { flags = (sensors & SENSORS_AKM_ACCELERATION) ? 1 : 0; if (ioctl(fd, ECS_IOCTL_APP_SET_AFLAG, &flags) < 0) { LOGE("ECS_IOCTL_APP_SET_AFLAG error (%s)", strerror(errno)); } } if (mask & SENSORS_AKM_TEMPERATURE) { flags = (sensors & SENSORS_AKM_TEMPERATURE) ? 1 : 0; if (ioctl(fd, ECS_IOCTL_APP_SET_TFLAG, &flags) < 0) { LOGE("ECS_IOCTL_APP_SET_TFLAG error (%s)", strerror(errno)); } } if (mask & SENSORS_AKM_MAGNETIC_FIELD) { flags = (sensors & SENSORS_AKM_MAGNETIC_FIELD) ? 1 : 0; if (ioctl(fd, ECS_IOCTL_APP_SET_MVFLAG, &flags) < 0) { LOGE("ECS_IOCTL_APP_SET_MVFLAG error (%s)", strerror(errno)); } } now_active_akm_sensors = read_akm_sensors_state(fd); LOGV("(after) akm sensors = %08x, real = %08x", sensors, now_active_akm_sensors); if (!sensors) close_akm(dev); return now_active_akm_sensors; }