Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnymaOutputPort.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  * AnymaOutputPort.h
17  * The output port for a Anyma device.
18  * Copyright (C) 2010 Simon Newton
19  *
20  * It takes around 21ms to send one universe of data. so we do this in a
21  * separate thread.
22  */
23 
24 #ifndef PLUGINS_USBDMX_ANYMAOUTPUTPORT_H_
25 #define PLUGINS_USBDMX_ANYMAOUTPUTPORT_H_
26 
27 #include <libusb.h>
28 #include <pthread.h>
29 #include <string>
30 #include "ola/DmxBuffer.h"
31 #include "ola/thread/Thread.h"
32 #include "olad/Port.h"
33 
34 namespace ola {
35 namespace plugin {
36 namespace usbdmx {
37 
38 class AnymaDevice;
39 
41  public:
43  unsigned int id,
44  libusb_device_handle *usb_handle,
45  const std::string &serial);
46  ~AnymaOutputPort();
47  std::string SerialNumber() const { return m_serial; }
48 
49  bool Start();
50  void *Run();
51 
52  bool WriteDMX(const DmxBuffer &buffer, uint8_t priority);
53  std::string Description() const { return ""; }
54 
55  private:
56  static const unsigned int URB_TIMEOUT_MS = 500;
57  static const unsigned int UDMX_SET_CHANNEL_RANGE = 0x0002;
58 
59  bool m_term;
60  std::string m_serial;
61  libusb_device_handle *m_usb_handle;
62  DmxBuffer m_buffer;
63  ola::thread::Mutex m_data_mutex;
64  ola::thread::Mutex m_term_mutex;
65 
66  bool SendDMX(const DmxBuffer &buffer_old);
67  bool GetDescriptorString(libusb_device_handle *usb_handle,
68  uint8_t desc_index,
69  std::string *data);
70 };
71 } // namespace usbdmx
72 } // namespace plugin
73 } // namespace ola
74 #endif // PLUGINS_USBDMX_ANYMAOUTPUTPORT_H_