Compare commits

...

7 Commits

Author SHA1 Message Date
Roberto Viola
21728f0655 handling close event 2024-09-12 14:59:22 +02:00
Roberto Viola
40c37d98b3 Update bluetoothdevice.cpp 2024-09-12 09:18:12 +02:00
Roberto Viola
02557bd9ca trying again 2024-09-11 17:44:55 +02:00
Roberto Viola
ce9ff3ae65 Update horizontreadmill.cpp 2024-09-09 17:34:35 +02:00
Roberto Viola
b39d7c0965 Update horizontreadmill.cpp 2024-09-06 17:04:58 +02:00
Roberto Viola
d5466af2a4 Update horizontreadmill.cpp 2024-09-06 16:42:50 +02:00
Roberto Viola
09b676d87a Update tacxneo2.cpp 2024-09-06 16:21:30 +02:00
6 changed files with 41 additions and 2 deletions

View File

@@ -1350,6 +1350,7 @@ void bluetooth::deviceDiscovered(const QBluetoothDeviceInfo &device) {
(b.name().toUpper().startsWith(QStringLiteral("ANPLUS-"))) || // FTMS
b.name().toUpper().startsWith(QStringLiteral("ESANGLINKER"))) &&
!horizonTreadmill && filter) {
discoveryAgent->stop();
this->setLastBluetoothDevice(b);
this->stopDiscovery();
horizonTreadmill = new horizontreadmill(noWriteResistance, noHeartService);

View File

@@ -134,6 +134,7 @@ metric bluetoothdevice::elevationGain() { return elevationAcc; }
void bluetoothdevice::heartRate(uint8_t heart) { Heart.setValue(heart); }
void bluetoothdevice::disconnectBluetooth() {
if (m_control) {
closing = true;
m_control->disconnectFromDevice();
}
}

View File

@@ -732,6 +732,8 @@ class bluetoothdevice : public QObject {
protected:
// useful to understand if a power sensor device for treadmill, it's a real one like the stryd or it's a dumb one like the runpod from Zwift
bool powerReceivedFromPowerSensor = false;
volatile bool closing = false;
};
#endif // BLUETOOTHDEVICE_H

View File

@@ -2278,12 +2278,26 @@ void horizontreadmill::serviceScanDone(void) {
firstStateChanged = 0;
auto services_list = m_control->services();
QBluetoothUuid ftmsService((quint16)0x1826);
QBluetoothUuid RSCService((quint16)0x1814);
QBluetoothUuid CustomService((quint16)0xFFF0);
for (const QBluetoothUuid &s : qAsConst(services_list)) {
#ifdef Q_OS_WIN
if (s == ftmsService || s == RSCService || s == CustomService)
#endif
{
qDebug() << s << "discovering...";
gattCommunicationChannelService.append(m_control->createServiceObject(s));
connect(gattCommunicationChannelService.constLast(), &QLowEnergyService::stateChanged, this,
&horizontreadmill::stateChanged);
gattCommunicationChannelService.constLast()->discoverDetails();
}
#ifdef Q_OS_WIN
else {
qDebug() << s << "NOT discovering!";
}
#endif
}
}
@@ -2388,7 +2402,9 @@ void horizontreadmill::deviceDiscovered(const QBluetoothDeviceInfo &device) {
connect(m_control, &QLowEnergyController::connected, this, [this]() {
Q_UNUSED(this);
emit debug(QStringLiteral("Controller connected. Search services..."));
#ifndef Q_OS_WIN
m_control->discoverServices();
#endif
});
connect(m_control, &QLowEnergyController::disconnected, this, [this]() {
Q_UNUSED(this);
@@ -2398,10 +2414,19 @@ void horizontreadmill::deviceDiscovered(const QBluetoothDeviceInfo &device) {
// Connect
m_control->connectToDevice();
#ifdef Q_OS_WIN
QThread::sleep(1);
m_control->discoverServices();
#endif
return;
}
}
horizontreadmill::~horizontreadmill() {
if(connected())
m_control->disconnectFromDevice();
}
bool horizontreadmill::connected() {
if (!m_control) {
@@ -2412,8 +2437,8 @@ bool horizontreadmill::connected() {
void horizontreadmill::controllerStateChanged(QLowEnergyController::ControllerState state) {
qDebug() << QStringLiteral("controllerStateChanged") << state;
if (state == QLowEnergyController::UnconnectedState && m_control) {
qDebug() << QStringLiteral("trying to connect back again...");
if (state == QLowEnergyController::UnconnectedState && m_control && !closing) {
qDebug() << QStringLiteral("trying to connect back again...") << closing;
initDone = false;
m_control->connectToDevice();

View File

@@ -38,6 +38,7 @@ class horizontreadmill : public treadmill {
Q_OBJECT
public:
horizontreadmill(bool noWriteResistance, bool noHeartService);
~horizontreadmill();
bool connected() override;
void forceSpeed(double requestSpeed);
void forceIncline(double requestIncline);

View File

@@ -707,6 +707,15 @@ void tacxneo2::serviceScanDone(void) {
auto services = m_control->services();
for (const QBluetoothUuid &s : services) {
#ifdef Q_OS_WIN
QBluetoothUuid custom = QBluetoothUuid(QStringLiteral("6e40fec1-b5a3-f393-e0a9-e50e24dcca9e"));
QBluetoothUuid ftms = QBluetoothUuid((quint16)0x1826);
QBluetoothUuid power = QBluetoothUuid((quint16)0x1818);
if(s != custom && s != power && s != ftms) {
qDebug() << "skipping service";
continue;
}
#endif
gattCommunicationChannelService.append(m_control->createServiceObject(s));
connect(gattCommunicationChannelService.constLast(), &QLowEnergyService::stateChanged, this,
&tacxneo2::stateChanged);