Update AkmSensor to manually set poll interval
authorEspen Fjellvær Olsen <espen@mrfjo.org>
Thu, 19 Apr 2012 08:05:35 +0000 (10:05 +0200)
committerEspen Fjellvær Olsen <espen@mrfjo.org>
Thu, 19 Apr 2012 08:05:35 +0000 (10:05 +0200)
Change-Id: I84fc5c3fc1cb552874129512ea6dfc19b1f9a60a

exynos4/hal/libsensors/AkmSensor.cpp
exynos4/hal/libsensors/AkmSensor.h

index c147bd6818294f48ef88729d30e351889b73f8d7..98a17cb4504385325f20bed4433aa358168023bc 100644 (file)
@@ -175,6 +175,7 @@ int AkmSensor::enable(int32_t handle, int en)
 
 int AkmSensor::setDelay(int32_t handle, int64_t ns)
 {
+    int what = -1;
     uint32_t sensor_type = 0;
 
     if (ns < 0)
@@ -189,9 +190,29 @@ int AkmSensor::setDelay(int32_t handle, int64_t ns)
     if (sensor_type == 0)
         return -EINVAL;
 
-    return akm_set_delay(sensor_type, ns);
+    mDelays[what] = ns;
+    return update_delay();
+}
+
+int AkmSensor::update_delay()
+{
+    if (mEnabled) {
+        uint64_t wanted = -1LLU;
+        for (int i=0 ; i<numSensors ; i++) {
+            if (mEnabled & (1<<i)) {
+                uint64_t ns = mDelays[i];
+                wanted = wanted < ns ? wanted : ns;
+            }
+        }
+        short delay = int64_t(wanted) / 1000000;
+        if (ioctl(dev_fd, ECS_IOCTL_APP_SET_DELAY, &delay)) {
+            return -errno;
+        }
+    }
+    return 0;
 }
 
+
 int AkmSensor::loadAKMLibrary()
 {
     mLibAKM = dlopen("libakm.so", RTLD_NOW);
index 44214e023b0d392eb251cc87774dd5b928b64a33..c155ec20bc599b5cfcddb48934a965e2326951aa 100644 (file)
@@ -50,11 +50,13 @@ public:
 
 private:
     int loadAKMLibrary();
+    int update_delay();
     void *mLibAKM;
     uint32_t mEnabled;
     uint32_t mPendingMask;
     InputEventCircularReader mInputReader;
     sensors_event_t mPendingEvents[numSensors];
+    uint64_t mDelays[numSensors];
 };
 
 /*****************************************************************************/