Merge PR #6: Fix a deadlock and some typos

This commit is contained in:
Jenkins nymea 2021-11-07 00:39:46 +01:00
commit cd11846be4
5 changed files with 15 additions and 11 deletions

View File

@ -164,7 +164,7 @@ void GpioButton::onTimeout()
emit longPressed(); emit longPressed();
} }
void GpioButton::onInterruptOccured(bool value) void GpioButton::onInterruptOccurred(bool value)
{ {
if (value) { if (value) {
// Pressed // Pressed
@ -206,7 +206,7 @@ bool GpioButton::enable()
m_monitor = nullptr; m_monitor = nullptr;
return false; return false;
} }
connect(m_monitor, &GpioMonitor::interruptOccured, this, &GpioButton::onInterruptOccured); connect(m_monitor, &GpioMonitor::interruptOccurred, this, &GpioButton::onInterruptOccurred);
// 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);

View File

@ -77,7 +77,7 @@ signals:
private slots: private slots:
void onTimeout(); void onTimeout();
void onInterruptOccured(bool value); void onInterruptOccurred(bool value);
public slots: public slots:
bool enable(); bool enable();

View File

@ -147,10 +147,10 @@ void GpioMonitor::setValue(Gpio::Value value)
switch (m_value) { switch (m_value) {
case Gpio::ValueLow: case Gpio::ValueLow:
emit interruptOccured(false); emit interruptOccurred(false);
break; break;
case Gpio::ValueHigh: case Gpio::ValueHigh:
emit interruptOccured(true); emit interruptOccurred(true);
break; break;
default: default:
break; break;
@ -219,8 +219,12 @@ void GpioMonitor::run()
} }
// Check if we should stop the thread // Check if we should stop the thread
QMutexLocker stopLocker(&m_stopMutex); m_stopMutex.lock();
if (m_stop) break; if (m_stop) {
m_stopMutex.unlock();
break;
}
m_stopMutex.unlock();
// No interrupt occured // No interrupt occured
if (rc == 0) if (rc == 0)
@ -264,7 +268,7 @@ void GpioMonitor::onThreadFinished()
/*! Returns true, if this GpioMonitor was enabled successfully. */ /*! Returns true, if this GpioMonitor was enabled successfully. */
bool GpioMonitor::enable() bool GpioMonitor::enable()
{ {
qCDebug(dcGpio()) << "Enable gpio monitor"; qCDebug(dcGpio()) << "Enabling gpio monitor";
if (isRunning()) { if (isRunning()) {
qCWarning(dcGpio()) << "This GPIO monitor is already running."; qCWarning(dcGpio()) << "This GPIO monitor is already running.";
return true; return true;
@ -287,7 +291,7 @@ bool GpioMonitor::enable()
/*! Disables this GpioMonitor. The \l{interruptOccured()} signal will not be emitted any more and the Gpio will be unexported. */ /*! Disables this GpioMonitor. The \l{interruptOccured()} signal will not be emitted any more and the Gpio will be unexported. */
void GpioMonitor::disable() void GpioMonitor::disable()
{ {
qCDebug(dcGpio()) << "Disable gpio monitor"; qCDebug(dcGpio()) << "Disabling gpio monitor";
// Stop the thread if not already disabled // Stop the thread if not already disabled
QMutexLocker locker(&m_stopMutex); QMutexLocker locker(&m_stopMutex);
if (m_stop) return; if (m_stop) return;

View File

@ -76,7 +76,7 @@ protected:
void run() override; void run() override;
signals: signals:
void interruptOccured(bool value); void interruptOccurred(bool value);
void enabledChanged(bool enabled); void enabledChanged(bool enabled);
private slots: private slots:

View File

@ -170,7 +170,7 @@ int main(int argc, char *argv[])
}); });
// Inform about interrupt // Inform about interrupt
QObject::connect(monitor, &GpioMonitor::interruptOccured, [gpioNumber](bool value) { QObject::connect(monitor, &GpioMonitor::interruptOccurred, [gpioNumber](bool value) {
qDebug() << "GPIO" << gpioNumber << "interrupt occured. Current value:" << (value ? "1" : "0"); qDebug() << "GPIO" << gpioNumber << "interrupt occured. Current value:" << (value ? "1" : "0");
}); });