Skip to content

Commit

Permalink
Merge pull request #561 from peternewman/libusb
Browse files Browse the repository at this point in the history
Get the usbdmx plugin working with older versions of libusb
  • Loading branch information
peternewman committed Dec 6, 2014
2 parents c01ed1d + 12e5592 commit 18f5f8c
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 35 deletions.
4 changes: 2 additions & 2 deletions common/rdm/AdvancedDimmerResponder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,12 @@ const RDMResponse *AdvancedDimmerResponder::SetPresetStatus(

if (args.programmed == 1) {
preset.fade_up_time = 0;
preset.fade_down_time= 0;
preset.fade_down_time = 0;
preset.wait_time = 0;
preset.programmed = PRESET_NOT_PROGRAMMED;
} else {
preset.fade_up_time = NetworkToHost(args.fade_up_time);
preset.fade_down_time= NetworkToHost(args.fade_down_time);
preset.fade_down_time = NetworkToHost(args.fade_down_time);
preset.wait_time = NetworkToHost(args.wait_time);
preset.programmed = PRESET_PROGRAMMED;
}
Expand Down
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,14 @@ AS_IF([test "x$enable_libusb" != xno],
AS_IF([test "x$have_libusb" = xyes],
[AC_DEFINE([HAVE_LIBUSB], [1], [define if libusb is installed])])

have_libusb_error_name="no"
AS_IF([test "x$enable_libusb" != xno],
[PKG_CHECK_MODULES([libusb_error_name], [libusb-1.0 >= 1.0.9],
[have_libusb_error_name="yes"], [true])])
AS_IF([test "x$have_libusb_error_name" = xyes],
[AC_DEFINE([HAVE_LIBUSB_ERROR_NAME], [1],
[define if libusb is installed and has libusb_error_name])])

# UART direct plugin
AC_ARG_ENABLE(
[uart],
Expand Down
2 changes: 1 addition & 1 deletion examples/ola-dmxconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ void stdin_ready() {
case KEY_IC:
undoprep();
for (n = ola::DMX_UNIVERSE_SIZE - 1; n > current_channel && n > 0; n--)
dmx[n]=dmx[n - 1];
dmx[n] = dmx[n - 1];
setall();
break;

Expand Down
28 changes: 14 additions & 14 deletions examples/ola-dmxmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,23 +580,23 @@ void DmxMonitor::ChangePalette(int p) {
goto color;

color:
palette[CHANNEL]=COLOR_PAIR(CHANNEL);
palette[ZERO]=COLOR_PAIR(ZERO);
palette[NORM]=COLOR_PAIR(NORM);
palette[FULL]=COLOR_PAIR(FULL);
palette[HEADLINE]=COLOR_PAIR(HEADLINE);
palette[HEADEMPH]=COLOR_PAIR(HEADEMPH);
palette[HEADERROR]=COLOR_PAIR(HEADERROR);
palette[CHANNEL] = COLOR_PAIR(CHANNEL);
palette[ZERO] = COLOR_PAIR(ZERO);
palette[NORM] = COLOR_PAIR(NORM);
palette[FULL] = COLOR_PAIR(FULL);
palette[HEADLINE] = COLOR_PAIR(HEADLINE);
palette[HEADEMPH] = COLOR_PAIR(HEADEMPH);
palette[HEADERROR] = COLOR_PAIR(HEADERROR);
break;

case 1:
palette[CHANNEL]=A_REVERSE;
palette[ZERO]=A_NORMAL;
palette[NORM]=A_NORMAL;
palette[FULL]=A_BOLD;
palette[HEADLINE]=A_NORMAL;
palette[HEADEMPH]=A_NORMAL;
palette[HEADERROR]=A_BOLD;
palette[CHANNEL] = A_REVERSE;
palette[ZERO] = A_NORMAL;
palette[NORM] = A_NORMAL;
palette[FULL] = A_BOLD;
palette[HEADLINE] = A_NORMAL;
palette[HEADEMPH] = A_NORMAL;
palette[HEADERROR] = A_BOLD;
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions include/ola/ExportMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ class ExportMap {
StringVariable *GetStringVar(const std::string &name);

StringMap *GetStringMapVar(const std::string &name,
const std::string &label="");
IntMap *GetIntMapVar(const std::string &name, const std::string &label="");
const std::string &label = "");
IntMap *GetIntMapVar(const std::string &name, const std::string &label = "");
UIntMap *GetUIntMapVar(const std::string &name,
const std::string &label="");
const std::string &label = "");

/**
* @brief Fetch a list of all known variables.
Expand Down
2 changes: 1 addition & 1 deletion include/ola/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ enum { HEX_BIT_WIDTH = 4 };
*/
void StringSplit(const std::string &input,
std::vector<std::string> &tokens, // NOLINT
const std::string &delimiters=" ");
const std::string &delimiters = " ");

/**
* @brief Trim leading and trailing whitespace from a string
Expand Down
2 changes: 1 addition & 1 deletion include/ola/http/HTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class HTTPServer: public ola::thread::Thread {
const std::string DataDir() const { return m_data_dir; }

// Return an error
int ServeError(HTTPResponse *response, const std::string &details="");
int ServeError(HTTPResponse *response, const std::string &details = "");
int ServeNotFound(HTTPResponse *response);
static int ServeRedirect(HTTPResponse *response, const std::string &location);

Expand Down
2 changes: 1 addition & 1 deletion olad/RDMHTTPModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ class RDMHTTPModule {
void AddSection(std::vector<section_info> *sections,
const std::string &section_id,
const std::string &section_name,
const std::string &hint="");
const std::string &hint = "");

static const uint32_t INVALID_PERSONALITY = 0xffff;
static const char BACKEND_DISCONNECTED_ERROR[];
Expand Down
2 changes: 1 addition & 1 deletion plugins/pathport/PathportNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool PathportNode::Start() {
delete picker;

m_config_addr = IPV4Address(HostToNetwork(PATHPORT_CONFIG_GROUP));
m_status_addr= IPV4Address(HostToNetwork(PATHPORT_STATUS_GROUP));
m_status_addr = IPV4Address(HostToNetwork(PATHPORT_STATUS_GROUP));
m_data_addr = IPV4Address(HostToNetwork(PATHPORT_DATA_GROUP));

if (!InitNetwork())
Expand Down
3 changes: 2 additions & 1 deletion plugins/usbdmx/AsyncUsbSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ void AsyncUsbSender::FillInterruptTransfer(unsigned char endpoint,
int AsyncUsbSender::SubmitTransfer() {
int ret = m_adaptor->SubmitTransfer(m_transfer);
if (ret) {
OLA_WARN << "libusb_submit_transfer returned " << libusb_error_name(ret);
OLA_WARN << "libusb_submit_transfer returned "
<< m_adaptor->ErrorCodeToString(ret);
if (ret == LIBUSB_ERROR_NO_DEVICE) {
m_transfer_state = DISCONNECTED;
}
Expand Down
18 changes: 15 additions & 3 deletions plugins/usbdmx/LibUsbAdaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <libusb.h>
#include <ola/Logging.h>
#include <sstream>
#include <string>

#include "plugins/usbdmx/LibUsbThread.h"
Expand All @@ -30,6 +31,7 @@ namespace ola {
namespace plugin {
namespace usbdmx {

using std::ostringstream;
using std::string;

namespace {
Expand All @@ -50,7 +52,7 @@ bool GetStringDescriptorAscii(libusb_device_handle *usb_handle,

if (r <= 0) {
OLA_INFO << "libusb_get_string_descriptor_ascii failed: "
<< libusb_error_name(r);
<< LibUsbAdaptor::ErrorCodeToString(r);
return false;
}
data->assign(reinterpret_cast<char*>(buffer));
Expand All @@ -65,7 +67,7 @@ bool Open(libusb_device *usb_device,
int r = libusb_open(usb_device, usb_handle);
if (r) {
OLA_WARN << "Failed to open libusb device: " << usb_device << ": "
<< libusb_error_name(r);;
<< LibUsbAdaptor::ErrorCodeToString(r);;
return false;
}
return true;
Expand All @@ -82,7 +84,7 @@ bool OpenHandleAndClaimInterface(libusb_device *usb_device,
if (r) {
OLA_WARN << "Failed to claim interface " << interface
<< " on device: " << usb_device << ": "
<< libusb_error_name(r);
<< LibUsbAdaptor::ErrorCodeToString(r);
libusb_close(*usb_handle);
return false;
}
Expand Down Expand Up @@ -144,6 +146,16 @@ bool LibUsbAdaptor::CheckProduct(const string &expected,
return true;
}

string LibUsbAdaptor::ErrorCodeToString(const int error_code) {
#ifdef HAVE_LIBUSB_ERROR_NAME
return libusb_error_name(error_code);
#else
ostringstream str;
str << "Error code " << error_code;
return str.str();
#endif
}

// BaseLibUsbAdaptor
// ----------------------------------------------------------------------------
libusb_device* BaseLibUsbAdaptor::RefDevice(libusb_device *dev) {
Expand Down
7 changes: 7 additions & 0 deletions plugins/usbdmx/LibUsbAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ class LibUsbAdaptor {
*/
static bool CheckProduct(const std::string &expected,
const DeviceInformation &device_info);

/**
* @brief Try and convert an error code to a string
* @param error_code The error code.
* @returns A string representing the error code.
*/
static std::string ErrorCodeToString(const int error_code);
};

/**
Expand Down
6 changes: 4 additions & 2 deletions plugins/usbdmx/ScanlimeFadecandy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ bool InitializeWidget(LibUsbAdaptor *adaptor,
if (r == 0) {
OLA_INFO << "Config transferred " << bytes_sent << " bytes";
} else {
OLA_WARN << "Config transfer failed with error " << libusb_error_name(r);
OLA_WARN << "Config transfer failed with error "
<< adaptor->ErrorCodeToString(r);
}

// Build the Look Up Table
Expand Down Expand Up @@ -225,7 +226,8 @@ bool FadecandyThreadedSender::TransmitBuffer(libusb_device_handle *handle,
sizeof(m_data_packets), &bytes_sent,
URB_TIMEOUT_MS);
if (r != 0) {
OLA_WARN << "Data transfer failed with error " << libusb_error_name(r);
OLA_WARN << "Data transfer failed with error "
<< m_adaptor->ErrorCodeToString(r);
}
return r == 0;
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/usbdmx/UsbDmxPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ string UsbDmxPlugin::Description() const {
"\n"
"--- Config file : ola-usbdmx.conf ---\n"
"\n"
"libusb_debug_level = {0,1,2,3}\n"
"libusb_debug_level = {0,1,2,3,4}\n"
"The debug level for libusb, see http://libusb.sourceforge.net/api-1.0/ .\n"
"0 = No logging, 3 = Verbose.\n"
"0 = No logging, 4 = Verbose debug.\n"
"\n";
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/usbdmx/VellemanK8062.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ libusb_device_handle *OpenVellemenWidget(LibUsbAdaptor *adaptor,
int ret_code = adaptor->DetachKernelDriver(usb_handle, INTERFACE);
if (ret_code != 0 && ret_code != LIBUSB_ERROR_NOT_FOUND) {
OLA_WARN << "Failed to detach kernel driver: "
<< libusb_error_name(ret_code);
<< adaptor->ErrorCodeToString(ret_code);
adaptor->Close(usb_handle);
return NULL;
}
Expand Down Expand Up @@ -285,7 +285,7 @@ bool VellemanThreadedSender::SendDataChunk(libusb_device_handle *handle,
handle, ENDPOINT, reinterpret_cast<unsigned char*>(usb_data),
chunk_size, &transferred, URB_TIMEOUT_MS);
if (ret) {
OLA_WARN << "InterruptTransfer():" << libusb_error_name(ret)
OLA_WARN << "InterruptTransfer():" << m_adaptor->ErrorCodeToString(ret)
<< ", transferred " << transferred << " / " << chunk_size;
}
return ret == 0;
Expand Down
2 changes: 1 addition & 1 deletion plugins/usbpro/DmxTriWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ void DmxTriWidgetImpl::HandleDiscoverStatResponse(uint8_t return_code,
MaybeSendNextRequest();
} else {
RDMDiscoveryCallback *callback = m_discovery_callback;
m_discovery_callback= NULL;
m_discovery_callback = NULL;
RunDiscoveryCallback(callback);
}
}
Expand Down

0 comments on commit 18f5f8c

Please sign in to comment.