@@ -35,22 +35,21 @@ int receiver(int fd, int events, void* data)
3535
3636 while ((n = q->read (buffer, 8 )) > 0 ) {
3737 for (int i=0 ; i<n ; i++) {
38- if (buffer[i].type == Sensor::TYPE_ACCELEROMETER) {
39- printf (" time=%lld, value=<%5.1f,%5.1f,%5.1f>\n " ,
40- buffer[i].timestamp ,
41- buffer[i].acceleration .x ,
42- buffer[i].acceleration .y ,
43- buffer[i].acceleration .z );
44- }
45-
38+ float t;
4639 if (oldTimeStamp) {
47- float t = float (buffer[i].timestamp - oldTimeStamp) / s2ns (1 );
48- printf (" %f ms (%f Hz)\n " , t*1000 , 1.0 /t);
40+ t = float (buffer[i].timestamp - oldTimeStamp) / s2ns (1 );
4941 } else {
50- float t = float (buffer[i].timestamp - sStartTime ) / s2ns (1 );
51- printf (" first event: %f ms\n " , t*1000 );
42+ t = float (buffer[i].timestamp - sStartTime ) / s2ns (1 );
5243 }
5344 oldTimeStamp = buffer[i].timestamp ;
45+
46+ if (buffer[i].type == Sensor::TYPE_ACCELEROMETER) {
47+ printf (" %lld\t %8f\t %8f\t %8f\t %f\n " ,
48+ buffer[i].timestamp ,
49+ buffer[i].data [0 ], buffer[i].data [1 ], buffer[i].data [2 ],
50+ 1.0 /t);
51+ }
52+
5453 }
5554 }
5655 if (n<0 && n != -EAGAIN) {
@@ -79,7 +78,7 @@ int main(int argc, char** argv)
7978
8079 q->enableSensor (accelerometer);
8180
82- q->setEventRate (accelerometer, ms2ns (200 ));
81+ q->setEventRate (accelerometer, ms2ns (10 ));
8382
8483 sp<Looper> loop = new Looper (false );
8584 loop->addFd (q->getFd (), 0 , ALOOPER_EVENT_INPUT, receiver, q.get ());
0 commit comments