Update source formating using new clang format

add-clang-format
Simon Stürz 2025-12-19 10:53:11 +01:00
parent 5e1654d783
commit f151646295
9 changed files with 36 additions and 51 deletions

View File

@ -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<Gpio::Value>();
}
/*! 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)
{

View File

@ -28,10 +28,10 @@
#ifndef GPIO_H
#define GPIO_H
#include <QDir>
#include <QDebug>
#include <QObject>
#include <QDir>
#include <QLoggingCategory>
#include <QObject>
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

View File

@ -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

View File

@ -29,8 +29,8 @@
#define GPIOBUTTON_H
#include <QElapsedTimer>
#include <QTimer>
#include <QObject>
#include <QTimer>
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

View File

@ -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;
}

View File

@ -28,10 +28,10 @@
#ifndef GPIOMONITOR_H
#define GPIOMONITOR_H
#include <QObject>
#include <QDebug>
#include <QSocketNotifier>
#include <QFile>
#include <QObject>
#include <QSocketNotifier>
#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

View File

@ -24,12 +24,12 @@
#include "application.h"
#include <QDebug>
#include <signal.h>
#include <QDebug>
static void catchUnixSignals(const std::vector<int>& quitSignals, const std::vector<int>& ignoreSignals = std::vector<int>())
static void catchUnixSignals(const std::vector<int> &quitSignals, const std::vector<int> &ignoreSignals = std::vector<int>())
{
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<int>& 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});
}

View File

@ -25,15 +25,14 @@
#ifndef APPLICATION_H
#define APPLICATION_H
#include <QObject>
#include <QCoreApplication>
#include <QObject>
class Application : public QCoreApplication
{
Q_OBJECT
public:
explicit Application(int &argc, char **argv);
};
#endif // APPLICATION_H

View File

@ -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();