HID functions to read back the status of an HID controller (like MIDI SYSEX)#3317
HID functions to read back the status of an HID controller (like MIDI SYSEX)#3317Be-ing merged 32 commits intomixxxdj:mainfrom
Conversation
uklotzde
left a comment
There was a problem hiding this comment.
Thanks for keeping track of the latest additions ;)
Unfortunately we cannot safely assume that version 0.10 is available on all platforms. We need a minimum version check and static linkage if it fails.
| << "(including report ID of" << reportID << ")"); | ||
| bytesRead -= kReportIdSize; | ||
|
|
||
| if (bytesRead == m_iLastPollSize && |
There was a problem hiding this comment.
An empty if arm is unusual.
Moreover this code for buffering and de-duplicating the input should be extracted into a private member function instead of duplicating it. I suggest to return a const char* pointer to the incoming data on success and nullptr otherwise. Pass the actual hidapi call as a function pointer, the signatures of hid_get_input_report and hid_read should match.
There was a problem hiding this comment.
Or add an enum that you pass as argument and a switch case, might be easier to read.
There was a problem hiding this comment.
I moved buffering and de-duplicating in a private member function, as suggested.
Regarding merging getInputReport and getFeatureReport I decided against it, for multiple reasons:
- A function pointer would expose the symbols of the low level library below hidcontroler to one abstraction level above hidcontroller
- The argument list would differ between the C++ method and the JavaScript proxy method
- The internal buffer of de-duplicating code must never be used for a feature report. This would require copying of the buffer array.
- Code differences would require multiple branches inside the function
| controllerDebug(bytesRead << "bytes received by hid_get_input_report" << getName() | ||
| << "serial #" << hid_serial | ||
| << "(including report ID of" << reportID << ")"); | ||
| bytesRead -= kReportIdSize; |
There was a problem hiding this comment.
Stripping off the last byte unconditionally is wrong in many ways.
Depending on the arguments the report ID will be included in the result or not. And it will be included as the first byte, not the last byte. Please refer to the implementation in hid.c.
There was a problem hiding this comment.
The Windows implementation of hid_get_input_report in HIDAPI is wrong, it returns always a byte count incremented by 1. I started a upstream PR to fix this: libusb/hidapi#232
I don't know, if the implementations for the other platforms return the correct byte count.
Nethertheless, this has no influence on the Mixxx application logic. You just see one byte more than read from the device.
|
@Be-ing @Holzhaus Btw, I suggest to drop the |
Force static linkage if system HIDAP is older than 0.10.0
Suggested by Holzhaus Co-authored-by: Jan Holthuis <holthuis.jan@googlemail.com>
8a40b82 to
2b74b98
Compare
2b74b98 to
57270d4
Compare
…igned chars, but QString::number expects an unsigned 8 bit integer)
c1a9e3b to
aeaffe2
Compare
05b3997 to
37112d6
Compare
Co-authored-by: Be <be.0@gmx.com>
Co-authored-by: Be <be.0@gmx.com>
Co-authored-by: Be <be.0@gmx.com>
|
Please be mindful to type a useful commit message when applying suggestions from the GitHub web UI. |
Removed class name before private method call
fe935b5 to
79e1392
Compare
|
Considering |
Good point! I'm considering to remove the automatic trigger of |
|
I agree that would be easier to understand. The call to |
…nfinite loops in mapping scripts Fixed some comments mentioned in review
953da3f to
fb7d30d
Compare
Co-authored-by: Be <be.0@gmx.com>
Co-authored-by: Be <be.0@gmx.com>
|
Thank you! |
The new hidapi 0.10 offers new functionality:
I implemented two new HID functions to read back the status of an HID controller:
QList getInputReport(unsigned int reportID);
QList getFeatureReport(unsigned int reportID);
Usage example 1 (Read and Set all buttons, knob or fader positions at Mixxx startup):
Usage example 2 (Read and print state of Input an Feature reports):
Usage example 3 (Set a single bit in FeatureReport):