Complete documentations

This commit is contained in:
Simon Stürz 2019-09-13 17:09:46 +02:00
parent 2dea4225e4
commit 4984618797
3 changed files with 95 additions and 15 deletions

View File

@ -39,35 +39,41 @@
\code
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(PiGpio::DirectionOutput)) {
qWarning() << "Could not set direction of Gpio" << gpioOut->gpioNumber();
gpioOut->deleteLater();
return;
}
gpioOut->setValue(Gpio::ValueHigh)
\endcode
\code
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(PiGpio::DirectionInput)) {
qWarning() << "Could not set direction of Gpio" << gpioIn->gpioNumber();
gpioIn->deleteLater();
return;
}
qDebug() << "Current value" << gpioIn->value();
\endcode
\sa GpioMonitor

View File

@ -20,56 +20,128 @@
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*!
\class GpioButton
\brief Represents a GPIO Button with some helper methods.
\inmodule nymea-gpio
This class represents a Button based on a GPIO. The class takes care about the \l{clicked()} signal handling, debounces the GPIO signal
and offers a nice interface for \l{longPressed()} behaviour.
In order to get the button signals, the button has to be enabled using \l{enable()}.
\code
GpioButton *button = new GpioButton(15, this);
button->setName("User button");
if (!button->enable()) {
qWarning() << "Could not enable the" << this;
}
connect(button, &GpioButton::clicked, this, [this, button](){
qDebug() << button << "clicked";
});
\endcode
*/
/*!
\fn void GpioButton::clicked();
This signal will be emitted when the button gets clicked. A button will has been clicked, if it was pressed at leased for 10 ms and at most 500 ms.
*/
/*!
\fn void GpioButton::pressed();
This signal will be emitted when the button gets pressed.
*/
/*!
\fn void GpioButton::released();
This signal will be emitted whenever the button gets released.
*/
/*!
\fn void GpioButton::longPressed();
This signal will be emitted whenever the button gets pressed for a certain time.
\sa longPressedTimeout(), repeateLongPressed()
*/
#include "gpiobutton.h"
#include "gpiomonitor.h"
GpioButton::GpioButton(int gpioNumber, QObject *parent) :
/*! Constructs a \l{GpioButton} object with the given \a gpio number and \a parent. */
GpioButton::GpioButton(int gpio, QObject *parent) :
QObject(parent),
m_gpioNumber(gpioNumber)
m_gpioNumber(gpio)
{
}
/*! Returns the gpio number for this GpioButton. */
int GpioButton::gpioNumber() const
{
return m_gpioNumber;
}
/*! Returns \c true the gpio button is configured as active low.
\sa Gpio::activeLow()
*/
bool GpioButton::activeLow() const
{
return m_activeLow;
}
/*! Sets the gpio button active low configuration to \a activeLow for this GpioButton.
\sa Gpio::setActiveLow()
*/
void GpioButton::setActiveLow(bool activeLow)
{
m_activeLow = activeLow;
}
/*! Returns \c true, if the \l{longPressed()} signal will be emited again if the button will be hold down. */
bool GpioButton::repeateLongPressed() const
{
return m_repeateLongPressed;
}
/*! Sets repeate long pressed configuration to \a repeateLongPressed. If \a repeateLongPressed is true, the longPressed() signal will be repeated as long the button will be hold down.
\sa longPressedTimeout()
*/
void GpioButton::setRepeateLongPressed(bool repeateLongPressed)
{
m_repeateLongPressed = repeateLongPressed;
}
/*! Returns the long pressed timout duration in milliseconds. If the button gets hold down for this duration, the longPressed() signal will be emitted.
\sa longPressed()
*/
int GpioButton::longPressedTimeout() const
{
return m_longPressedTimeout;
}
/*! Sets the long pressed timout duration to \a longPressedTimeout in milliseconds. If the button gets hold down for this duration, the longPressed() signal will be emitted.
\sa longPressed()
*/
void GpioButton::setLongPressedTimeout(int longPressedTimeout)
{
m_longPressedTimeout = longPressedTimeout;
}
/*! Returns the \c name for this GpioButton. This is optional, but will be printed in the debug operator. */
QString GpioButton::name() const
{
return m_name;
}
/*! Sets the \a name for this GpioButton. This is optional, but will be printed in the debug operator. */
void GpioButton::setName(const QString &name)
{
m_name = name;
@ -107,6 +179,7 @@ void GpioButton::onInterruptOccured(bool value)
}
}
/*! Returns \c true, if this GpioButton was enabled successfully. */
bool GpioButton::enable()
{
// Make sure we have a clean start
@ -133,6 +206,7 @@ bool GpioButton::enable()
return true;
}
/*! Disable this GpioButton. The Gpio will be unexported. */
void GpioButton::disable()
{
if (m_monitor) {
@ -146,6 +220,7 @@ void GpioButton::disable()
}
}
/*! Prints the given \a gpioButton to \a debug. */
QDebug operator<<(QDebug debug, GpioButton *gpioButton)
{
debug.nospace() << "GpioButton(" << gpioButton->gpioNumber() << ", ";

View File

@ -25,7 +25,12 @@
\brief Monitor for GPIO interrupts.
\inmodule nymea-gpio
This class allows to monitor an input GPIO for the interrupts depending on the \l{Gpio:Edge} configuration.
This class allows to monitor an input GPIO for the interrupts depending on the edge interrupt configuration.
This class will start a poll thread in the background. Depending on the Gpio::Edge configuration, the \l{interruptOccured()} signal
will be emitted. Default is Gpio::EdgeBoth which means the interrupt will be on rising and falling signal of the Gpio.
The behavior of the interrupt can also be inverted using the \l{activeLow()} parameter.
\code
GpioMonitor *monitor = new GpioMonitor(112, this);
@ -44,13 +49,15 @@
*/
/*! \fn void GpioMonitor::interruptOccured(bool value);
/*!
\fn void GpioMonitor::interruptOccured(bool value);
This signal will be emitted, if an interrupt on the monitored Gpio occured with the new \a value. This event depends on the Gpio::Edge configuration of the Gpio.
\sa edge(), setEdge()
*/
/*! \fn void GpioMonitor::enabledChanged(bool enabled);
/*!
\fn void GpioMonitor::enabledChanged(bool enabled);
This signal will be emitted when the GpioMonitor \a enabled changed.
*/
@ -76,21 +83,13 @@ GpioMonitor::~GpioMonitor()
wait(200);
}
/*! Returns the edge interrupt configuration for this GpioMonitor.
\sa Gpio::Edge
*/
/*! Returns the edge interrupt configuration for this GpioMonitor. */
Gpio::Edge GpioMonitor::edge() const
{
return m_edge;
}
/*! Sets the edge interrupt configuration for this GpioMonitor to the given \a edge.
\sa Gpio::Edge
*/
/*! Sets the edge interrupt configuration for this GpioMonitor to the given \a edge. */
void GpioMonitor::setEdge(Gpio::Edge edge)
{
if (m_edge == edge)