From e1e88ba2cfe6019bd19f164d08e3c716f6c38375 Mon Sep 17 00:00:00 2001 From: johan Date: Fri, 15 Nov 2013 18:16:00 +0100 Subject: [PATCH] Close Lightpack device handle after error; Changed retrieve Lightpack firmware version call Former-commit-id: 7aa38d40e9918894e602519366ac1b28d3d533a2 --- deploy/hyperiond.REMOVED.git-id | 2 +- libsrc/hyperion/device/LedDeviceLightpack.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/deploy/hyperiond.REMOVED.git-id b/deploy/hyperiond.REMOVED.git-id index aaacfc20..784d46ce 100644 --- a/deploy/hyperiond.REMOVED.git-id +++ b/deploy/hyperiond.REMOVED.git-id @@ -1 +1 @@ -616598d4b62e2da40b2deeca332718c00209acfb \ No newline at end of file +db2c75aa5829d405c7120255af5dbee38c9272d7 \ No newline at end of file diff --git a/libsrc/hyperion/device/LedDeviceLightpack.cpp b/libsrc/hyperion/device/LedDeviceLightpack.cpp index 3e41787c..5acc3049 100644 --- a/libsrc/hyperion/device/LedDeviceLightpack.cpp +++ b/libsrc/hyperion/device/LedDeviceLightpack.cpp @@ -147,7 +147,7 @@ int LedDeviceLightpack::open() } catch(int e) { - std::cerr << "unable to retrieve open Lightpack device(" << e << "): " << libusb_error_name(e) << std::endl; + std::cerr << "unable to open Lightpack device(" << e << "): " << libusb_error_name(e) << std::endl; } } } @@ -223,7 +223,8 @@ int LedDeviceLightpack::write(const std::vector &ledValues) // switches to determine what to do and some bit shuffling } - return writeBytes(_ledBuffer.data(), _ledBuffer.size()); + int error = writeBytes(_ledBuffer.data(), _ledBuffer.size()); + return error >= 0 ? 0 : error; } int LedDeviceLightpack::switchOff() @@ -263,12 +264,14 @@ libusb_device_handle * LedDeviceLightpack::openDevice(libusb_device *device) error = libusb_detach_kernel_driver(handle, LIGHTPACK_INTERFACE); if (error != LIBUSB_SUCCESS) { + libusb_close(handle); throw error; } error = libusb_claim_interface(handle, LIGHTPACK_INTERFACE); if (error != LIBUSB_SUCCESS) { + libusb_close(handle); throw error; } @@ -283,6 +286,7 @@ std::string LedDeviceLightpack::getString(libusb_device * device, int stringDesc int error = libusb_get_string_descriptor_ascii(deviceHandle, stringDescriptorIndex, reinterpret_cast(buffer), sizeof(buffer)); if (error <= 0) { + libusb_close(deviceHandle); throw error; } @@ -295,9 +299,16 @@ LedDeviceLightpack::Version LedDeviceLightpack::getVersion(libusb_device *device libusb_device_handle * deviceHandle = openDevice(device); uint8_t buffer[256]; - int error = libusb_get_descriptor(deviceHandle, LIBUSB_DT_REPORT, 0, buffer, sizeof(buffer)); - if (error <= 3) + int error = libusb_control_transfer( + deviceHandle, + LIBUSB_ENDPOINT_IN | LIBUSB_RECIPIENT_INTERFACE, + LIBUSB_REQUEST_GET_DESCRIPTOR, + (LIBUSB_DT_REPORT << 8), + 0, + buffer, sizeof(buffer), 100); + if (error < 3) { + libusb_close(deviceHandle); throw error; }