From e11637aed6b58085c13bcc4e88cef706a5184964 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Tue, 25 Aug 2015 18:57:31 -0700 Subject: [PATCH] common: motion_sense: Fix Light sensor sequencing Light was gathered too often: - missing timestamp when reading completes. - error when calculating next timestamp. BRANCH=ryu BUG=chrome-os-partner:32829 TEST=check the light is sampled ~ every seconds, whatever the motion task frequency Change-Id: Id070af3c8d2e080780334822278dda267bea058c Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/295636 Reviewed-by: Sheng-liang Song --- common/motion_sense.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/common/motion_sense.c b/common/motion_sense.c index 64179750f3..b5de3480ff 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -123,11 +123,11 @@ static inline int motion_sensor_time_to_read(const timestamp_t *ts, if (rate == 0) return 0; /* - * converting from mHz to ms, need 1e6, + * converting from mHz to us, need 1e9, * If within 95% of the time, check sensor. */ return time_after(ts->le.lo, - sensor->last_collection + (950000 / rate) / 10); + sensor->last_collection + 950000000 / rate); } /* @@ -373,8 +373,10 @@ static int motion_sense_process(struct motion_sensor_t *sensor, #ifdef CONFIG_ACCEL_INTERRUPTS if ((event & TASK_EVENT_MOTION_INTERRUPT_MASK) && - (sensor->drv->irq_handler != NULL)) + (sensor->drv->irq_handler != NULL)) { sensor->drv->irq_handler(sensor, event); + sensor->last_collection = ts->le.lo; + } #endif #ifdef CONFIG_ACCEL_FIFO if (sensor->drv->load_fifo != NULL) { @@ -464,8 +466,7 @@ void motion_sense_task(void) /* if the sensor is active in the current power state */ if (SENSOR_ACTIVE(sensor)) { if (sensor->state != SENSOR_INITIALIZED) { - CPRINTS("S%d active, not initalized", - sensor); + CPRINTS("S%d active not initalized", i); continue; }