From ea122954f0ac0d098674ede61f320f3dfbc27ce5 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Tue, 22 Oct 2024 10:48:27 +0200 Subject: [PATCH 1/2] n Wellfit treadmill support #2659 --- .../horizontreadmill/horizontreadmill.cpp | 32 ++++++++++++++++++- .../horizontreadmill/horizontreadmill.h | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/devices/horizontreadmill/horizontreadmill.cpp b/src/devices/horizontreadmill/horizontreadmill.cpp index f97fb83de..1e8f91412 100644 --- a/src/devices/horizontreadmill/horizontreadmill.cpp +++ b/src/devices/horizontreadmill/horizontreadmill.cpp @@ -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; } @@ -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); @@ -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!"); } } } @@ -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!"); diff --git a/src/devices/horizontreadmill/horizontreadmill.h b/src/devices/horizontreadmill/horizontreadmill.h index d216971a0..2758d6e69 100644 --- a/src/devices/horizontreadmill/horizontreadmill.h +++ b/src/devices/horizontreadmill/horizontreadmill.h @@ -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; From 22edbab2eec4764faf524f55343a205720c6a5e8 Mon Sep 17 00:00:00 2001 From: Roberto Viola Date: Tue, 22 Oct 2024 16:50:40 +0200 Subject: [PATCH 2/2] Update horizontreadmill.cpp --- src/devices/horizontreadmill/horizontreadmill.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/devices/horizontreadmill/horizontreadmill.cpp b/src/devices/horizontreadmill/horizontreadmill.cpp index 1e8f91412..d0e3b4399 100644 --- a/src/devices/horizontreadmill/horizontreadmill.cpp +++ b/src/devices/horizontreadmill/horizontreadmill.cpp @@ -2137,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; @@ -2150,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