How to clear buffer before call libevdev_next_event

Peter Hutterer peter.hutterer at who-t.net
Tue Jan 15 06:15:02 UTC 2019


On Tue, Jan 15, 2019 at 08:54:18AM +0300, Knoppix wrote:
> Mr. Hutterer
> Thank you for your kindness. (Execuse me for my english I am not native)
> 
> Indeed, the problem is I cannot figure out which data is calibration and how
> much lines it will take. Sometimes when I do calibration the device gives me
> 20 lines garbage data but sometimes much more.
> If I use 10 second sleep everything is okey but this is not good solution.
> 
> Lastly, do you know is there any way to clear device buffer with kernel's
> call? I mean
> I am not asking for libevdev but I am asking for different way, may you
> advice me anything please? (I tried fsync, fflush, ioctl(fd, I_FLUSH,
> FLUSHRW),
> tcflush(fd, TCIOFLUSH) but not worked.)

i'm not exactly sure what you're asking for, but the same approach applies:
just read() the data and discard it and the buffer will be empty. That's
what e.g. libinput does as well.

Cheers,
   Peter

> 
> Best Regards.
> 
> On Tue, Jan 15, 2019 at 1:53 AM Peter Hutterer <peter.hutterer at who-t.net>
> wrote:
> 
> > On Fri, Jan 11, 2019 at 11:52:35AM +0300, Knoppix wrote:
> > > Hi,
> > >
> > > I set some calibration/settings on input device (*turn device wheel to
> > > left. I did this with write() function*) while this happens input system
> > > gathers data. So when I first call libevdev_next_event it gives me old
> > > garbage data. But I dont want those.
> > >
> > > How can I flush/clear buffered data with libevdev? Is there any way?
> >
> > If the device continuously sends data at a high frequency, it'll be hard
> > to
> > figure out exactly when the new data represents whatever you set the device
> > to, so you'll need some guessed delay anyway. But the easiest way is to
> > just
> > discard the data coming out of libevdev until you're convinced it's within
> > the new calibration range.
> >
> > libevdev doesn't do anything other than update a few internal states with
> > the data, so if you take the libevdev_next_event() and not do anything with
> > it, that event is discarded.
> >
> > Cheers,
> >    Peter
> >
> >
> >


More information about the Input-tools mailing list