From 80dd57a8ea975ef1c7a68c51efbc186432d216f9 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 6 Nov 2021 23:31:17 +0100 Subject: [PATCH] Fix active low logic --- libnymea-gpio/gpio.cpp | 6 +++--- nymea-gpio-tool/main.cpp | 16 +++------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/libnymea-gpio/gpio.cpp b/libnymea-gpio/gpio.cpp index e0fe34b..28a0e2d 100644 --- a/libnymea-gpio/gpio.cpp +++ b/libnymea-gpio/gpio.cpp @@ -346,9 +346,9 @@ bool Gpio::setActiveLow(bool activeLow) QTextStream out(&activeLowFile); if (activeLow) { - out << "0"; - } else { out << "1"; + } else { + out << "0"; } activeLowFile.close(); @@ -369,7 +369,7 @@ bool Gpio::activeLow() in >> value; activeLowFile.close(); - if (value == "0") + if (value == "1") return true; return false; diff --git a/nymea-gpio-tool/main.cpp b/nymea-gpio-tool/main.cpp index 2fbfb97..08d27b7 100644 --- a/nymea-gpio-tool/main.cpp +++ b/nymea-gpio-tool/main.cpp @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) QCommandLineOption monitorOption(QStringList() << "m" << "monitor", "Monitor the given GPIO. The GPIO will automatically configured as input and print any change regarding to the given interrupt behaviour."); parser.addOption(monitorOption); - QCommandLineOption activeLowOption(QStringList() << "a" << "active-low", "Set the GPIO to active low. Allowerd values are: [0, 1]", "VALUE"); + QCommandLineOption activeLowOption(QStringList() << "l" << "active-low", "Configure the pin as active low (default is active high)."); parser.addOption(activeLowOption); parser.process(application); @@ -102,17 +102,7 @@ int main(int argc, char *argv[]) } } - bool activeLow = true; - if (parser.isSet(activeLowOption)) { - if (parser.value(activeLowOption) == "1") { - activeLow = false; - } else if (parser.value(activeLowOption) == "0") { - activeLow = true; - } else { - qCritical() << "Invalid active low parameter" << parser.value(activeLowOption) << "passed. Valid options are [0, 1]."; - return EXIT_FAILURE; - } - } + bool activeLow = parser.isSet(activeLowOption); Gpio::Value value = Gpio::ValueInvalid; if (parser.isSet(valueOption)) { @@ -171,7 +161,7 @@ int main(int argc, char *argv[]) // Inform about interrupt QObject::connect(monitor, &GpioMonitor::interruptOccurred, [gpioNumber](bool value) { - qDebug() << "GPIO" << gpioNumber << "interrupt occured. Current value:" << (value ? "1" : "0"); + qDebug() << "GPIO" << gpioNumber << "interrupt occurred. Current value:" << (value ? "1" : "0"); }); // Enable the monitor