mirror of https://github.com/nymea/nymea-gpio
Fix gpio button
parent
4e6081ef60
commit
81200a0d63
|
|
@ -198,14 +198,14 @@ bool GpioButton::enable()
|
||||||
m_monitor = nullptr;
|
m_monitor = nullptr;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
connect(m_monitor, &GpioMonitor::interruptOccured, this, &GpioButton::onInterruptOccured, Qt::DirectConnection);
|
connect(m_monitor, &GpioMonitor::interruptOccured, this, &GpioButton::onInterruptOccured);
|
||||||
|
|
||||||
// Setup timer, if this timer reaches timeout, a long pressed happend
|
// Setup timer, if this timer reaches timeout, a long pressed happend
|
||||||
m_timer = new QTimer(this);
|
m_timer = new QTimer(this);
|
||||||
m_timer->setTimerType(Qt::PreciseTimer);
|
m_timer->setTimerType(Qt::PreciseTimer);
|
||||||
m_timer->setSingleShot(!m_repeateLongPressed);
|
m_timer->setSingleShot(!m_repeateLongPressed);
|
||||||
m_timer->setInterval(m_longPressedTimeout);
|
m_timer->setInterval(m_longPressedTimeout);
|
||||||
connect(m_timer, &QTimer::timeout, this, &GpioButton::onTimeout, Qt::DirectConnection);
|
connect(m_timer, &QTimer::timeout, this, &GpioButton::onTimeout);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,38 +157,33 @@ void GpioMonitor::setEnabled(bool enabled)
|
||||||
void GpioMonitor::run()
|
void GpioMonitor::run()
|
||||||
{
|
{
|
||||||
// Create GPIO in the thread for initialisation
|
// Create GPIO in the thread for initialisation
|
||||||
Gpio *inputGpio = new Gpio(m_gpioNumber);
|
Gpio inputGpio(m_gpioNumber);
|
||||||
if (!inputGpio->exportGpio()) {
|
if (!inputGpio.exportGpio()) {
|
||||||
qCWarning(dcGpio()) << "Could not enable GPIO monitor.";
|
qCWarning(dcGpio()) << "Could not enable GPIO monitor.";
|
||||||
delete inputGpio;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputGpio->setDirection(Gpio::DirectionInput)) {
|
if (!inputGpio.setDirection(Gpio::DirectionInput)) {
|
||||||
qCWarning(dcGpio()) << "Could not enable GPIO monitor.";
|
qCWarning(dcGpio()) << "Could not enable GPIO monitor.";
|
||||||
delete inputGpio;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputGpio->setEdgeInterrupt(m_edge)) {
|
if (!inputGpio.setEdgeInterrupt(m_edge)) {
|
||||||
qCWarning(dcGpio()) << "Could not set interrupt for the GPIO monitor.";
|
qCWarning(dcGpio()) << "Could not set interrupt for the GPIO monitor.";
|
||||||
delete inputGpio;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputGpio->setActiveLow(m_activeLow)) {
|
if (!inputGpio.setActiveLow(m_activeLow)) {
|
||||||
qCWarning(dcGpio()) << "Could not set active low for the GPIO monitor.";
|
qCWarning(dcGpio()) << "Could not set active low for the GPIO monitor.";
|
||||||
delete inputGpio;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// In order to do correctly, use poll (2) according to the kernel documentation
|
// In order to do correctly, use poll (2) according to the kernel documentation
|
||||||
// https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
|
// https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
|
||||||
QFile valueFile(inputGpio->gpioDirectory() + QDir::separator() + "value");
|
QFile valueFile(inputGpio.gpioDirectory() + QDir::separator() + "value");
|
||||||
if (!valueFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (!valueFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
qCWarning(dcGpio()) << "Could not open GPIO" << inputGpio << "value file:" << valueFile.errorString();
|
qCWarning(dcGpio()) << "Could not open GPIO" << &inputGpio << "value file:" << valueFile.errorString();
|
||||||
delete inputGpio;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,7 +201,7 @@ void GpioMonitor::run()
|
||||||
|
|
||||||
// Poll failed...
|
// Poll failed...
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
qCWarning(dcGpio()) << "Failed to poll" << inputGpio;
|
qCWarning(dcGpio()) << "Failed to poll" << &inputGpio;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,7 +218,7 @@ void GpioMonitor::run()
|
||||||
QString valueString;
|
QString valueString;
|
||||||
QTextStream readStream(&valueFile);
|
QTextStream readStream(&valueFile);
|
||||||
if (!readStream.seek(0)) {
|
if (!readStream.seek(0)) {
|
||||||
qCWarning(dcGpio()) << "Failed to seek value file of" << inputGpio;
|
qCWarning(dcGpio()) << "Failed to seek value file of" << &inputGpio;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,7 +234,6 @@ void GpioMonitor::run()
|
||||||
|
|
||||||
// Clean up once done
|
// Clean up once done
|
||||||
valueFile.close();
|
valueFile.close();
|
||||||
delete inputGpio;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GpioMonitor::onThreadStarted()
|
void GpioMonitor::onThreadStarted()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue