Skip to content
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

Merged
merged 1 commit into from
Aug 6, 2019

Conversation

neverpanic
Copy link
Contributor

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.

neverpanic added a commit to neverpanic/co2monitor that referenced this pull request Mar 4, 2018
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.
@stamp
Copy link

stamp commented Dec 13, 2018

@karalabe @fjl could you consider merging this one? Seems to work just fine in linux as well :)

@pafuent
Copy link

pafuent commented Dec 14, 2018

I tested just the SendFeatureReport() on a Win10 and it also works

@kpeu3i
Copy link

kpeu3i commented Jan 7, 2019

@neverpanic, great work! @karalabe maybe it's time to merge this PR?

Copy link
Contributor

@gballet gballet left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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.
@muesli
Copy link

muesli commented Jun 23, 2019

Anything still blocking this?

@muesli
Copy link

muesli commented Jul 5, 2019

@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?

@fjl fjl merged commit 9c14560 into karalabe:master Aug 6, 2019
@fjl
Copy link
Collaborator

fjl commented Aug 6, 2019

Sorry for the delay.

@neverpanic neverpanic deleted the support-feature-reports branch August 6, 2019 10:21
@muesli
Copy link

muesli commented Aug 6, 2019

Thank you!

trinode added a commit to trinode/hid that referenced this pull request Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants