diff options
author | Nick Vaccaro <nvaccaro@google.com> | 2015-11-21 01:33:48 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2015-11-21 01:33:48 +0000 |
commit | 52e65be6cd18750cda3934585c6dad3389a67c23 (patch) | |
tree | cbc75630d5b6dbfcecf8cc7ee15a423ce0aca0e0 | |
parent | f1a0a3e22f8e974571a268f593710bb33c426dbe (diff) | |
parent | 63e566cd0bff765e37f12391cfc7131702b00dd9 (diff) | |
download | invensense-52e65be6cd18750cda3934585c6dad3389a67c23.tar.gz |
Sensors: Invensense: 6515: ignore SMD event if vibrator active
am: 63e566cd0b
* commit '63e566cd0bff765e37f12391cfc7131702b00dd9':
Sensors: Invensense: 6515: ignore SMD event if vibrator active
-rw-r--r-- | 6515/libsensors_iio/MPLSensor.cpp | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/6515/libsensors_iio/MPLSensor.cpp b/6515/libsensors_iio/MPLSensor.cpp index c7d1e6e..aef93e1 100644 --- a/6515/libsensors_iio/MPLSensor.cpp +++ b/6515/libsensors_iio/MPLSensor.cpp @@ -63,6 +63,15 @@ #define MAX_SYSFS_ATTRB (sizeof(struct sysfs_attrbs) / sizeof(char*)) +// query path to determine if vibrator is currently vibrating +#define VIBRATOR_ENABLE_FILE "/sys/class/timed_output/vibrator/enable" + + +// Minimum time after vibrator triggers SMD before SMD can be declared valid +// This allows 100mS for events to propogate +#define MIN_TRIGGER_TIME_AFTER_VIBRATOR_NS 100000000 + + /******************************************************************************/ /* MPL Interface */ /******************************************************************************/ @@ -6490,29 +6499,46 @@ int MPLSensor::readDmpSignificantMotionEvents(sensors_event_t* data, int count) int res = 0; char dummy[4]; - int significantMotion; + int vibrator = 0; FILE *fp; int sensors = mEnabled; int numEventReceived = 0; int update = 0; + static int64_t lastVibTrigger = 0; - /* Technically this step is not necessary for now */ - /* In the future, we may have meaningful values */ - fp = fopen(mpu.event_smd, "r"); - if (fp == NULL) { - LOGE("HAL:cannot open event_smd"); - return 0; - } else { - if (fscanf(fp, "%d\n", &significantMotion) < 0) { - LOGE("HAL:cannot read event_smd"); - } - if (fclose(fp) < 0) { - LOGE("HAL:cannot close event_smd"); + if (mDmpSignificantMotionEnabled && count > 0) { + + // If vibrator is going off, ignore this event + fp = fopen(VIBRATOR_ENABLE_FILE, "r"); + if (fp != NULL) { + if (fscanf(fp, "%d\n", &vibrator) < 0) { + LOGE("HAL:cannot read %s", VIBRATOR_ENABLE_FILE); + } + if (fclose(fp) < 0) { + LOGE("HAL:cannot close %s", VIBRATOR_ENABLE_FILE); + } + if (vibrator != 0) { + lastVibTrigger = android::elapsedRealtimeNano(); + LOGV_IF(ENG_VERBOSE, "SMD triggered by vibrator, ignoring SMD event"); + return 0; + } else if (lastVibTrigger) { + // vibrator recently triggered SMD, discard related events + int64_t now = android::elapsedRealtimeNano(); + if ((now - lastVibTrigger) < MIN_TRIGGER_TIME_AFTER_VIBRATOR_NS) { + LOGV_IF(ENG_VERBOSE, "HAL: SMD triggered too close to vibrator (delta %lldnS), ignoring", + (now-lastVibTrigger)); + return 0; + } else { + LOGV_IF(ENG_VERBOSE, "HAL: SMD triggered %lld after vibrator (last %lld now %lld)", + now-lastVibTrigger, lastVibTrigger, now); + lastVibTrigger = 0; + } + } + } else { + LOGE("HAL:cannot open %s", VIBRATOR_ENABLE_FILE); } - } - if(mDmpSignificantMotionEnabled && count > 0) { - /* By implementation, smd is disabled once an event is triggered */ + /* By implementation, smd is disabled once an event is triggered */ sensors_event_t temp; /* Handles return event */ |