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

OpenLightingProject / ola / 16911433572

12 Aug 2025 02:08PM UTC coverage: 45.869% (-0.04%) from 45.909%
16911433572

Pull #1739

github

web-flow
Merge 02faeaa2d into 3566c28d9
Pull Request #1739: New web UI, store highest channel number used

7157 of 16316 branches covered (43.86%)

20915 of 45597 relevant lines covered (45.87%)

52.03 hits per line

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

12.77
/plugins/uartdmx/UartDmxPlugin.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
 * UartDmxPlugin.cpp
17
 * The DMX through a UART plugin for ola
18
 * Copyright (C) 2011 Rui Barreiros
19
 * Copyright (C) 2014 Richard Ash
20
 */
21

22
#include <fcntl.h>
23
#include <errno.h>
24

25
#include <memory>
26
#include <string>
27
#include <vector>
28

29
#include "ola/StringUtils.h"
30
#include "ola/io/IOUtils.h"
31
#include "olad/Preferences.h"
32
#include "olad/PluginAdaptor.h"
33
#include "plugins/uartdmx/UartDmxPlugin.h"
34
#include "plugins/uartdmx/UartDmxDevice.h"
35
#include "plugins/uartdmx/UartWidget.h"
36

37
namespace ola {
38
namespace plugin {
39
namespace uartdmx {
40

41
using std::string;
42
using std::vector;
43

44
const char UartDmxPlugin::PLUGIN_NAME[] = "UART native DMX";
45
const char UartDmxPlugin::PLUGIN_PREFIX[] = "uartdmx";
46
const char UartDmxPlugin::K_DEVICE[] = "device";
47
const char UartDmxPlugin::DEFAULT_DEVICE[] = "/dev/ttyACM0";
48

49
/*
50
 * Start the plug-in, using only the configured device(s) (we cannot sensibly
51
 * scan for UARTs!). Stolen from the opendmx plugin.
52
 */
53
bool UartDmxPlugin::StartHook() {
×
54
  vector<string> devices = m_preferences->GetMultipleValue(K_DEVICE);
×
55
  vector<string>::const_iterator iter;  // iterate over devices
×
56

57
  // start counting device ids from 0
58

59
  for (iter = devices.begin(); iter != devices.end(); ++iter) {
×
60
    // first check if device configured
61
    if (iter->empty()) {
×
62
      OLA_DEBUG << "No path configured for device, please set one in "
×
63
                << "ola-uartdmx.conf";
×
64
      continue;
×
65
    }
66

67
    OLA_DEBUG << "Trying to open UART device " << *iter;
×
68
    int fd;
×
69
    if (!ola::io::Open(*iter, O_WRONLY, &fd)) {
×
70
      OLA_WARN << "Could not open " << *iter << " " << strerror(errno);
×
71
      continue;
×
72
    }
73

74
    // can open device, so shut the temporary file descriptor
75
    close(fd);
×
76
    std::auto_ptr<UartDmxDevice> device(new UartDmxDevice(
×
77
        this, m_preferences, PLUGIN_NAME, *iter));
×
78

79
    // got a device, now lets see if we can configure it before we announce
80
    // it to the world
81
    if (!device->GetWidget()->SetupOutput()) {
×
82
      OLA_WARN << "Unable to setup device for output, device ignored "
×
83
               << device->DeviceId();
×
84
      continue;
×
85
    }
86
    // OK, device is good to go
87
    if (!device->Start()) {
×
88
      OLA_WARN << "Failed to start UartDmxDevice for " << *iter;
×
89
      continue;
×
90
    }
91

92
    OLA_DEBUG << "Started UartDmxDevice " << *iter;
×
93
    m_plugin_adaptor->RegisterDevice(device.get());
×
94
    m_devices.push_back(device.release());
×
95
  }
×
96
  return true;
×
97
}
×
98

99
/**
100
 * Stop all the devices.
101
 */
102
bool UartDmxPlugin::StopHook() {
×
103
  UartDeviceVector::iterator iter;
×
104
  for (iter = m_devices.begin(); iter != m_devices.end(); ++iter) {
×
105
    m_plugin_adaptor->UnregisterDevice(*iter);
×
106
    (*iter)->Stop();
×
107
    delete *iter;
×
108
  }
109
  m_devices.clear();
×
110
  return true;
×
111
}
112

113

114
/**
115
 * Return a description for this plugin.
116
 */
117
string UartDmxPlugin::Description() const {
×
118
  return
×
119
"Native UART DMX Plugin\n"
×
120
"----------------------\n"
121
"\n"
122
"This plugin drives a supported POSIX UART (plus extensions)\n"
123
"to produce a direct DMX output stream. The host needs to\n"
124
"create the DMX stream itself as there is no external microcontroller.\n"
125
"This is tested with the on-board UART of the Raspberry Pi.\n"
126
"See here for a possible schematic:\n"
127
"http://eastertrail.blogspot.co.uk/2014/04/command-and-control-ii.html\n"
128
"\n"
129
"--- Config file : ola-uartdmx.conf ---\n"
130
"\n"
131
"enabled = true\n"
132
"Enable this plugin (DISABLED by default).\n"
133
"device = /dev/ttyAMA0\n"
134
"The device to use for DMX output (optional). Multiple devices are \n"
135
"supported if the hardware exists.\n"
136
"On later software it may also be /dev/serial0.\n"
137
"Using USB-serial adapters is not supported (try the ftdidmx plugin \n"
138
"instead).\n"
139
"--- Per Device Settings (using above device name) ---\n"
140
"<device>-break = 100\n"
141
"The DMX break time in microseconds for this device (optional).\n"
142
"<device>-malf = 100\n"
143
"The Mark After Last Frame time in microseconds for this device (optional).\n"
144
"\n";
×
145
}
146

147

148
/**
149
 * Set the default preferences
150
 */
151
bool UartDmxPlugin::SetDefaultPreferences() {
1✔
152
  if (!m_preferences) {
1✔
153
    return false;
154
  }
155

156
  // only insert default device name, no others at this stage
157
  bool save = m_preferences->SetDefaultValue(K_DEVICE, StringValidator(),
1✔
158
                                             DEFAULT_DEVICE);
159
  if (save) {
1✔
160
    m_preferences->Save();
1✔
161
  }
162

163
  // Just check key exists, as we've set it to ""
164
  if (!m_preferences->HasKey(K_DEVICE)) {
1✔
165
    return false;
166
  }
167
  return true;
168
}
169
}  // namespace uartdmx
170
}  // namespace plugin
171
}  // 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