Open Lighting Architecture  Latest Git
SPIDMXPort.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  * SPIDMXPort.h
17  * This represents the input / output ports that hook into the thread.
18  * Copyright (C) 2017 Florian Edelmann
19  */
20 
21 #ifndef PLUGINS_SPIDMX_SPIDMXPORT_H_
22 #define PLUGINS_SPIDMX_SPIDMXPORT_H_
23 
24 #include <string>
25 
26 #include "ola/DmxBuffer.h"
27 #include "olad/Port.h"
28 #include "olad/Preferences.h"
29 #include "plugins/spidmx/SPIDMXDevice.h"
30 #include "plugins/spidmx/SPIDMXWidget.h"
31 #include "plugins/spidmx/SPIDMXThread.h"
32 
33 namespace ola {
34 namespace plugin {
35 namespace spidmx {
36 
38  public:
40  unsigned int id,
41  PluginAdaptor *plugin_adaptor,
42  SPIDMXWidget *widget,
43  SPIDMXThread *thread)
44  : BasicInputPort(parent, id, plugin_adaptor, false),
45  m_widget(widget),
46  m_thread(thread) {
47  }
48  ~SPIDMXInputPort() {}
49 
50  const DmxBuffer &ReadDMX() const {
51  return m_thread->GetDmxInBuffer();
52  }
53 
54  bool PreSetUniverse(Universe *old_universe, Universe *new_universe) {
55  if (!old_universe && new_universe) {
56  return m_thread->SetReceiveCallback(NewCallback(
57  static_cast<BasicInputPort*>(this),
59  }
60  if (old_universe && !new_universe) {
61  return m_thread->SetReceiveCallback(NULL);
62  }
63  return true;
64  }
65 
66  std::string Description() const {
67  return m_widget->Description();
68  }
69 
70  private:
71  SPIDMXWidget *m_widget;
72  SPIDMXThread *m_thread;
73 
74  DISALLOW_COPY_AND_ASSIGN(SPIDMXInputPort);
75 };
76 
77 } // namespace spidmx
78 } // namespace plugin
79 } // namespace ola
80 #endif // PLUGINS_SPIDMX_SPIDMXPORT_H_
Definition: Universe.h:46
BasicInputPort(AbstractDevice *parent, unsigned int port_id, const PluginAdaptor *plugin_adaptor, bool supports_rdm=false)
Create a new basic input port.
Definition: Port.cpp:38
Definition: SPIDMXWidget.h:38
Definition: Port.h:199
std::string Description() const
Fetch the string description for a Port.
Definition: SPIDMXPort.h:66
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
Definition: SPIDMXThread.h:36
A class used to hold a single universe of DMX data.
void DmxChanged()
Called when there is new data for this port.
Definition: Port.cpp:83
const DmxBuffer & GetDmxInBuffer() const
Get DMX Buffer.
Definition: SPIDMXThread.cpp:90
Definition: PluginAdaptor.h:41
Definition: SPIDMXPort.h:37
Callback0< ReturnType > * NewCallback(ReturnType(*callback)())
A helper function to create a new Callback with 0 create-time arguments and 0 execution time argument...
Definition: Callback.h:211
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
bool SetReceiveCallback(Callback0< void > *callback)
Set the callback to be called when the receive buffer is updated.
Definition: SPIDMXThread.cpp:100
Definition: SPIDMXDevice.h:37