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_device_info #432

Merged
merged 28 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4155be7
feat: Add hid_get_device_info
Julusian Jun 20, 2022
1818b59
chore: formatting
Julusian Jun 20, 2022
19e03fb
Apply suggestions from code review
Julusian Jun 23, 2022
5497de1
Update hidapi/hidapi.h
Julusian Jun 23, 2022
f88c36c
fix: segfaults
Julusian Jun 23, 2022
575b133
fix: windows hopefully
Julusian Jun 23, 2022
372c89b
fix: code review suggestions
Julusian Jul 17, 2022
c42b4b8
fix: lazy load hid_get_device_info result on some platforms
Julusian Jul 26, 2022
3d992cd
Update libusb/hid.c
Youw Aug 1, 2022
8d2954c
Update libusb/hid.c
Youw Aug 1, 2022
29f3826
Update libusb/hid.c
Youw Aug 1, 2022
5c75cd0
Update hidapi/hidapi.h
Youw Aug 1, 2022
938b912
Apply suggestions from code review
Julusian Aug 1, 2022
1832674
code review comments
Julusian Aug 1, 2022
fdddfc6
refactor libusb fill_device_info_for_device into create_device_info_f…
Julusian Aug 1, 2022
cd7349e
review comments
Julusian Aug 1, 2022
e6241f9
Explicit documentation NOTE
Youw Aug 6, 2022
79a77a7
libusb: lazy initialisation for get_device_info
Youw Aug 6, 2022
acd4788
fix invasive detach build
Youw Aug 6, 2022
e48a449
fix usage_page/usage fill
Youw Aug 7, 2022
4471fce
compilation fix
Youw Aug 7, 2022
e22cc65
typo
Youw Aug 7, 2022
d5bfa6e
use MAX_REPORT_DESCRIPTOR_SIZE constant
Youw Aug 7, 2022
5bb05a9
correct woding
Youw Aug 7, 2022
c7a8a71
check for handle
Youw Aug 7, 2022
8d11ec5
code style
Youw Aug 7, 2022
0296250
hidtest: print all of hid_get_device_info
Youw Aug 7, 2022
4779d63
refactor hidraw create_device_info_for_hid_device
Youw Aug 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions hidapi/hidapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,21 @@ extern "C" {
*/
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen);

/** @brief Get The struct #hid_device_info from a HID device.

@ingroup API
@param dev A device handle returned from hid_open().

@returns
This function returns a pointer to the struct #hid_device_info
for this hid_device, or NULL in the case of failure.
Youw marked this conversation as resolved.
Show resolved Hide resolved
Call hid_error(dev) to get the failure reason.
This struct is valid until the device is closed with hid_close().

@note The returned object is owned by the @p dev, and SHOULD NOT be freed by the user.
*/
HID_API_EXPORT struct hid_device_info * HID_API_CALL hid_get_device_info(hid_device *dev);

/** @brief Get a string from a HID device, based on its string index.

@ingroup API
Expand Down
40 changes: 27 additions & 13 deletions hidtest/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@
#endif
//

void print_device(struct hid_device_info *cur_dev) {
printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
printf("\n");
printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
printf(" Product: %ls\n", cur_dev->product_string);
printf(" Release: %hx\n", cur_dev->release_number);
printf(" Interface: %d\n", cur_dev->interface_number);
printf(" Usage (page): 0x%hx (0x%hx)\n", cur_dev->usage, cur_dev->usage_page);
printf("\n");
}

void print_devices(struct hid_device_info *cur_dev) {
while (cur_dev) {
print_device(cur_dev);
cur_dev = cur_dev->next;
}
}

int main(int argc, char* argv[])
{
(void)argc;
Expand All @@ -63,7 +81,7 @@ int main(int argc, char* argv[])
hid_device *handle;
int i;

struct hid_device_info *devs, *cur_dev;
struct hid_device_info *devs;

printf("hidapi test/example tool. Compiled with hidapi version %s, runtime version %s.\n", HID_API_VERSION_STR, hid_version_str());
if (HID_API_VERSION == HID_API_MAKE_VERSION(hid_version()->major, hid_version()->minor, hid_version()->patch)) {
Expand All @@ -83,18 +101,7 @@ int main(int argc, char* argv[])
#endif

devs = hid_enumerate(0x0, 0x0);
cur_dev = devs;
while (cur_dev) {
printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
printf("\n");
printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
printf(" Product: %ls\n", cur_dev->product_string);
printf(" Release: %hx\n", cur_dev->release_number);
printf(" Interface: %d\n", cur_dev->interface_number);
printf(" Usage (page): 0x%hx (0x%hx)\n", cur_dev->usage, cur_dev->usage_page);
printf("\n");
cur_dev = cur_dev->next;
}
print_devices(devs);
hid_free_enumeration(devs);

// Set up the command buffer.
Expand Down Expand Up @@ -134,6 +141,13 @@ int main(int argc, char* argv[])
printf("Serial Number String: (%d) %ls", wstr[0], wstr);
printf("\n");

struct hid_device_info* info = hid_get_device_info(handle);
if (info == NULL) {
printf("Unable to get device info\n");
} else {
print_devices(info);
}

// Read Indexed String 1
wstr[0] = 0x0000;
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
Expand Down
Loading