Skip to content

Commit

Permalink
everal Issues Using QZ with Rouvy and Zwift Play Controllers (Issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
cagnulein committed Dec 21, 2024
1 parent 445646f commit ddfc60b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion src/zwift_play/abstractZapDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit ddfc60b

Please sign in to comment.