-
Notifications
You must be signed in to change notification settings - Fork 227
Adding initial support for the img Stage Line DMX-1USB device #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
peternewman
wants to merge
54
commits into
OpenLightingProject:master
Choose a base branch
from
peternewman:trivial-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 d5a8475
Adding intial support for the img Stage line DMX-1USB device. This is…
peternewman 9a5a694
Fix the build
peternewman 7243b8f
Fix the comments
peternewman 561ffe2
Tidy up some whitespace
peternewman c43cd40
Standardise some whitespace
peternewman a87aaba
Clarify how to use OLA_PLUGIN_EXPERIMENTAL
peternewman ae5e687
Correct a comment and add another example script that Sean wrote
peternewman 946607f
Remove a duplicate license line in files
peternewman 6f810cf
Standardise some JS license headers
peternewman 175c287
Handle a lack of shebangs when checking Python licenses
peternewman 34e1fbf
Don't trash files while trying to fix license issues if we can't find…
peternewman ff28a6b
Add JS support to the licence enforcer and start checking the JS
peternewman 0f272d9
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman 06b3007
Print some more debugging info when looking for devices
peternewman 0be487b
Tweak the logging level
peternewman c67c710
Resync with trunk
peternewman ec7e792
Update JS licence
peternewman f64e86a
Fix the build
peternewman 15dc714
Fix some licenses
peternewman 4b206f6
Make the JS licence style a closer match to C++
peternewman 79fb8b8
Add some more debugging
peternewman e34cb8b
Add more debugging
peternewman 8d64b29
Upgrade the priority of the debugging due to apparent issues with -l …
peternewman 0d09735
Sort out a few admin type bits ready for getting the code merged
peternewman 57161a9
Remove the example, now Sean has added a more polished version
peternewman e0c2df6
Try setting a configuration to make it work better, first find out wh…
peternewman 4a5ef08
More debugging
peternewman 1b798d5
Resync with trunk
peternewman ae86acd
Fix a faulty license post merge
peternewman 8bac815
Resync with trunk
peternewman dc2f8af
Resync with trunk
peternewman e812792
Resync with trunk
peternewman f1d724e
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman 457a6dd
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman 1bf35dc
Resync with trunk
peternewman 265583a
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman 4c86c96
Resync with trunk
peternewman 89a7e59
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman 4dbda3b
Resync with trunk.
peternewman d558d13
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman f17df6e
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman d7dca32
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman 082f3af
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman eedf26e
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman d6f8682
Resync with trunk
peternewman c29b364
Resync with trunk
peternewman 5b9f26b
Resync with trunk
peternewman 565581e
Resync with trunk
peternewman 7d6c3d7
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman ab0611b
Tweak NEWS
peternewman 2a0a63b
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman e67b83b
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman 849dcb5
Merge branch 'master' of https://github.com/OpenLightingProject/ola i…
peternewman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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) .
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.