Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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 * FtdiWidget.h
17 * This class is based on QLCFTDI class from
18 *
19 * Q Light Controller
20 * qlcftdi.h
21 *
22 * Copyright (C) Heikki Junnila
23 *
24 * Only standard CPP conversion was changed and function name changed
25 * to follow OLA coding standards.
26 *
27 * by Rui Barreiros
28 *
29 * Additional modifications to enable support for multiple outputs and
30 * additional devices ids did change the original structure.
31 *
32 * by E.S. Rosenberg a.k.a. Keeper of the Keys 5774/2014
33 */
34
35#ifndef PLUGINS_FTDIDMX_FTDIWIDGET_H_
36#define PLUGINS_FTDIDMX_FTDIWIDGET_H_
37
38#if HAVE_CONFIG_H
39#include <config.h>
40#endif // HAVE_CONFIG_H
41
42#ifdef HAVE_LIBFTDI1
43#include <libftdi1/ftdi.h>
44#else
45#include <ftdi.h>
46#endif // HAVE_LIBFTDI1
47
48#include <stdint.h>
49#include <string.h>
50
51#include <string>
52#include <vector>
53
54#include "ola/DmxBuffer.h"
55
56namespace ola {
57namespace plugin {
58namespace ftdidmx {
59
64 public:
65 static const uint16_t FTDI_VID;
66 static const uint16_t FT232_PID;
67 static const uint16_t FT4232_PID;
68
69 FtdiWidgetInfo(const std::string &name,
70 const std::string &serial,
71 unsigned int id,
72 const uint16_t vid = FTDI_VID,
73 const uint16_t pid = FT232_PID)
74 : m_name(name),
75 m_serial(serial),
76 m_id(id),
77 m_vid(vid),
78 m_pid(pid) {
79 }
80
82 : m_name(info.Name()),
83 m_serial(info.Serial()),
84 m_id(info.Id()),
85 m_vid(info.Vid()),
86 m_pid(info.Pid()) {
87 }
88
90
91 std::string Name() const { return m_name; }
92 std::string Serial() const { return m_serial; }
93
94 unsigned int Id() const { return m_id; }
95 uint16_t Vid() const { return m_vid; }
96 uint16_t Pid() const { return m_pid; }
97
98 std::string Description() const {
99 return m_name + " with serial number : " + m_serial + " ";
100 }
101
102 FtdiWidgetInfo& operator=(const FtdiWidgetInfo &other) {
103 if (this != &other) {
104 m_name = other.Name();
105 m_serial = other.Serial();
106 m_id = other.Id();
107 m_vid = other.Vid();
108 m_pid = other.Pid();
109 }
110 return *this;
111 }
112
113 private:
114 std::string m_name;
115 std::string m_serial;
116
117 unsigned int m_id;
118 uint16_t m_vid;
119 uint16_t m_pid;
120};
121
126 public:
135 FtdiWidget(const std::string &serial,
136 const std::string &name,
137 uint32_t id = 0,
138 const uint16_t vid = FtdiWidgetInfo::FTDI_VID,
139 const uint16_t pid = FtdiWidgetInfo::FT232_PID);
140
142 virtual ~FtdiWidget();
143
145 std::string Serial() const { return m_serial; }
146
148 std::string Name() const { return m_name; }
149
150 uint16_t Vid() const { return m_vid; }
151 uint16_t Pid() const { return m_pid; }
152
154 uint32_t Id() const { return m_id; }
155
156 std::string Description() const {
157 return m_name + " with serial number : " + m_serial +" ";
158 }
159
161 int GetInterfaceCount();
162
167 static void Widgets(std::vector<FtdiWidgetInfo> *widgets);
168
169 // From reading libftdi docs it seems they may reuse error codes, which is
170 // why I chose to name this const <lib>_<function>_<error>.
171 static const int libftdi_ftdi_usb_get_strings_get_serial_failed = -9;
172
173 static bool m_missing_serial;
174
175 private:
176 std::string m_serial;
177 std::string m_name;
178 uint32_t m_id;
179 const uint16_t m_vid;
180 const uint16_t m_pid;
181};
182
184 public:
185 FtdiInterface(const FtdiWidget * parent,
186 const ftdi_interface interface);
187
188 virtual ~FtdiInterface();
189
190 std::string Description() const {
191 return m_parent->Description();
192 }
193
195 bool SetInterface();
196
198 bool Open();
199
201 bool Close();
202
204 bool IsOpen() const;
205
207 bool Reset();
208
210 bool SetLineProperties();
211
213 bool SetBaudRate(int speed = 250000);
214
216 bool SetFlowControl();
217
219 bool ClearRts();
220
222 bool PurgeBuffers();
223
225 bool SetBreak(bool on);
226
228 bool Write(const ola::DmxBuffer &data);
229
231 bool Read(unsigned char* buff, int size);
232
234 bool SetupOutput();
235
236 private:
237 const FtdiWidget * m_parent;
238 struct ftdi_context m_handle;
239 const ftdi_interface m_interface;
240}; // FtdiInterface
241} // namespace ftdidmx
242} // namespace plugin
243} // namespace ola
244#endif // PLUGINS_FTDIDMX_FTDIWIDGET_H_
A class used to hold a single universe of DMX data.
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
Definition FtdiWidget.h:183
bool SetInterface()
Set interface on the widget.
Definition FtdiWidget.cpp:229
bool Open()
Open the widget.
Definition FtdiWidget.cpp:240
bool SetBreak(bool on)
Toggle communications line BREAK condition on/off.
Definition FtdiWidget.cpp:341
bool PurgeBuffers()
Purge TX & RX buffers.
Definition FtdiWidget.cpp:331
bool Close()
Close the widget.
Definition FtdiWidget.cpp:267
bool ClearRts()
Clear the RTS bit.
Definition FtdiWidget.cpp:321
bool IsOpen() const
Check if the widget is open.
Definition FtdiWidget.cpp:277
bool Reset()
Reset the communications line.
Definition FtdiWidget.cpp:281
bool SetFlowControl()
Disable flow control.
Definition FtdiWidget.cpp:311
bool SetupOutput()
Setup device for DMX Output.
Definition FtdiWidget.cpp:379
bool SetBaudRate(int speed=250000)
Set 250kbps baud rate.
Definition FtdiWidget.cpp:301
bool SetLineProperties()
Setup communications line for 8N2 traffic.
Definition FtdiWidget.cpp:291
bool Write(const ola::DmxBuffer &data)
Write data to a previously-opened line.
Definition FtdiWidget.cpp:352
bool Read(unsigned char *buff, int size)
Read data from a previously-opened line.
Definition FtdiWidget.cpp:368
An FTDI widget.
Definition FtdiWidget.h:125
std::string Name() const
Get the widget's USB name.
Definition FtdiWidget.h:148
virtual ~FtdiWidget()
Destructor.
Definition FtdiWidget.cpp:80
uint32_t Id() const
Get the widget's FTD2XX ID number.
Definition FtdiWidget.h:154
std::string Serial() const
Get the widget's USB serial number.
Definition FtdiWidget.h:145
FtdiWidget(const std::string &serial, const std::string &name, uint32_t id=0, const uint16_t vid=FtdiWidgetInfo::FTDI_VID, const uint16_t pid=FtdiWidgetInfo::FT232_PID)
Construct a new FtdiWidget instance for one widget.
Definition FtdiWidget.cpp:69
int GetInterfaceCount()
Get Widget available interface count.
Definition FtdiWidget.cpp:90
static void Widgets(std::vector< FtdiWidgetInfo > *widgets)
Build a list of available ftdi widgets.
Definition FtdiWidget.cpp:107
This class holds information about an attached FTDI chip.
Definition FtdiWidget.h:63
The namespace containing all OLA symbols.
Definition Credentials.cpp:44