|
|
||
|---|---|---|
| debian-qt5 | ||
| debian-qt6 | ||
| docs | ||
| libnymea-gpio | ||
| nymea-gpio-tool | ||
| tools | ||
| .clang-format | ||
| .gitignore | ||
| COPYING | ||
| COPYING.LESSER | ||
| LICENSE.GPL3 | ||
| LICENSE.LGPL3 | ||
| README.md | ||
| debian | ||
| nymea-gpio.pri | ||
| nymea-gpio.pro | ||
README.md
nymea-gpio
nymea-gpio is a small Qt/C++ GPIO helper library for Linux and a matching CLI tool. The library is used by nymea but can be embedded in other Qt applications, while the CLI is handy for scripting, bring-up, and diagnostics.
Components
libnymea-gpio: Qt library withGpio,GpioMonitor, andGpioButtonhelpers.nymea-gpio-tool: CLI wrapper around the same API.
Supported GPIO backends
- Linux libgpiod API v1 or v2 (auto-detected via pkg-config).
- Linux sysfs GPIO (deprecated upstream, build-time opt-in).
Requirements
- Linux
- Qt 5 or Qt 6 (qmake)
pkg-configandlibgpiod(unless building the legacy sysfs backend)dpkg-parsechangelog(fromdpkg-dev) to populateVERSION_STRINGduring build
Build
Build both the library and the CLI:
qmake nymea-gpio.pro
make -j
If you are building with Qt 6, use qmake6 instead of qmake.
To force the legacy sysfs backend:
qmake "CONFIG+=nymea_gpio_sysfs" nymea-gpio.pro
make -j
Install (optional):
make install
The install step drops the library, headers, and a nymea-gpio pkg-config file into your Qt prefix.
CLI usage
nymea-gpio-tool requires a GPIO number and then either sets an output value or monitors input changes.
Set a GPIO output:
nymea-gpio-tool --gpio 17 --set-value 1
Monitor input changes (default edge is both):
nymea-gpio-tool --gpio 17 --monitor --interrupt both
Active-low input or output:
nymea-gpio-tool --gpio 17 --set-value 0 --active-low
Library examples
Output GPIO:
Gpio *gpioOut = new Gpio(23, this);
// Export Gpio
if (!gpioOut->exportGpio()) {
qWarning() << "Could not export Gpio" << gpioOut->gpioNumber();
gpioOut->deleteLater();
return;
}
// Configure Gpio direction
if (!gpioOut->setDirection(Gpio::DirectionOutput)) {
qWarning() << "Could not set direction of Gpio" << gpioOut->gpioNumber();
gpioOut->deleteLater();
return;
}
gpioOut->setValue(Gpio::ValueHigh);
Input GPIO:
Gpio *gpioIn = new Gpio(24, this);
// Export Gpio
if (!gpioIn->exportGpio()) {
qWarning() << "Could not export Gpio" << gpioIn->gpioNumber();
gpioIn->deleteLater();
return;
}
// Configure Gpio direction
if (!gpioIn->setDirection(Gpio::DirectionInput)) {
qWarning() << "Could not set direction of Gpio" << gpioIn->gpioNumber();
gpioIn->deleteLater();
return;
}
qDebug() << "Current value" << gpioIn->value();
Monitor a button with GpioMonitor:
Button::Button(QObject *parent) :
QObject(parent)
{
m_button = new GpioMonitor(110, this);
connect(m_button, &GpioMonitor::valueChanged, this, &Button::stateChanged);
}
bool Button::init()
{
return m_button->enable();
}
void Button::stateChanged(const bool &value)
{
if (m_pressed != value) {
m_pressed = value;
if (value) {
emit buttonPressed();
} else {
emit buttonReleased();
}
}
}
Button helper with debounced GpioButton:
GpioButton *button = new GpioButton(15, this);
button->setName("User button");
if (!button->enable()) {
qWarning() << "Could not enable the" << this;
button->deleteLater();
return;
}
connect(button, &GpioButton::clicked, this, [this, button](){
qDebug() << button << "clicked";
});
License
libnymea-gpiois licensed under the GNU Lesser General Public License v3.0 or (at your option) any later version. SeeLICENSE.LGPL3.nymea-gpio-toolis licensed under the GNU General Public License v3.0 or (at your option) any later version. SeeLICENSE.GPL3.