Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b60eb3b
Tidy up a comment
peternewman May 31, 2014
d5a8475
Adding intial support for the img Stage line DMX-1USB device. This is…
peternewman May 31, 2014
9a5a694
Fix the build
peternewman Jun 1, 2014
7243b8f
Fix the comments
peternewman Jun 1, 2014
561ffe2
Tidy up some whitespace
peternewman Jun 1, 2014
c43cd40
Standardise some whitespace
peternewman Jun 1, 2014
a87aaba
Clarify how to use OLA_PLUGIN_EXPERIMENTAL
peternewman Jun 1, 2014
ae5e687
Correct a comment and add another example script that Sean wrote
peternewman Jun 4, 2014
946607f
Remove a duplicate license line in files
peternewman Jun 4, 2014
6f810cf
Standardise some JS license headers
peternewman Jun 4, 2014
175c287
Handle a lack of shebangs when checking Python licenses
peternewman Jun 4, 2014
34e1fbf
Don't trash files while trying to fix license issues if we can't find…
peternewman Jun 4, 2014
ff28a6b
Add JS support to the licence enforcer and start checking the JS
peternewman Jun 4, 2014
0f272d9
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Jun 5, 2014
06b3007
Print some more debugging info when looking for devices
peternewman Jun 15, 2014
0be487b
Tweak the logging level
peternewman Jun 15, 2014
c67c710
Resync with trunk
peternewman Jun 15, 2014
ec7e792
Update JS licence
peternewman Jun 15, 2014
f64e86a
Fix the build
peternewman Jun 15, 2014
15dc714
Fix some licenses
peternewman Jun 15, 2014
4b206f6
Make the JS licence style a closer match to C++
peternewman Jun 15, 2014
79fb8b8
Add some more debugging
peternewman Jun 15, 2014
e34cb8b
Add more debugging
peternewman Jun 15, 2014
8d64b29
Upgrade the priority of the debugging due to apparent issues with -l …
peternewman Jun 15, 2014
0d09735
Sort out a few admin type bits ready for getting the code merged
peternewman Jun 15, 2014
57161a9
Remove the example, now Sean has added a more polished version
peternewman Jun 16, 2014
e0c2df6
Try setting a configuration to make it work better, first find out wh…
peternewman Jun 17, 2014
4a5ef08
More debugging
peternewman Jun 18, 2014
1b798d5
Resync with trunk
peternewman Aug 12, 2014
ae86acd
Fix a faulty license post merge
peternewman Aug 12, 2014
8bac815
Resync with trunk
peternewman Aug 18, 2014
dc2f8af
Resync with trunk
peternewman Aug 21, 2014
e812792
Resync with trunk
peternewman Aug 23, 2014
f1d724e
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Aug 23, 2014
457a6dd
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Aug 24, 2014
1bf35dc
Resync with trunk
peternewman Aug 26, 2014
265583a
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Aug 31, 2014
4c86c96
Resync with trunk
peternewman Sep 3, 2014
89a7e59
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Oct 20, 2014
4dbda3b
Resync with trunk.
peternewman Oct 22, 2014
d558d13
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Oct 23, 2014
f17df6e
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Oct 24, 2014
d7dca32
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Oct 27, 2014
082f3af
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Oct 30, 2014
eedf26e
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Oct 30, 2014
d6f8682
Resync with trunk
peternewman Nov 3, 2014
c29b364
Resync with trunk
peternewman Nov 10, 2014
5b9f26b
Resync with trunk
peternewman Nov 10, 2014
565581e
Resync with trunk
peternewman Nov 11, 2014
7d6c3d7
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Nov 17, 2014
ab0611b
Tweak NEWS
peternewman Nov 17, 2014
2a0a63b
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Nov 24, 2014
e67b83b
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Nov 26, 2014
849dcb5
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman Nov 28, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
x/y/2014 ola-0.9.4
Features:
* Added support for the img Stage Line DMX-1USB - #398
*

