Open Lighting Architecture  0.9.1
 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 
54  public:
55  FtdiWidgetInfo(const std::string &name,
56  const std::string &serial,
57  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  std::string Name() const { return m_name; }
72  std::string Serial() const { return m_serial; }
73  int unsigned Id() const { return m_id; }
74 
75  std::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  std::string m_name;
90  std::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 std::string &serial,
110  const std::string &name,
111  uint32_t id = 0);
112 
114  virtual ~FtdiWidget();
115 
117  std::string Serial() const { return m_serial; }
118 
120  std::string Name() const { return m_name; }
121 
123  uint32_t Id() const { return m_id; }
124 
125  std::string Description() const {
126  return m_name + " with serial number : " + m_serial +" ";
127  }
128 
130  bool Open();
131 
133  bool Close();
134 
136  bool IsOpen() const;
137 
139  bool Reset();
140 
142  bool SetLineProperties();
143 
145  bool SetBaudRate();
146 
148  bool SetFlowControl();
149 
151  bool ClearRts();
152 
154  bool PurgeBuffers();
155 
157  bool SetBreak(bool on);
158 
160  bool Write(const ola::DmxBuffer &data);
161 
163  bool Read(unsigned char* buff, int size);
164 
166  bool SetupOutput();
167 
172  static void Widgets(std::vector<FtdiWidgetInfo> *widgets);
173 
174  private:
175  std::string m_serial;
176  std::string m_name;
177  uint32_t m_id;
178 
179 #ifdef FTD2XX
180  FT_HANDLE m_handle;
181 #else
182  struct ftdi_context m_handle;
183 #endif
184 };
185 } // namespace ftdidmx
186 } // namespace plugin
187 } // namespace ola
188 #endif // PLUGINS_FTDIDMX_FTDIWIDGET_H_