-
-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathbluetooth.cpp
More file actions
4814 lines (4469 loc) · 273 KB
/
Copy pathbluetooth.cpp
File metadata and controls
4814 lines (4469 loc) · 273 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "bluetooth.h"
#include "homeform.h"
#include "mywhooshlink.h"
#include <QBluetoothLocalDevice>
#include <QRegularExpression>
#include <QDateTime>
#include <QFile>
#include <QMetaEnum>
#include <QtXml>
#ifdef Q_OS_ANDROID
#include "androidactivityresultreceiver.h"
#include "keepawakehelper.h"
#include <QAndroidJniObject>
#endif
static void updateDiscoveredDevice(QList<QBluetoothDeviceInfo> &devices, const QBluetoothDeviceInfo &device) {
QMutableListIterator<QBluetoothDeviceInfo> i(devices);
while (i.hasNext()) {
const QBluetoothDeviceInfo existing = i.next();
if (SAME_BLUETOOTH_DEVICE(existing, device)) {
if (!device.name().isEmpty() || existing.name().isEmpty()) {
i.setValue(device);
} else {
QBluetoothDeviceInfo updated = existing;
updated.setCached(device.isCached());
updated.setRssi(device.rssi());
updated.setCoreConfigurations(device.coreConfigurations());
updated.setDeviceUuid(device.deviceUuid());
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
updated.setServiceUuids(device.serviceUuids());
#else
updated.setServiceUuids(device.serviceUuids().toVector());
#endif
const QHash<quint16, QByteArray> manufacturerData = device.manufacturerData();
for (auto it = manufacturerData.cbegin(); it != manufacturerData.cend(); ++it) {
updated.setManufacturerData(it.key(), it.value());
}
i.setValue(updated);
}
return;
}
}
devices.append(device);
}
bluetooth::bluetooth(const discoveryoptions &options)
: bluetooth(options.logs, options.deviceName, options.noWriteResistance, options.noHeartService,
options.pollDeviceTime, options.noConsole, options.testResistance, options.bikeResistanceOffset,
options.bikeResistanceGain, options.startDiscovery) {}
bluetooth::bluetooth(bool logs, const QString &deviceName, bool noWriteResistance, bool noHeartService,
uint32_t pollDeviceTime, bool noConsole, bool testResistance, int8_t bikeResistanceOffset,
double bikeResistanceGain, bool startDiscovery) {
QSettings settings;
bool gymMode = settings.value(QZSettings::gym_mode, QZSettings::default_gym_mode).toBool();
QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
filterDevice = deviceName;
this->testResistance = testResistance;
this->noWriteResistance = noWriteResistance;
this->noHeartService = noHeartService;
this->pollDeviceTime = pollDeviceTime;
this->noConsole = noConsole;
this->logs = logs;
this->bikeResistanceGain = bikeResistanceGain;
this->bikeResistanceOffset = bikeResistanceOffset;
this->useDiscovery = startDiscovery;
QString nordictrack_2950_ip =
settings.value(QZSettings::nordictrack_2950_ip, QZSettings::default_nordictrack_2950_ip).toString();
QString tdf_10_ip_ctor = settings.value(QZSettings::tdf_10_ip, QZSettings::default_tdf_10_ip).toString();
QString proform_elliptical_ip_ctor =
settings.value(QZSettings::proform_elliptical_ip, QZSettings::default_proform_elliptical_ip).toString();
QString proform_rower_ip_ctor =
settings.value(QZSettings::proform_rower_ip, QZSettings::default_proform_rower_ip).toString();
bool waterrower_usb_ctor =
settings.value(QZSettings::waterrower_usb, QZSettings::default_waterrower_usb).toBool();
bool fake_bike =
settings.value(QZSettings::applewatch_fakedevice, QZSettings::default_applewatch_fakedevice).toBool();
bool fake_treadmill =
settings.value(QZSettings::fakedevice_treadmill, QZSettings::default_fakedevice_treadmill).toBool();
bool fakedevice_elliptical_ctor =
settings.value(QZSettings::fakedevice_elliptical, QZSettings::default_fakedevice_elliptical).toBool();
bool fakedevice_rower_ctor =
settings.value(QZSettings::fakedevice_rower, QZSettings::default_fakedevice_rower).toBool();
bool antbike_ctor = settings.value(QZSettings::antbike, QZSettings::default_antbike).toBool();
bool android_antbike_ctor =
settings.value(QZSettings::android_antbike, QZSettings::default_android_antbike).toBool();
// The 15s discovery watchdog below exists solely to unstick fake/virtual devices
// (Fake Treadmill/Bike/etc, IP-based trainers) on platforms where the discovery
// agent's finished() signal never fires (e.g. Waydroid containers without a
// functional Bluetooth radio). If none of those virtual devices are configured,
// there is nothing relying on the watchdog, so we leave real discovery alone and
// let it take as long as it genuinely needs instead of forcing it to end early.
bool reliesOnFakeOrVirtualDevice = fake_bike || fake_treadmill || fakedevice_elliptical_ctor ||
fakedevice_rower_ctor || !nordictrack_2950_ip.isEmpty() ||
!tdf_10_ip_ctor.isEmpty() || !proform_elliptical_ip_ctor.isEmpty() ||
!proform_rower_ip_ctor.isEmpty() || antbike_ctor || android_antbike_ctor ||
waterrower_usb_ctor;
if (!gymMode && settings.value(QZSettings::peloton_bike_ocr, QZSettings::default_peloton_bike_ocr).toBool() &&
!pelotonBike) {
pelotonBike = new pelotonbike(noWriteResistance, noHeartService);
emit deviceConnected(QBluetoothDeviceInfo());
connect(pelotonBike, &bluetoothdevice::connectedAndDiscovered, this, &bluetooth::connectedAndDiscovered);
connect(pelotonBike, &pelotonbike::debug, this, &bluetooth::debug);
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
// this signal is not associated to anything in this moment, since the homeform is not loaded yet
this->signalBluetoothDeviceConnected(pelotonBike);
}/* else if (fake_bike) {
fakeBike = new fakebike(noWriteResistance, noHeartService, false);
emit deviceConnected(QBluetoothDeviceInfo());
connect(fakeBike, &bluetoothdevice::connectedAndDiscovered, this, &bluetooth::connectedAndDiscovered);
connect(fakeBike, &fakebike::debug, this, &bluetooth::debug);
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
// this signal is not associated to anything in this moment, since the homeform is not loaded yet
this->signalBluetoothDeviceConnected(fakeBike);
return;
} else if (fake_treadmill) {
fakeTreadmill = new faketreadmill(noWriteResistance, noHeartService, false);
emit deviceConnected(QBluetoothDeviceInfo());
connect(fakeTreadmill, &bluetoothdevice::connectedAndDiscovered, this, &bluetooth::connectedAndDiscovered);
connect(fakeTreadmill, &faketreadmill::debug, this, &bluetooth::debug);
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
// this signal is not associated to anything in this moment, since the homeform is not loaded yet
this->signalBluetoothDeviceConnected(fakeBike);
return;
}*/
#ifdef TEST
schwinnIC4Bike = (schwinnic4bike *)new bike();
// this signal is not associated to anything in this moment, since the homeform is not loaded yet
this->signalBluetoothDeviceConnected(schwinnIC4Bike);
connectedAndDiscovered();
return;
#endif
if (!startDiscovery) {
this->discoveryAgent = nullptr;
return;
}
#if !defined(WIN32) && !defined(Q_OS_IOS)
if (QBluetoothLocalDevice::allDevices().isEmpty()) {
debug(QStringLiteral("no bluetooth dongle found!"));
} else
#endif
{
// Create a discovery agent and connect to its signals
discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &bluetooth::deviceDiscovered);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceUpdated, this, &bluetooth::deviceUpdated);
#endif
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &bluetooth::canceled);
#ifndef Q_OS_WIN
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &bluetooth::finished);
#endif
// Safety net: on some platforms (e.g. Android containers/emulators without a functional
// Bluetooth adapter, such as Waydroid) the discovery agent's finished()/timeout signal never
// fires even though a discoveryAgent object was created, leaving fake devices (Fake
// Treadmill/Bike/etc) stuck forever waiting for a scan that will never complete. finished()
// guards against being invoked twice, so this is a no-op once the real signal has fired.
// Only armed when a fake/virtual device is actually configured: real hardware users have
// nothing depending on this fallback, so we don't risk cutting a genuine (if slow) scan short.
if (reliesOnFakeOrVirtualDevice) {
connect(&discoveryTimeout, &QTimer::timeout, this, &bluetooth::finished);
discoveryTimeout.setSingleShot(true);
discoveryTimeout.start(15000);
}
// Start a discovery
#ifndef Q_OS_WIN
discoveryAgent->setLowEnergyDiscoveryTimeout(10000);
#endif
this->startDiscovery();
}
}
bluetooth::~bluetooth() {
/*if(device())
{
device()->disconnectBluetooth();
}*/
}
void bluetooth::signalBluetoothDeviceConnected(bluetoothdevice *b) { emit this->bluetoothDeviceConnected(b); }
void bluetooth::finished() {
if (discoveryFinishedHandled)
return;
discoveryFinishedHandled = true;
discoveryTimeout.stop();
debug(QStringLiteral("BTLE scanning finished"));
QSettings settings;
bool antbike =
settings.value(QZSettings::antbike, QZSettings::default_antbike).toBool();
bool android_antbike =
settings.value(QZSettings::android_antbike, QZSettings::default_android_antbike).toBool();
QString nordictrack_2950_ip =
settings.value(QZSettings::nordictrack_2950_ip, QZSettings::default_nordictrack_2950_ip).toString();
QString tdf_10_ip = settings.value(QZSettings::tdf_10_ip, QZSettings::default_tdf_10_ip).toString();
QString proform_elliptical_ip = settings.value(QZSettings::proform_elliptical_ip, QZSettings::default_proform_elliptical_ip).toString();
QString proform_rower_ip = settings.value(QZSettings::proform_rower_ip, QZSettings::default_proform_rower_ip).toString();
bool fake_bike =
settings.value(QZSettings::applewatch_fakedevice, QZSettings::default_applewatch_fakedevice).toBool();
bool fakedevice_elliptical =
settings.value(QZSettings::fakedevice_elliptical, QZSettings::default_fakedevice_elliptical).toBool();
bool fakedevice_rower = settings.value(QZSettings::fakedevice_rower, QZSettings::default_fakedevice_rower).toBool();
bool fakedevice_treadmill =
settings.value(QZSettings::fakedevice_treadmill, QZSettings::default_fakedevice_treadmill).toBool();
bool waterrower_usb = settings.value(QZSettings::waterrower_usb, QZSettings::default_waterrower_usb).toBool();
// wifi devices on windows
if (!nordictrack_2950_ip.isEmpty() || !tdf_10_ip.isEmpty() || fake_bike || fakedevice_elliptical || fakedevice_rower || fakedevice_treadmill || !proform_elliptical_ip.isEmpty() || !proform_rower_ip.isEmpty() || antbike || android_antbike || waterrower_usb) {
// faking a bluetooth device for non-BLE devices
qDebug() << "faking a bluetooth device for non-BLE device";
deviceDiscovered(QBluetoothDeviceInfo());
}
if (device()) {
qDebug() << QStringLiteral("bluetooth::finished but discoveryAgent is not active");
return;
}
QString heartRateBeltName =
settings.value(QZSettings::heart_rate_belt_name, QZSettings::default_heart_rate_belt_name).toString();
QString ftmsAccessoryName =
settings.value(QZSettings::ftms_accessory_name, QZSettings::default_ftms_accessory_name).toString();
bool csc_as_bike =
settings.value(QZSettings::cadence_sensor_as_bike, QZSettings::default_cadence_sensor_as_bike).toBool();
bool csc_as_treadmill =
settings.value(QZSettings::cadence_sensor_as_treadmill, QZSettings::default_cadence_sensor_as_treadmill)
.toBool();
bool power_as_bike =
settings.value(QZSettings::power_sensor_as_bike, QZSettings::default_power_sensor_as_bike).toBool();
bool power_as_treadmill =
settings.value(QZSettings::power_sensor_as_treadmill, QZSettings::default_power_sensor_as_treadmill).toBool();
QString cscName =
settings.value(QZSettings::cadence_sensor_name, QZSettings::default_cadence_sensor_name).toString();
QString powerSensorName =
settings.value(QZSettings::power_sensor_name, QZSettings::default_power_sensor_name).toString();
QString eliteRizerName =
settings.value(QZSettings::elite_rizer_name, QZSettings::default_elite_rizer_name).toString();
QString eliteSterzoSmartName =
settings.value(QZSettings::elite_sterzo_smart_name, QZSettings::default_elite_sterzo_smart_name).toString();
bool cscFound = cscName.startsWith(QStringLiteral("Disabled")) && !csc_as_bike && !csc_as_treadmill;
bool powerSensorFound =
powerSensorName.startsWith(QStringLiteral("Disabled")) && !power_as_bike && !power_as_treadmill;
bool eliteRizerFound = eliteRizerName.startsWith(QStringLiteral("Disabled"));
bool eliteSterzoSmartFound = eliteSterzoSmartName.startsWith(QStringLiteral("Disabled"));
bool heartRateBeltFound = heartRateBeltName.startsWith(QStringLiteral("Disabled"));
bool ftmsAccessoryFound = ftmsAccessoryName.startsWith(QStringLiteral("Disabled"));
bool ss2k_peloton = settings.value(QZSettings::ss2k_peloton, QZSettings::default_ss2k_peloton).toBool();
if (ss2k_peloton)
ftmsAccessoryFound = true;
// since i can have multiple fanfit i can't wait more because i don't have the full list of the fanfit
// devices connected to QZ. edit: let's wait at the last one item
bool fitmetriaFanfitFound =
!settings.value(QZSettings::fitmetria_fanfit_enable, QZSettings::default_fitmetria_fanfit_enable).toBool();
bool zwiftDeviceFound =
!settings.value(QZSettings::zwift_click, QZSettings::default_zwift_click).toBool() && !settings.value(QZSettings::zwift_play, QZSettings::default_zwift_play).toBool();
bool sramDeviceFound = !settings.value(QZSettings::sram_axs_controller, QZSettings::default_sram_axs_controller).toBool();
bool cycplusBC2DeviceFound =
!settings.value(QZSettings::cycplus_bc2_controller, QZSettings::default_cycplus_bc2_controller).toBool();
bool thinkriderDeviceFound = !settings.value(QZSettings::thinkrider_controller, QZSettings::default_thinkrider_controller).toBool();
if ((!heartRateBeltFound && !heartRateBeltAvaiable()) || (!ftmsAccessoryFound && !ftmsAccessoryAvaiable()) ||
(!cscFound && !cscSensorAvaiable()) || (!powerSensorFound && !powerSensorAvaiable()) ||
(!eliteRizerFound && !eliteRizerAvaiable()) || (!eliteSterzoSmartFound && !eliteSterzoSmartAvaiable()) ||
(!fitmetriaFanfitFound && !fitmetriaFanfitAvaiable()) ||
(!zwiftDeviceFound && !zwiftDeviceAvaiable()) ||
(!sramDeviceFound && !sramDeviceAvaiable()) ||
(!cycplusBC2DeviceFound && !cycplusBC2DeviceAvaiable()) ||
(!thinkriderDeviceFound && !thinkriderDeviceAvaiable())) {
// force heartRateBelt off
forceHeartBeltOffForTimeout = true;
}
this->startDiscovery();
}
void bluetooth::startDiscovery() {
if (!this->useDiscovery)
return;
#ifndef Q_OS_IOS
QSettings settings;
bool technogym_myrun_treadmill_experimental = settings
.value(QZSettings::technogym_myrun_treadmill_experimental,
QZSettings::default_technogym_myrun_treadmill_experimental)
.toBool();
bool trx_route_key = settings.value(QZSettings::trx_route_key, QZSettings::default_trx_route_key).toBool();
bool bh_spada_2 = settings.value(QZSettings::bh_spada_2, QZSettings::default_bh_spada_2).toBool();
bool iconcept_elliptical =
settings.value(QZSettings::iconcept_elliptical, QZSettings::default_iconcept_elliptical).toBool();
if (!trx_route_key && !bh_spada_2 && !technogym_myrun_treadmill_experimental && !iconcept_elliptical) {
#endif
discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
#ifndef Q_OS_IOS
} else {
discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::ClassicMethod |
QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
}
#endif
}
void bluetooth::stopDiscovery() {
if (this->discoveryAgent)
this->discoveryAgent->stop();
else
qDebug() << "bluetooth::stopDiscovery() called when discoveryAgent is not defined. ";
}
void bluetooth::canceled() {
debug(QStringLiteral("BTLE scanning stops"));
emit searchingStop();
}
void bluetooth::debug(const QString &text) {
if (logs) {
qDebug() << text;
}
}
bool bluetooth::gymModeEnabled() const {
QSettings settings;
return settings.value(QZSettings::gym_mode, QZSettings::default_gym_mode).toBool();
}
bool bluetooth::cscSensorAvaiable() {
QSettings settings;
bool csc_as_bike =
settings.value(QZSettings::cadence_sensor_as_bike, QZSettings::default_cadence_sensor_as_bike).toBool();
bool csc_as_treadmill =
settings.value(QZSettings::cadence_sensor_as_treadmill, QZSettings::default_cadence_sensor_as_treadmill)
.toBool();
QString cscName =
settings.value(QZSettings::cadence_sensor_name, QZSettings::default_cadence_sensor_name).toString();
if (csc_as_bike || csc_as_treadmill) {
return false;
}
for (const QBluetoothDeviceInfo &b : qAsConst(devices)) {
if (!cscName.compare(b.name())) {
return true;
}
}
return false;
}
bool bluetooth::ftmsAccessoryAvaiable() {
QSettings settings;
QString ftmsAccessoryName =
settings.value(QZSettings::ftms_accessory_name, QZSettings::default_ftms_accessory_name).toString();
bool ss2k_peloton = settings.value(QZSettings::ss2k_peloton, QZSettings::default_ss2k_peloton).toBool();
if (ss2k_peloton)
return false;
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (!ftmsAccessoryName.compare(b.name())) {
return true;
}
}
return false;
}
bool bluetooth::fitmetriaFanfitAvaiable() {
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (!b.name().compare("FITFAN-", Qt::CaseInsensitive)) {
return true;
} else if (b.name().toUpper().startsWith("HEADWIND ")) {
return true;
}
}
return false;
}
bool bluetooth::zwiftDeviceAvaiable() {
uint8_t count = 0;
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (b.name().toUpper().startsWith("ZWIFT ")) {
count++;
if(count >= 2)
return true;
}
}
return false;
}
bool bluetooth::sramDeviceAvaiable() {
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (b.name().toUpper().startsWith("SRAM ")) {
return true;
}
}
return false;
}
bool bluetooth::thinkriderDeviceAvaiable() {
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (b.name().toUpper().startsWith("THINK VS") || b.name().toUpper().startsWith("THINKRIDER")) {
return true;
}
}
return false;
}
bool bluetooth::cycplusBC2DeviceAvaiable() {
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (b.name().toUpper().contains("BC2") ||
deviceHasService(b, QBluetoothUuid(QStringLiteral("6e400001-b5a3-f393-e0a9-e50e24dcca9e")))) {
return true;
}
}
return false;
}
bool bluetooth::powerSensorAvaiable() {
QSettings settings;
bool power_as_bike =
settings.value(QZSettings::power_sensor_as_bike, QZSettings::default_power_sensor_as_bike).toBool();
bool power_as_treadmill =
settings.value(QZSettings::power_sensor_as_treadmill, QZSettings::default_power_sensor_as_treadmill).toBool();
QString powerSensorName =
settings.value(QZSettings::power_sensor_name, QZSettings::default_power_sensor_name).toString();
if (power_as_bike || power_as_treadmill) {
return false;
}
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (!powerSensorName.compare(b.name())) {
return true;
}
}
return false;
}
bool bluetooth::eliteRizerAvaiable() {
QSettings settings;
QString eliteRizerName =
settings.value(QZSettings::elite_rizer_name, QZSettings::default_elite_rizer_name).toString();
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (!eliteRizerName.compare(b.name())) {
return true;
}
}
return false;
}
bool bluetooth::eliteSterzoSmartAvaiable() {
QSettings settings;
QString eliteSterzoSmartName =
settings.value(QZSettings::elite_sterzo_smart_name, QZSettings::default_elite_sterzo_smart_name).toString();
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (!eliteSterzoSmartName.compare(b.name())) {
return true;
}
}
return false;
}
bool bluetooth::heartRateBeltAvaiable() {
QSettings settings;
QString heartRateBeltName =
settings.value(QZSettings::heart_rate_belt_name, QZSettings::default_heart_rate_belt_name).toString();
Q_FOREACH (QBluetoothDeviceInfo b, devices) {
if (!heartRateBeltName.compare(b.name())) {
return true;
}
}
return false;
}
void bluetooth::setLastBluetoothDevice(const QBluetoothDeviceInfo &b) {
QSettings settings;
settings.setValue(QZSettings::bluetooth_lastdevice_name, b.name());
#ifndef Q_OS_IOS
settings.setValue(QZSettings::bluetooth_lastdevice_address, b.address().toString());
#else
settings.setValue(QZSettings::bluetooth_lastdevice_address, b.deviceUuid().toString());
#endif
}
// this doesn't work on Windows. So be careful!
bool bluetooth::deviceHasService(const QBluetoothDeviceInfo &device, QBluetoothUuid service) {
foreach(QBluetoothUuid s, device.serviceUuids()) {
if(s == service) {
return true;
}
}
return false;
}
void bluetooth::deviceDiscovered(const QBluetoothDeviceInfo &device) {
QSettings settings;
QString heartRateBeltName =
settings.value(QZSettings::heart_rate_belt_name, QZSettings::default_heart_rate_belt_name).toString();
QString ftmsAccessoryName =
settings.value(QZSettings::ftms_accessory_name, QZSettings::default_ftms_accessory_name).toString();
bool heartRateBeltFound = heartRateBeltName.startsWith(QStringLiteral("Disabled"));
bool ftmsAccessoryFound = ftmsAccessoryName.startsWith(QStringLiteral("Disabled"));
bool sramDeviceFound = !settings.value(QZSettings::sram_axs_controller, QZSettings::default_sram_axs_controller).toBool();
bool zwiftDeviceFound =
!settings.value(QZSettings::zwift_click, QZSettings::default_zwift_click).toBool() && !settings.value(QZSettings::zwift_play, QZSettings::default_zwift_play).toBool();
bool cycplusBC2DeviceFound =
!settings.value(QZSettings::cycplus_bc2_controller, QZSettings::default_cycplus_bc2_controller).toBool();
bool thinkriderDeviceFound = !settings.value(QZSettings::thinkrider_controller, QZSettings::default_thinkrider_controller).toBool();
bool fitmetriaFanfitFound =
!settings.value(QZSettings::fitmetria_fanfit_enable, QZSettings::default_fitmetria_fanfit_enable).toBool();
bool toorx_ftms = settings.value(QZSettings::toorx_ftms, QZSettings::default_toorx_ftms).toBool();
bool toorx_ftms_treadmill =
settings.value(QZSettings::toorx_ftms_treadmill, QZSettings::default_toorx_ftms_treadmill).toBool();
bool toorx_bike = (settings.value(QZSettings::toorx_bike, QZSettings::default_toorx_bike).toBool() ||
settings.value(QZSettings::jll_IC400_bike, QZSettings::default_jll_IC400_bike).toBool() ||
settings.value(QZSettings::fytter_ri08_bike, QZSettings::default_fytter_ri08_bike).toBool() ||
settings.value(QZSettings::asviva_bike, QZSettings::default_asviva_bike).toBool() ||
settings.value(QZSettings::enerfit_SPX_9500, QZSettings::default_enerfit_SPX_9500).toBool() ||
settings.value(QZSettings::toorx_srx_3500, QZSettings::default_toorx_srx_3500).toBool() ||
settings.value(QZSettings::hop_sport_hs_090h_bike, QZSettings::default_hop_sport_hs_090h_bike).toBool() ||
settings.value(QZSettings::toorx_bike_srx_500, QZSettings::default_toorx_bike_srx_500).toBool() ||
settings.value(QZSettings::hertz_xr_770, QZSettings::default_hertz_xr_770).toBool() ||
settings.value(QZSettings::taurua_ic90, QZSettings::default_taurua_ic90).toBool()) &&
!toorx_ftms;
bool snode_bike = settings.value(QZSettings::snode_bike, QZSettings::default_snode_bike).toBool();
bool fitplus_bike = settings.value(QZSettings::fitplus_bike, QZSettings::default_fitplus_bike).toBool() ||
settings.value(QZSettings::virtufit_etappe, QZSettings::default_virtufit_etappe).toBool();
bool csc_as_bike =
settings.value(QZSettings::cadence_sensor_as_bike, QZSettings::default_cadence_sensor_as_bike).toBool();
bool csc_as_treadmill =
settings.value(QZSettings::cadence_sensor_as_treadmill, QZSettings::default_cadence_sensor_as_treadmill)
.toBool();
bool power_as_bike =
settings.value(QZSettings::power_sensor_as_bike, QZSettings::default_power_sensor_as_bike).toBool();
bool power_as_treadmill =
settings.value(QZSettings::power_sensor_as_treadmill, QZSettings::default_power_sensor_as_treadmill).toBool();
QString cscName =
settings.value(QZSettings::cadence_sensor_name, QZSettings::default_cadence_sensor_name).toString();
bool cscFound = cscName.startsWith(QStringLiteral("Disabled")) || csc_as_bike || csc_as_treadmill;
bool hammerRacerS = settings.value(QZSettings::hammer_racer_s, QZSettings::default_hammer_racer_s).toBool();
bool flywheel_life_fitness_ic8 =
settings.value(QZSettings::flywheel_life_fitness_ic8, QZSettings::default_flywheel_life_fitness_ic8).toBool();
bool life_fitness_ic5 =
settings.value(QZSettings::life_fitness_ic5, QZSettings::default_life_fitness_ic5).toBool();
bool technogym_bike =
settings.value(QZSettings::technogym_bike, QZSettings::default_technogym_bike).toBool();
QString powerSensorName =
settings.value(QZSettings::power_sensor_name, QZSettings::default_power_sensor_name).toString();
QString eliteRizerName =
settings.value(QZSettings::elite_rizer_name, QZSettings::default_elite_rizer_name).toString();
QString eliteSterzoSmartName =
settings.value(QZSettings::elite_sterzo_smart_name, QZSettings::default_elite_sterzo_smart_name).toString();
bool powerSensorFound =
powerSensorName.startsWith(QStringLiteral("Disabled")) || power_as_bike || power_as_treadmill;
bool eliteRizerFound = eliteRizerName.startsWith(QStringLiteral("Disabled"));
bool eliteSterzoSmartFound = eliteSterzoSmartName.startsWith(QStringLiteral("Disabled"));
bool fake_bike =
settings.value(QZSettings::applewatch_fakedevice, QZSettings::default_applewatch_fakedevice).toBool();
bool fakedevice_elliptical =
settings.value(QZSettings::fakedevice_elliptical, QZSettings::default_fakedevice_elliptical).toBool();
bool fakedevice_rower = settings.value(QZSettings::fakedevice_rower, QZSettings::default_fakedevice_rower).toBool();
bool fakedevice_treadmill =
settings.value(QZSettings::fakedevice_treadmill, QZSettings::default_fakedevice_treadmill).toBool();
bool pafers_treadmill = settings.value(QZSettings::pafers_treadmill, QZSettings::default_pafers_treadmill).toBool();
QString proformtdf4ip = settings.value(QZSettings::proformtdf4ip, QZSettings::default_proformtdf4ip).toString();
QString proformtdf1ip = settings.value(QZSettings::proformtdf1ip, QZSettings::default_proformtdf1ip).toString();
QString proformtreadmillip =
settings.value(QZSettings::proformtreadmillip, QZSettings::default_proformtreadmillip).toString();
bool antbike_setting =
settings.value(QZSettings::antbike, QZSettings::default_antbike).toBool();
bool android_antbike_setting =
settings.value(QZSettings::android_antbike, QZSettings::default_android_antbike).toBool();
QString nordictrack_2950_ip =
settings.value(QZSettings::nordictrack_2950_ip, QZSettings::default_nordictrack_2950_ip).toString();
QString tdf_10_ip = settings.value(QZSettings::tdf_10_ip, QZSettings::default_tdf_10_ip).toString();
QString proform_elliptical_ip = settings.value(QZSettings::proform_elliptical_ip, QZSettings::default_proform_elliptical_ip).toString();
QString proform_rower_ip = settings.value(QZSettings::proform_rower_ip, QZSettings::default_proform_rower_ip).toString();
QString computrainerSerialPort =
settings.value(QZSettings::computrainer_serialport, QZSettings::default_computrainer_serialport).toString();
QString kettlerUsbSerialPort =
settings.value(QZSettings::kettler_usb_serialport, QZSettings::default_kettler_usb_serialport).toString();
QString freebeatSerialPort =
settings.value(QZSettings::freebeat_serialport, QZSettings::default_freebeat_serialport).toString();
QString csaferowerSerialPort = settings.value(QZSettings::csafe_rower, QZSettings::default_csafe_rower).toString();
bool waterrowerUSBEnabled = settings.value(QZSettings::waterrower_usb, QZSettings::default_waterrower_usb).toBool();
QString csafeellipticalSerialPort =
settings.value(QZSettings::csafe_elliptical_port, QZSettings::default_csafe_elliptical_port).toString();
bool manufacturerDeviceFound = false;
bool ss2k_peloton = settings.value(QZSettings::ss2k_peloton, QZSettings::default_ss2k_peloton).toBool();
bool pafers_treadmill_bh_iboxster_plus =
settings
.value(QZSettings::pafers_treadmill_bh_iboxster_plus, QZSettings::default_pafers_treadmill_bh_iboxster_plus)
.toBool();
bool gem_module_inclination =
settings.value(QZSettings::gem_module_inclination, QZSettings::default_gem_module_inclination).toBool();
bool iconcept_elliptical =
settings.value(QZSettings::iconcept_elliptical, QZSettings::default_iconcept_elliptical).toBool();
bool horizon_treadmill_force_ftms =
settings.value(QZSettings::horizon_treadmill_force_ftms, QZSettings::default_horizon_treadmill_force_ftms)
.toBool();
bool sole_inclination =
settings.value(QZSettings::sole_treadmill_inclination, QZSettings::default_sole_treadmill_inclination).toBool();
QString ftms_rower = settings.value(QZSettings::ftms_rower, QZSettings::default_ftms_rower).toString();
QString ftms_bike = settings.value(QZSettings::ftms_bike, QZSettings::default_ftms_bike).toString();
QString ftms_treadmill = settings.value(QZSettings::ftms_treadmill, QZSettings::default_ftms_treadmill).toString();
QString ftms_elliptical = settings.value(QZSettings::ftms_elliptical, QZSettings::default_ftms_elliptical).toString();
bool saris_trainer = settings.value(QZSettings::saris_trainer, QZSettings::default_saris_trainer).toBool();
bool iconsole_elliptical = settings.value(QZSettings::iconsole_elliptical, QZSettings::default_iconsole_elliptical).toBool();
bool iconsole_rower = settings.value(QZSettings::iconsole_rower, QZSettings::default_iconsole_rower).toBool();
bool trx_route_key = settings.value(QZSettings::trx_route_key, QZSettings::default_trx_route_key).toBool();
if (!heartRateBeltFound) {
heartRateBeltFound = heartRateBeltAvaiable();
}
if (!fitmetriaFanfitFound) {
fitmetriaFanfitFound = fitmetriaFanfitAvaiable();
}
if (!zwiftDeviceFound) {
zwiftDeviceFound = zwiftDeviceAvaiable();
}
if(!sramDeviceFound) {
sramDeviceFound = sramDeviceAvaiable();
}
if(!cycplusBC2DeviceFound) {
cycplusBC2DeviceFound = cycplusBC2DeviceAvaiable();
}
if(!thinkriderDeviceFound) {
thinkriderDeviceFound = thinkriderDeviceAvaiable();
}
if (!ftmsAccessoryFound) {
ftmsAccessoryFound = ftmsAccessoryAvaiable();
}
if (ss2k_peloton) {
ftmsAccessoryFound = true;
}
if (!cscFound) {
cscFound = cscSensorAvaiable();
}
if (!powerSensorFound) {
powerSensorFound = powerSensorAvaiable();
}
if (!eliteRizerFound) {
eliteRizerFound = eliteRizerAvaiable();
}
if (!eliteSterzoSmartFound) {
eliteSterzoSmartFound = eliteSterzoSmartAvaiable();
}
#ifdef Q_OS_IOS
// Schwinn bikes on iOS allows to be connected to several instances, so in this way
// QZ will remember the address and will try to connect to it
QString b =
settings.value(QZSettings::bluetooth_lastdevice_name, QZSettings::default_bluetooth_lastdevice_name).toString();
qDebug() << "last device name (IC BIKE workaround)" << b;
if ((!gymModeEnabled() || !gymModeSessionDevice.isEmpty()) && !schwinnIC4Bike &&
!b.compare(settings.value(QZSettings::filter_device, QZSettings::default_filter_device).toString()) &&
(b.toUpper().startsWith("IC BIKE") || b.toUpper().startsWith("C7-"))) {
// Don't stop discovery here to allow time for accessories (heart rate, power, cadence sensors) to be found
// Discovery will stop naturally after 10 seconds or when all configured accessories are discovered
schwinnIC4Bike = new schwinnic4bike(noWriteResistance, noHeartService);
// stateFileRead();
QBluetoothDeviceInfo bt;
bt.setDeviceUuid(QBluetoothUuid(
settings.value(QZSettings::bluetooth_lastdevice_address, QZSettings::default_bluetooth_lastdevice_address)
.toString()));
// set name method doesn't exist
emit(deviceConnected(bt));
connect(schwinnIC4Bike, SIGNAL(connectedAndDiscovered()), this, SLOT(connectedAndDiscovered()));
// connect(echelonConnectSport, SIGNAL(disconnected()), this, SLOT(restart()));
connect(schwinnIC4Bike, SIGNAL(debug(QString)), this, SLOT(debug(QString)));
// connect(echelonConnectSport, SIGNAL(speedChanged(double)), this, SLOT(speedChanged(double)));
// connect(echelonConnectSport, SIGNAL(inclinationChanged(double)), this, SLOT(inclinationChanged(double)));
qDebug() << "UUID" << bt.deviceUuid();
schwinnIC4Bike->deviceDiscovered(bt);
this->signalBluetoothDeviceConnected(schwinnIC4Bike);
qDebug() << "connecting directly";
}
#endif
QVector<quint16> ids = device.manufacturerIds();
qDebug() << "manufacturerData" << ids;
foreach (quint16 id, ids) {
qDebug() << id << device.manufacturerData(id).toHex(' ');
#ifdef Q_OS_ANDROID
// yesoul bike on android 13 doesn't send anymore the name
if (device.name().count() == 0 && id == yesoulbike::manufacturerDataId &&
device.manufacturerData(id).startsWith(
QByteArray((const char *)yesoulbike::manufacturerData, yesoulbike::manufacturerDataSize))) {
qDebug() << "yesoulBikeFromManufacturerData forcing!";
QBluetoothDeviceInfo manufacturerDevice(device.address(), yesoulbike::bluetoothName,
device.majorDeviceClass());
updateDiscoveredDevice(devices, manufacturerDevice);
manufacturerDeviceFound = true;
}
#endif
}
if (manufacturerDeviceFound == false) {
updateDiscoveredDevice(devices, device);
}
emit deviceFound(device.name());
qDebug() << QStringLiteral("Found new device: ") << device.name() << QStringLiteral(" (") << device.address().toString() <<
')' << " " << device.majorDeviceClass() << QStringLiteral(":") << device.minorDeviceClass() << device.serviceUuids()
#if defined(Q_OS_DARWIN) || defined(Q_OS_IOS)
<< device.deviceUuid();
#endif
;
// not required for mobile I guess
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
if(!homeformLoaded) {
qDebug() << "homeform not yet loaded";
return;
}
#endif
if (onlyDiscover)
return;
if (gymModeEnabled() && gymModeSessionDevice.isEmpty())
return;
#ifdef Q_OS_WIN
if (this->device()) {
qDebug() << QStringLiteral("bluetooth::finished but discoveryAgent is not active");
return;
}
#endif
bool searchDevices = (heartRateBeltFound && ftmsAccessoryFound && cscFound && powerSensorFound && eliteRizerFound &&
eliteSterzoSmartFound && fitmetriaFanfitFound && zwiftDeviceFound && sramDeviceFound &&
cycplusBC2DeviceFound && thinkriderDeviceFound) ||
forceHeartBeltOffForTimeout;
if (searchDevices) {
const QString effectiveFilterDevice =
!gymModeSessionDevice.isEmpty() ? gymModeSessionDevice : filterDevice;
for (const QBluetoothDeviceInfo &b : qAsConst(devices)) {
bool filter = true;
if (!effectiveFilterDevice.isEmpty() && !effectiveFilterDevice.startsWith(QStringLiteral("Disabled"))) {
filter = (b.name().compare(effectiveFilterDevice, Qt::CaseInsensitive) == 0);
}
const QString deviceName = b.name();
const QString upperDeviceName = deviceName.toUpper();
const bool isConfiguredFtmsRowerDevice =
!ftms_rower.contains(QZSettings::default_ftms_rower) &&
!deviceName.compare(ftms_rower, Qt::CaseInsensitive);
bool isRI009R = upperDeviceName.contains(QStringLiteral("RI009R"));
bool isTrxAppGateUsbBikeTC = false;
if (upperDeviceName.startsWith(QStringLiteral("TC")) && deviceName.length() == 5) {
isTrxAppGateUsbBikeTC = true;
for (int idx = 2; idx < deviceName.length(); ++idx) {
if (!deviceName.at(idx).isDigit()) {
isTrxAppGateUsbBikeTC = false;
break;
}
}
}
if (deviceName.startsWith(QStringLiteral("M3")) && !m3iBike && filter) {
if (m3ibike::isCorrectUnit(b)) {
this->setLastBluetoothDevice(b);
this->stopDiscovery();
m3iBike = new m3ibike(noWriteResistance, noHeartService);
emit deviceConnected(b);
connect(m3iBike, &bluetoothdevice::connectedAndDiscovered, this,
&bluetooth::connectedAndDiscovered);
// connect(domyosBike, SIGNAL(disconnected()), this, SLOT(restart()));
connect(m3iBike, &m3ibike::debug, this, &bluetooth::debug);
m3iBike->deviceDiscovered(b);
connect(this, &bluetooth::searchingStop, m3iBike, &m3ibike::searchingStop);
if (this->discoveryAgent && !this->discoveryAgent->isActive())
emit searchingStop();
this->signalBluetoothDeviceConnected(m3iBike);
}
} else if (fake_bike && !fakeBike) {
this->stopDiscovery();
fakeBike = new fakebike(noWriteResistance, noHeartService, false);
emit deviceConnected(b);
connect(fakeBike, &bluetoothdevice::connectedAndDiscovered, this, &bluetooth::connectedAndDiscovered);
connect(fakeBike, &fakebike::inclinationChanged, this, &bluetooth::inclinationChanged);
connect(fakeBike, &fakebike::debug, this, &bluetooth::debug);
// connect(cscBike, SIGNAL(disconnected()), this, SLOT(restart()));
// connect(this, SIGNAL(searchingStop()), fakeBike, SLOT(searchingStop())); //NOTE: Commented due to
// #358
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(fakeBike);
} else if (fakedevice_elliptical && !fakeElliptical) {
this->stopDiscovery();
fakeElliptical = new fakeelliptical(noWriteResistance, noHeartService, false);
emit deviceConnected(b);
connect(fakeElliptical, &bluetoothdevice::connectedAndDiscovered, this,
&bluetooth::connectedAndDiscovered);
connect(fakeElliptical, &fakeelliptical::inclinationChanged, this, &bluetooth::inclinationChanged);
connect(fakeElliptical, &fakeelliptical::debug, this, &bluetooth::debug);
// connect(cscBike, SIGNAL(disconnected()), this, SLOT(restart()));
// connect(this, SIGNAL(searchingStop()), fakeBike, SLOT(searchingStop())); //NOTE: Commented due to
// #358
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(fakeElliptical);
} else if (fakedevice_rower && !fakeRower) {
this->stopDiscovery();
fakeRower = new fakerower(noWriteResistance, noHeartService, false);
emit deviceConnected(b);
connect(fakeRower, &bluetoothdevice::connectedAndDiscovered, this, &bluetooth::connectedAndDiscovered);
connect(fakeRower, &fakerower::inclinationChanged, this, &bluetooth::inclinationChanged);
connect(fakeRower, &fakerower::debug, this, &bluetooth::debug);
// connect(cscBike, SIGNAL(disconnected()), this, SLOT(restart()));
// connect(this, SIGNAL(searchingStop()), fakeBike, SLOT(searchingStop())); //NOTE: Commented due to
// #358
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(fakeRower);
} else if (fakedevice_treadmill && !fakeTreadmill) {
this->stopDiscovery();
fakeTreadmill = new faketreadmill(noWriteResistance, noHeartService, false);
emit deviceConnected(b);
connect(fakeTreadmill, &bluetoothdevice::connectedAndDiscovered, this,
&bluetooth::connectedAndDiscovered);
connect(fakeTreadmill, &faketreadmill::inclinationChanged, this, &bluetooth::inclinationChanged);
connect(fakeTreadmill, &faketreadmill::debug, this, &bluetooth::debug);
// connect(cscBike, SIGNAL(disconnected()), this, SLOT(restart()));
// connect(this, SIGNAL(searchingStop()), fakeBike, SLOT(searchingStop())); //NOTE: Commented due to
// #358
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(fakeTreadmill);
} else if (!proformtdf4ip.isEmpty() && !proformWifiBike) {
this->stopDiscovery();
proformWifiBike =
new proformwifibike(noWriteResistance, noHeartService, bikeResistanceOffset, bikeResistanceGain);
emit deviceConnected(b);
connect(proformWifiBike, &bluetoothdevice::connectedAndDiscovered, this,
&bluetooth::connectedAndDiscovered);
// connect(cscBike, SIGNAL(disconnected()), this, SLOT(restart()));
connect(proformWifiBike, &proformwifibike::debug, this, &bluetooth::debug);
proformWifiBike->deviceDiscovered(b);
// connect(this, SIGNAL(searchingStop()), cscBike, SLOT(searchingStop())); //NOTE: Commented due to #358
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(proformWifiBike);
} else if (!proformtdf1ip.isEmpty() && !proformTelnetBike) {
this->stopDiscovery();
proformTelnetBike =
new proformtelnetbike(noWriteResistance, noHeartService, bikeResistanceOffset, bikeResistanceGain);
emit deviceConnected(b);
connect(proformTelnetBike, &bluetoothdevice::connectedAndDiscovered, this,
&bluetooth::connectedAndDiscovered);
// connect(cscBike, SIGNAL(disconnected()), this, SLOT(restart()));
connect(proformTelnetBike, &proformtelnetbike::debug, this, &bluetooth::debug);
proformTelnetBike->deviceDiscovered(b);
// connect(this, SIGNAL(searchingStop()), cscBike, SLOT(searchingStop())); //NOTE: Commented due to #358
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(proformTelnetBike);
#ifndef Q_OS_IOS
} else if (!computrainerSerialPort.isEmpty() && !computrainerBike) {
this->stopDiscovery();
computrainerBike =
new computrainerbike(noWriteResistance, noHeartService, bikeResistanceOffset, bikeResistanceGain);
emit deviceConnected(b);
connect(computrainerBike, &bluetoothdevice::connectedAndDiscovered, this,
&bluetooth::connectedAndDiscovered);
// connect(cscBike, SIGNAL(disconnected()), this, SLOT(restart()));
connect(computrainerBike, &computrainerbike::debug, this, &bluetooth::debug);
computrainerBike->deviceDiscovered(b);
// connect(this, SIGNAL(searchingStop()), cscBike, SLOT(searchingStop())); //NOTE: Commented due to #358
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(computrainerBike);
} else if (!kettlerUsbSerialPort.isEmpty() && !kettlerUsbBike) {
this->stopDiscovery();
kettlerUsbBike =
new kettlerusbbike(noWriteResistance, noHeartService, bikeResistanceOffset, bikeResistanceGain);
emit deviceConnected(b);
connect(kettlerUsbBike, &bluetoothdevice::connectedAndDiscovered, this,
&bluetooth::connectedAndDiscovered);
connect(kettlerUsbBike, &kettlerusbbike::debug, this, &bluetooth::debug);
kettlerUsbBike->deviceDiscovered(b);
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(kettlerUsbBike);
} else if (!freebeatSerialPort.isEmpty() && !freebeatBike) {
this->stopDiscovery();
freebeatBike =
new freebeatbike(noWriteResistance, noHeartService, bikeResistanceOffset, bikeResistanceGain);
emit deviceConnected(b);
connect(freebeatBike, &bluetoothdevice::connectedAndDiscovered, this,
&bluetooth::connectedAndDiscovered);
connect(freebeatBike, &freebeatbike::debug, this, &bluetooth::debug);
freebeatBike->deviceDiscovered(b);
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(freebeatBike);
} else if (!csaferowerSerialPort.isEmpty() && !csafeRower) {
this->stopDiscovery();
csafeRower = new csaferower(noWriteResistance, noHeartService, false);
emit deviceConnected(b);
connect(csafeRower, &bluetoothdevice::connectedAndDiscovered, this, &bluetooth::connectedAndDiscovered);
// connect(cscBike, SIGNAL(disconnected()), this, SLOT(restart()));
connect(csafeRower, &csaferower::debug, this, &bluetooth::debug);
csafeRower->deviceDiscovered(b);
// connect(this, SIGNAL(searchingStop()), cscBike, SLOT(searchingStop())); //NOTE: Commented due to #358
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(csafeRower);
} else if (waterrowerUSBEnabled && !waterRowerUSB) {
qDebug() << QStringLiteral("WaterRower USB enabled, creating USB rower device");
this->stopDiscovery();
waterRowerUSB = new waterrowerusb(noWriteResistance, noHeartService, false);
emit deviceConnected(b);
connect(waterRowerUSB, &bluetoothdevice::connectedAndDiscovered, this, &bluetooth::connectedAndDiscovered);
connect(waterRowerUSB, &waterrowerusb::debug, this, &bluetooth::debug);
waterRowerUSB->deviceDiscovered(b);
if (this->discoveryAgent && !this->discoveryAgent->isActive()) {
emit searchingStop();
}
this->signalBluetoothDeviceConnected(waterRowerUSB);
} else if (!csafeellipticalSerialPort.isEmpty() && !csafeElliptical) {
this->stopDiscovery();
// csafeElliptical = new csafeelliptical(noWriteResistance, noHeartService, false);