-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hid: Support sending & retrieving feature reports #13
Conversation
Only Linux has a hidraw driver providing file-based access to HID devices. For other operating systems such as Windows or macOS, USB HID devices must be accessed through a library. Depend on karalabe/hid (with karalabe/hid#13 merged) for USB communication. This also removes the necessity to manually specify the correct hidraw device file, since HIDAPI can do enumeration based on the USB vendor ID and product ID. This also simplifies supporting multiple devices with a single server process, so implement that. Note that all CO2 detectors I could get a hold had non-unique serial numbers, so the device serial number could not be used to distinguish them in the prometheus output. Instead, the path of the USB device is used now. Unfortunately this means that the sensor ID changes when the detector is plugged into a different USB port. Also note that these paths can get very large and contain special characters and spaces, but prometheus does not allow these in gauge identifiers. To work around this, apply SHA1 to the path and use it as identifier.
I tested just the SendFeatureReport() on a Win10 and it also works |
@neverpanic, great work! @karalabe maybe it's time to merge this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Please fix the nitpick.
hid_enabled.go
Outdated
// sure to allow space for this extra byte in []b. Upon return, the first byte | ||
// will still contain the Report ID, and the report data will start in b[1]. | ||
func (dev *Device) GetFeatureReport(b []byte) (int, error) { | ||
// Abort if nothing to read |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this comment more accurate: there might be something to read, it's simply that there is no provided space to copy it to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Some USB devices require sending a feature report before they will answer to read requests. Implement wrapper functions for the hidapi hid_send_feature_report and hid_get_feature_report functions to support doing so.
757d6c8
to
6d68e5b
Compare
Anything still blocking this? |
@karalabe I hope this doesn't come across as offensive, it's really not meant that way. If you just don't have the time for it currently, I'll understand. But since I'm depending on this library with a project, I'm wondering: are you still planning to maintain this library or shall we concentrate on a fork? |
Sorry for the delay. |
Thank you! |
This reverts commit 9c14560.
Some USB devices require sending a feature report before they will answer to read requests. Implement wrapper functions for the hidapi hid_send_feature_report and hid_get_feature_report functions to support doing so.
I have tested this on macOS.
Note that this is only my second time writing Go, so please pull with review and care.
See also #10.