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

[Mac] Set a valid interface number on hid_device_info for USB HID devices #380

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dylanmckay
Copy link

@dylanmckay dylanmckay commented Feb 15, 2018

Previously the interface would never be set on Mac.

This presents a big pain because retrieving interface numbers can be the
only way to distinguish between the interfaces returned by HIDAPI.

This change makes it possible to retrieve interface number from an
hid_device_info on Mac for USB HID devices only.

It is unclear if the Mac OS IOKit library returns valid interface numbers for non-HID USB devices. Because of this, I have opted to simply skip that case - leave it initialised to -1.

In the future, we can easily relax this restriction if it turns out IOKit correctly returns interface number with non-HID USB devices. For now, this PR brings 90% of the value at 5% of the risk.

mac/hid.c Outdated
@@ -432,6 +433,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
if ((vendor_id == 0x0 || vendor_id == dev_vid) &&
(product_id == 0x0 || product_id == dev_pid)) {
struct hid_device_info *tmp;
bool is_hid; /* Is this an actual HID usb device */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this to is_usb_hid since technically an IOHIDDeviceRef is a HID device object

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have updated it and pushed

…ices

Previously the interface would never be set on Mac.

This presents a big pain because retrieving interface numbers can be the
only way to distinguish between the interfaces returned by HIDAPI.

This change makes it possible to retrieve interface number from an
hid_device_info on Mac for USB HID devices only.

It is unclear if the Mac OS IOKit library returns valid interface numbers for non-HID USB devices. Because of this, I have opted to simply skip that case - leave it initialised to `-1`.

In the future, we can easily relax this restriction if it turns out IOKit correctly returns interface number with non-HID USB devices. For now, this PR brings 90% of the value at 5% of the risk.
@dylanmckay dylanmckay force-pushed the mac-hid-interface-support branch from 2bfcd3e to c283c71 Compare March 17, 2018 07:15
@samflores23
Copy link

I would vote yes on this pull request. Interface number definitely comes in handy

@TheOnlyJoey
Copy link

Can confirm this patch working for OpenHMD on OSX, please merge as it currently means that OSX is broken for our library.

TheOnlyJoey referenced this pull request in OpenHMD/OpenHMD Apr 2, 2018
@snooc snooc mentioned this pull request Apr 7, 2018
pH5 added a commit to OpenHMD/OpenHMD that referenced this pull request Apr 24, 2018
Instead of trying to parse the device path to match the interface
number, use the interface_number field in hid_device_info. This
currently does not work on recent Mac OS X [1]. Since there is nothing
we can do about it here, warn loudly.

Also ignore all but the IMU interfaces when building the device list.
Besides removing bogus devices from the list, this should also fix
multiple PSVR headsets connected at the same time.

[1] signal11/hidapi#380
…ices

Previously the interface would never be set on Mac.

This presents a big pain because retrieving interface numbers can be the
only way to distinguish between the interfaces returned by HIDAPI.

This change makes it possible to retrieve interface number from an
hid_device_info on Mac for USB HID devices only.

It is unclear if the Mac OS IOKit library returns valid interface numbers for non-HID USB devices. Because of this, I have opted to simply skip that case - leave it initialised to `-1`.

In the future, we can easily relax this restriction if it turns out IOKit correctly returns interface number with non-HID USB devices. For now, this PR brings 90% of the value at 5% of the risk.
@dylanmckay dylanmckay force-pushed the mac-hid-interface-support branch from 23cb76c to 2357fb5 Compare November 21, 2018 22:36
@dylanmckay
Copy link
Author

Gentle ping

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.

4 participants