Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FtdiWidget.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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * This class is based on QLCFTDI class from
17  *
18  * Q Light Controller
19  * qlcftdi.h
20  *
21  * Copyright (C) Heikki Junnila
22  *
23  * Only standard CPP conversion was changed and function name changed
24  * to follow OLA coding standards.
25  *
26  * by Rui Barreiros
27  */
28 
29 #ifndef PLUGINS_FTDIDMX_FTDIWIDGET_H_
30 #define PLUGINS_FTDIDMX_FTDIWIDGET_H_
31 
32 #ifdef FTD2XX
33 # ifdef WIN32
34 # include <windows.h>
35 # endif
36 # include <ftd2xx.h>
37 #else
38 # include <ftdi.h>
39 #endif
40 
41 #include <string>
42 #include <vector>
43 
44 #include "ola/DmxBuffer.h"
45 
46 namespace ola {
47 namespace plugin {
48 namespace ftdidmx {
49 
50 using std::string;
51 
56  public:
57  FtdiWidgetInfo(const string &name, const string &serial, int unsigned id)
58  : m_name(name),
59  m_serial(serial),
60  m_id(id) {
61  }
62 
63  FtdiWidgetInfo(const FtdiWidgetInfo &info)
64  : m_name(info.Name()),
65  m_serial(info.Serial()),
66  m_id(info.Id()) {
67  }
68 
69  virtual ~FtdiWidgetInfo() {}
70 
71  string Name() const { return m_name; }
72  string Serial() const { return m_serial; }
73  int unsigned Id() const { return m_id; }
74 
75  string Description() const {
76  return m_name + " with serial number : " + m_serial + " ";
77  }
78 
79  FtdiWidgetInfo& operator=(const FtdiWidgetInfo &other) {
80  if (this != &other) {
81  m_name = other.Name();
82  m_serial = other.Serial();
83  m_id = other.Id();
84  }
85  return *this;
86  }
87 
88  private:
89  string m_name;
90  string m_serial;
91  int unsigned m_id;
92 };
93 
94 
98 class FtdiWidget {
99  public:
100  static const int VID = 0x0403; // FTDI Vendor ID
101  static const int PID = 0x6001; // FTDI Product ID
102 
109  FtdiWidget(const string &serial, const string &name, uint32_t id = 0);
110 
112  virtual ~FtdiWidget();
113 
115  string Serial() const { return m_serial; }
116 
118  string Name() const { return m_name; }
119 
121  uint32_t Id() const { return m_id; }
122 
123  string Description() const {
124  return m_name + " with serial number : " + m_serial +" ";
125  }
126 
128  bool Open();
129 
131  bool Close();
132 
134  bool IsOpen() const;
135 
137  bool Reset();
138 
140  bool SetLineProperties();
141 
143  bool SetBaudRate();
144 
146  bool SetFlowControl();
147 
149  bool ClearRts();
150 
152  bool PurgeBuffers();
153 
155  bool SetBreak(bool on);
156 
158  bool Write(const ola::DmxBuffer &data);
159 
161  bool Read(unsigned char* buff, int size);
162 
164  bool SetupOutput();
165 
170  static void Widgets(std::vector<FtdiWidgetInfo> *widgets);
171 
172  private:
173  string m_serial;
174  string m_name;
175  uint32_t m_id;
176 
177 #ifdef FTD2XX
178  FT_HANDLE m_handle;
179 #else
180  struct ftdi_context m_handle;
181 #endif
182 };
183 } // namespace ftdidmx
184 } // namespace plugin
185 } // namespace ola
186 #endif // PLUGINS_FTDIDMX_FTDIWIDGET_H_