From 16bcf66afa333f8d3f3b835ed556e4fce8fa35bf Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 15 Aug 2011 17:10:23 -0700 Subject: [PATCH] have the sensorsevice test print the delay of the first received event Change-Id: I89d63122574c3f8790f00512c76d59b463acf18f --- .../sensorservice/tests/sensorservicetest.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/services/sensorservice/tests/sensorservicetest.cpp b/services/sensorservice/tests/sensorservicetest.cpp index aea106224..54bce091f 100644 --- a/services/sensorservice/tests/sensorservicetest.cpp +++ b/services/sensorservice/tests/sensorservicetest.cpp @@ -22,6 +22,9 @@ using namespace android; +static nsecs_t sStartTime = 0; + + int receiver(int fd, int events, void* data) { sp q((SensorEventQueue*)data); @@ -32,7 +35,7 @@ int receiver(int fd, int events, void* data) while ((n = q->read(buffer, 8)) > 0) { for (int i=0 ; i\n", buffer[i].timestamp, buffer[i].acceleration.x, @@ -43,9 +46,11 @@ int receiver(int fd, int events, void* data) if (oldTimeStamp) { float t = float(buffer[i].timestamp - oldTimeStamp) / s2ns(1); printf("%f ms (%f Hz)\n", t*1000, 1.0/t); + } else { + float t = float(buffer[i].timestamp - sStartTime) / s2ns(1); + printf("first event: %f ms\n", t*1000); } oldTimeStamp = buffer[i].timestamp; - } } if (n<0 && n != -EAGAIN) { @@ -66,12 +71,15 @@ int main(int argc, char** argv) sp q = mgr.createEventQueue(); printf("queue=%p\n", q.get()); - Sensor const* accelerometer = mgr.getDefaultSensor(Sensor::TYPE_GYROSCOPE); + Sensor const* accelerometer = mgr.getDefaultSensor(Sensor::TYPE_ACCELEROMETER); printf("accelerometer=%p (%s)\n", accelerometer, accelerometer->getName().string()); + + sStartTime = systemTime(); + q->enableSensor(accelerometer); - q->setEventRate(accelerometer, ms2ns(10)); + q->setEventRate(accelerometer, ms2ns(200)); sp loop = new Looper(false); loop->addFd(q->getFd(), 0, ALOOPER_EVENT_INPUT, receiver, q.get());