API:
Expand Down
3 changes: 3 additions & 0 deletions debian/ola.udev
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ SUBSYSTEM=="usb|usb_device", ACTION=="add", ATTRS{idVendor}=="10cf", ATTRS{idPro

# udev rules for the Eurolite
SUBSYSTEM=="usb|usb_device", ACTION=="add", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="fa63", GROUP="plugdev" MODE="660"

# udev rules for the img Stage Line DMX device
SUBSYSTEM=="usb|usb_device", ACTION=="add", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="ff86", GROUP="plugdev"
47 changes: 47 additions & 0 deletions plugins/usbdmx/ImgStageLineDevice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.
*
* ImgStageLineDevice.cpp
* The img Stage Line DMX-1USB device
* Copyright (C) 2014 Peter Newman
*/

#include <string.h>
#include <sys/time.h>

#include "ola/Logging.h"
#include "plugins/usbdmx/ImgStageLineDevice.h"
#include "plugins/usbdmx/ImgStageLineOutputPort.h"

namespace ola {
namespace plugin {
namespace usbdmx {

/*
* Start this device.
*/
bool ImgStageLineDevice::StartHook() {
ImgStageLineOutputPort *output_port =
new ImgStageLineOutputPort(this, 0, m_usb_device);
if (!output_port->Start()) {
delete output_port;
return false;
}
AddPort(output_port);
return true;
}
} // namespace usbdmx
} // namespace plugin
} // namespace ola
50 changes: 50 additions & 0 deletions plugins/usbdmx/ImgStageLineDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.
*
* ImgStageLineDevice.h
* Interface for the ImgStageLine device
* Copyright (C) 2014 Peter Newman
*/

#ifndef PLUGINS_USBDMX_IMGSTAGELINEDEVICE_H_
#define PLUGINS_USBDMX_IMGSTAGELINEDEVICE_H_

#include <libusb.h>
#include <string>
#include "plugins/usbdmx/UsbDevice.h"

namespace ola {
namespace plugin {
namespace usbdmx {

/*
* An ImgStageLine device
*/
class ImgStageLineDevice: public UsbDevice {
public:
ImgStageLineDevice(ola::AbstractPlugin *owner,
libusb_device *usb_device)
: UsbDevice(owner, "ImgStageLine USB Device", usb_device) {
}

std::string DeviceId() const { return "dmx-1usb"; }

protected:
bool StartHook();
};
} // namespace usbdmx
} // namespace plugin
} // namespace ola
#endif // PLUGINS_USBDMX_IMGSTAGELINEDEVICE_H_
230 changes: 230 additions & 0 deletions plugins/usbdmx/ImgStageLineOutputPort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
/*
* 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.
*
* ImgStageLineOutputPort.cpp
* Thread for the img Stage Line DMX-1USB Output Port
* Copyright (C) 2014 Peter Newman
*
* See the comments in ImgStageLineOutputPort.h
*/

#include <string.h>
#include <sys/types.h>
#include <algorithm>

#include "ola/Logging.h"
#include "plugins/usbdmx/ImgStageLineOutputPort.h"
#include "plugins/usbdmx/ImgStageLineDevice.h"


namespace ola {
namespace plugin {
namespace usbdmx {


/*
* Create a new ImgStageLineOutputPort object
*/
ImgStageLineOutputPort::ImgStageLineOutputPort(ImgStageLineDevice *parent,
unsigned int id,
libusb_device *usb_device)
: BasicOutputPort(parent, id),
m_term(false),
m_new_data(false),
m_usb_device(usb_device),
m_usb_handle(NULL),
m_packet_count(0) {
}


/*
* Cleanup
*/
ImgStageLineOutputPort::~ImgStageLineOutputPort() {
{
ola::thread::MutexLocker locker(&m_term_mutex);
m_term = true;
}
OLA_INFO << "In total sent " << m_packet_count << " packets";
Join();
}


/*
* Start this thread
*/
bool ImgStageLineOutputPort::Start() {
libusb_device_handle *usb_handle;

if (libusb_open(m_usb_device, &usb_handle)) {
OLA_WARN << "Failed to open img USB device";
return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try adding a libusb_set_configuration(usb_handle, 1) here.

For bonus marks, print the result of libusb_get_configuration(usb_handle, &config_value) before calling set() . I'm going to guess it's 0 (unconfigured) .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, I mean print the value of config_value after the call to libusb_get_configuration.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, stolen from the Velleman interface.

int ret_code;
int config_value;
ret_code = libusb_get_configuration(usb_handle, &config_value);
if (ret_code) {
OLA_WARN << "img Stage Line get config failed, with libusb error code " <<
ret_code;
} else {
OLA_INFO << "img Stage Line original config is " << config_value;
}

ret_code = libusb_set_configuration(usb_handle, 1);
if (ret_code) {
OLA_WARN << "img Stage Line set config failed, with libusb error code " <<
ret_code;
}

ret_code = libusb_get_configuration(usb_handle, &config_value);
if (ret_code) {
OLA_WARN << "img Stage Line get config failed, with libusb error code " <<
ret_code;
} else {
OLA_INFO << "img Stage Line new config is " << config_value;
}

if (libusb_claim_interface(usb_handle, 0)) {
OLA_WARN << "Failed to claim img USB device";
libusb_close(usb_handle);
return false;
}

m_usb_handle = usb_handle;
bool ret = ola::thread::Thread::Start();
if (!ret) {
OLA_WARN << "pthread create failed";
libusb_release_interface(m_usb_handle, 0);
libusb_close(usb_handle);
return false;
}
return true;
}


/*
* Run this thread
*/
void *ImgStageLineOutputPort::Run() {
DmxBuffer buffer;
bool new_data;

if (!m_usb_handle)
return NULL;

while (true) {
{
ola::thread::MutexLocker locker(&m_term_mutex);
if (m_term)
break;
}

{
ola::thread::MutexLocker locker(&m_data_mutex);
buffer.Set(m_buffer);
new_data = m_new_data;
m_new_data = false;
}

if (new_data) {
if (!SendDMX(buffer)) {
OLA_WARN << "Send failed, stopping thread...";
break;
}
} else {
// sleep for a bit
usleep(40000);
}
}
libusb_release_interface(m_usb_handle, 0);
libusb_close(m_usb_handle);
return NULL;
}


/*
* Store the data in the shared buffer
*/
bool ImgStageLineOutputPort::WriteDMX(const DmxBuffer &buffer,
uint8_t priority) {
ola::thread::MutexLocker locker(&m_data_mutex);
m_buffer.Set(buffer);
m_new_data = true;
return true;
(void) priority;
}


/*
* Send DMX to the widget
*/
bool ImgStageLineOutputPort::SendDMX(const DmxBuffer &buffer) {
bool success = false;

m_packet_count++;
OLA_INFO << "About to send packet " << m_packet_count;

for (unsigned int i = 0;
i < DMX_MAX_TRANSMIT_CHANNELS;
i = i + CHANNELS_PER_PACKET) {
// zero everything
memset(m_packet, 0, IMGSTAGELINE_PACKET_SIZE);

if (i == 0) {
m_packet[0] = CHANNEL_HEADER_LOW;
} else if (i == CHANNELS_PER_PACKET) {
m_packet[0] = CHANNEL_HEADER_HIGH;
} else {
OLA_FATAL << "Unknown channel value " << i << ", couldn't find channel "
"header value";
}
OLA_INFO << "Sending sub packet " << i << " with header value "
<< static_cast<int>(m_packet[0]);

// Copy the data if there is some, otherwise we'll just send a packet of
// zeros for the channel values
if ((buffer.Size() - i) > 0) {
unsigned int channels = std::min((unsigned int) CHANNELS_PER_PACKET,
(buffer.Size() - i));

buffer.GetRange(i, &m_packet[1], &channels);
}

int transferred;
int r = libusb_bulk_transfer(
m_usb_handle,
ENDPOINT,
(unsigned char*) m_packet,
IMGSTAGELINE_PACKET_SIZE,
&transferred,
TIMEOUT);
if (transferred != IMGSTAGELINE_PACKET_SIZE) {
// not sure if this is fatal or not
OLA_WARN << "img driver failed to transfer all data, transferred "
<< transferred << " bytes, expected to send "
<< IMGSTAGELINE_PACKET_SIZE;
}
success = (r == 0);
if (!success) {
OLA_FATAL << "Failed with error " << r;
return success;
}
}
return success;
}
} // namespace usbdmx
} // namespace plugin
} // namespace ola
Loading