From 7fea2d442f9464051456e132581008de7ca31cc8 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Wed, 25 Dec 2024 11:17:52 +0100 Subject: [PATCH] Several Issues Using QZ with Rouvy and Zwift Play Controllers (Issue #2541) --- src/zwift_play/abstractZapDevice.h | 23 ++++++++++++++++++----- src/zwift_play/zwiftclickremote.cpp | 3 +++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/zwift_play/abstractZapDevice.h b/src/zwift_play/abstractZapDevice.h index 880f5aeb3..6acf9f5dc 100755 --- a/src/zwift_play/abstractZapDevice.h +++ b/src/zwift_play/abstractZapDevice.h @@ -29,16 +29,23 @@ class AbstractZapDevice: public QObject { QByteArray REQUEST_START; QByteArray RESPONSE_START; - AbstractZapDevice() : autoRepeatTimer(new QTimer(this)) { + AbstractZapDevice() { RIDE_ON = QByteArray::fromRawData("\x52\x69\x64\x65\x4F\x6E", 6); // "RideOn" REQUEST_START = QByteArray::fromRawData("\x00\x09", 2); // {0, 9} RESPONSE_START = QByteArray::fromRawData("\x01\x03", 2); // {1, 3} // Setup auto-repeat + autoRepeatTimer = new QTimer(); autoRepeatTimer->setInterval(500); connect(autoRepeatTimer, &QTimer::timeout, this, &AbstractZapDevice::handleAutoRepeat); } + ~AbstractZapDevice() { + if (autoRepeatTimer) { + autoRepeatTimer->stop(); + } + } + int processCharacteristic(const QString& characteristicName, const QByteArray& bytes, ZWIFT_PLAY_TYPE zapType) { if (bytes.isEmpty()) return 0; @@ -322,13 +329,19 @@ class AbstractZapDevice: public QObject { private: QByteArray devicePublicKeyBytes; static volatile int8_t risingEdge; - QTimer* autoRepeatTimer; // Timer for auto-repeat - bool lastButtonPlus = false; // Track which button was last pressed - QDateTime lastFrame = QDateTime::currentDateTime(); + static QTimer* autoRepeatTimer; // Static timer for auto-repeat + static bool lastButtonPlus; // Static track of which button was last pressed + static QDateTime lastFrame; private slots: void handleAutoRepeat() { - qDebug() << "gear auto repeat" << lastButtonPlus << lastFrame; + uint64_t delta = lastFrame.msecsTo(QDateTime::currentDateTime()); + qDebug() << "gear auto repeat" << lastButtonPlus << lastFrame << delta; + if(delta > 500) { + qDebug() << "stopping repeat timer"; + autoRepeatTimer->stop(); + return; + } if(lastButtonPlus) emit plus(); else diff --git a/src/zwift_play/zwiftclickremote.cpp b/src/zwift_play/zwiftclickremote.cpp index 7ae9aa489..f731ec0e0 100755 --- a/src/zwift_play/zwiftclickremote.cpp +++ b/src/zwift_play/zwiftclickremote.cpp @@ -15,6 +15,9 @@ extern quint8 QZ_EnableDiscoveryCharsAndDescripttors; #endif volatile int8_t AbstractZapDevice::risingEdge = 0; +QTimer* AbstractZapDevice::autoRepeatTimer = nullptr; +bool AbstractZapDevice::lastButtonPlus = false; +QDateTime AbstractZapDevice::lastFrame = QDateTime::currentDateTime(); zwiftclickremote::zwiftclickremote(bluetoothdevice *parentDevice, AbstractZapDevice::ZWIFT_PLAY_TYPE typeZap) { #ifdef Q_OS_IOS