Skip to content

Commit

Permalink
Wellfit treadmill support #2659 (#2686)
Browse files Browse the repository at this point in the history
* n Wellfit treadmill support #2659

* Update horizontreadmill.cpp
  • Loading branch information
cagnulein authored Oct 22, 2024
1 parent a2009fa commit 637b571
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/devices/horizontreadmill/horizontreadmill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,15 @@ void horizontreadmill::btinit() {
messageID = 0x10;
}

if(wellfit_treadmill) {
uint8_t write[] = {FTMS_REQUEST_CONTROL};
writeCharacteristic(gattFTMSService, gattWriteCharControlPointId, write, sizeof(write), "requestControl", false,
false);
QThread::msleep(500);
writeCharacteristic(gattFTMSService, gattWriteCharControlPointId, write, sizeof(write), "requestControl", false,
false);
}

initDone = true;
}

Expand Down Expand Up @@ -1140,7 +1149,7 @@ void horizontreadmill::forceSpeed(double requestSpeed) {
}
} else if (gattFTMSService) {
// for the Tecnogym Myrun
if(!anplus_treadmill && !trx3500_treadmill) {
if(!anplus_treadmill && !trx3500_treadmill && !wellfit_treadmill) {
uint8_t write[] = {FTMS_REQUEST_CONTROL};
writeCharacteristic(gattFTMSService, gattWriteCharControlPointId, write, sizeof(write), "requestControl", false,
false);
Expand Down Expand Up @@ -2128,9 +2137,9 @@ void horizontreadmill::stateChanged(QLowEnergyService::ServiceState state) {

auto characteristics_list = s->characteristics();
for (const QLowEnergyCharacteristic &c : qAsConst(characteristics_list)) {
qDebug() << QStringLiteral("char uuid") << c.uuid() << QStringLiteral("handle") << c.handle();
qDebug() << QStringLiteral("char uuid") << c.uuid() << QStringLiteral("handle") << c.handle() << c.properties();

if (c.properties() & QLowEnergyCharacteristic::Write && c.uuid() == _gattWriteCharControlPointId) {
if (c.uuid() == _gattWriteCharControlPointId) {
qDebug() << QStringLiteral("FTMS service and Control Point found");
gattWriteCharControlPointId = c;
gattFTMSService = s;
Expand All @@ -2141,10 +2150,10 @@ void horizontreadmill::stateChanged(QLowEnergyService::ServiceState state) {
// some treadmills doesn't have the control point and also are Cross Trainer devices so i need
// anyway to get the FTMS Service at least
gattFTMSService = s;
} else if (c.uuid() == _gattInclinationSupported) {
}/* else if (c.uuid() == _gattInclinationSupported) {
s->readCharacteristic(c);
qDebug() << s->serviceUuid() << c.uuid() << "reading!";
}
}*/

if (c.properties() & QLowEnergyCharacteristic::Write && c.uuid() == _gattWriteCharCustomService &&
!settings
Expand Down Expand Up @@ -2188,6 +2197,24 @@ void horizontreadmill::stateChanged(QLowEnergyService::ServiceState state) {
}

qDebug() << s->serviceUuid() << c.uuid() << QStringLiteral("notification subscribed!");
} else if ((c.properties() & QLowEnergyCharacteristic::Indicate) == QLowEnergyCharacteristic::Indicate &&
// if it's a FTMS treadmill and has FTMS and/or RSC service too
((((gattFTMSService && s->serviceUuid() == gattFTMSService->serviceUuid()))
&& !gattCustomService))) {
QByteArray descriptor;
descriptor.append((char)0x02);
descriptor.append((char)0x00);
if (c.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration).isValid()) {
s->writeDescriptor(c.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), descriptor);
notificationSubscribed++;
} else {
qDebug() << QStringLiteral("ClientCharacteristicConfiguration") << c.uuid()
<< c.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration).uuid()
<< c.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration).handle()
<< QStringLiteral(" is not valid");
}

qDebug() << s->serviceUuid() << c.uuid() << QStringLiteral("indication subscribed!");
}
}
}
Expand Down Expand Up @@ -2320,6 +2347,9 @@ void horizontreadmill::deviceDiscovered(const QBluetoothDeviceInfo &device) {
} else if (device.name().toUpper().startsWith(QStringLiteral("KETTLER TREADMILL"))) {
kettler_treadmill = true;
qDebug() << QStringLiteral("KETTLER TREADMILL workaround ON!");
} else if (device.name().toUpper().startsWith(QStringLiteral("WELLFIT TM"))) {
wellfit_treadmill = true;
qDebug() << QStringLiteral("WELLFIT TREADMILL workaround ON!");
} else if (device.name().toUpper().startsWith(QStringLiteral("ANPLUS-"))) {
anplus_treadmill = true;
qDebug() << QStringLiteral("ANPLUS TREADMILL workaround ON!");
Expand Down
1 change: 1 addition & 0 deletions src/devices/horizontreadmill/horizontreadmill.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class horizontreadmill : public treadmill {

bool mobvoi_treadmill = false;
bool kettler_treadmill = false;
bool wellfit_treadmill = false;
bool sole_tt8_treadmill = false;
bool anplus_treadmill = false;
bool tunturi_t60_treadmill = false;
Expand Down

0 comments on commit 637b571

Please sign in to comment.