• 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

53.45
/plugins/gpio/GPIOPlugin.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
 * GPIOPlugin.cpp
17
 * The General Purpose digital I/O plugin.
18
 * Copyright (C) 2014 Simon Newton
19
 */
20

21
#include "plugins/gpio/GPIOPlugin.h"
22

23
#include <memory>
24
#include <string>
25
#include <vector>
26
#include "olad/Preferences.h"
27
#include "ola/Logging.h"
28
#include "ola/StringUtils.h"
29
#include "plugins/gpio/GPIODevice.h"
30
#include "plugins/gpio/GPIODriver.h"
31

32
namespace ola {
33
namespace plugin {
34
namespace gpio {
35

36
using std::auto_ptr;
37
using std::string;
38
using std::vector;
39

40
const char GPIOPlugin::GPIO_PINS_KEY[] = "gpio_pins";
41
const char GPIOPlugin::GPIO_SLOT_OFFSET_KEY[] = "gpio_slot_offset";
42
const char GPIOPlugin::GPIO_TURN_OFF_KEY[] = "gpio_turn_off";
43
const char GPIOPlugin::GPIO_TURN_ON_KEY[] = "gpio_turn_on";
44
const char GPIOPlugin::PLUGIN_NAME[] = "GPIO";
45
const char GPIOPlugin::PLUGIN_PREFIX[] = "gpio";
46

47
bool GPIOPlugin::StartHook() {
1✔
48
  GPIODriver::Options options;
1✔
49
  if (!StringToInt(m_preferences->GetValue(GPIO_TURN_ON_KEY),
1✔
50
                   &options.turn_on)) {
51
    OLA_WARN << "Invalid value for " << GPIO_TURN_ON_KEY;
×
52
    return false;
×
53
  }
54

55
  if (!StringToInt(m_preferences->GetValue(GPIO_TURN_OFF_KEY),
1✔
56
                   &options.turn_off)) {
57
    OLA_WARN << "Invalid value for " << GPIO_TURN_OFF_KEY;
×
58
    return false;
×
59
  }
60

61
  if (!StringToInt(m_preferences->GetValue(GPIO_SLOT_OFFSET_KEY),
1✔
62
                   &options.start_address)) {
63
    OLA_WARN << "Invalid value for " << GPIO_SLOT_OFFSET_KEY;
×
64
    return false;
×
65
  }
66

67
  if (options.turn_off >= options.turn_on) {
1✔
68
    OLA_WARN << GPIO_TURN_OFF_KEY << " must be strictly less than "
×
69
             << GPIO_TURN_ON_KEY;
×
70
    return false;
×
71
  }
72

73
  vector<string> pin_list;
1✔
74
  StringSplit(m_preferences->GetValue(GPIO_PINS_KEY), &pin_list, ",");
2✔
75
  vector<string>::const_iterator iter = pin_list.begin();
1✔
76
  for (; iter != pin_list.end(); ++iter) {
2✔
77
    if (iter->empty()) {
1✔
78
      continue;
1✔
79
    }
80

81
    uint16_t pin;
×
82
    if (!StringToInt(*iter, &pin)) {
×
83
      OLA_WARN << "Invalid value for GPIO pin: " << *iter;
×
84
      return false;
×
85
    }
86
    options.gpio_pins.push_back(pin);
×
87
  }
88

89
  if (options.gpio_pins.empty()) {
1✔
90
    return true;
91
  }
92

93
  std::auto_ptr<GPIODevice> device(new GPIODevice(this, options));
×
94
  if (!device->Start()) {
×
95
    return false;
96
  }
97

98
  m_plugin_adaptor->RegisterDevice(device.get());
×
99
  m_device = device.release();
×
100
  return true;
×
101
}
2✔
102

103
bool GPIOPlugin::StopHook() {
1✔
104
  if (m_device) {
1✔
105
    m_plugin_adaptor->UnregisterDevice(m_device);
×
106
    m_device->Stop();
×
107
    delete m_device;
×
108
    m_device = NULL;
×
109
  }
110
  return true;
1✔
111
}
112

113
string GPIOPlugin::Description() const {
×
114
  return
×
115
"General Purpose I/O Plugin\n"
×
116
"----------------------------\n"
117
"\n"
118
"This plugin controls the General Purpose Digital I/O (GPIO) pins on devices\n"
119
"like a Raspberry Pi. It creates a single device, with a single output port.\n"
120
"The offset (start address) of the GPIO pins is configurable.\n"
121
"\n"
122
"--- Config file : ola-gpio.conf ---\n"
123
"\n"
124
"gpio_pins = [int]\n"
125
"The list of GPIO pins to control, each pin is mapped to a DMX512 slot.\n"
126
"\n"
127
"gpio_slot_offset = <int>\n"
128
"The DMX512 slot for the first pin. Slots are indexed from 1\n."
129
"\n"
130
"gpio_turn_on = <int>\n"
131
"The DMX512 value above which a GPIO pin will be turned on.\n"
132
"\n"
133
"gpio_turn_off = <int>\n"
134
"The DMX512 value below which a GPIO pin will be turned off.\n"
135
"\n";
×
136
}
137

138
bool GPIOPlugin::SetDefaultPreferences() {
1✔
139
  bool save = false;
1✔
140

141
  if (!m_preferences)
1✔
142
    return false;
143

144
  save |= m_preferences->SetDefaultValue(GPIO_PINS_KEY,
1✔
145
                                         StringValidator(),
1✔
146
                                         "");
147
  save |= m_preferences->SetDefaultValue(GPIO_SLOT_OFFSET_KEY,
1✔
148
                                         UIntValidator(1, DMX_UNIVERSE_SIZE),
1✔
149
                                         "1");
150
  save |= m_preferences->SetDefaultValue(
1✔
151
      GPIO_TURN_ON_KEY,
152
      UIntValidator(DMX_MIN_SLOT_VALUE + 1, DMX_MAX_SLOT_VALUE),
1✔
153
      "128");
154
  save |= m_preferences->SetDefaultValue(
1✔
155
      GPIO_TURN_OFF_KEY,
156
      UIntValidator(DMX_MIN_SLOT_VALUE, DMX_MAX_SLOT_VALUE - 1),
1✔
157
      "127");
158

159
  if (save) {
1✔
160
    m_preferences->Save();
1✔
161
  }
162

163
  if (m_preferences->GetValue(GPIO_SLOT_OFFSET_KEY).empty()) {
1✔
164
    return false;
165
  }
166

167
  return true;
168
}
169
}  // namespace gpio
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