sensor: fix lsm6ds3 HAL bug for more accurate sampling rate
fix the bug for all HW/SW sensors
Change-Id: Idc9809f55a3f3fe3171beb8b2bb55962a08d7b6b
Tracked-On: https://jira.ndg.intel.com/browse/MARVIN-882
Signed-off-by: Fei Li <[email protected]>
Reviewed-on: https://android.intel.com/421790
Reviewed-by: jenkins_ndg <[email protected]>
Reviewed-by: Ledentec, AlexandreX <[email protected]>
Reviewed-by: Tasayco Loarte, VictorX <[email protected]>
diff --git a/libsensors_iio/src/HWSensorBase.cpp b/libsensors_iio/src/HWSensorBase.cpp
index e569c2a..43f7fbb 100644
--- a/libsensors_iio/src/HWSensorBase.cpp
+++ b/libsensors_iio/src/HWSensorBase.cpp
@@ -446,15 +446,7 @@
if (!GetStatusOfHandle(sensor_t_data.handle))
return;
- /** Actually, the actual ODR would be slightly bigger than the requested,
- * Eg: for lsm6ds3, real ODR is 26, 52, 104..., so the actual ODR is 104Hz
- * when 100Hz is requested.
- * As a result, the reporting time interval between two adjacent events
- * would be smaller than that from GetDelay().
- * To guarantee the requested ODR in all cases, the reporting time interval
- * should be greater than GetDelay()/2.
- */
- if (sensor_event.timestamp > (last_data_timestamp + GetDelay() / 2)) {
+ if (sensor_event.timestamp >= (last_data_timestamp + real_pollrate)) {
err = write(android_pipe_fd, &sensor_event, sizeof(sensor_event));
if (err < 0) {
ALOGE("%s: Failed to write sensor data to pipe.", android_name);
diff --git a/libsensors_iio/src/SWSensorBase.cpp b/libsensors_iio/src/SWSensorBase.cpp
index 320752e..0acd26d 100644
--- a/libsensors_iio/src/SWSensorBase.cpp
+++ b/libsensors_iio/src/SWSensorBase.cpp
@@ -136,7 +136,7 @@
if (!GetStatusOfHandle(sensor_t_data.handle))
return;
- if (sensor_event.timestamp > (last_data_timestamp + GetDelay())) {
+ if (sensor_event.timestamp >= (last_data_timestamp + real_pollrate)) {
err = write(android_pipe_fd, &sensor_event, sizeof(sensor_event));
if (err < 0) {
ALOGE("%s: Failed to write sensor data to pipe.", android_name);