summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaadi Maalem <saadi.maalem@intel.com>2015-06-16 16:12:10 +0800
committerZhengyin Qian <qianzy@google.com>2015-08-13 19:37:36 -0700
commit76227f0914d2f20b9af44c8fce0a849dba01dbe9 (patch)
treeffd2d0f90a992ce7aa0548b93f6f4b64d8372814
parent90158e87ed2bd35ff6e07a0eb6a281600d03a9f8 (diff)
downloadsensors-76227f0914d2f20b9af44c8fce0a849dba01dbe9.tar.gz
Sensor: load calibration data for wakeup/non-wakeup sensor
JIRA: MARVIN-99 Change-Id: Idc737ca92faaa1074262b1fa418f3f04d9e6e561 Signed-off-by: Fei Li <feix.f.li@intel.com> Reviewed-on: https://android.intel.com/380493 Reviewed-by: jenkins_ndg <jenkins_ndg@intel.com> Reviewed-by: Maalem, Saadi <saadi.maalem@intel.com> Reviewed-by: Pujol, Benjamin <benjamin.pujol@intel.com>
-rw-r--r--libsensors_iio/src/SensorHAL.cpp6
-rw-r--r--libsensors_iio/src/sensor_cal.c14
-rw-r--r--libsensors_iio/src/sensor_cal.h17
3 files changed, 26 insertions, 11 deletions
diff --git a/libsensors_iio/src/SensorHAL.cpp b/libsensors_iio/src/SensorHAL.cpp
index 213cb85..15366db 100644
--- a/libsensors_iio/src/SensorHAL.cpp
+++ b/libsensors_iio/src/SensorHAL.cpp
@@ -749,8 +749,10 @@ static int st_hal_open_sensors(const struct hw_module_t *module,
hal_data->poll_device.batch = st_hal_dev_batch;
hal_data->poll_device.flush = st_hal_dev_flush;
- do_cal_data_loading(ACCEL_SINDEX);
- do_cal_data_loading(GYRO_SINDEX);
+ do_cal_data_loading(ACCEL_SINDEX, NON_WAKEUP);
+ do_cal_data_loading(ACCEL_SINDEX, WAKEUP);
+ do_cal_data_loading(GYRO_SINDEX, NON_WAKEUP);
+ do_cal_data_loading(GYRO_SINDEX, WAKEUP);
*device = &hal_data->poll_device.common;
diff --git a/libsensors_iio/src/sensor_cal.c b/libsensors_iio/src/sensor_cal.c
index 1d14611..94fae63 100644
--- a/libsensors_iio/src/sensor_cal.c
+++ b/libsensors_iio/src/sensor_cal.c
@@ -23,6 +23,10 @@ int load_cali_data(const int sindex)
int err = 0, num, sum;
FILE *filp;
+ if (((sindex == ACCEL_SINDEX) && accl_cal_data_loaded) ||
+ ((sindex == GYRO_SINDEX) && gyro_cal_data_loaded))
+ return 0;
+
filp = fopen(sensor_cali_data_path[sindex], "r");
if (filp == NULL) {
err = -errno;
@@ -51,7 +55,7 @@ out:
}
/* Write calibration data to iio channel offset */
-void set_cali_offset(const int sindex)
+void set_cali_offset(const int sindex, const bool wakeup)
{
#define MAX_BUF_LEN 64
int err, j;
@@ -60,10 +64,10 @@ void set_cali_offset(const int sindex)
for (j = 0; j < (Z_AXIS_INDEX + 1); j++) {
err = snprintf(buf, MAX_BUF_LEN, "%s/%s",
- sensor_sysfs_dir[sindex], sensor_offset[sindex][j]);
+ sensor_sysfs_dir[sindex][wakeup], sensor_offset[sindex][j]);
if (err < 0) {
ALOGE("%s/%s snprintf err=%d",
- sensor_sysfs_dir[sindex], sensor_offset[sindex][j], err);
+ sensor_sysfs_dir[sindex][wakeup], sensor_offset[sindex][j], err);
return;
}
filp = fopen(buf, "w");
@@ -82,7 +86,7 @@ void set_cali_offset(const int sindex)
}
-void do_cal_data_loading(const int sindex)
+void do_cal_data_loading(const int sindex, const bool wakeup)
{
int err;
@@ -90,6 +94,6 @@ void do_cal_data_loading(const int sindex)
if (err != 0)
return;
- set_cali_offset(sindex);
+ set_cali_offset(sindex, wakeup);
}
diff --git a/libsensors_iio/src/sensor_cal.h b/libsensors_iio/src/sensor_cal.h
index 3102b9d..5b0ba40 100644
--- a/libsensors_iio/src/sensor_cal.h
+++ b/libsensors_iio/src/sensor_cal.h
@@ -20,6 +20,9 @@
#include <stdio.h>
#include <stdbool.h>
+#define NON_WAKEUP 0
+#define WAKEUP 1
+
enum SENSOR_INDEX {
ACCEL_SINDEX = 0,
GYRO_SINDEX,
@@ -36,9 +39,15 @@ static const char * const sensor_cali_data_path[] = {
[GYRO_SINDEX] = "/config/sensor/gyro_cali",
};
-static const char * const sensor_sysfs_dir[] = {
- [ACCEL_SINDEX] = "/sys/devices/iio:device1",
- [GYRO_SINDEX] = "/sys/devices/iio:device2",
+static const char * const sensor_sysfs_dir[][2] = {
+ {
+ [NON_WAKEUP] = "/sys/devices/iio:device1",
+ [WAKEUP] = "/sys/devices/iio:device2",
+ },
+ {
+ [NON_WAKEUP] = "/sys/devices/iio:device3",
+ [WAKEUP] = "/sys/devices/iio:device4",
+ },
};
static const char * const sensor_offset[][3] = {
@@ -58,6 +67,6 @@ static bool accl_cal_data_loaded;
static bool gyro_cal_data_loaded;
static int cal_data[2][3];
-void do_cal_data_loading(const int sindex);
+void do_cal_data_loading(const int sindex, const bool wakeup);
#endif