From 0545906db2463684887ee84ab2775930c37f5128 Mon Sep 17 00:00:00 2001
From: Pawit Pornkitprasan
Date: Wed, 16 May 2012 16:27:37 +0700
Subject: 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
---
libsensors/CompassSensor.cpp | 22 ++++++++++++++++------
1 file 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;
--
cgit v1.1