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

Add hid_get_path to API resolves #163 #164

Closed
wants to merge 2 commits into from
Closed

Conversation

gotnone
Copy link

@gotnone gotnone commented May 14, 2020

This resolves the ability to get the device path from hid_device pointer issue in #163

Add a new hid_get_path function to the API. This adds a new path member
to the opaque structure of each hid implementation. The path is
dynamically allocated and populated in the respective hid_open_path
functions. The function returns a const char pointer to this path
string.

  • Add path string to each hid_device_ structure in hid.c files
  • Add hid_get_path function to hidapi.h and hid.c files
  • Add init and free code for dev->path to hid.c files
  • Allocate and populate dev->path in hid_open_path in hid.c files
  • Add example of hid_get_path usage in test.c

Add a new hid_get_path function to the API.  This adds a new path member
to the opaque structure of each hid implementation.  The path is
dynamically allocated and populated in the respective hid_open_path
functions.  The function returns a const char pointer to this path
string.

- Add path string to each hid_device_ structure in hid.c files
- Add hid_get_path function to hidapi.h and hid.c files
- Add init and free code for dev->path to hid.c files
- Allocate and populate dev->path in hid_open_path in hid.c files
- Add example of hid_get_path usage in test.c
@gotnone
Copy link
Author

gotnone commented May 14, 2020

This PR does have a significant caveat:

I don't have the ability to test this on anything other than windows at the moment. The use of char * may not be appropriate on some implementations (I am thinking of linux with UTF-8 capable filesystems). Please let me know if you can test this on other hidapi implementations.

@gotnone
Copy link
Author

gotnone commented May 14, 2020

After getting my hands on a linux machine. I can say that the libusb and hidraw implementations also appear to work correctly. The limitation on this may be the fact that this linux machine was set up to be en_US.UTF-8.

TODO: somehow test on a mac

@gotnone gotnone changed the title Add hid_get_path to API Add hid_get_path to API (resolves #163) May 14, 2020
@gotnone gotnone changed the title Add hid_get_path to API (resolves #163) Add hid_get_path to API resolves #163 May 14, 2020
@gotnone gotnone changed the title Add hid_get_path to API resolves #163 resolves #163 Add hid_get_path to API May 14, 2020
@gotnone gotnone changed the title resolves #163 Add hid_get_path to API Add hid_get_path to API resolves #163 May 14, 2020
@Youw
Copy link
Member

Youw commented May 14, 2020

What's on to of my mind - replace calloc + strcpy with strdup
I'll check everything closely a bit later

Use strdup instead of strlen + calloc + strncpy.
@Youw
Copy link
Member

Youw commented Nov 24, 2020

I'm probably going to spend some more time on this.
I think it is possible to postpone initialization of the "path" variable until it is first time called (at least for some backends).

@mcuee mcuee added the enhancement New feature or request label Dec 11, 2020
@Youw
Copy link
Member

Youw commented Jul 28, 2021

I haven't forgot about this one, but I remember I wanted to perform some kind of optimisation, at least for one of the platforms, before merging it.

@mcuee mcuee mentioned this pull request Aug 29, 2021
@Julusian Julusian mentioned this pull request Jun 20, 2022
@Youw Youw closed this in #432 Aug 13, 2022
Youw pushed a commit that referenced this pull request Aug 13, 2022
- new API function: `struct hid_device_info * hid_get_device_info(hid_device *dev);` to get `hid_device_info` after the device already opened;
- reused existing implementation on Windows and macOS from enumeration routines to have the implementation;
- refactored libusb implementation to have a shared routine for `hid_enumerate` and `hid_get_device_info`;
- refactored hidraw implementation to have a shared routine for `hid_enumerate` and `hid_get_device_info`;

Resolves: #431
Closes: #164
Closes: #163
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants