Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MilInstWidget.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  * MilInstWidget.h
17  * Interface for the milinst widget
18  * Copyright (C) 2013 Peter Newman
19  */
20 
21 #ifndef PLUGINS_MILINST_MILINSTWIDGET_H_
22 #define PLUGINS_MILINST_MILINSTWIDGET_H_
23 
24 #include <fcntl.h>
25 #include <termios.h>
26 #include <string>
27 
28 #include "ola/io/SelectServer.h"
29 #include "ola/DmxBuffer.h"
30 
31 namespace ola {
32 namespace plugin {
33 namespace milinst {
34 
36  public:
37  static int ConnectToWidget(const std::string &path, speed_t speed = B9600);
38 
39  explicit MilInstWidget(const std::string &path)
40  : m_enabled(false),
41  m_path(path),
42  m_socket(NULL) {}
43 
44  virtual ~MilInstWidget();
45 
46  // these methods are for communicating with the device
47  virtual bool Connect() = 0;
48  int Disconnect();
49  ola::io::ConnectedDescriptor *GetSocket() { return m_socket; }
50  std::string GetPath() { return m_path; }
51  virtual std::string Type() = 0;
52 
53  std::string Description() {
54  std::ostringstream str;
55  str << GetPath() << ", " << Type();
56  return str.str();
57  }
58 
59  virtual bool SendDmx(const DmxBuffer &buffer) const = 0;
60  virtual bool DetectDevice() = 0;
61 
62  protected:
63  virtual int SetChannel(unsigned int chan, uint8_t val) const = 0;
64 
65  // instance variables
66  bool m_enabled;
67  const std::string m_path;
69 };
70 } // namespace milinst
71 } // namespace plugin
72 } // namespace ola
73 #endif // PLUGINS_MILINST_MILINSTWIDGET_H_