[Letux-kernel] evtest /dev/input/accel

H. Nikolaus Schaller hns at goldelico.com
Tue Apr 17 10:45:59 CEST 2018

I now have extracted the QtMoko accelerometer handler code [1]
into a simple command line utility.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: accel-test.c
Type: application/octet-stream
Size: 6568 bytes
Desc: not available
URL: <http://lists.goldelico.com/pipermail/letux-kernel/attachments/20180417/89865f8b/attachment.obj>
-------------- next part --------------

This basically works, except for the following observations:

1. sometimes one axis is reported as "0" in between.

This comes because there may be SYN_REPORT (EV_SYN) on
the first read after opening the device before all
3 axis are reported. This may be a race between opening
the event device and the driver providing the first events.

This is harmless, because QtMoko or QtMaze opens the
device only once and future events are collected while
the accel-test program opens and closes the device for
each call.

2. accel-test does not have a background thread to
collect events.

In QtMoko there is a background thread that tries
every 12.5 ms to collect events. This seems to differ
from GTA02 which has 2 ms.

So the GTA02 may sample more often, but that should
not have an influence on the game speed. Because
it runs in a background thread *and* the game defines
the frame rate which likely defines the visual physics.

3. it seems as if there is an active polling loop
until data becomes available. This is

 325                 /* Call accelerometer_moo() until we have an
 326                    acceleration measurement. */
 327                 while (!accelerometer_moo(accel))
 328                   ;

This makes the background thread poll until a SYN_REPORT
has been received where we can assume that all axis
information is available.

For me this looks as if this is done at 100% CPU load
because the select() call has a zero timeout.

This could of course slow down the main application,
i.e. drawing of the graphics.

I am not sure, but I think this should either become
a blocking select() call.

Or there should not be an inner while loop in the thread

The Neo GTA02 code also does a non-blocking select() but
then always makes the thread sleep for 2 ms.

So maybe accel_work() should look like:

 323       while ( !(my_thread_data->finished) ) {
 325                 /* Call accelerometer_moo() until we have an
 326                    acceleration measurement. */
 327                 if (accelerometer_moo(accel))
 328                   {
 330                 /* If the library user specified a callback, call
 331                    it. */
 332                 if (my_thread_data->callback)
 333                   (*my_thread_data->callback)(my_thread_data->closure,
 334                                               acx, acy, acz);
 335                   }
 336                 /* Sleep before taking another measurement. */
 337                 usleep(my_thread_data->interval_us);
 338         }

Please comment while I'll test...


[1]: http://git.goldelico.com/?p=gta04-qtmoko.git;a=blob;f=src/libraries/accelerometer/accelerometers.cpp;h=4bd95bccf91d301512800b9fafdd7e4a610b1a70;hb=618ac5b867ba807e749213fde74fe9b0afe935c4

More information about the Letux-kernel mailing list