tslib icon indicating copy to clipboard operation
tslib copied to clipboard

How to check if there are pending events when tslib opened in blocking mode

Open guillerodriguez opened this issue 5 years ago • 5 comments

I need to open tslib in blocking mode, but need a way to check if there are outstanding events. Basically I need to:

  • Block until at least one event is ready. This part is easy
  • But if there are many events ready, discard all but the most recent one. This is the way I don't know how to handle.

I would try to get the fd using ts_fd and then use select or poll, like this: https://github.com/nicupavel/android-tslib/blob/master/tests/ts_calibrate.c#L166

However #53 suggests that this is not supported.

What is the proper way to do it then?

guillerodriguez avatar Jul 09 '19 09:07 guillerodriguez

in blocking mode, ts_read_mt() will return if there's an event (or the number of events you want to read at once). I might get you wrong, but why would you want to lose events? This can result in bad user experience, can't it?

merge avatar Jul 09 '19 09:07 merge

I have a touch controller that reports events at a very high rate (more than 200 per second). This is creating an unnecessary load in the system so I am trying to filter the event stream and limit the max rate to e.g. 60 Hz.

My current approach for this is to have the app force a minimum delay of 16.7ms between reads. If there are no pending events, the read call should block (this works). But if there are more than one pending event, I am only interested in the last one, and want to skip the others.

guillerodriguez avatar Jul 09 '19 10:07 guillerodriguez

if poll() or select() doesn't work on the original file-descriptor, ts_fd(), then we might have a problem. But still, what if you skip "critical" samples that mess up the UX?

merge avatar Jul 09 '19 13:07 merge

select() on the fd returned by ts_fd() does certainly work. I am just slightly concerned because of your comments in #53:

select()ing on ts_fd and then reading samples from tslib is simply wrong usage

That's why I was asking, if this is wrong, then what's the proper way to do what I need.

Re. skipping critical samples, I don't see how that could happen. The last event you look at always contains the full state -- either pressed (plus coordinates) or not pressed (note that I'm not doing multitouch).

The only thing that could happen is if the user manages to touch, then release, all within a 16.7ms window, and then the touch goes unnoticed. But that's rather unusual I think, and something I can perfectly live with (in fact if the touch controller was reporting events at 60Hz instead of 200+ Hz, the result would be exactly the same).

guillerodriguez avatar Jul 09 '19 15:07 guillerodriguez

select() on the fd returned by ts_fd() does certainly work. I am just slightly concerned because of your comments in #53:

select()ing on ts_fd and then reading samples from tslib is simply wrong usage

That's why I was asking, if this is wrong, then what's the proper way to do what I need.

IIRC that was (just) because the fd doesn't belong to libts. You actually can use it, if you carefully choose the filter modules you apply in between it (the fd of the original device) and the samples you get after libts (from ts_read_mt).

I actually think you will be fine if you just don't use the variance filter. You'd need to test.

merge avatar Jul 10 '19 05:07 merge