From ddfc60bbf56046a8c1b98a5866d3158adeac5b8f Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Sat, 21 Dec 2024 16:24:52 +0100 Subject: [PATCH] everal Issues Using QZ with Rouvy and Zwift Play Controllers (Issue #2541) https://github.com/cagnulein/qdomyos-zwift/issues/2541#issuecomment-2557707654 --- .../qdomyoszwift.xcodeproj/project.pbxproj | 12 ++++++------ src/zwift_play/abstractZapDevice.h | 14 +++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/build-qdomyos-zwift-Qt_5_15_2_for_iOS-Debug/qdomyoszwift.xcodeproj/project.pbxproj b/build-qdomyos-zwift-Qt_5_15_2_for_iOS-Debug/qdomyoszwift.xcodeproj/project.pbxproj index 704d72889..2033bf31c 100644 --- a/build-qdomyos-zwift-Qt_5_15_2_for_iOS-Debug/qdomyoszwift.xcodeproj/project.pbxproj +++ b/build-qdomyos-zwift-Qt_5_15_2_for_iOS-Debug/qdomyoszwift.xcodeproj/project.pbxproj @@ -4197,7 +4197,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 976; + CURRENT_PROJECT_VERSION = 978; DEVELOPMENT_TEAM = 6335M7T29D; ENABLE_BITCODE = NO; GCC_PREPROCESSOR_DEFINITIONS = "ADB_HOST=1"; @@ -4391,7 +4391,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 976; + CURRENT_PROJECT_VERSION = 978; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = 6335M7T29D; ENABLE_BITCODE = NO; @@ -4621,7 +4621,7 @@ CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 976; + CURRENT_PROJECT_VERSION = 978; DEVELOPMENT_TEAM = 6335M7T29D; ENABLE_BITCODE = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -4717,7 +4717,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 976; + CURRENT_PROJECT_VERSION = 978; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = 6335M7T29D; ENABLE_BITCODE = YES; @@ -4809,7 +4809,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 976; + CURRENT_PROJECT_VERSION = 978; DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\""; ENABLE_BITCODE = YES; ENABLE_PREVIEWS = YES; @@ -4923,7 +4923,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 976; + CURRENT_PROJECT_VERSION = 978; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\""; ENABLE_BITCODE = YES; diff --git a/src/zwift_play/abstractZapDevice.h b/src/zwift_play/abstractZapDevice.h index 607b8f7dd..a2d466ef2 100755 --- a/src/zwift_play/abstractZapDevice.h +++ b/src/zwift_play/abstractZapDevice.h @@ -40,6 +40,7 @@ class AbstractZapDevice: public QObject { RESPONSE_START = QByteArray::fromRawData("\x01\x03", 2); // {1, 3} buttonState = OFF; lastButtonCheck = QDateTime::currentDateTime(); + lastValidFrame = QDateTime::currentDateTime(); } int processCharacteristic(const QString& characteristicName, const QByteArray& bytes, ZWIFT_PLAY_TYPE zapType) { @@ -51,9 +52,16 @@ class AbstractZapDevice: public QObject { qDebug() << zapType << characteristicName << bytes.toHex() << zwiftplay_swap << gears_volume_debouncing << risingEdge; + QDateTime currentTime = QDateTime::currentDateTime(); + + // Check for timeout on valid frames (reset after 1 second of no valid frames) + if (buttonState != OFF && lastValidFrame.msecsTo(currentTime) > 400) { + buttonState = OFF; + return 1; + } + // Check if enough time has passed (500ms) and button is still pressed if (buttonState != OFF) { - QDateTime currentTime = QDateTime::currentDateTime(); if (lastButtonCheck.msecsTo(currentTime) >= 500) { lastButtonCheck = currentTime; if (buttonState == PLUS_PRESSED) { @@ -85,6 +93,7 @@ class AbstractZapDevice: public QObject { #else switch(bytes[0]) { case 0x37: + lastValidFrame = currentTime; if(bytes.length() == 5) { if(bytes[2] == 0) { if(DEBOUNCE) { @@ -124,6 +133,7 @@ class AbstractZapDevice: public QObject { } break; case 0x07: // zwift play + lastValidFrame = currentTime; if(bytes.length() > 5 && bytes[bytes.length() - 5] == 0x40 && ( (((uint8_t)bytes[bytes.length() - 4]) == 0xc7 && zapType == RIGHT) || (((uint8_t)bytes[bytes.length() - 4]) == 0xc8 && zapType == LEFT) @@ -199,6 +209,7 @@ class AbstractZapDevice: public QObject { qDebug() << "ignoring this frame"; return 1; case 0x23: // zwift ride + lastValidFrame = currentTime; if(bytes.length() > 12 && ((((uint8_t)bytes[12]) == 0xc7 && zapType == RIGHT) || (((uint8_t)bytes[12]) == 0xc8 && zapType == LEFT)) @@ -337,6 +348,7 @@ class AbstractZapDevice: public QObject { static volatile int8_t risingEdge; BUTTON_STATE buttonState; QDateTime lastButtonCheck; + QDateTime lastValidFrame; // Timestamp of last valid frame signals: void plus();