Skip to content

Commit 497b76c

Browse files
committed
Update ftmsbike.cpp
1 parent d03e8f1 commit 497b76c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/devices/ftmsbike/ftmsbike.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ void ftmsbike::init() {
131131
if (initDone)
132132
return;
133133

134+
if (USDC_D700) {
135+
// This bike may emit a few spontaneous FTMS frames before we request control.
136+
// Reset the counter here so post-init resistance writes wait for fresh frames
137+
// that confirm the stream survived the control-point handshake.
138+
usdc_d700_ftms_frames_received = 0;
139+
}
140+
134141
if(ICSE || HAMMER) {
135142
uint8_t write[] = {FTMS_REQUEST_CONTROL};
136143
bool ret = writeCharacteristic(write, sizeof(write), "requestControl", false, true);
@@ -1775,6 +1782,16 @@ void ftmsbike::descriptorWritten(const QLowEnergyDescriptor &descriptor, const Q
17751782
static bool connectedAndDiscoveredOk = false;
17761783
emit debug(QStringLiteral("descriptorWritten ") + descriptor.name() + QStringLiteral(" ") + newValue.toHex(' '));
17771784

1785+
if (USDC_D700 && gattWriteCharControlPointId.isValid()) {
1786+
const auto controlPointCccd =
1787+
gattWriteCharControlPointId.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
1788+
if (controlPointCccd.isValid() && descriptor.handle() == controlPointCccd.handle() &&
1789+
newValue == QByteArray::fromHex("0200")) {
1790+
qDebug() << "USDC-D700 control point indication subscribed, sending early init";
1791+
init();
1792+
}
1793+
}
1794+
17781795
initRequest = true;
17791796
if(!connectedAndDiscoveredOk) {
17801797
connectedAndDiscoveredOk = true;
@@ -2089,6 +2106,7 @@ void ftmsbike::controllerStateChanged(QLowEnergyController::ControllerState stat
20892106
if (state == QLowEnergyController::UnconnectedState && m_control) {
20902107
qDebug() << QStringLiteral("trying to connect back again...");
20912108
initDone = false;
2109+
usdc_d700_ftms_frames_received = 0;
20922110
gearInclinationSent = false;
20932111
m_control->connectToDevice();
20942112
}

0 commit comments

Comments
 (0)