diff options
author | Pawit Pornkitprasan <p.pawit@gmail.com> | 2012-05-16 16:27:37 +0700 |
---|---|---|
committer | Pawit Pornkitprasan <p.pawit@gmail.com> | 2012-05-16 16:39:38 +0700 |
commit | 0545906db2463684887ee84ab2775930c37f5128 (patch) | |
tree | 597212d936fc40ed0703b51a4a6062f7c7a24580 /libsensors/CompassSensor.cpp | |
parent | 3899679acadf3a64a1a72dcaf15e983b15d2231d (diff) | |
download | device_samsung_aries-common-0545906db2463684887ee84ab2775930c37f5128.zip device_samsung_aries-common-0545906db2463684887ee84ab2775930c37f5128.tar.gz device_samsung_aries-common-0545906db2463684887ee84ab2775930c37f5128.tar.bz2 |
libsensors: Fix setting delay for compass sensor
The kernel driver only supports specific values and setting the delay
will fail if other values are choosen
Thanks to burakgon for reporting
Change-Id: Ia3a2b73bad13cc8da75e5ce654962ae192af9a4c
Diffstat (limited to 'libsensors/CompassSensor.cpp')
-rw-r--r-- | libsensors/CompassSensor.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/libsensors/CompassSensor.cpp b/libsensors/CompassSensor.cpp index f4b3685..c98d068 100644 --- a/libsensors/CompassSensor.cpp +++ b/libsensors/CompassSensor.cpp @@ -106,19 +106,29 @@ bool CompassSensor::hasPendingEvents() const { int CompassSensor::setDelay(int32_t handle, int64_t ns) { - LOGD("CompassSensor::~setDelay(%d, %lld)", handle, ns); - int fd; - - if (ns < 10000000) { - ns = 10000000; // Minimum on stock + int val; + + // Kernel driver only support specific values + if (ns < 20000000L) { + val = 1; + } else if (ns < 60000000L) { + val = 20; + } else if (ns < 200000000L) { + val = 60; + } else if (ns < 1000000000L) { + val = 200; + } else { + val = 1000; } + LOGD("CompassSensor::~setDelay(%d, %lld) val = %d", handle, ns, val); + strcpy(&input_sysfs_path[input_sysfs_path_len], "delay"); fd = open(input_sysfs_path, O_RDWR); if (fd >= 0) { char buf[80]; - sprintf(buf, "%lld", ns / 10000000 * 10); // Some flooring to match stock value + sprintf(buf, "%d", val); write(fd, buf, strlen(buf)+1); close(fd); return 0; |