[fpc-pascal] USB Human Interface Devices
Stefan V. Pantazi
svpantazi at gmail.com
Fri Aug 16 15:41:49 CEST 2019
On 8/16/19 6:23 AM, James Richters wrote:
> DATA!!!!!!!!!!!!!!
> Is there a way I can read data from the device with a timeout instead of just waiting forever for it? It doesn't send anything unless I push a button, but I need to do other things like update the LCD if I am not pushing a button. My python example uses a function called hid.read(size,timeout) so I'm trying to do something similar. This is going to be a console application when I am done, do I don't have a way to do anything else, so a timeout would work best.
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'm also trying to figure out how to write to the LCD...
> I think there is a bug because 7 bytes would be data[0..6] and it would not duplicate byte 7.... but the 0x06 must tell it to send from bytes 0 to 6... but anyway, regardless of that, how do I do something like hid.send_feature_report?
I have checked an old example where I use a HID set feature report. I
can see that the first byte of the output data (your hidOutData array)
is always set to the reportNum. So the length of the hidOutData array
send to the device includes the actual report number which prepends one
byte to the data. So the Python example is correct.
For example, in this call where I was trying to set a Wacom graphic
tablet mode, the length of hid_data is 3 bytes (the first being the
report number) but the report length in the call is 2
(WACOM_FEATURE_REPORT_LENGTH).
hid_data[0]:=WACOM_REPORT_NUMBER;
hid_data[1]:=WACOM_TABLET_MODE_FINGER_ENABLED;
hid_data[2]:=0;
libusbhid_set_report(device_context,HID_REPORT_TYPE_FEATURE{=$03},
WACOM_REPORT_NUMBER_ID{=2}, WACOM_FEATURE_REPORT_LENGTH{=2}, hid_data);
> I'm guessing that libusbhid_set_report() is maybe something similar? But it has parameters for reportType and reportNum... any clue what to put there? Or is this not even the right
You got it. Report type can be input, output or feature, just choose the
appropriate constant. Report number, for me was a lot of guesses, trial
and error combined with other examples of similar devices, etc.
function? I thought maybe putting HID_REPORT_TYPE_FEATURE would mean
to send a feature report? But reportNum I have no idea... I stuck a 1
in there just to see and tried:
> libusbhid_set_report(device_context,HID_REPORT_TYPE_FEATURE,1,7,hidOutData[0..6]);
> but then I get:
> libusb: warning [_hid_set_report] mismatched report ID (data is FE, parameter is 01)
> control transfer to usb device failed!
> $FE is what I have in hidOutData[0], but I'm not sure what it wants for a report id?
Just make hidOutData[0]=Report_id (i.e., the first byte of your array)
and cross your fingers that the report id is correct.
>
> Can you tell me where to get libusb_1.0_X86.dll ? I had the x64 version from the sample Jean sent me, but I would like to make my program work on 32bit machines as well.
I remember that I had to build those from source but I am sure you can
find binaries online.
Happy hacking!
More information about the fpc-pascal
mailing list