Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VellemanOutputPort.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * VellemanOutputPort.h
17  * The output port for a Velleman 8062 device.
18  * Copyright (C) 2010 Simon Newton
19  *
20  * Because this interface is so slow we run the output in a separate thread. It
21  * takes around 8ms to respond to an urb and in the worst case we send 74 urbs
22  * per universe.
23  *
24  * It would be interesting to see if you can pipeline the urbs to improve the
25  * performance.
26  */
27 
28 #ifndef PLUGINS_USBDMX_VELLEMANOUTPUTPORT_H_
29 #define PLUGINS_USBDMX_VELLEMANOUTPUTPORT_H_
30 
31 #include <libusb.h>
32 #include <pthread.h>
33 #include <string>
34 #include "ola/DmxBuffer.h"
35 #include "ola/thread/Thread.h"
36 #include "olad/Port.h"
37 
38 namespace ola {
39 namespace plugin {
40 namespace usbdmx {
41 
42 class VellemanDevice;
43 
45  public:
47  unsigned int id,
48  libusb_device *usb_device);
50 
51  bool Start();
52  void *Run();
53 
54  bool WriteDMX(const DmxBuffer &buffer, uint8_t priority);
55  std::string Description() const;
56 
57  private:
58  static const unsigned char ENDPOINT = 0x01;
59  // 25ms seems to be about the shortest we can go
60  static const unsigned int URB_TIMEOUT_MS = 25;
61  static const int CONFIGURATION = 1;
62  static const int INTERFACE = 0;
63  static const unsigned int UPGRADED_CHUNK_SIZE = 64;
64 
65  bool m_term;
66  unsigned int m_chunk_size;
67  libusb_device *m_usb_device;
68  libusb_device_handle *m_usb_handle;
69  DmxBuffer m_buffer;
70  ola::thread::Mutex m_data_mutex;
71  ola::thread::Mutex m_term_mutex;
72 
73  bool SendDMX(const DmxBuffer &buffer_old);
74  bool SendDataChunk(uint8_t *usb_data);
75 };
76 } // namespace usbdmx
77 } // namespace plugin
78 } // namespace ola
79 #endif // PLUGINS_USBDMX_VELLEMANOUTPUTPORT_H_