Lumiverse  2.5
A framework for creating lighting control applications
DMXPro2Interface.h
Go to the documentation of this file.
1 
4 #ifndef _DMXPRO2INTERFACE_H_
5 #define _DMXPRO2INTERFACE_H_
6 
7 #pragma once
8 #include "LumiverseCoreConfig.h"
9 
10 // Note: If you want Doxygen to generate documentation for this class,
11 // you must have the following line uncommented.
12 // #define USE_DMXPRO2
13 
14 #ifdef USE_DMXPRO2
15 
16 #include "DMXInterface.h"
17 #include "pro_driver.h"
18 #include "../Logger.h"
19 #include "../lib/libjson/libjson.h"
20 #include <chrono>
21 #include <thread>
22 #include <cstring>
23 #include <sstream>
24 
25 namespace Lumiverse {
30  class DMXPro2Interface : public DMXInterface
31  {
32  public:
33  // Makes a new interface for the ENTTEC DMX USB Pro Mk 2 interface.
34  // If you have more than one interface connected, specify which interface
35  // to open in the constructor. Default maps output 1 to universe 1 and output
36  // 2 to universe 2 and opens the first found D2XX device.
37  DMXPro2Interface(string id, int proNum = 0, int out1 = 0, int out2 = 1);
38 
39  // Destroys the interface (not the physical one)
40  virtual ~DMXPro2Interface();
41 
42  // Initializes the DMX USB Pro Mk 2 device.
43  virtual void init();
44 
45  // Sends DMX through the interface. Also includes the universe number, for
46  // devices that may manage more than one universe or need to know the universe number (like this one)
47  // NOTE: The universe passed in here is ZERO-INDEXED as it is in the DMXPatch class.
48  virtual void sendDMX(unsigned char* data, unsigned int universe);
49 
50  // Closes the connection to the DMX device
51  virtual void closeInt();
52 
53  // Resets the connected interface.
54  // I think this function will actually kick out D2XX devices...
55  // Might want to only use this in emergencies right now.
56  virtual void reset();
57 
58  // Gets the JSON version of this object
59  virtual JSONNode toJSON();
60 
61  virtual string getInterfaceType() { return "DMXPro2Interface"; }
62 
63  // Functions from the FTDI interface will be public in the event that someone needs
64  // to access a certain property specific to this device.
65  // Most of these functions were adapted from ENTTEC's sample code.
66 
67  /* Function : FTDI_ListDevices
68  * Author : ENTTEC
69  * Purpose : Returns the no. of PRO's conneced to the PC
70  * Parameters: none
71  **/
72  int listDevices();
73 
74  /* Function : FTDI_SendData
75  * Author : ENTTEC
76  * Purpose : Send Data (DMX or other packets) to the PRO
77  * Parameters: Label, Pointer to Data Structure, Length of Data
78  **/
79  int sendData(int label, unsigned char *data, int length);
80 
81  /* Function : FTDI_ReceiveData
82  * Author : ENTTEC
83  * Purpose : Receive Data (DMX or other packets) from the PRO
84  * Parameters: Label, Pointer to Data Structure, Length of Data
85  **/
86  int receiveData(int label, unsigned char *data, unsigned int expected_length);
87 
88  /* Function : FTDI_OpenDevice
89  * Author : ENTTEC
90  * Purpose : Opens the PRO; Tests various parameters; outputs info
91  * Parameters: device num (returned by the List Device fuc), Fw Version MSB, Fw Version LSB
92  **/
93  bool openDevice(int device_num);
94 
95  /* Function : FTDI_PurgeBuffer
96  * Author : ENTTEC
97  * Purpose : Clears the buffer used internally by the PRO
98  * Parameters: none
99  **/
100  void purgeBuffer();
101 
102  // Settings for the two DMX/MIDI ports for the interface.
103  // port1 - 0 = disabled, 1 = enabled for DMX
104  // port2 - 0 = disabled, 1 = enabled for DMX, 2 = enabled for MIDI In and Out
105  void setPorts(uint8_t port1, uint8_t port2);
106 
107  int getProNum() { return m_proNum; }
108  void setProNum(int proNum) { m_proNum = proNum; }
109 
110  void setOut1Universe(int u) { m_out1Universe = u; }
111  int getOut1Universe() { return m_out1Universe; }
112 
113  void setOut2Universe(int u) { m_out2Universe = u; }
114  int getOut2Universe() { return m_out2Universe; }
115 
116  private:
117  // Specifies which DMX PRO interface numnber is controlled by this instance
118  int m_proNum;
119 
120  // Indicates if a device is connected.
121  bool m_connected;
122 
123  // Handle to the connected interface.
124  FT_HANDLE m_deviceHandle;
125 
126  // Parameters for the interface
127  DMXUSBPROParamsType m_PROParams;
128 
129  // The universe that the first output is assigned to.
130  int m_out1Universe;
131 
132  // The universe that the second output is assigned to.
133  int m_out2Universe;
134 
135  // Defined by the DMX open function originally. Shouldn't need to adjust
136  // unless there are problems.
137 
138  // Timeout in microseconds. Too high or too low values discouraged.
139  int m_readTimeout;
140 
141  // Timeout in microseconds. Too high or too low values discouraged.
142  int m_writeTimeout;
143 
144  int m_versionMSB;
145  int m_versionLSB;
146  };
147 }
148 #endif
149 
150 #endif
void init(const char *jsonPatchStr, const char *filename)
Initializes data structures.
Definition: Dumiverse.cpp:29
Base class describing how DMX Interfaces should act.
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
Definition: pro_driver.h:69