[fpc-pascal] USB Human Interface Devices
Stefan V. Pantazi
svpantazi at gmail.com
Fri Aug 16 19:30:01 CEST 2019
On 8/16/19 11:11 AM, James Richters wrote:
>>> Remember that interrupt reads are blocking so the way to deal with them is to put them away from the main thread, in their own thread. The moment something is available from the device, then the main thread of your application is signaled to read a buffer with the device report data. So, I can see some thread programming in your future or,
I see I did not finish my sentence. What I had in mind is that you could
use a library that already implements (using a thread I assume) a call
with a timeout. I checked and it looks like the original libusb call
that I used did have a timeout parameter that I hardcoded to 0 (infinite
timeout). libusb report a timeout as an error code. That did not sit
well with me and I preferred to use threads instead of time-out mechanism.
> Is there another way to do a read that has a timeout?
yes, it took only a few minutes to add the time-out parameter to the
libusbhid_interrupt_read call. Have a look at the github repository for
the updated version.
>
> Can I even do threads in a console program?
Sure you can, here is one of the simplest example you can start with
should you ever need to have multiple threads in your programs.
https://github.com/graemeg/freepascal/blob/master/packages/fcl-base/examples/threads.pp
--
_______________________________________________________
More information about the fpc-pascal
mailing list