diff --git a/lib/libusbx52/usb_x52_stub.c b/lib/libusbx52/usb_x52_stub.c index 1293fd6..a65de70 100644 --- a/lib/libusbx52/usb_x52_stub.c +++ b/lib/libusbx52/usb_x52_stub.c @@ -8,6 +8,7 @@ #include #include +#include #include #include "libusbx52.h" @@ -129,6 +130,26 @@ void libusb_set_debug(libusb_context *ctx, int level) ctx->debug_level = level; } +#if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000106) +int libusb_set_option(libusb_context *ctx, enum libusb_option option, ...) +{ + va_list args; + va_start(args, option); + + /* Check if the option was provided */ + if (option == LIBUSB_OPTION_LOG_LEVEL) { + int level = va_arg(args, int); + + /* Set the debug level */ + ctx->debug_level = level; + } + + va_end(args); + + return 0; +} +#endif + ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list) { /* Allocate a list of num_devices, each pointing to a corresponding diff --git a/lib/libusbx52/util/log_actions.c b/lib/libusbx52/util/log_actions.c index e94a01d..a350d0d 100644 --- a/lib/libusbx52/util/log_actions.c +++ b/lib/libusbx52/util/log_actions.c @@ -41,7 +41,16 @@ static libusb_device_handle *libusbx52_init(void) return NULL; } + #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000106) + /* + * Use the libusb_set_option flag instead of libusb_set_debug. This + * was introduced in libusb 1.0.22 + */ + libusb_set_option(global_context, LIBUSB_OPTION_LOG_LEVEL, + LIBUSB_LOG_LEVEL_ERROR); + #else libusb_set_debug(global_context, LIBUSB_LOG_LEVEL_ERROR); + #endif count = libusb_get_device_list(global_context, &list); for (i = 0; i < count; i++) { diff --git a/lib/libx52/x52_core.c b/lib/libx52/x52_core.c index ed693e9..156068d 100644 --- a/lib/libx52/x52_core.c +++ b/lib/libx52/x52_core.c @@ -69,7 +69,16 @@ int libx52_init(libx52_device **dev) rc = LIBX52_ERROR_INIT_FAILURE; goto err_recovery; } + #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000106) + /* + * Use the libusb_set_option flag instead of libusb_set_debug. This + * was introduced in libusb 1.0.22 + */ + libusb_set_option(x52_dev->ctx, LIBUSB_OPTION_LOG_LEVEL, + LIBUSB_LOG_LEVEL_WARNING); + #else libusb_set_debug(x52_dev->ctx, LIBUSB_LOG_LEVEL_WARNING); + #endif count = libusb_get_device_list(x52_dev->ctx, &list); for (i = 0; i < count; i++) {