• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenLightingProject / ola / 24635061330

19 Apr 2026 05:36PM UTC coverage: 44.862% (-0.002%) from 44.864%
24635061330

Pull #2046

github

web-flow
Merge 8d08f158d into c6196f753
Pull Request #2046: Plugfest discovered fixes

8554 of 19846 branches covered (43.1%)

11 of 32 new or added lines in 7 files covered. (34.38%)

2 existing lines in 2 files now uncovered.

22105 of 49273 relevant lines covered (44.86%)

47.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/plugins/spidmx/SPIDMXThread.cpp
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.cpp
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
#include <string>
23
#include "ola/Logging.h"
24
#include "plugins/spidmx/SPIDMXWidget.h"
25
#include "plugins/spidmx/SPIDMXThread.h"
26
#include "plugins/spidmx/SPIDMXParser.h"
27

28
namespace ola {
29
namespace plugin {
30
namespace spidmx {
31

32
SPIDMXThread::SPIDMXThread(SPIDMXWidget *widget, unsigned int blocklength)
×
33
  : m_widget(widget),
×
34
    m_blocklength(blocklength),
×
35
    m_term(false),
×
36
    m_registered_ports(0),
×
37
    m_spi_rx_buffer(blocklength),
×
38
    m_spi_tx_buffer(blocklength) {
×
39
}
×
40

41
SPIDMXThread::~SPIDMXThread() {
×
42
  Stop();
×
43
}
×
44

45
/**
46
 * This thread only has to run if ports using it are patched to a universe.
47
 * Thus, they must register and unregister to notify this thread.
48
 */
49
void SPIDMXThread::RegisterPort() {
×
50
  m_registered_ports++;
×
51

52
  if (m_registered_ports >= 1) {
×
53
    Start();
×
54
  }
55
}
×
56
void SPIDMXThread::UnregisterPort() {
×
57
  m_registered_ports--;
×
58

59
  if (m_registered_ports <= 0) {
×
60
    Stop();
×
61
  }
62
}
×
63

64

65
/**
66
 * Stop this thread
67
 */
68
bool SPIDMXThread::Stop() {
×
69
  {
×
70
    ola::thread::MutexLocker locker(&m_term_mutex);
×
71
    m_term = true;
×
72
  }
×
73
  return Join();
×
74
}
75

76

77
/**
78
 * Copy a DmxBuffer to the output thread
79
 */
80
bool SPIDMXThread::WriteDMX(const DmxBuffer &buffer) {
×
81
  ola::thread::MutexLocker locker(&m_buffer_mutex);
×
82
  m_dmx_tx_buffer.Set(buffer);
×
83
  return true;
×
84
}
×
85

86
/**
87
  * @brief Get DMX Buffer
88
  * @returns DmxBuffer with current input values.
89
  */
90
const DmxBuffer &SPIDMXThread::GetDmxInBuffer() const {
×
91
  return m_dmx_rx_buffer;
×
92
}
93

94

95
/**
96
  * @brief Set the callback to be called when the receive buffer is updated.
97
  * @param callback The callback to call or NULL to unregister.
98
  * @return false if there was an error, true otherwise.
99
  */
100
bool SPIDMXThread::SetReceiveCallback(Callback0<void> *callback) {
×
101
  if (!callback) {
×
102
    // InputPort unregistered
103
    UnregisterPort();
×
104
    m_receive_callback.reset(NULL);
×
105
    return true;
×
106
  }
107

108
  if (m_widget->SetupOutput()) {
×
109
    RegisterPort();
×
110
    m_receive_callback.reset(callback);
×
111
    return true;
×
112
  }
113

114
  return false;
115
}
116

117

118
/**
119
 * The method called by the thread
120
 */
121
void *SPIDMXThread::Run() {
×
122
  DmxBuffer dmx_buffer;
×
123

124
  uint8_t *spi_rx_ptr;
×
125
  uint8_t *spi_tx_ptr;
×
126

127
  // Setup the widget
128
  if (!m_widget->IsOpen()) {
×
129
    if (!m_widget->SetupOutput()) {
×
130
      OLA_INFO << "SPIDMXThread stopped because SPI widget could not be opened";
×
131
      return NULL;
×
132
    }
133
  }
134

135
  // Setup the parser
136
  SPIDMXParser *parser = new SPIDMXParser(&m_dmx_rx_buffer,
×
137
                                          m_receive_callback.get());
×
138

139
  while (1) {
×
140
    {
×
141
      ola::thread::MutexLocker locker(&m_term_mutex);
×
142
      if (m_term) {
×
143
        parser->SetCallback(NULL);
×
144
        break;
×
145
      }
146
    }
×
147

148
    {
×
149
      ola::thread::MutexLocker locker(&m_buffer_mutex);
×
150
      dmx_buffer.Set(m_dmx_tx_buffer);
×
151
    }
×
152

153
    // TODO(FloEdelmann) fill m_spi_tx_buffer with the values from dmx_buffer
154
    //                   (each bit repeated 8 times)
155

156
    // vectors store their contents contiguously,
157
    // so we can get a pointer to the elements like so
158
    spi_rx_ptr = &m_spi_rx_buffer[0];
×
159
    spi_tx_ptr = &m_spi_tx_buffer[0];
×
160

161
    if (!m_widget->ReadWrite(spi_tx_ptr, spi_rx_ptr, m_blocklength)) {
×
162
      OLA_WARN << "SPIDMX Read / Write failed, stopping thread...";
×
163
      break;
×
164
    }
165

NEW
166
    parser->ParseDmx(spi_rx_ptr, static_cast<uint64_t>(m_blocklength));
×
167
  }
168

169
  delete parser;
×
170

171
  return NULL;
×
172
}
×
173

174
}  // namespace spidmx
175
}  // namespace plugin
176
}  // namespace ola
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc