Skip to content

Commit

Permalink
Several 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 25, 2024
1 parent 7427676 commit 7fea2d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/zwift_play/abstractZapDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/zwift_play/zwiftclickremote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7fea2d4

Please sign in to comment.