int64_t OriSensor::getDelay(int32_t handle) { int id = handle2id(handle); if (id > 0) { return mDelay[id]; } else { return 0; } }
int LightSensor::getEnable(int32_t handle) { int id = handle2id(handle); if (id >= 0) { return mEnabled[id]; } else { return 0; } }
int OriSensor::getEnable(int32_t handle) { int id = handle2id(handle); if (id >= 0) { return enabled; } else { return 0; } }
int AkmSensor::setEnable(int32_t handle, int enabled) { int id = handle2id(handle); int err = 0; char buffer[2]; switch (id) { case Accelerometer: strcpy(&input_sysfs_path[input_sysfs_path_len], "enable_acc"); break; case MagneticField: strcpy(&input_sysfs_path[input_sysfs_path_len], "enable_mag"); break; case Orientation: strcpy(&input_sysfs_path[input_sysfs_path_len], "enable_ori"); break; default: ALOGE("AkmSensor: unknown handle (%d)", handle); return -EINVAL; } buffer[0] = '\0'; buffer[1] = '\0'; if (mEnabled[id] <= 0) { if(enabled) buffer[0] = '1'; } else if (mEnabled[id] == 1) { if(!enabled) buffer[0] = '0'; } if (buffer[0] != '\0') { err = write_sys_attribute(input_sysfs_path, buffer, 1); if (err != 0) { return err; } ALOGD("AkmSensor: set %s to %s", &input_sysfs_path[input_sysfs_path_len], buffer); /* for AKMD specification */ if (buffer[0] == '1') { setDelay(handle, AKMD_DEFAULT_INTERVAL); } else { setDelay(handle, -1); } } if (enabled) { (mEnabled[id])++; if (mEnabled[id] > 32767) mEnabled[id] = 32767; } else { (mEnabled[id])--; if (mEnabled[id] < 0) mEnabled[id] = 0; } ALOGD("AkmSensor: mEnabled[%d] = %d", id, mEnabled[id]); return err; }
int OriSensor::setDelay(int32_t handle, int64_t ns) { int what = -1; what = handle2id(handle); if (what >= __numSensors) return -EINVAL; if (ns < 0) return -EINVAL; mDelay[what] = ns; if (enabled) { uint64_t wanted = -1LLU; for (int i=0 ; i<__numSensors ; i++) { if (enabled & (1<<i)) { uint64_t ns = mDelay[i]; wanted = wanted < ns ? wanted : ns; } } short delay = int64_t(wanted) / 1000000; if(delay < 26) { mLevel = 1; } else if( (delay >=26) && (delay <= 52) ) { mLevel = 2; } else if( (delay > 52) && (delay <= 100) ) { mLevel = 3; } else if((delay > 100) && (delay <= 200)) { mLevel = 4; } else { mLevel = 5; } delay = (int)(1000/ST480_FREQUENCY); if (ioctl(dev_fd, ECS_IOCTL_APP_SET_DELAY, &delay)) { return -errno; } } return 0; }
int LightSensor::setEnable(int32_t handle, int enabled) { int id = handle2id(handle); int err = 0; char buffer[2]; switch (id) { case Light: strcpy(&input_sysfs_path[input_sysfs_path_len], "enable_als"); break; case Proximity: strcpy(&input_sysfs_path[input_sysfs_path_len], "enable_ps"); break; default: LOGE("llightSensor: unknown handle (%d)", handle); return -EINVAL; } buffer[0] = '\0'; buffer[1] = '\0'; if (mEnabled[id] <= 0) { if(enabled) buffer[0] = '1'; } else if (mEnabled[id] == 1) { if(!enabled) buffer[0] = '0'; } if (buffer[0] != '\0') { err = write_sys_attribute(input_sysfs_path, buffer, 1); if (err != 0) { return err; } LOGD("lightSensor: set %s to %s", &input_sysfs_path[input_sysfs_path_len], buffer); } if (enabled) { (mEnabled[id])++; if (mEnabled[id] > 32767) mEnabled[id] = 32767; } else { (mEnabled[id])--; if (mEnabled[id] < 0) mEnabled[id] = 0; } LOGD("LightSensor: mEnabled[%d] = %d", id, mEnabled[id]); return err; }
int AkmSensor::setDelay(int32_t handle, int64_t ns) { int id = handle2id(handle); int err = 0; char buffer[32]; int bytes; ALOGD("AkmSensor::setDelay handle=%d, ns=%lld", handle, ns); if (ns < -1 || 2147483647 < ns) { ALOGE("AkmSensor::setDelay invalid delay (%lld)", ns); return -EINVAL; } switch (id) { case Accelerometer: strncpy(&input_sysfs_path[input_sysfs_path_len], "delay_acc", PATH_MAX - input_sysfs_path_len); break; case MagneticField: strncpy(&input_sysfs_path[input_sysfs_path_len], "delay_mag", PATH_MAX - input_sysfs_path_len); break; case Orientation: case RotationVector: strncpy(&input_sysfs_path[input_sysfs_path_len], "delay_fusion", PATH_MAX - input_sysfs_path_len); break; default: ALOGE("AkmSensor::setDelay unknown handle (%d)", handle); return -EINVAL; } if (ns != mDelay[id]) { bytes = sprintf(buffer, "%lld", ns); err = write_sys_attribute(input_sysfs_path, buffer, bytes); if (err == 0) { mDelay[id] = ns; ALOGD("AkmSensor::setDelay %s to %f ms.", &input_sysfs_path[input_sysfs_path_len], ns/1000000.0f); } } return err; }
int AkmSensor::setDelay(int32_t handle, int64_t ns) { int id = handle2id(handle); int err = 0; char buffer[32]; int bytes; if (ns < -1 || 2147483647 < ns) { //LOGE("AkmSensor: invalid delay (%lld)", ns); return -EINVAL; } switch (id) { case Accelerometer: strcpy(&input_sysfs_path[input_sysfs_path_len], "delay_acc"); break; case MagneticField: strcpy(&input_sysfs_path[input_sysfs_path_len], "delay_mag"); break; case Orientation: strcpy(&input_sysfs_path[input_sysfs_path_len], "delay_ori"); break; default: //LOGE("AkmSensor: unknown handle (%d)", handle); return -EINVAL; } if (ns != mDelay[id]) { ns = 125000000; bytes = sprintf(buffer, "%lld", ns); err = write_sys_attribute(input_sysfs_path, buffer, bytes); if (err == 0) { mDelay[id] = ns; //LOGD("AkmSensor: set %s to %f ms.", //&input_sysfs_path[input_sysfs_path_len], ns/1000000.0f); } } return err; }
int OriSensor::setEnable(int32_t handle, int en) { int what = -1; int cmd = -1; ALOGD("handle = %d,en = %d",handle,en); what = handle2id(handle); if (what >= __numSensors) return -EINVAL; int newState = en ? 1 : 0; int err = 0; if ((newState<<what) != (enabled & (1<<what))) { if (!enabled) { open_device(); } switch (what) { case MagneticField: cmd = ECS_IOCTL_APP_SET_MFLAG; mMaEnabled = en; break; case Orientation: cmd = ECS_IOCTL_APP_SET_MVFLAG; mOrEnabled = en; break; default: return -EINVAL; } short flags = newState; err = ioctl(dev_fd, cmd, &flags); err = err<0 ? -errno : 0; ALOGE_IF(err, "ECS_IOCTL_APP_SET_XXX failed (%s)", strerror(-err)); if (!err) { enabled &= ~(1<<what); enabled |= (uint32_t(flags)<<what); } if (!enabled) { close_device(); } } return err; }
int AkmSensor::setEnable(int32_t handle, int enabled) { int id = handle2id(handle); int err = 0; char buffer[2]; ALOGD("AkmSensor::setEnable handle=%d, enabled=%d", handle, enabled); switch (id) { case Accelerometer: strncpy(&input_sysfs_path[input_sysfs_path_len], "enable_acc", PATH_MAX - input_sysfs_path_len); break; case MagneticField: strncpy(&input_sysfs_path[input_sysfs_path_len], "enable_mag", PATH_MAX - input_sysfs_path_len); break; case Orientation: case RotationVector: strncpy(&input_sysfs_path[input_sysfs_path_len], "enable_fusion", PATH_MAX - input_sysfs_path_len); break; default: ALOGE("AkmSensor::setEnable unknown handle (%d)", handle); return -EINVAL; } buffer[0] = '\0'; buffer[1] = '\0'; if ((id == Accelerometer)||(id == MagneticField)) { if (enabled) { if (mEnabled[id] <= 0) { buffer[0] = '1'; } } else { if (mEnabled[id] == 1) { buffer[0] = '0'; } } } else { int tmp = mEnabled[Orientation] + mEnabled[RotationVector]; if (enabled) { if (tmp <= 0) { buffer[0] = '1'; } } else { if (tmp == 1) { buffer[0] = '0'; } } } if (buffer[0] != '\0') { err = write_sys_attribute(input_sysfs_path, buffer, 1); if (err != 0) { return err; } ALOGD("AkmSensor::setEnable write %s to %s", buffer, &input_sysfs_path[input_sysfs_path_len]); } if (enabled) { mEnabled[id] = 1; } else { mEnabled[id] = 0; } return err; }