From dabaf34bae54392498cfb608e47f76117006cbaa Mon Sep 17 00:00:00 2001 From: loosrob <79396812+loosrob@users.noreply.github.com> Date: Mon, 1 May 2023 16:59:46 +0200 Subject: [PATCH] Fix press/rotation repeated forever --- philipshue/huetapdial.cpp | 20 ++++++++++---------- philipshue/huetapdial.h | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/philipshue/huetapdial.cpp b/philipshue/huetapdial.cpp index cdc6df99..f19184e1 100644 --- a/philipshue/huetapdial.cpp +++ b/philipshue/huetapdial.cpp @@ -111,16 +111,16 @@ void HueTapDial::updateStates(const QVariantMap &sensorMap) // If rotated if (sensorMap.value("uniqueid").toString() == m_rotaryUuid) { - QString lastUpdate = stateMap.value("lastupdated").toString(); + QString lastUpdateRotation = stateMap.value("lastupdated").toString(); int rotationCode = stateMap.value("expectedrotation").toInt(); // If we never polled, just store lastUpdate/rotationCode and not emit a false rotated event - if (m_lastUpdate.isEmpty() || m_lastRotationCode == 0) { - m_lastUpdate = lastUpdate; + if (m_lastUpdateRotation.isEmpty() || m_lastRotationCode == 0) { + m_lastUpdateRotation = lastUpdateRotation; m_lastRotationCode = rotationCode; } - if (m_lastUpdate != lastUpdate || m_lastRotationCode != rotationCode) { - m_lastUpdate = lastUpdate; + if (m_lastUpdateRotation != lastUpdateRotation || m_lastRotationCode != rotationCode) { + m_lastUpdateRotation = lastUpdateRotation; m_lastRotationCode = rotationCode; qCDebug(dcPhilipsHue) << "rotated" << rotationCode; emit rotated(rotationCode); @@ -129,16 +129,16 @@ void HueTapDial::updateStates(const QVariantMap &sensorMap) // If button press if (sensorMap.value("uniqueid").toString() == m_switchUuid) { - QString lastUpdate = stateMap.value("lastupdated").toString(); + QString lastUpdateButton = stateMap.value("lastupdated").toString(); int buttonCode = stateMap.value("buttonevent").toInt(); // If we never polled, just store lastUpdate/buttonCode and not emit a false button pressed event - if (m_lastUpdate.isEmpty() || m_lastButtonCode == -1) { - m_lastUpdate = lastUpdate; + if (m_lastUpdateButton.isEmpty() || m_lastButtonCode == -1) { + m_lastUpdateButton = lastUpdateButton; m_lastButtonCode = buttonCode; } - if (m_lastUpdate != lastUpdate || m_lastButtonCode != buttonCode) { - m_lastUpdate = lastUpdate; + if (m_lastUpdateButton != lastUpdateButton || m_lastButtonCode != buttonCode) { + m_lastUpdateButton = lastUpdateButton; m_lastButtonCode = buttonCode; qCDebug(dcPhilipsHue) << "button pressed" << buttonCode; emit buttonPressed(buttonCode); diff --git a/philipshue/huetapdial.h b/philipshue/huetapdial.h index 546f251a..54643199 100644 --- a/philipshue/huetapdial.h +++ b/philipshue/huetapdial.h @@ -84,7 +84,8 @@ private: QString m_switchUuid; // States - QString m_lastUpdate; + QString m_lastUpdateButton; + QString m_lastUpdateRotation; double m_level = 0; int m_batteryLevel = 0; int m_lastButtonCode = -1;