From 575203aeaf9fd284c3b25ae2d5f1b83397c7d61d Mon Sep 17 00:00:00 2001 From: nymea Date: Thu, 8 Aug 2019 17:19:48 +0200 Subject: [PATCH] fix long pressed event --- senic/devicepluginsenic.cpp | 1 + senic/nuimo.cpp | 19 ++++++++----------- senic/nuimo.h | 1 - 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/senic/devicepluginsenic.cpp b/senic/devicepluginsenic.cpp index c8cfa066..da922927 100644 --- a/senic/devicepluginsenic.cpp +++ b/senic/devicepluginsenic.cpp @@ -80,6 +80,7 @@ Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) connect(nuimo, &Nuimo::rotationValueChanged, this, &DevicePluginSenic::onRotationValueChanged); connect(nuimo, &Nuimo::connectedChanged, this, &DevicePluginSenic::onConnectedChanged); connect(nuimo, &Nuimo::deviceInformationChanged, this, &DevicePluginSenic::onDeviceInformationChanged); + connect(nuimo, &Nuimo::batteryValueChanged, this, &DevicePluginSenic::onBatteryValueChanged); m_nuimos.insert(nuimo, device); nuimo->bluetoothDevice()->connectDevice(); diff --git a/senic/nuimo.cpp b/senic/nuimo.cpp index 9501471d..818e2d34 100644 --- a/senic/nuimo.cpp +++ b/senic/nuimo.cpp @@ -290,11 +290,7 @@ void Nuimo::printService(QLowEnergyService *service) void Nuimo::onLongPressTimer() { - if (m_buttonPressed) { - emit buttonLongPressed(); - } else { - emit buttonPressed(); - } + emit buttonLongPressed(); } @@ -503,15 +499,16 @@ void Nuimo::onInputServiceStateChanged(const QLowEnergyService::ServiceState &st void Nuimo::onInputCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value) { if (characteristic.uuid() == m_inputButtonCharacteristic.uuid()) { - m_buttonPressed = (bool)value.toHex().toUInt(nullptr, 16); - qCDebug(dcSenic()) << "Button:" << (m_buttonPressed ? "pressed": "released"); - if (m_buttonPressed) { - //emit buttonPressed(); + bool pressed = (bool)value.toHex().toUInt(nullptr, 16); + qCDebug(dcSenic()) << "Button:" << (pressed ? "pressed": "released"); + if (pressed) { m_longPressTimer->start(m_longPressTime); } else { - if (!m_longPressTimer->isActive()) + if (m_longPressTimer->isActive()) { m_longPressTimer->stop(); - emit buttonLongPressed(); + emit buttonPressed(); + } + // else the time run out and has the long pressed event emittted } return; } diff --git a/senic/nuimo.h b/senic/nuimo.h index b51f04f9..71a040d0 100644 --- a/senic/nuimo.h +++ b/senic/nuimo.h @@ -82,7 +82,6 @@ private: uint m_rotationValue; QTimer *m_longPressTimer = nullptr; int m_longPressTime = 250; - bool m_buttonPressed = false; void showMatrix(const QByteArray &matrix, const int &seconds); void printService(QLowEnergyService *service);