From f15164629580fecab5d16627fb5cf1fb6416c2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 19 Dec 2025 10:53:11 +0100 Subject: [PATCH] Update source formating using new clang format --- libnymea-gpio/gpio.cpp | 14 +++++--------- libnymea-gpio/gpio.h | 7 +++---- libnymea-gpio/gpiobutton.cpp | 10 ++++------ libnymea-gpio/gpiobutton.h | 6 ++---- libnymea-gpio/gpiomonitor.cpp | 11 ++++------- libnymea-gpio/gpiomonitor.h | 7 +++---- nymea-gpio-tool/application.cpp | 11 +++++------ nymea-gpio-tool/application.h | 3 +-- nymea-gpio-tool/main.cpp | 18 +++++++++--------- 9 files changed, 36 insertions(+), 51 deletions(-) diff --git a/libnymea-gpio/gpio.cpp b/libnymea-gpio/gpio.cpp index a427df6..b0c583a 100644 --- a/libnymea-gpio/gpio.cpp +++ b/libnymea-gpio/gpio.cpp @@ -85,7 +85,6 @@ \sa GpioMonitor */ - /*! \enum Gpio::Direction This enum type specifies the dirction a Gpio. @@ -130,14 +129,13 @@ Q_LOGGING_CATEGORY(dcGpio, "Gpio") /*! Constructs a Gpio object to represent a GPIO with the given \a gpio number and \a parent. */ -Gpio::Gpio(int gpio, QObject *parent) : - QObject(parent), - m_gpio(gpio), - m_direction(Gpio::DirectionInvalid), - m_gpioDirectory(QDir(QString("/sys/class/gpio/gpio%1").arg(QString::number(gpio)))) +Gpio::Gpio(int gpio, QObject *parent) + : QObject(parent) + , m_gpio(gpio) + , m_direction(Gpio::DirectionInvalid) + , m_gpioDirectory(QDir(QString("/sys/class/gpio/gpio%1").arg(QString::number(gpio)))) { qRegisterMetaType(); - } /*! Destroys and unexports the Gpio. */ @@ -376,7 +374,6 @@ bool Gpio::activeLow() /*! Returns true if the \a edge of this GPIO could be set correctly. The \a edge parameter specifies, when an interrupt occurs. */ bool Gpio::setEdgeInterrupt(Gpio::Edge edge) { - if (m_direction == Gpio::DirectionOutput) { qCWarning(dcGpio()) << "Could not set edge interrupt, GPIO is configured as an output."; return false; @@ -436,7 +433,6 @@ Gpio::Edge Gpio::edgeInterrupt() return Gpio::EdgeNone; } - /*! Prints the given \a gpio to \a debug. */ QDebug operator<<(QDebug debug, Gpio *gpio) { diff --git a/libnymea-gpio/gpio.h b/libnymea-gpio/gpio.h index db66b8d..a78d765 100644 --- a/libnymea-gpio/gpio.h +++ b/libnymea-gpio/gpio.h @@ -28,10 +28,10 @@ #ifndef GPIO_H #define GPIO_H -#include #include -#include +#include #include +#include Q_DECLARE_LOGGING_CATEGORY(dcGpio) @@ -89,9 +89,8 @@ private: int m_gpio = 0; Gpio::Direction m_direction = Gpio::DirectionOutput; QDir m_gpioDirectory; - }; -QDebug operator<< (QDebug debug, Gpio *gpio); +QDebug operator<<(QDebug debug, Gpio *gpio); #endif // GPIO_H diff --git a/libnymea-gpio/gpiobutton.cpp b/libnymea-gpio/gpiobutton.cpp index 037c412..122b743 100644 --- a/libnymea-gpio/gpiobutton.cpp +++ b/libnymea-gpio/gpiobutton.cpp @@ -79,12 +79,10 @@ #include "gpiomonitor.h" /*! Constructs a \l{GpioButton} object with the given \a gpio number and \a parent. */ -GpioButton::GpioButton(int gpio, QObject *parent) : - QObject(parent), - m_gpioNumber(gpio) -{ - -} +GpioButton::GpioButton(int gpio, QObject *parent) + : QObject(parent) + , m_gpioNumber(gpio) +{} /*! Returns the gpio number for this GpioButton. */ int GpioButton::gpioNumber() const diff --git a/libnymea-gpio/gpiobutton.h b/libnymea-gpio/gpiobutton.h index 76b29f6..3987e69 100644 --- a/libnymea-gpio/gpiobutton.h +++ b/libnymea-gpio/gpiobutton.h @@ -29,8 +29,8 @@ #define GPIOBUTTON_H #include -#include #include +#include class GpioMonitor; @@ -79,10 +79,8 @@ private slots: public slots: bool enable(); void disable(); - }; -QDebug operator<< (QDebug debug, GpioButton *gpioButton); - +QDebug operator<<(QDebug debug, GpioButton *gpioButton); #endif // GPIOBUTTON_H diff --git a/libnymea-gpio/gpiomonitor.cpp b/libnymea-gpio/gpiomonitor.cpp index 107c4e5..9534299 100644 --- a/libnymea-gpio/gpiomonitor.cpp +++ b/libnymea-gpio/gpiomonitor.cpp @@ -71,9 +71,9 @@ #include "gpiomonitor.h" /*! Constructs a \l{GpioMonitor} object with the given \a gpio number and \a parent. */ -GpioMonitor::GpioMonitor(int gpio, QObject *parent) : - QObject(parent), - m_gpioNumber(gpio) +GpioMonitor::GpioMonitor(int gpio, QObject *parent) + : QObject(parent) + , m_gpioNumber(gpio) { m_valueFile.setFileName("/sys/class/gpio/gpio" + QString::number(m_gpioNumber) + "/value"); } @@ -86,10 +86,7 @@ bool GpioMonitor::enable(bool activeLow, Gpio::Edge edgeInterrupt) return false; m_gpio = new Gpio(m_gpioNumber, this); - if (!m_gpio->exportGpio() || - !m_gpio->setDirection(Gpio::DirectionInput) || - !m_gpio->setActiveLow(activeLow) || - !m_gpio->setEdgeInterrupt(edgeInterrupt)) { + if (!m_gpio->exportGpio() || !m_gpio->setDirection(Gpio::DirectionInput) || !m_gpio->setActiveLow(activeLow) || !m_gpio->setEdgeInterrupt(edgeInterrupt)) { qCWarning(dcGpio()) << "GpioMonitor: Error while initializing GPIO" << m_gpio->gpioNumber(); return false; } diff --git a/libnymea-gpio/gpiomonitor.h b/libnymea-gpio/gpiomonitor.h index f9217f6..dedfd27 100644 --- a/libnymea-gpio/gpiomonitor.h +++ b/libnymea-gpio/gpiomonitor.h @@ -28,10 +28,10 @@ #ifndef GPIOMONITOR_H #define GPIOMONITOR_H -#include #include -#include #include +#include +#include #include "gpio.h" @@ -48,7 +48,7 @@ public: bool isRunning() const; bool value() const; - Gpio* gpio(); + Gpio *gpio(); private: int m_gpioNumber; @@ -62,7 +62,6 @@ signals: private slots: void readyReady(const int &ready); - }; #endif // GPIOMONITOR_H diff --git a/nymea-gpio-tool/application.cpp b/nymea-gpio-tool/application.cpp index b03f3a2..face1a7 100644 --- a/nymea-gpio-tool/application.cpp +++ b/nymea-gpio-tool/application.cpp @@ -24,12 +24,12 @@ #include "application.h" -#include #include +#include -static void catchUnixSignals(const std::vector& quitSignals, const std::vector& ignoreSignals = std::vector()) +static void catchUnixSignals(const std::vector &quitSignals, const std::vector &ignoreSignals = std::vector()) { - auto handler = [](int sig) ->void { + auto handler = [](int sig) -> void { switch (sig) { case SIGQUIT: qDebug() << "Cought SIGQUIT quit signal..."; @@ -60,11 +60,10 @@ static void catchUnixSignals(const std::vector& quitSignals, const std::vec for (int sig : quitSignals) signal(sig, handler); - } -Application::Application(int &argc, char **argv) : - QCoreApplication(argc, argv) +Application::Application(int &argc, char **argv) + : QCoreApplication(argc, argv) { catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP, SIGSEGV}); } diff --git a/nymea-gpio-tool/application.h b/nymea-gpio-tool/application.h index 2111928..631f1a8 100644 --- a/nymea-gpio-tool/application.h +++ b/nymea-gpio-tool/application.h @@ -25,15 +25,14 @@ #ifndef APPLICATION_H #define APPLICATION_H -#include #include +#include class Application : public QCoreApplication { Q_OBJECT public: explicit Application(int &argc, char **argv); - }; #endif // APPLICATION_H diff --git a/nymea-gpio-tool/main.cpp b/nymea-gpio-tool/main.cpp index ae87dec..cffbcd9 100644 --- a/nymea-gpio-tool/main.cpp +++ b/nymea-gpio-tool/main.cpp @@ -42,19 +42,23 @@ int main(int argc, char *argv[]) "Copyright (C) 2013 - 2024 nymea GmbH\n" "Copyright (C) 2024 - 2025 chargebyte austria GmbH\n\n" "Released under the GNU General Public License v3.0 or (at your option) any later version.\n") - .arg(application.applicationVersion()); + .arg(application.applicationVersion()); parser.setApplicationDescription(applicationDescription); QCommandLineOption gpioOption(QStringList() << "g" << "gpio", "The gpio number to use.", "GPIO"); parser.addOption(gpioOption); - QCommandLineOption interruptOption(QStringList() << "i" << "interrupt", "Configure the input GPIO to the given interrupt. This option is only allowed for monitoring. Allowerd interrupts are: [rising, falling, both, none]. Default is \"both\".", "INTERRUPT"); + QCommandLineOption interruptOption( + QStringList() << "i" << "interrupt", + "Configure the input GPIO to the given interrupt. This option is only allowed for monitoring. Allowerd interrupts are: [rising, falling, both, none]. Default is \"both\".", + "INTERRUPT"); parser.addOption(interruptOption); QCommandLineOption valueOption(QStringList() << "s" << "set-value", "Configure the GPIO to output and set the value. Allowerd values are: [0, 1].", "VALUE"); parser.addOption(valueOption); - 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."); + 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() << "l" << "active-low", "Configure the pin as active low (default is active high)."); @@ -149,9 +153,7 @@ int main(int argc, char *argv[]) GpioMonitor *monitor = new GpioMonitor(gpioNumber); // Inform about interrupt - QObject::connect(monitor, &GpioMonitor::valueChanged, [gpioNumber](bool value) { - qDebug() << "GPIO" << gpioNumber << "value changed:" << (value ? "1" : "0"); - }); + QObject::connect(monitor, &GpioMonitor::valueChanged, [gpioNumber](bool value) { qDebug() << "GPIO" << gpioNumber << "value changed:" << (value ? "1" : "0"); }); // Enable the monitor if (!monitor->enable(activeLow, edge)) { @@ -160,9 +162,7 @@ int main(int argc, char *argv[]) } // Clean up the gpio once done - QObject::connect(&application, &Application::aboutToQuit, [monitor](){ - delete monitor; - }); + QObject::connect(&application, &Application::aboutToQuit, [monitor]() { delete monitor; }); } return application.exec();