int GmaSensor::setDelay(int32_t handle, int64_t delay_ns) { int err = 0; int32_t us; char buffer[16]; int bytes; /* handle check */ if (handle != ID_A) { ALOGE("GmaSensor: Invalid handle (%d)", handle); return -EINVAL; } if (mDelay != delay_ns) { us = (int32_t)(delay_ns / 1000000); strcpy(&input_sysfs_path[input_sysfs_path_len], "delay"); bytes = sprintf(buffer, "%d", (int)us); err = write_sys_attribute(input_sysfs_path, buffer, bytes); if (err == 0) { mDelay = delay_ns; ALOGD("GmaSensor: Control set delay %f ms requetsed, ", delay_ns/1000000.0f); } } return err; }
int DmtSensor::setEnable(int32_t handle, int enabled) { char value[2]={0,0}; value[0]= enabled ? '1':'0'; LOGE("DmtSensor: %s:enable=%s\n",__func__,value); write_sys_attribute(path_en,value, 1); 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 DmtSensor::setDelay(int32_t handle, int64_t delay_ns) { int err = 0; int ms; char value[11]={0}; //int bytes; ms = delay_ns / 1000000; err = sprintf(value,"%u",ms); LOGE("DmtSensor: value=%s ,gsensor=%u, bytes=%d\n",value,ms,err); write_sys_attribute(path_de,value, err); mDelay = delay_ns; return err; }
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 OriSensor::setAccel(sensors_event_t * data) { int err; int16_t acc[3]; acc[0] = (int16_t) (data->acceleration.x / GRAVITY_EARTH * AKSC_LSG); acc[1] = (int16_t) (data->acceleration.y / GRAVITY_EARTH * AKSC_LSG); acc[2] = (int16_t) (data->acceleration.z / GRAVITY_EARTH * AKSC_LSG); strcpy(&input_sysfs_path[input_sysfs_path_len], "accel"); err = write_sys_attribute(input_sysfs_path, (char *)acc, 6); if (err < 0) { ALOGD("OriSensor: %s write failed.", &input_sysfs_path[input_sysfs_path_len]); } return err; }
int GmaSensor::setEnable(int32_t handle, int enabled) { int err = 0; char buffer[2]={0,0}; // handle check if (handle != ID_A) { ALOGE("GmaSensor: Invalid handle (%d)", handle); return -EINVAL; } buffer[0]= enabled ? '1':'0'; //ALOGD("GmaSensor: enabled = %s", buffer); strcpy(&input_sysfs_path[input_sysfs_path_len], "enable"); err = write_sys_attribute(input_sysfs_path, buffer, 1); if (err != 0) return err; 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::setAccel(sensors_event_t* data) { int err; int16_t acc[3]; /* Input data is already formated to Android definition. */ acc[0] = (int16_t)(data->acceleration.x / GRAVITY_EARTH * AKSC_LSG); acc[1] = (int16_t)(data->acceleration.y / GRAVITY_EARTH * AKSC_LSG); acc[2] = (int16_t)(data->acceleration.z / GRAVITY_EARTH * AKSC_LSG); strncpy(&input_sysfs_path[input_sysfs_path_len], "accel", PATH_MAX - input_sysfs_path_len); err = write_sys_attribute(input_sysfs_path, (char*)acc, 6); if (err < 0) { ALOGD("AkmSensor: %s write failed.", &input_sysfs_path[input_sysfs_path_len]); } 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 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; }