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 1 commit
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
Prev Previous commit
Next Next commit
fix: lazy load hid_get_device_info result on some platforms
  • Loading branch information
Julusian committed Jul 26, 2022
commit c42b4b89437f4afd50a09cdcbd7245cf99abad3c
28 changes: 15 additions & 13 deletions linux/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,6 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)

/* If we have a good handle, return it. */
if (dev->device_handle >= 0) {
dev->device_info = get_device_info_for_hid_device(dev);

/* Get the report descriptor */
int res, desc_size = 0;
struct hidraw_report_descriptor rpt_desc;
Expand Down Expand Up @@ -1067,9 +1065,10 @@ void HID_API_EXPORT hid_close(hid_device *dev)

int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
if (!dev->device_info)
struct hid_device_info *info = hid_get_device_info(dev);
if (!info)
{
register_device_error(dev, "NULL device/info");
// hid_get_device_info will have set an error already
return -1;
}

Expand All @@ -1079,17 +1078,18 @@ int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *st
return -1;
}

wcsncpy(string, dev->device_info->manufacturer_string, maxlen);
wcsncpy(string, info->manufacturer_string, maxlen);
string[maxlen - 1] = L'\0';

return 0;
}

int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
if (!dev->device_info)
struct hid_device_info *info = hid_get_device_info(dev);
if (!info)
{
register_device_error(dev, "NULL device/info");
// hid_get_device_info will have set an error already
return -1;
}

Expand All @@ -1099,17 +1099,18 @@ int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string,
return -1;
}

wcsncpy(string, dev->device_info->product_string, maxlen);
wcsncpy(string, info->product_string, maxlen);
string[maxlen - 1] = L'\0';

return 0;
}

int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
if (!dev->device_info)
struct hid_device_info *info = hid_get_device_info(dev);
if (!info)
{
register_device_error(dev, "NULL device/info");
// hid_get_device_info will have set an error already
return -1;
}

Expand All @@ -1119,7 +1120,7 @@ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *s
return -1;
}

wcsncpy(string, dev->device_info->serial_number, maxlen);
wcsncpy(string, info->serial_number, maxlen);
string[maxlen - 1] = L'\0';

return 0;
Expand All @@ -1129,10 +1130,11 @@ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *s
HID_API_EXPORT struct hid_device_info *HID_API_CALL hid_get_device_info(hid_device *dev) {
if (!dev->device_info)
{
register_device_error(dev, "NULL device/info");
return NULL;
// Lazy initialize device_info
dev->device_info = get_device_info_for_hid_device(dev);
}

// get_device_info_for_hid_device will set an error if needed
return dev->device_info;
}

Expand Down
26 changes: 13 additions & 13 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,6 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
goto return_error;
}

dev->device_info = create_device_info(dev->device_handle);

/* Open the IOHIDDevice */
ret = IOHIDDeviceOpen(dev->device_handle, dev->open_options);
if (ret == kIOReturnSuccess) {
Expand Down Expand Up @@ -1166,9 +1164,10 @@ void HID_API_EXPORT hid_close(hid_device *dev)

int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
if (!dev->device_info)
struct hid_device_info *info = hid_get_device_info(dev);
if (!info)
{
// register_device_error(dev, "NULL device/info");
// hid_get_device_info will have set an error already
return -1;
}

Expand All @@ -1178,17 +1177,18 @@ int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *dev, wchar_t *st
return -1;
}

wcsncpy(string, dev->device_info->manufacturer_string, maxlen);
wcsncpy(string, info->manufacturer_string, maxlen);
string[maxlen - 1] = L'\0';

return 0;
}

int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
if (!dev->device_info)
struct hid_device_info *info = hid_get_device_info(dev);
if (!info)
{
// register_device_error(dev, "NULL device/info");
// hid_get_device_info will have set an error already
return -1;
}

Expand All @@ -1198,17 +1198,18 @@ int HID_API_EXPORT_CALL hid_get_product_string(hid_device *dev, wchar_t *string,
return -1;
}

wcsncpy(string, dev->device_info->product_string, maxlen);
wcsncpy(string, info->product_string, maxlen);
string[maxlen - 1] = L'\0';

return 0;
}

int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
if (!dev->device_info)
struct hid_device_info *info = hid_get_device_info(dev);
if (!info)
{
// register_device_error(dev, "NULL device/info");
// hid_get_device_info will have set an error already
return -1;
}

Expand All @@ -1218,7 +1219,7 @@ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *s
return -1;
}

wcsncpy(string, dev->device_info->serial_number, maxlen);
wcsncpy(string, info->serial_number, maxlen);
string[maxlen - 1] = L'\0';

return 0;
Expand All @@ -1227,8 +1228,7 @@ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *s
HID_API_EXPORT struct hid_device_info *HID_API_CALL hid_get_device_info(hid_device *dev) {
if (!dev->device_info)
{
// register_string_error(dev, L"NULL device/info");
return NULL;
dev->device_info = create_device_info(dev->device_handle);
}

return dev->device_info;
Expand Down