From 19e3f128bdc706b96b3eac65e0bd48bececfaa63 Mon Sep 17 00:00:00 2001 From: Archana Date: Thu, 6 Feb 2014 04:45:17 -0500 Subject: [PATCH] Sensors: Setting sensor's sensitivity value to default retrieved from fw 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 Reviewed-on: https://android.intel.com/160777 Reviewed-by: Sesha, Subramony Tested-by: Sesha, Subramony Tested-by: sys_abtbuild Reviewed-by: Persson, Per Tested-by: Persson, Per Reviewed-by: Lilja, Ola --- SensorIIODev.cpp | 27 +++++++++++++++++++++++---- SensorIIODev.h | 3 ++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/SensorIIODev.cpp b/SensorIIODev.cpp index f1273a4..51d85e8 100644 --- a/SensorIIODev.cpp +++ b/SensorIIODev.cpp @@ -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; diff --git a/SensorIIODev.h b/SensorIIODev.h index 2372ad0..59e6350 100644 --- a/SensorIIODev.h +++ b/SensorIIODev.h @@ -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); -- 2.11.0