Let libx52_init also translate libusb error codes

feature/cpp-library
nirenjan 2018-07-17 16:00:19 -07:00
parent b1139806f5
commit 9e581bf051
3 changed files with 6 additions and 2 deletions

View File

@ -104,4 +104,6 @@ static inline uint32_t tst_bit(uint32_t *value, uint32_t bit)
return (*value & (1UL << bit)); return (*value & (1UL << bit));
} }
int libx52internal_translate_libusb_error(enum libusb_error errcode);
#endif /* !defined X52JOY_COMMON_H */ #endif /* !defined X52JOY_COMMON_H */

View File

@ -17,7 +17,7 @@
#include "x52_common.h" #include "x52_common.h"
/* Translate a libusb error to a libx52 error */ /* Translate a libusb error to a libx52 error */
static int libx52_translate_libusb_error(enum libusb_error errcode) int libx52internal_translate_libusb_error(enum libusb_error errcode)
{ {
switch (errcode) { switch (errcode) {
case LIBUSB_SUCCESS: case LIBUSB_SUCCESS:
@ -81,7 +81,7 @@ int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value)
} }
} }
return libx52_translate_libusb_error(rc); return libx52internal_translate_libusb_error(rc);
} }
static int libx52_write_line(libx52_device *x52, uint8_t line_index) static int libx52_write_line(libx52_device *x52, uint8_t line_index)

View File

@ -78,6 +78,7 @@ int libx52_init(libx52_device **dev)
if (libx52_check_product(desc.idVendor, desc.idProduct)) { if (libx52_check_product(desc.idVendor, desc.idProduct)) {
rc = libusb_open(device, &hdl); rc = libusb_open(device, &hdl);
if (rc) { if (rc) {
rc = libx52internal_translate_libusb_error(rc);
goto err_recovery; goto err_recovery;
} }
@ -94,6 +95,7 @@ int libx52_init(libx52_device **dev)
/* Make sure we actually have an X52 device detected */ /* Make sure we actually have an X52 device detected */
if (!x52_dev->hdl) { if (!x52_dev->hdl) {
rc = LIBX52_ERROR_NO_DEVICE;
goto err_recovery; goto err_recovery;
} }