@@ -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+
116133void 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 ();
0 commit comments