Skip to content

Commit

Permalink
Add the missing files.
Browse files Browse the repository at this point in the history
  • Loading branch information
nomis52 committed Nov 26, 2014
1 parent 7d23763 commit 3e171d9
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 0 deletions.
86 changes: 86 additions & 0 deletions plugins/usbdmx/EuroliteProFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* EuroliteProFactory.cpp
* The WidgetFactory for EurolitePro widgets.
* Copyright (C) 2014 Simon Newton
*/

#include "plugins/usbdmx/EuroliteProFactory.h"

#include "ola/Logging.h"
#include "ola/base/Flags.h"
#include "plugins/usbdmx/LibUsbAdaptor.h"

DECLARE_bool(use_async_libusb);

namespace ola {
namespace plugin {
namespace usbdmx {

const char EuroliteProFactory::EXPECTED_MANUFACTURER[] = "Eurolite";
const char EuroliteProFactory::EXPECTED_PRODUCT[] = "Eurolite DMX512 Pro";
const uint16_t EuroliteProFactory::PRODUCT_ID = 0xfa63;
const uint16_t EuroliteProFactory::VENDOR_ID = 0x04d;


bool EuroliteProFactory::DeviceAdded(
WidgetObserver *observer,
libusb_device *usb_device,
const struct libusb_device_descriptor &descriptor) {
if (descriptor.idVendor != VENDOR_ID || descriptor.idProduct != PRODUCT_ID ||
HasDevice(usb_device)) {
return false;
}

OLA_INFO << "Found a new EurolitePro device";
LibUsbAdaptor::DeviceInformation info;
if (!m_adaptor->GetDeviceInfo(usb_device, descriptor, &info)) {
return false;
}

if (!m_adaptor->CheckManufacturer(EXPECTED_MANUFACTURER, info)) {
return false;
}

if (!m_adaptor->CheckProduct(EXPECTED_PRODUCT, info)) {
return false;
}

// The Eurolite doesn't have a serial number, so instead we use the device &
// bus number.
// TODO(simon): check if this supports the SERIAL NUMBER label and use that
// instead.

// There is no Serialnumber--> work around: bus+device number
int bus_number = libusb_get_bus_number(usb_device);
int device_address = libusb_get_device_address(usb_device);

std::ostringstream serial_str;
serial_str << bus_number << "-" << device_address;

EurolitePro *widget = NULL;
if (FLAGS_use_async_libusb) {
widget = new AsynchronousEurolitePro(m_adaptor, usb_device,
serial_str.str());
} else {
widget = new SynchronousEurolitePro(m_adaptor, usb_device,
serial_str.str());
}
return AddWidget(observer, usb_device, widget);
}
} // namespace usbdmx
} // namespace plugin
} // namespace ola
59 changes: 59 additions & 0 deletions plugins/usbdmx/EuroliteProFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* EuroliteProFactory.h
* The WidgetFactory for EurolitePro widgets.
* Copyright (C) 2014 Simon Newton
*/

#ifndef PLUGINS_USBDMX_EUROLITEPROFACTORY_H_
#define PLUGINS_USBDMX_EUROLITEPROFACTORY_H_

#include "ola/base/Macro.h"
#include "plugins/usbdmx/EurolitePro.h"
#include "plugins/usbdmx/WidgetFactory.h"

namespace ola {
namespace plugin {
namespace usbdmx {

/**
* @brief Creates EurolitePro widgets.
*/
class EuroliteProFactory
: public BaseWidgetFactory<class EurolitePro> {
public:
explicit EuroliteProFactory(class LibUsbAdaptor *adaptor)
: m_adaptor(adaptor) {}

bool DeviceAdded(WidgetObserver *observer,
libusb_device *usb_device,
const struct libusb_device_descriptor &descriptor);

private:
class LibUsbAdaptor *m_adaptor;

static const uint16_t PRODUCT_ID;
static const uint16_t VENDOR_ID;
static const char EXPECTED_MANUFACTURER[];
static const char EXPECTED_PRODUCT[];


DISALLOW_COPY_AND_ASSIGN(EuroliteProFactory);
};
} // namespace usbdmx
} // namespace plugin
} // namespace ola
#endif // PLUGINS_USBDMX_EUROLITEPROFACTORY_H_
25 changes: 25 additions & 0 deletions plugins/usbdmx/Flags.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Flags.cpp
* Flags for the libusb plugin.
* Copyright (C) 2014 Simon Newton
*/

#include "ola/base/Flags.h"

DEFINE_default_bool(use_async_libusb, false,
"Use the asyncronous libusb calls.");

