OSDN Git Service

Sensors: Setting sensor's sensitivity value to default retrieved from fw
authorArchana <archana.patni@linux.intel.com>
Thu, 6 Feb 2014 09:45:17 +0000 (04:45 -0500)
committerLilja, Ola <ola.lilja@intel.com>
Fri, 7 Feb 2014 12:06:17 +0000 (04:06 -0800)
Currently, the sensitivity value for sensors are set to DEF_HYST_VALUE
which is set to zero. This causes a continous stream of events even
when the device is still. This patch changes the behavior by initially
reading the default value of the sensor's sensitivity from firmware and
setting it back. If we are unable to read it, then we will set it to 0.

Issue: APDEV-1304
Issue: APDEV-1000

Change-Id: I1b5b9d5e9d059b65f5a91f6867ec29e24f56d4cb
Signed-off-by: Archana Patni <archana.patni@intel.com>
Reviewed-on: https://android.intel.com/160777
Reviewed-by: Sesha, Subramony <subramony.sesha@intel.com>
Tested-by: Sesha, Subramony <subramony.sesha@intel.com>
Tested-by: sys_abtbuild <sys_abtbuild@intel.com>
Reviewed-by: Persson, Per <per.persson@intel.com>
Tested-by: Persson, Per <per.persson@intel.com>
Reviewed-by: Lilja, Ola <ola.lilja@intel.com>
SensorIIODev.cpp
SensorIIODev.h

index f1273a4..51d85e8 100644 (file)
@@ -143,6 +143,7 @@ int SensorIIODev::startStop(int enabled)
         return 0;
 
     int ret =0;
+    double sensitivity;
 
     ALOGD(">>%s enabled:%d", __func__, enabled);
 
@@ -172,7 +173,8 @@ int SensorIIODev::startStop(int enabled)
             goto err_ret;
         if (DeviceActivate(GetDeviceNumber(), 1) < 0)
             goto err_ret;
-        if (DeviceSetSensitivity(GetDeviceNumber(), DEF_HYST_VALUE) < 0)
+        sensitivity =  DeviceGetSensitivity(GetDeviceNumber());
+        if (DeviceSetSensitivity(GetDeviceNumber(), sensitivity) < 0)
             goto err_ret;
         if (AllocateRxBuffer() < 0)
             goto err_ret;
@@ -184,8 +186,6 @@ int SensorIIODev::startStop(int enabled)
             goto err_ret;
         if (DeviceActivate(GetDeviceNumber(), 0) < 0)
             goto err_ret;
-        if (DeviceSetSensitivity(GetDeviceNumber(), 0))
-            goto err_ret;
         if (FreeRxBuffer() < 0)
             goto err_ret;
         mDevPath = "";
@@ -600,8 +600,27 @@ int SensorIIODev::DeviceActivate(int dev_num, int state){
     return 0;
 }
 
+// Get sensitivity in absolute terms
+double SensorIIODev::DeviceGetSensitivity(int dev_num){
+    std::stringstream filename;
+    std::string sensitivity_str;
+    double value;
+
+    filename << IIO_DIR << "/" << "iio:device" << dev_num << "/" << channel_prefix_str << "hysteresis";
+
+    PathOps path_ops;
+    int ret = path_ops.read(filename.str(), sensitivity_str);
+    if (ret < 0) {
+        ALOGE("Read Error %s", filename.str().c_str());
+       return DEF_HYST_VALUE;
+    }
+    istringstream buffer(sensitivity_str);
+    buffer >> value;
+    return value;
+}
+
 // Set sensitivity in absolute terms
-int SensorIIODev::DeviceSetSensitivity(int dev_num, int value){
+int SensorIIODev::DeviceSetSensitivity(int dev_num, double value){
     std::stringstream filename;
     std::stringstream sensitivity_str;
 
index 2372ad0..59e6350 100644 (file)
@@ -112,7 +112,8 @@ protected:
     int EnableBuffer(int status);
     int SetSampleDelay(int dev_num, int rate);
     int DeviceActivate(int dev_num, int state);
-    int DeviceSetSensitivity(int dev_num, int value);
+    double DeviceGetSensitivity(int dev_num);
+    int DeviceSetSensitivity(int dev_num, double value);
     long GetUnitValue();
     long GetExponentValue();
     int ReadHIDMeasurmentUnit(long *unit);