Skip to content

Commit

Permalink
Tactile Feedback for Zwift Play controllers (and Ride?) (Issue #2752) (
Browse files Browse the repository at this point in the history
…#2753)

* Tactile Feedback for Zwift Play controllers (and Ride?) (Issue #2752)

* it works!

* vibrate on the right controller
  • Loading branch information
cagnulein authored Dec 28, 2024
1 parent d176779 commit 486c90a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4213,7 +4213,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 985;
CURRENT_PROJECT_VERSION = 986;
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = "ADB_HOST=1";
Expand Down Expand Up @@ -4407,7 +4407,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 985;
CURRENT_PROJECT_VERSION = 986;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -4637,7 +4637,7 @@
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 985;
CURRENT_PROJECT_VERSION = 986;
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -4733,7 +4733,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 985;
CURRENT_PROJECT_VERSION = 986;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 6335M7T29D;
ENABLE_BITCODE = YES;
Expand Down Expand Up @@ -4825,7 +4825,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 985;
CURRENT_PROJECT_VERSION = 986;
DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\"";
ENABLE_BITCODE = YES;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -4939,7 +4939,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 985;
CURRENT_PROJECT_VERSION = 986;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\"";
ENABLE_BITCODE = YES;
Expand Down
24 changes: 24 additions & 0 deletions src/devices/bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2843,6 +2843,8 @@ void bluetooth::connectedAndDiscovered() {
connect(zwiftPlayDevice.last(), &zwiftclickremote::debug, this, &bluetooth::debug);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::plus, (bike*)this->device(), &bike::gearUp);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::minus, (bike*)this->device(), &bike::gearDown);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::plus, this, &bluetooth::gearUp);
connect(zwiftPlayDevice.last()->playDevice, &ZwiftPlayDevice::minus, this, &bluetooth::gearDown);
zwiftPlayDevice.last()->deviceDiscovered(b);
if(homeform::singleton())
homeform::singleton()->setToastRequested("Zwift Play/Ride Connected!");
Expand Down Expand Up @@ -2918,6 +2920,28 @@ void bluetooth::connectedAndDiscovered() {
firstConnected = false;
}

void bluetooth::gearUp() {
QSettings settings;
bool zwiftplay_swap = settings.value(QZSettings::zwiftplay_swap, QZSettings::default_zwiftplay_swap).toBool();
foreach(zwiftclickremote* p, zwiftPlayDevice) {
if((p->typeZap == AbstractZapDevice::LEFT && !zwiftplay_swap) || (p->typeZap == AbstractZapDevice::RIGHT && zwiftplay_swap)) {
p->vibrate();
return;
}
}
}

void bluetooth::gearDown() {
QSettings settings;
bool zwiftplay_swap = settings.value(QZSettings::zwiftplay_swap, QZSettings::default_zwiftplay_swap).toBool();
foreach(zwiftclickremote* p, zwiftPlayDevice) {
if((p->typeZap == AbstractZapDevice::RIGHT && !zwiftplay_swap) || (p->typeZap == AbstractZapDevice::LEFT && zwiftplay_swap)) {
p->vibrate();
return;
}
}
}

void bluetooth::heartRate(uint8_t heart) { Q_UNUSED(heart) }

void bluetooth::restart() {
Expand Down
2 changes: 2 additions & 0 deletions src/devices/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ class bluetooth : public QObject, public SignalHandler {
void speedChanged(double);
void inclinationChanged(double, double);
void connectedAndDiscovered();
void gearDown();
void gearUp();

signals:
};
Expand Down
11 changes: 9 additions & 2 deletions src/zwift_play/zwiftclickremote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ zwiftclickremote::zwiftclickremote(bluetoothdevice *parentDevice, AbstractZapDev
void zwiftclickremote::update() {
if (initRequest && !initDone) {
initRequest = false;
initDone = true;
QByteArray s = playDevice->buildHandshakeStart();
qDebug() << s.length();
writeCharacteristic(gattWrite1Service, &gattWrite1Characteristic, (uint8_t *) s.data(), s.length(), "handshakeStart");
initDone = true;
} else if(initDone) {
countRxTimeout++;
if(countRxTimeout == 10) {
Expand Down Expand Up @@ -121,7 +121,8 @@ void zwiftclickremote::writeCharacteristic(QLowEnergyService *service, QLowEnerg
qDebug() << QStringLiteral(" >> ") + writeBuffer->toHex(' ') + QStringLiteral(" // ") + info;
}

loop.exec();
if(wait_for_response) // without this, it crashes on ios after sometimes
loop.exec();
}

void zwiftclickremote::stateChanged(QLowEnergyService::ServiceState state) {
Expand Down Expand Up @@ -313,3 +314,9 @@ void zwiftclickremote::controllerStateChanged(QLowEnergyController::ControllerSt
m_control->connectToDevice();
}
}

void zwiftclickremote::vibrate() {
if(!initDone) return;
QByteArray s = QByteArray::fromHex("1212080A06080210001820");
writeCharacteristic(gattWrite1Service, &gattWrite1Characteristic, (uint8_t *) s.data(), s.length(), "vibrate", false, false);
}
5 changes: 3 additions & 2 deletions src/zwift_play/zwiftclickremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class zwiftclickremote : public bluetoothdevice {
zwiftclickremote(bluetoothdevice *parentDevice, AbstractZapDevice::ZWIFT_PLAY_TYPE typeZap);
bool connected() override;
ZwiftPlayDevice* playDevice = new ZwiftPlayDevice();
void vibrate();
AbstractZapDevice::ZWIFT_PLAY_TYPE typeZap = AbstractZapDevice::NONE;

private:
QList<QLowEnergyService *> gattCommunicationChannelService;
Expand All @@ -45,13 +47,12 @@ class zwiftclickremote : public bluetoothdevice {

void writeCharacteristic(QLowEnergyService *service, QLowEnergyCharacteristic *writeChar, uint8_t *data,
uint8_t data_len, const QString &info, bool disable_log = false,
bool wait_for_response = false);
bool wait_for_response = false);

bluetoothdevice *parentDevice = nullptr;

bool initDone = false;
bool initRequest = false;
AbstractZapDevice::ZWIFT_PLAY_TYPE typeZap = AbstractZapDevice::NONE;

QTimer *refresh;

Expand Down

0 comments on commit 486c90a

Please sign in to comment.