Sensors: Invensense: 6515: don't send duplicate events
Discard any duplicate events found instead of sending to
Sensor Services.
Bug: 25290258
Bug: 25766824
Change-Id: I8af60eee1e5112f3df22a96c74a9d6607ccd5adb
diff --git a/6515/libsensors_iio/MPLSensor.cpp b/6515/libsensors_iio/MPLSensor.cpp
index aef93e1..cfdded8 100644
--- a/6515/libsensors_iio/MPLSensor.cpp
+++ b/6515/libsensors_iio/MPLSensor.cpp
@@ -178,6 +178,7 @@
memset(mInitial6QuatValue, 0, sizeof(mInitial6QuatValue));
mFlushSensorEnabledVector.setCapacity(NumSensors);
memset(mEnabledTime, 0, sizeof(mEnabledTime));
+ memset(mLastTimestamp, 0, sizeof(mLastTimestamp));
/* setup sysfs paths */
inv_init_sysfs_attributes();
@@ -3896,9 +3897,15 @@
update = readDmpPedometerEvents(data, count, ID_P, 1);
mPedUpdate = 0;
if(update == 1 && count > 0) {
- data->timestamp = mStepSensorTimestamp;
- count--;
- numEventReceived++;
+ if (mLastTimestamp[i] != mStepSensorTimestamp) {
+ count--;
+ numEventReceived++;
+ data->timestamp = mStepSensorTimestamp;
+ mLastTimestamp[i] = mStepSensorTimestamp;
+ } else {
+ ALOGE("Event from type=%d with duplicate timestamp %lld discarded",
+ mPendingEvents[i].type, mStepSensorTimestamp);
+ }
continue;
}
} else {
@@ -3914,9 +3921,16 @@
mPendingMask |= (1 << i);
if (update && (count > 0)) {
- *data++ = mPendingEvents[i];
- count--;
- numEventReceived++;
+ // Discard any events with duplicate timestamps
+ if (mLastTimestamp[i] != mPendingEvents[i].timestamp) {
+ mLastTimestamp[i] = mPendingEvents[i].timestamp;
+ *data++ = mPendingEvents[i];
+ count--;
+ numEventReceived++;
+ } else {
+ ALOGE("Event from type=%d with duplicate timestamp %lld discarded",
+ mPendingEvents[i].type, mStepSensorTimestamp);
+ }
}
}
}
diff --git a/6515/libsensors_iio/MPLSensor.h b/6515/libsensors_iio/MPLSensor.h
index 63df411..306a07f 100644
--- a/6515/libsensors_iio/MPLSensor.h
+++ b/6515/libsensors_iio/MPLSensor.h
@@ -370,6 +370,7 @@
int64_t mBatchTimeouts[NumSensors];
hfunc_t mHandlers[NumSensors];
int64_t mEnabledTime[NumSensors];
+ int64_t mLastTimestamp[NumSensors];
short mCachedGyroData[3];
long mCachedAccelData[3];
long mCachedCompassData[3];