Fix build on musl and rename wrapper function to match hidapi's name

This commit is contained in:
Adam Honse 2023-01-28 11:34:56 -06:00
parent 6fdc70d650
commit e30fbdef71
3 changed files with 24 additions and 20 deletions

View file

@ -18,7 +18,7 @@ HyperXQuadcastSController::HyperXQuadcastSController(hidapi_wrapper hid_wrapper,
location = path; location = path;
wchar_t serial_string[128]; wchar_t serial_string[128];
int ret = wrapper.hid_get_serial_num_string(dev, serial_string, 128); int ret = wrapper.hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0) if(ret != 0)
{ {

View file

@ -26,14 +26,14 @@
const hidapi_wrapper default_wrapper = const hidapi_wrapper default_wrapper =
{ {
NULL, NULL,
(hidapi_wrapper_send_feature_report) hid_send_feature_report, (hidapi_wrapper_send_feature_report) hid_send_feature_report,
(hidapi_wrapper_get_feature_report) hid_get_feature_report, (hidapi_wrapper_get_feature_report) hid_get_feature_report,
(hidapi_wrapper_get_serial_num_string) hid_get_serial_number_string, (hidapi_wrapper_get_serial_number_string) hid_get_serial_number_string,
(hidapi_wrapper_open_path) hid_open_path, (hidapi_wrapper_open_path) hid_open_path,
(hidapi_wrapper_enumerate) hid_enumerate, (hidapi_wrapper_enumerate) hid_enumerate,
(hidapi_wrapper_free_enumeration) hid_free_enumeration, (hidapi_wrapper_free_enumeration) hid_free_enumeration,
(hidapi_wrapper_close) hid_close, (hidapi_wrapper_close) hid_close,
(hidapi_wrapper_error) hid_error (hidapi_wrapper_error) hid_error
}; };
ResourceManager* ResourceManager::instance; ResourceManager* ResourceManager::instance;
@ -1263,22 +1263,26 @@ void ResourceManager::DetectDevicesThreadFunction()
/*-------------------------------------------------*\ /*-------------------------------------------------*\
| Load the libhidapi-libusb library | | Load the libhidapi-libusb library |
\*-------------------------------------------------*/ \*-------------------------------------------------*/
#ifdef __GLIBC__
if(dyn_handle = dlopen("libhidapi-libusb.so", RTLD_NOW | RTLD_NODELETE | RTLD_DEEPBIND)) if(dyn_handle = dlopen("libhidapi-libusb.so", RTLD_NOW | RTLD_NODELETE | RTLD_DEEPBIND))
#else
if(dyn_handle = dlopen("libhidapi-libusb.so", RTLD_NOW | RTLD_NODELETE ))
#endif
{ {
/*-------------------------------------------------*\ /*-------------------------------------------------*\
| Create a wrapper with the libusb functions | | Create a wrapper with the libusb functions |
\*-------------------------------------------------*/ \*-------------------------------------------------*/
wrapper = wrapper =
{ {
.dyn_handle = dyn_handle, .dyn_handle = dyn_handle,
.hid_send_feature_report = (hidapi_wrapper_send_feature_report) dlsym(dyn_handle,"hid_send_feature_report"), .hid_send_feature_report = (hidapi_wrapper_send_feature_report) dlsym(dyn_handle,"hid_send_feature_report"),
.hid_get_feature_report = (hidapi_wrapper_get_feature_report) dlsym(dyn_handle,"hid_get_feature_report"), .hid_get_feature_report = (hidapi_wrapper_get_feature_report) dlsym(dyn_handle,"hid_get_feature_report"),
.hid_get_serial_num_string = (hidapi_wrapper_get_serial_num_string) dlsym(dyn_handle,"hid_get_serial_number_string"), .hid_get_serial_number_string = (hidapi_wrapper_get_serial_number_string) dlsym(dyn_handle,"hid_get_serial_number_string"),
.hid_open_path = (hidapi_wrapper_open_path) dlsym(dyn_handle,"hid_open_path"), .hid_open_path = (hidapi_wrapper_open_path) dlsym(dyn_handle,"hid_open_path"),
.hid_enumerate = (hidapi_wrapper_enumerate) dlsym(dyn_handle,"hid_enumerate"), .hid_enumerate = (hidapi_wrapper_enumerate) dlsym(dyn_handle,"hid_enumerate"),
.hid_free_enumeration = (hidapi_wrapper_free_enumeration) dlsym(dyn_handle,"hid_free_enumeration"), .hid_free_enumeration = (hidapi_wrapper_free_enumeration) dlsym(dyn_handle,"hid_free_enumeration"),
.hid_close = (hidapi_wrapper_close) dlsym(dyn_handle,"hid_close"), .hid_close = (hidapi_wrapper_close) dlsym(dyn_handle,"hid_close"),
.hid_error = (hidapi_wrapper_error) dlsym(dyn_handle,"hid_free_enumeration") .hid_error = (hidapi_wrapper_error) dlsym(dyn_handle,"hid_free_enumeration")
}; };
hid_devices = wrapper.hid_enumerate(0, 0); hid_devices = wrapper.hid_enumerate(0, 0);

View file

@ -21,7 +21,7 @@
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
typedef int (*hidapi_wrapper_send_feature_report) (hid_device*, const unsigned char*, size_t); typedef int (*hidapi_wrapper_send_feature_report) (hid_device*, const unsigned char*, size_t);
typedef int (*hidapi_wrapper_get_feature_report) (hid_device*, unsigned char*, size_t); typedef int (*hidapi_wrapper_get_feature_report) (hid_device*, unsigned char*, size_t);
typedef int (*hidapi_wrapper_get_serial_num_string) (hid_device*, wchar_t*, size_t); typedef int (*hidapi_wrapper_get_serial_number_string) (hid_device*, wchar_t*, size_t);
typedef hid_device* (*hidapi_wrapper_open_path) (const char*); typedef hid_device* (*hidapi_wrapper_open_path) (const char*);
typedef hid_device_info* (*hidapi_wrapper_enumerate) (unsigned short, unsigned short); typedef hid_device_info* (*hidapi_wrapper_enumerate) (unsigned short, unsigned short);
typedef void (*hidapi_wrapper_free_enumeration) (hid_device_info*); typedef void (*hidapi_wrapper_free_enumeration) (hid_device_info*);
@ -37,7 +37,7 @@ struct hidapi_wrapper
void* dyn_handle; void* dyn_handle;
hidapi_wrapper_send_feature_report hid_send_feature_report; hidapi_wrapper_send_feature_report hid_send_feature_report;
hidapi_wrapper_get_feature_report hid_get_feature_report; hidapi_wrapper_get_feature_report hid_get_feature_report;
hidapi_wrapper_get_serial_num_string hid_get_serial_num_string; hidapi_wrapper_get_serial_number_string hid_get_serial_number_string;
hidapi_wrapper_open_path hid_open_path; hidapi_wrapper_open_path hid_open_path;
hidapi_wrapper_enumerate hid_enumerate; hidapi_wrapper_enumerate hid_enumerate;
hidapi_wrapper_free_enumeration hid_free_enumeration; hidapi_wrapper_free_enumeration hid_free_enumeration;