Open Lighting Architecture
0.9.6
|
Send DMX data using libusb, from a separate thread.
The synchronous libusb calls can sometimes take a while to complete, I've seen cases of up to 21ms.
To avoid blocking the main thread, we need to perform the libusb transfer calls in a separate thread. This class contains all the thread management code, leaving the subclass to implement TransmitBuffer(), which performs the actual transfer.
ThreadedUsbSender can be used as a building block for synchronous widgets.
Public Member Functions | |
ThreadedUsbSender (libusb_device *usb_device, libusb_device_handle *usb_handle) | |
Create a new ThreadedUsbSender. | |
bool | Start () |
Start the new thread. | |
void * | Run () |
Entry point for the new thread. | |
bool | SendDMX (const DmxBuffer &buffer) |
Buffer a DMX frame for sending. |
Protected Member Functions | |
virtual bool | TransmitBuffer (libusb_device_handle *handle, const DmxBuffer &buffer)=0 |
Perform the DMX transfer. |
Additional Inherited Members | |
Private Member Functions inherited from ola::thread::Thread | |
Thread (const Options &options=Options()) | |
Create a new thread with the specified thread options. | |
virtual | ~Thread () |
Destructor. | |
virtual bool | Start () |
Start the thread and wait for the thread to be running. | |
virtual bool | FastStart () |
Start the thread and return immediately. | |
virtual bool | Join (void *ptr=NULL) |
Join this thread. | |
bool | IsRunning () |
Check if the thread is running. | |
ThreadId | Id () const |
Return the thread id. | |
std::string | Name () const |
Return the thread name. | |
virtual void * | Run ()=0 |
The entry point for the new thread. | |
Static Private Member Functions inherited from ola::thread::Thread | |
static ThreadId | Self () |
Returns the current thread's id. |
ola::plugin::usbdmx::ThreadedUsbSender::ThreadedUsbSender | ( | libusb_device * | usb_device, |
libusb_device_handle * | usb_handle | ||
) |
Create a new ThreadedUsbSender.
usb_device | The usb_device to use. The ThreadedUsbSender takes a ref on the device, while the ThreadedUsbSender object exists. |
usb_handle | The handle to use for the DMX transfer. |
void * ola::plugin::usbdmx::ThreadedUsbSender::Run | ( | ) |
Entry point for the new thread.
bool ola::plugin::usbdmx::ThreadedUsbSender::SendDMX | ( | const DmxBuffer & | buffer | ) |
Buffer a DMX frame for sending.
buffer | the DmxBuffer to send. |
This should be called in the main thread.
bool ola::plugin::usbdmx::ThreadedUsbSender::Start | ( | ) |
Start the new thread.
|
protectedpure virtual |
Perform the DMX transfer.
handle | the libusb_device_handle to use for the transfer. |
buffer | The DmxBuffer to transfer. |
This is called from the sender thread.