Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/devices/wahookickrsnapbike/wahookickrsnapbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ void wahookickrsnapbike::stateChanged(QLowEnergyService::ServiceState state) {

qDebug() << QStringLiteral("all services discovered!");

const QBluetoothUuid cyclingPowerMeasurementUuid = QBluetoothUuid::CyclingPowerMeasurement;

for (QLowEnergyService *s : qAsConst(gattCommunicationChannelService)) {
if (s->state() == QLowEnergyService::ServiceDiscovered) {
// establish hook into notifications
Expand Down Expand Up @@ -745,6 +747,15 @@ void wahookickrsnapbike::stateChanged(QLowEnergyService::ServiceState state) {
gattPowerChannelService = s;
}

// Only subscribe to CyclingPowerMeasurement to avoid a race where the
// descriptorWritten counter (17 descriptors on KICKR CORE) hasn't reached
// zero before Zwift sends the first indoor-bike-simulation-parameters
// write, causing setSimGrade to be sent without a prior setSimMode.
if (c.uuid() != cyclingPowerMeasurementUuid) {
qDebug() << QStringLiteral("skipping subscription for") << s->serviceUuid() << c.uuid();
continue;
}

if ((c.properties() & QLowEnergyCharacteristic::Notify) == QLowEnergyCharacteristic::Notify) {
QByteArray descriptor;
descriptor.append((char)0x01);
Expand Down Expand Up @@ -784,6 +795,15 @@ void wahookickrsnapbike::stateChanged(QLowEnergyService::ServiceState state) {
}
}

// If no CyclingPowerMeasurement subscription was established (e.g. device not yet
// advertising that characteristic), fire init immediately so setSimMode is always
// sent before the first setSimGrade arrives from Zwift.
if (!notificationSubscribed) {
qDebug() << QStringLiteral("No CyclingPowerMeasurement subscription established, firing init immediately");
initRequest = true;
emit connectedAndDiscovered();
}

// ******************************************* virtual bike init *************************************
if (!firstStateChanged && !this->hasVirtualDevice()
#ifdef Q_OS_IOS
Expand Down
Loading