summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawit Pornkitprasan <p.pawit@gmail.com>2012-05-16 20:37:43 +0700
committerPawit Pornkitprasan <p.pawit@gmail.com>2012-05-16 20:39:50 +0700
commit88cf71c68494491ded3c3e9e26747e7255c7bbdb (patch)
treed7b23c7c766e46d4e8369ea6b63c5edbcae005f2
parent1225284123d6e87f8dcde679d56206dfcf65451d (diff)
downloaddevice_samsung_aries-common-88cf71c68494491ded3c3e9e26747e7255c7bbdb.zip
device_samsung_aries-common-88cf71c68494491ded3c3e9e26747e7255c7bbdb.tar.gz
device_samsung_aries-common-88cf71c68494491ded3c3e9e26747e7255c7bbdb.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: Ib26595b65b972d32898272e13fcc492f8f0d00fa
-rw-r--r--libsensors/CompassSensor.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/libsensors/CompassSensor.cpp b/libsensors/CompassSensor.cpp
index cea0249..f58b568 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;