Complete documentations
This commit is contained in:
parent
2dea4225e4
commit
4984618797
@ -39,35 +39,41 @@
|
|||||||
|
|
||||||
\code
|
\code
|
||||||
Gpio *gpioOut = new Gpio(23, this);
|
Gpio *gpioOut = new Gpio(23, this);
|
||||||
|
|
||||||
// Export Gpio
|
// Export Gpio
|
||||||
if (!gpioOut->exportGpio()) {
|
if (!gpioOut->exportGpio()) {
|
||||||
qWarning() << "Could not export Gpio" << gpioOut->gpioNumber();
|
qWarning() << "Could not export Gpio" << gpioOut->gpioNumber();
|
||||||
gpioOut->deleteLater();
|
gpioOut->deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure Gpio direction
|
// Configure Gpio direction
|
||||||
if (!gpioOut->setDirection(PiGpio::DirectionOutput)) {
|
if (!gpioOut->setDirection(PiGpio::DirectionOutput)) {
|
||||||
qWarning() << "Could not set direction of Gpio" << gpioOut->gpioNumber();
|
qWarning() << "Could not set direction of Gpio" << gpioOut->gpioNumber();
|
||||||
gpioOut->deleteLater();
|
gpioOut->deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpioOut->setValue(Gpio::ValueHigh)
|
gpioOut->setValue(Gpio::ValueHigh)
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
\code
|
\code
|
||||||
Gpio *gpioIn = new Gpio(24, this);
|
Gpio *gpioIn = new Gpio(24, this);
|
||||||
|
|
||||||
// Export Gpio
|
// Export Gpio
|
||||||
if (!gpioIn->exportGpio()) {
|
if (!gpioIn->exportGpio()) {
|
||||||
qWarning() << "Could not export Gpio" << gpioIn->gpioNumber();
|
qWarning() << "Could not export Gpio" << gpioIn->gpioNumber();
|
||||||
gpioIn->deleteLater();
|
gpioIn->deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure Gpio direction
|
// Configure Gpio direction
|
||||||
if (!gpioIn->setDirection(PiGpio::DirectionInput)) {
|
if (!gpioIn->setDirection(PiGpio::DirectionInput)) {
|
||||||
qWarning() << "Could not set direction of Gpio" << gpioIn->gpioNumber();
|
qWarning() << "Could not set direction of Gpio" << gpioIn->gpioNumber();
|
||||||
gpioIn->deleteLater();
|
gpioIn->deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Current value" << gpioIn->value();
|
qDebug() << "Current value" << gpioIn->value();
|
||||||
\endcode
|
\endcode
|
||||||
\sa GpioMonitor
|
\sa GpioMonitor
|
||||||
|
|||||||
@ -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 "gpiobutton.h"
|
||||||
#include "gpiomonitor.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),
|
QObject(parent),
|
||||||
m_gpioNumber(gpioNumber)
|
m_gpioNumber(gpio)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns the gpio number for this GpioButton. */
|
||||||
int GpioButton::gpioNumber() const
|
int GpioButton::gpioNumber() const
|
||||||
{
|
{
|
||||||
return m_gpioNumber;
|
return m_gpioNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns \c true the gpio button is configured as active low.
|
||||||
|
|
||||||
|
\sa Gpio::activeLow()
|
||||||
|
*/
|
||||||
bool GpioButton::activeLow() const
|
bool GpioButton::activeLow() const
|
||||||
{
|
{
|
||||||
return m_activeLow;
|
return m_activeLow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Sets the gpio button active low configuration to \a activeLow for this GpioButton.
|
||||||
|
|
||||||
|
\sa Gpio::setActiveLow()
|
||||||
|
*/
|
||||||
void GpioButton::setActiveLow(bool activeLow)
|
void GpioButton::setActiveLow(bool activeLow)
|
||||||
{
|
{
|
||||||
m_activeLow = 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
|
bool GpioButton::repeateLongPressed() const
|
||||||
{
|
{
|
||||||
return m_repeateLongPressed;
|
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)
|
void GpioButton::setRepeateLongPressed(bool repeateLongPressed)
|
||||||
{
|
{
|
||||||
m_repeateLongPressed = 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
|
int GpioButton::longPressedTimeout() const
|
||||||
{
|
{
|
||||||
return m_longPressedTimeout;
|
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)
|
void GpioButton::setLongPressedTimeout(int longPressedTimeout)
|
||||||
{
|
{
|
||||||
m_longPressedTimeout = 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
|
QString GpioButton::name() const
|
||||||
{
|
{
|
||||||
return m_name;
|
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)
|
void GpioButton::setName(const QString &name)
|
||||||
{
|
{
|
||||||
m_name = 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()
|
bool GpioButton::enable()
|
||||||
{
|
{
|
||||||
// Make sure we have a clean start
|
// Make sure we have a clean start
|
||||||
@ -133,6 +206,7 @@ bool GpioButton::enable()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Disable this GpioButton. The Gpio will be unexported. */
|
||||||
void GpioButton::disable()
|
void GpioButton::disable()
|
||||||
{
|
{
|
||||||
if (m_monitor) {
|
if (m_monitor) {
|
||||||
@ -146,6 +220,7 @@ void GpioButton::disable()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Prints the given \a gpioButton to \a debug. */
|
||||||
QDebug operator<<(QDebug debug, GpioButton *gpioButton)
|
QDebug operator<<(QDebug debug, GpioButton *gpioButton)
|
||||||
{
|
{
|
||||||
debug.nospace() << "GpioButton(" << gpioButton->gpioNumber() << ", ";
|
debug.nospace() << "GpioButton(" << gpioButton->gpioNumber() << ", ";
|
||||||
|
|||||||
@ -25,7 +25,12 @@
|
|||||||
\brief Monitor for GPIO interrupts.
|
\brief Monitor for GPIO interrupts.
|
||||||
\inmodule nymea-gpio
|
\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
|
\code
|
||||||
GpioMonitor *monitor = new GpioMonitor(112, this);
|
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.
|
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()
|
\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.
|
This signal will be emitted when the GpioMonitor \a enabled changed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -76,21 +83,13 @@ GpioMonitor::~GpioMonitor()
|
|||||||
wait(200);
|
wait(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the edge interrupt configuration for this GpioMonitor.
|
/*! Returns the edge interrupt configuration for this GpioMonitor. */
|
||||||
|
|
||||||
\sa Gpio::Edge
|
|
||||||
|
|
||||||
*/
|
|
||||||
Gpio::Edge GpioMonitor::edge() const
|
Gpio::Edge GpioMonitor::edge() const
|
||||||
{
|
{
|
||||||
return m_edge;
|
return m_edge;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Sets the edge interrupt configuration for this GpioMonitor to the given \a edge.
|
/*! Sets the edge interrupt configuration for this GpioMonitor to the given \a edge. */
|
||||||
|
|
||||||
\sa Gpio::Edge
|
|
||||||
|
|
||||||
*/
|
|
||||||
void GpioMonitor::setEdge(Gpio::Edge edge)
|
void GpioMonitor::setEdge(Gpio::Edge edge)
|
||||||
{
|
{
|
||||||
if (m_edge == edge)
|
if (m_edge == edge)
|
||||||
|
|||||||
Reference in New Issue
Block a user