Skip to content

Commit 01cac33

Browse files
committed
Confirm Stryd5 Indoor mode switch with pod ack, retry if missing
Andrea found (via BLE sniffing) that the Stryd5 pod acknowledges the 15 00/15 01 mode write on characteristic 7e78aa19, echoing the confirmed mode back in byte 2. Track that ack and resend the Indoor mode request (up to 3 times, 1s apart) if it's not received, in case the initial write is missed or the pod boots into Outdoor mode. Refs #4480
1 parent 926bcf1 commit 01cac33

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/devices/strydrunpowersensor/strydrunpowersensor.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,26 @@ void strydrunpowersensor::update() {
110110
sec1Update = 0;
111111
// updateDisplay(elapsed);
112112
}
113+
114+
if (strydIndoorModeRequested && !strydIndoorModeConfirmed && strydIndoorModeRetries < 3 &&
115+
strydIndoorModeRequestedAt.msecsTo(QDateTime::currentDateTime()) > 1000) {
116+
qDebug() << QStringLiteral("Stryd5: no ack for Indoor mode switch, retrying");
117+
requestStrydIndoorMode();
118+
}
113119
}
114120
}
115121

122+
void strydrunpowersensor::requestStrydIndoorMode() {
123+
if (!strydIndoorModeService || !strydIndoorModeChar.isValid())
124+
return;
125+
126+
qDebug() << QStringLiteral("Stryd5: switching power mode to Indoor");
127+
strydIndoorModeService->writeCharacteristic(strydIndoorModeChar, QByteArray::fromHex("1500"));
128+
strydIndoorModeRequested = true;
129+
strydIndoorModeRequestedAt = QDateTime::currentDateTime();
130+
strydIndoorModeRetries++;
131+
}
132+
116133
void strydrunpowersensor::serviceDiscovered(const QBluetoothUuid &gatt) {
117134
emit debug(QStringLiteral("serviceDiscovered ") + gatt.toString());
118135
}
@@ -506,6 +523,18 @@ void strydrunpowersensor::characteristicChanged(const QLowEnergyCharacteristic &
506523
//emit verticalOscillationChanged(VerticalOscillationMM.value());
507524
qDebug() << QStringLiteral("Current GroundContactMS:") << GroundContactMS.value();
508525
qDebug() << QStringLiteral("Current VerticalOscillationMM:") << VerticalOscillationMM.value();
526+
} else if (strydIndoorModeRequested && newValue.length() >= 3 && (uint8_t)newValue.at(0) == 0x15 &&
527+
(uint8_t)newValue.at(1) == 0x00) {
528+
// ack of the 15 00/15 01 mode switch written to 7e78aa18: byte 2 echoes back the confirmed
529+
// mode (0x00 = Indoor, 0x01 = Outdoor)
530+
uint8_t confirmedMode = (uint8_t)newValue.at(2);
531+
if (confirmedMode == 0x00) {
532+
strydIndoorModeConfirmed = true;
533+
qDebug() << QStringLiteral("Stryd5: Indoor mode confirmed by the pod");
534+
} else {
535+
qDebug() << QStringLiteral("Stryd5: pod acked mode ") << confirmedMode
536+
<< QStringLiteral(" instead of Indoor, will retry");
537+
}
509538
}
510539
}
511540

@@ -593,8 +622,9 @@ void strydrunpowersensor::stateChanged(QLowEnergyService::ServiceState state) {
593622
if (bluetoothDevice.name().startsWith(QStringLiteral("Stryd5"), Qt::CaseInsensitive) &&
594623
c.uuid() == QBluetoothUuid(QStringLiteral("7e78aa18-72cd-d3b8-a81f-5b7e589bea0f")) &&
595624
(c.properties() & QLowEnergyCharacteristic::Write)) {
596-
qDebug() << QStringLiteral("Stryd5: switching power mode to Indoor");
597-
s->writeCharacteristic(c, QByteArray::fromHex("1500"));
625+
strydIndoorModeService = s;
626+
strydIndoorModeChar = c;
627+
requestStrydIndoorMode();
598628
}
599629

600630
qDebug() << QStringLiteral("char uuid") << c.uuid() << QStringLiteral("handle") << c.handle();

src/devices/strydrunpowersensor/strydrunpowersensor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ class strydrunpowersensor : public treadmill {
7878

7979
bool FORERUNNER = false;
8080

81+
QLowEnergyService *strydIndoorModeService = nullptr;
82+
QLowEnergyCharacteristic strydIndoorModeChar;
83+
bool strydIndoorModeRequested = false;
84+
bool strydIndoorModeConfirmed = false;
85+
uint8_t strydIndoorModeRetries = 0;
86+
QDateTime strydIndoorModeRequestedAt;
87+
void requestStrydIndoorMode();
88+
8189
#ifdef Q_OS_IOS
8290
lockscreen *h = 0;
8391
#endif

0 commit comments

Comments
 (0)