Open Lighting Architecture  Latest Git
SPIDMXThread.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  * SPIDMXThread.h
17  * This thread runs while one or more ports are registered. It simultaneously
18  * reads / writes SPI data and then calls the parser. This is repeated forever.
19  * Copyright (C) 2017 Florian Edelmann
20  */
21 
22 #ifndef PLUGINS_SPIDMX_SPIDMXTHREAD_H_
23 #define PLUGINS_SPIDMX_SPIDMXTHREAD_H_
24 
25 #include <memory>
26 #include <vector>
27 #include "ola/Callback.h"
28 #include "ola/DmxBuffer.h"
29 #include "ola/base/Macro.h"
30 #include "ola/thread/Thread.h"
31 
32 namespace ola {
33 namespace plugin {
34 namespace spidmx {
35 
37  public:
38  SPIDMXThread(SPIDMXWidget *widget, unsigned int blocklength);
39  ~SPIDMXThread();
40 
41  void RegisterPort();
42  void UnregisterPort();
43 
44  bool Stop();
45  void *Run();
46 
47  bool WriteDMX(const DmxBuffer &buffer);
48  const DmxBuffer &GetDmxInBuffer() const;
49 
50  bool SetReceiveCallback(Callback0<void> *callback);
51 
52  private:
53  SPIDMXWidget *m_widget;
54  unsigned int m_blocklength;
55 
56  bool m_term;
57  int m_registered_ports;
58 
60  DmxBuffer m_dmx_rx_buffer;
62  DmxBuffer m_dmx_tx_buffer;
63 
65  std::vector<uint8_t> m_spi_rx_buffer;
67  std::vector<uint8_t> m_spi_tx_buffer;
68 
70  std::auto_ptr<Callback0<void> > m_receive_callback;
71 
72  ola::thread::Mutex m_term_mutex;
73  ola::thread::Mutex m_buffer_mutex;
74 
75  DISALLOW_COPY_AND_ASSIGN(SPIDMXThread);
76 };
77 
78 } // namespace spidmx
79 } // namespace plugin
80 } // namespace ola
81 #endif // PLUGINS_SPIDMX_SPIDMXTHREAD_H_
Definition: SPIDMXWidget.h:38
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.
const DmxBuffer & GetDmxInBuffer() const
Get DMX Buffer.
Definition: SPIDMXThread.cpp:90
bool Stop()
Definition: SPIDMXThread.cpp:68
Definition: Thread.h:52
void RegisterPort()
Definition: SPIDMXThread.cpp:49
void * Run()
Definition: SPIDMXThread.cpp:121
Helper macros.
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
bool WriteDMX(const DmxBuffer &buffer)
Definition: SPIDMXThread.cpp:80
Definition: Mutex.h:41