92 changes: 92 additions & 0 deletions plugins/usbdmx/ScanlimeFadecandyFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* ScanlimeFadecandyFactory.cpp
* The WidgetFactory for Fadecandy widgets.
* Copyright (C) 2014 Simon Newton
*/

#include "plugins/usbdmx/ScanlimeFadecandyFactory.h"

#include "ola/Logging.h"
#include "ola/base/Flags.h"
#include "plugins/usbdmx/ScanlimeFadecandy.h"
#include "plugins/usbdmx/LibUsbAdaptor.h"

DECLARE_bool(use_async_libusb);


namespace ola {
namespace plugin {
namespace usbdmx {

const char ScanlimeFadecandyFactory::EXPECTED_MANUFACTURER[] = "scanlime";
const char ScanlimeFadecandyFactory::EXPECTED_PRODUCT[] = "Fadecandy";
const uint16_t ScanlimeFadecandyFactory::PRODUCT_ID = 0x1D50;
const uint16_t ScanlimeFadecandyFactory::VENDOR_ID = 0x607A;


bool ScanlimeFadecandyFactory::DeviceAdded(
WidgetObserver *observer,
libusb_device *usb_device,
const struct libusb_device_descriptor &descriptor) {
if (descriptor.idVendor != VENDOR_ID || descriptor.idProduct != PRODUCT_ID ||
HasDevice(usb_device)) {
return false;
}

OLA_INFO << "Found a new Fadecandy device";
LibUsbAdaptor::DeviceInformation info;
if (!m_adaptor->GetDeviceInfo(usb_device, descriptor, &info)) {
return false;
}

if (!m_adaptor->CheckManufacturer(EXPECTED_MANUFACTURER, info)) {
return false;
}

if (!m_adaptor->CheckProduct(EXPECTED_PRODUCT, info)) {
return false;
}

// Fadecandy devices may be missing serial numbers. Since there isn't another
// good way to uniquely identify a USB device, we only support one of these
// types of devices per host.
if (info.serial.empty()) {
if (m_missing_serial_number) {
OLA_WARN << "Failed to read serial number or serial number empty. "
<< "We can only support one device without a serial number.";
return false;
} else {
OLA_WARN << "Failed to read serial number from " << info.manufacturer
<< " : " << info.product
<< " the device probably doesn't have one";
m_missing_serial_number = true;
}
}

ScanlimeFadecandy *widget = NULL;
if (FLAGS_use_async_libusb) {
widget = new AsynchronousScanlimeFadecandy(m_adaptor, usb_device,
info.serial);
} else {
widget = new SynchronousScanlimeFadecandy(m_adaptor, usb_device,
info.serial);
}
return AddWidget(observer, usb_device, widget);
}
} // namespace usbdmx
} // namespace plugin
} // namespace ola
61 changes: 61 additions & 0 deletions plugins/usbdmx/ScanlimeFadecandyFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* ScanlimeFadecandyFactory.h
* The WidgetFactory for Fadecandy / FadeCandy widgets.
* Copyright (C) 2014 Simon Newton
*/

#ifndef PLUGINS_USBDMX_SCANLIMEFADECANDYFACTORY_H_
#define PLUGINS_USBDMX_SCANLIMEFADECANDYFACTORY_H_

#include "ola/base/Macro.h"
#include "plugins/usbdmx/WidgetFactory.h"

namespace ola {
namespace plugin {
namespace usbdmx {

/**
* @brief Creates Fadecandy widgets.
*/
class ScanlimeFadecandyFactory
: public BaseWidgetFactory<class ScanlimeFadecandy> {
public:
explicit ScanlimeFadecandyFactory(class LibUsbAdaptor *adaptor)
: m_missing_serial_number(false),
m_adaptor(adaptor) {
}

bool DeviceAdded(
WidgetObserver *observer,
libusb_device *usb_device,
const struct libusb_device_descriptor &descriptor);

private:
bool m_missing_serial_number;
class LibUsbAdaptor *m_adaptor;

static const char EXPECTED_MANUFACTURER[];
static const char EXPECTED_PRODUCT[];
static const uint16_t PRODUCT_ID;
static const uint16_t VENDOR_ID;

DISALLOW_COPY_AND_ASSIGN(ScanlimeFadecandyFactory);
};
} // namespace usbdmx
} // namespace plugin
} // namespace ola
#endif // PLUGINS_USBDMX_SCANLIMEFADECANDYFACTORY_H_

0 comments on commit 3e171d9

Please sign in to comment.