Added more debugging to Lightpack device

Former-commit-id: b1451c4ca1c6a085abc582d40919d8bd27614456
This commit is contained in:
johan 2013-11-17 10:21:08 +01:00
parent 095e303443
commit 936ff85729
2 changed files with 24 additions and 11 deletions

View File

@ -1 +1 @@
1cb3f98f75d106f770d15416e067095bee750f8d 99d7d673c3a99dbb8f1952dabd9e5cbe0a979176

View File

@ -75,6 +75,7 @@ int LedDeviceLightpack::open()
_libusbContext = nullptr; _libusbContext = nullptr;
return -1; return -1;
} }
libusb_set_debug(_libusbContext, 3);
std::cout << "USB context initialized" << std::endl; std::cout << "USB context initialized" << std::endl;
// retrieve the list of usb devices // retrieve the list of usb devices
@ -113,6 +114,7 @@ int LedDeviceLightpack::open()
catch (int e) catch (int e)
{ {
std::cerr << "unable to retrieve serial number from Lightpack device(" << e << "): " << libusb_error_name(e) << std::endl; std::cerr << "unable to retrieve serial number from Lightpack device(" << e << "): " << libusb_error_name(e) << std::endl;
serialNumber = "";
} }
} }
@ -125,6 +127,7 @@ int LedDeviceLightpack::open()
catch (int e) catch (int e)
{ {
std::cerr << "unable to retrieve firmware version number from Lightpack device(" << e << "): " << libusb_error_name(e) << std::endl; std::cerr << "unable to retrieve firmware version number from Lightpack device(" << e << "): " << libusb_error_name(e) << std::endl;
version = {-1,-1};
} }
std::cout << "Lightpack device found: bus=" << busNumber << " address=" << addressNumber << " serial=" << serialNumber << " version=" << version.majorVersion << "." << version.minorVersion << std::endl; std::cout << "Lightpack device found: bus=" << busNumber << " address=" << addressNumber << " serial=" << serialNumber << " version=" << version.majorVersion << "." << version.minorVersion << std::endl;
@ -147,7 +150,7 @@ int LedDeviceLightpack::open()
} }
catch(int e) catch(int e)
{ {
std::cerr << "unable to open Lightpack device. Searching for other device(" << e << "): " << libusb_error_name(e) << std::endl; std::cerr << "Unable to open Lightpack device. Searching for other device(" << e << "): " << libusb_error_name(e) << std::endl;
} }
} }
} }
@ -219,7 +222,7 @@ int LedDeviceLightpack::write(const std::vector<ColorRgb> &ledValues)
_ledBuffer[6*i+3] = color.blue; _ledBuffer[6*i+3] = color.blue;
// leave the next three bytes on zero... // leave the next three bytes on zero...
// 12-bit values have zeros in the lowest 4 bits which is almost correct, but it saves extra // 12-bit values having zeros in the lowest 4 bits which is almost correct, but it saves extra
// switches to determine what to do and some bit shuffling // switches to determine what to do and some bit shuffling
} }
@ -235,14 +238,24 @@ int LedDeviceLightpack::switchOff()
int LedDeviceLightpack::writeBytes(uint8_t *data, int size) int LedDeviceLightpack::writeBytes(uint8_t *data, int size)
{ {
std::cout << "Writing " << size << " bytes to Lightpack device" << std::endl; std::cout << "Writing " << size << " bytes: ";
for (int i = 0; i < size ; ++i) printf("%02x ", data[i]);
std::cout << std::endl;
return libusb_control_transfer(_deviceHandle, int error = libusb_control_transfer(_deviceHandle,
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
0x09, LIBUSB_REQUEST_SET_CONFIGURATION,
(2 << 8), (2 << 8),
0x00, 0x00,
data, size, 100); data, size, 100);
if (error == size)
{
return 0;
}
std::cerr << "Unable to write " << size << " bytes to Lightpack device(" << error << "): " << libusb_error_name(error) << std::endl;
return error;
} }
int LedDeviceLightpack::disableSmoothing() int LedDeviceLightpack::disableSmoothing()
@ -317,10 +330,10 @@ LedDeviceLightpack::Version LedDeviceLightpack::getVersion(libusb_device *device
uint8_t buffer[256]; uint8_t buffer[256];
error = libusb_control_transfer( error = libusb_control_transfer(
handle, handle,
LIBUSB_ENDPOINT_IN | LIBUSB_RECIPIENT_INTERFACE, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
LIBUSB_REQUEST_GET_DESCRIPTOR, LIBUSB_REQUEST_GET_CONFIGURATION,
(LIBUSB_DT_REPORT << 8), (2 << 8),
0, 0x00,
buffer, sizeof(buffer), 100); buffer, sizeof(buffer), 100);
if (error < 3) if (error < 3)
{ {