mirror of
https://github.com/cagnulein/qdomyos-zwift.git
synced 2026-02-18 00:17:41 +01:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
254067d2b7 | ||
|
|
682f3f612b | ||
|
|
2604031967 | ||
|
|
aacb38aee1 | ||
|
|
6969bb2680 | ||
|
|
e8e17b5338 | ||
|
|
45f0240c3a | ||
|
|
88ee55d4b6 | ||
|
|
e20ec07926 | ||
|
|
cd56f632da | ||
|
|
b5463efa44 | ||
|
|
2f41754da9 | ||
|
|
3e82ac83ab |
@@ -473,6 +473,7 @@
|
||||
87BE6FDE272D2A3E00C35795 /* moc_horizongr7bike.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 87BE6FDD272D2A3E00C35795 /* moc_horizongr7bike.cpp */; };
|
||||
87BF116D298E28CA00B5B6E7 /* pelotonbike.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 87BF116C298E28CA00B5B6E7 /* pelotonbike.cpp */; };
|
||||
87BF116F298E28EC00B5B6E7 /* moc_pelotonbike.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 87BF116E298E28EC00B5B6E7 /* moc_pelotonbike.cpp */; };
|
||||
87BFEA2F2CEDDEEE00BDD759 /* ios_echelonconnectsport.mm in Compile Sources */ = {isa = PBXBuildFile; fileRef = 87BFEA2E2CEDDEEE00BDD759 /* ios_echelonconnectsport.mm */; };
|
||||
87C424262BC1294000503687 /* moc_treadmillErgTable.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 87C424252BC1294000503687 /* moc_treadmillErgTable.cpp */; };
|
||||
87C481FA26DFA7C3006211AD /* eliterizer.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 87C481F926DFA7C3006211AD /* eliterizer.cpp */; };
|
||||
87C481FC26DFA7D1006211AD /* moc_eliterizer.cpp in Compile Sources */ = {isa = PBXBuildFile; fileRef = 87C481FB26DFA7D1006211AD /* moc_eliterizer.cpp */; };
|
||||
@@ -1441,6 +1442,8 @@
|
||||
87BF116B298E28CA00B5B6E7 /* pelotonbike.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pelotonbike.h; path = ../src/devices/pelotonbike/pelotonbike.h; sourceTree = "<group>"; };
|
||||
87BF116C298E28CA00B5B6E7 /* pelotonbike.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = pelotonbike.cpp; path = ../src/devices/pelotonbike/pelotonbike.cpp; sourceTree = "<group>"; };
|
||||
87BF116E298E28EC00B5B6E7 /* moc_pelotonbike.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = moc_pelotonbike.cpp; sourceTree = "<group>"; };
|
||||
87BFEA2D2CEDDEEE00BDD759 /* ios_echelonconnectsport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ios_echelonconnectsport.h; path = ../src/ios/ios_echelonconnectsport.h; sourceTree = SOURCE_ROOT; };
|
||||
87BFEA2E2CEDDEEE00BDD759 /* ios_echelonconnectsport.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = ios_echelonconnectsport.mm; path = ../src/ios/ios_echelonconnectsport.mm; sourceTree = SOURCE_ROOT; };
|
||||
87C424252BC1294000503687 /* moc_treadmillErgTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = moc_treadmillErgTable.cpp; sourceTree = "<group>"; };
|
||||
87C481F826DFA7C3006211AD /* eliterizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = eliterizer.h; path = ../src/devices/eliterizer/eliterizer.h; sourceTree = "<group>"; };
|
||||
87C481F926DFA7C3006211AD /* eliterizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = eliterizer.cpp; path = ../src/devices/eliterizer/eliterizer.cpp; sourceTree = "<group>"; };
|
||||
@@ -2142,6 +2145,8 @@
|
||||
2EB56BE3C2D93CDAB0C52E67 /* Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
87BFEA2D2CEDDEEE00BDD759 /* ios_echelonconnectsport.h */,
|
||||
87BFEA2E2CEDDEEE00BDD759 /* ios_echelonconnectsport.mm */,
|
||||
8720891A2CE6567D008C2C17 /* mqttpublisher.cpp */,
|
||||
872088F02CE65451008C2C17 /* qmqttauthenticationproperties.h */,
|
||||
872088F12CE65451008C2C17 /* qmqttauthenticationproperties.cpp */,
|
||||
@@ -3654,6 +3659,7 @@
|
||||
873824BB27E64707004F1B46 /* moc_prober_p.cpp in Compile Sources */,
|
||||
877758B32C98627300BB1697 /* moc_sportstechelliptical.cpp in Compile Sources */,
|
||||
8742C2B227C92C30007D3FA0 /* wahookickrsnapbike.cpp in Compile Sources */,
|
||||
87BFEA2F2CEDDEEE00BDD759 /* ios_echelonconnectsport.mm in Compile Sources */,
|
||||
87EB918327EE5FE7002535E1 /* moc_inappstore.cpp in Compile Sources */,
|
||||
87CF516B293C87B000A7CABC /* moc_characteristicwriteprocessore005.cpp in Compile Sources */,
|
||||
8780D949264FB8B800192D41 /* moc_smartspin2k.cpp in Compile Sources */,
|
||||
@@ -4194,7 +4200,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 946;
|
||||
CURRENT_PROJECT_VERSION = 947;
|
||||
DEVELOPMENT_TEAM = 6335M7T29D;
|
||||
ENABLE_BITCODE = NO;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = "ADB_HOST=1";
|
||||
@@ -4388,7 +4394,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_ENTITLEMENTS = "../src/ios/qdomyos-zwift.entitlements";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
CURRENT_PROJECT_VERSION = 946;
|
||||
CURRENT_PROJECT_VERSION = 947;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = 6335M7T29D;
|
||||
ENABLE_BITCODE = NO;
|
||||
@@ -4618,7 +4624,7 @@
|
||||
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 946;
|
||||
CURRENT_PROJECT_VERSION = 947;
|
||||
DEVELOPMENT_TEAM = 6335M7T29D;
|
||||
ENABLE_BITCODE = YES;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
@@ -4714,7 +4720,7 @@
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 946;
|
||||
CURRENT_PROJECT_VERSION = 947;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEVELOPMENT_TEAM = 6335M7T29D;
|
||||
ENABLE_BITCODE = YES;
|
||||
@@ -4806,7 +4812,7 @@
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 946;
|
||||
CURRENT_PROJECT_VERSION = 947;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\"";
|
||||
ENABLE_BITCODE = YES;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
@@ -4920,7 +4926,7 @@
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = "watchkit Extension/WatchKit Extension.entitlements";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 946;
|
||||
CURRENT_PROJECT_VERSION = 947;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEVELOPMENT_ASSET_PATHS = "\"watchkit Extension/Preview Content\"";
|
||||
ENABLE_BITCODE = YES;
|
||||
|
||||
@@ -37,6 +37,7 @@ echelonconnectsport::echelonconnectsport(bool noWriteResistance, bool noHeartSer
|
||||
|
||||
void echelonconnectsport::writeCharacteristic(uint8_t *data, uint8_t data_len, const QString &info, bool disable_log,
|
||||
bool wait_for_response) {
|
||||
#ifndef Q_OS_IOS
|
||||
QEventLoop loop;
|
||||
QTimer timeout;
|
||||
|
||||
@@ -60,20 +61,29 @@ void echelonconnectsport::writeCharacteristic(uint8_t *data, uint8_t data_len, c
|
||||
qDebug() << QStringLiteral("gattWriteCharacteristic is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (writeBuffer) {
|
||||
delete writeBuffer;
|
||||
}
|
||||
writeBuffer = new QByteArray((const char *)data, data_len);
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
iOS_echelonConnectSport->echelonConnectSport_WriteCharacteristic((unsigned char*)writeBuffer->data(), data_len);
|
||||
#endif
|
||||
#else
|
||||
gattCommunicationChannelService->writeCharacteristic(gattWriteCharacteristic, *writeBuffer);
|
||||
#endif
|
||||
|
||||
if (!disable_log) {
|
||||
qDebug() << QStringLiteral(" >> ") + writeBuffer->toHex(' ') +
|
||||
QStringLiteral(" // ") + info;
|
||||
}
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
loop.exec();
|
||||
#endif
|
||||
}
|
||||
|
||||
void echelonconnectsport::forceResistance(resistance_t requestResistance) {
|
||||
@@ -105,17 +115,23 @@ void echelonconnectsport::sendPoll() {
|
||||
}
|
||||
|
||||
void echelonconnectsport::update() {
|
||||
#ifndef Q_OS_IOS
|
||||
if (m_control->state() == QLowEnergyController::UnconnectedState) {
|
||||
emit disconnected();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (initRequest) {
|
||||
initRequest = false;
|
||||
btinit();
|
||||
} else if (bluetoothDevice.isValid() && m_control->state() == QLowEnergyController::DiscoveredState &&
|
||||
} else if (
|
||||
#ifndef Q_OS_IOS
|
||||
bluetoothDevice.isValid() && m_control->state() == QLowEnergyController::DiscoveredState &&
|
||||
gattCommunicationChannelService && gattWriteCharacteristic.isValid() &&
|
||||
gattNotify1Characteristic.isValid() && gattNotify2Characteristic.isValid() && initDone) {
|
||||
gattNotify1Characteristic.isValid() && gattNotify2Characteristic.isValid() &&
|
||||
#endif
|
||||
initDone) {
|
||||
update_metrics(true, watts());
|
||||
|
||||
// sending poll every 2 seconds
|
||||
@@ -318,9 +334,11 @@ void echelonconnectsport::characteristicChanged(const QLowEnergyCharacteristic &
|
||||
qDebug() << QStringLiteral("Last CrankEventTime: ") + QString::number(LastCrankEventTime);
|
||||
qDebug() << QStringLiteral("Current Watt: ") + QString::number(watts());
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
if (m_control->error() != QLowEnergyController::NoError) {
|
||||
qDebug() << QStringLiteral("QLowEnergyController ERROR!!") << m_control->errorString();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
QTime echelonconnectsport::GetElapsedFromPacket(const QByteArray &packet) {
|
||||
@@ -366,6 +384,7 @@ void echelonconnectsport::btinit() {
|
||||
}
|
||||
|
||||
void echelonconnectsport::stateChanged(QLowEnergyService::ServiceState state) {
|
||||
#ifndef Q_OS_IOS
|
||||
QBluetoothUuid _gattWriteCharacteristicId(QStringLiteral("0bf669f2-45f2-11e7-9598-0800200c9a66"));
|
||||
QBluetoothUuid _gattNotify1CharacteristicId(QStringLiteral("0bf669f3-45f2-11e7-9598-0800200c9a66"));
|
||||
QBluetoothUuid _gattNotify2CharacteristicId(QStringLiteral("0bf669f4-45f2-11e7-9598-0800200c9a66"));
|
||||
@@ -393,7 +412,7 @@ void echelonconnectsport::stateChanged(QLowEnergyService::ServiceState state) {
|
||||
this, &echelonconnectsport::errorService);
|
||||
connect(gattCommunicationChannelService, &QLowEnergyService::descriptorWritten, this,
|
||||
&echelonconnectsport::descriptorWritten);
|
||||
|
||||
#endif
|
||||
// ******************************************* virtual bike init *************************************
|
||||
if (!firstStateChanged && !this->hasVirtualDevice()
|
||||
#ifdef Q_OS_IOS
|
||||
@@ -438,7 +457,7 @@ void echelonconnectsport::stateChanged(QLowEnergyService::ServiceState state) {
|
||||
}
|
||||
firstStateChanged = 1;
|
||||
// ********************************************************************************************************
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
QByteArray descriptor;
|
||||
descriptor.append((char)0x01);
|
||||
descriptor.append((char)0x00);
|
||||
@@ -447,6 +466,7 @@ void echelonconnectsport::stateChanged(QLowEnergyService::ServiceState state) {
|
||||
gattCommunicationChannelService->writeDescriptor(
|
||||
gattNotify2Characteristic.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), descriptor);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void echelonconnectsport::descriptorWritten(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue) {
|
||||
@@ -464,7 +484,7 @@ void echelonconnectsport::characteristicWritten(const QLowEnergyCharacteristic &
|
||||
|
||||
void echelonconnectsport::serviceScanDone(void) {
|
||||
qDebug() << QStringLiteral("serviceScanDone");
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
QBluetoothUuid _gattCommunicationChannelServiceId(QStringLiteral("0bf669f1-45f2-11e7-9598-0800200c9a66"));
|
||||
|
||||
gattCommunicationChannelService = m_control->createServiceObject(_gattCommunicationChannelServiceId);
|
||||
@@ -477,6 +497,7 @@ void echelonconnectsport::serviceScanDone(void) {
|
||||
homeform::singleton()->setToastRequested("Bluetooth Service Error! Restart the bike!");
|
||||
m_control->disconnectFromDevice();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void echelonconnectsport::errorService(QLowEnergyService::ServiceError err) {
|
||||
@@ -494,6 +515,14 @@ void echelonconnectsport::error(QLowEnergyController::Error err) {
|
||||
void echelonconnectsport::deviceDiscovered(const QBluetoothDeviceInfo &device) {
|
||||
qDebug() << QStringLiteral("Found new device: ") + device.name() + QStringLiteral(" (") +
|
||||
device.address().toString() + ')';
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
#ifndef IO_UNDER_QT
|
||||
iOS_echelonConnectSport = new lockscreen();
|
||||
iOS_echelonConnectSport->echelonConnectSport(device.name().toStdString().c_str(), this);
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
if (device.name().startsWith(QStringLiteral("ECH"))) {
|
||||
bluetoothDevice = device;
|
||||
|
||||
@@ -531,6 +560,10 @@ void echelonconnectsport::deviceDiscovered(const QBluetoothDeviceInfo &device) {
|
||||
}
|
||||
|
||||
bool echelonconnectsport::connected() {
|
||||
#ifdef Q_OS_IOS
|
||||
return true;
|
||||
#endif
|
||||
|
||||
if (!m_control) {
|
||||
return false;
|
||||
}
|
||||
@@ -657,10 +690,16 @@ uint16_t echelonconnectsport::wattsFromResistance(double resistance) {
|
||||
|
||||
void echelonconnectsport::controllerStateChanged(QLowEnergyController::ControllerState state) {
|
||||
qDebug() << QStringLiteral("controllerStateChanged") << state;
|
||||
if (state == QLowEnergyController::UnconnectedState && m_control) {
|
||||
if (state == QLowEnergyController::UnconnectedState
|
||||
#ifndef Q_OS_IOS
|
||||
&& m_control
|
||||
#endif
|
||||
) {
|
||||
lastResistanceBeforeDisconnection = Resistance.value();
|
||||
qDebug() << QStringLiteral("trying to connect back again...");
|
||||
initDone = false;
|
||||
#ifndef Q_OS_IOS
|
||||
m_control->connectToDevice();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +60,12 @@ class echelonconnectsport : public bike {
|
||||
|
||||
QTimer *refresh;
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
QLowEnergyService *gattCommunicationChannelService = nullptr;
|
||||
QLowEnergyCharacteristic gattWriteCharacteristic;
|
||||
QLowEnergyCharacteristic gattNotify1Characteristic;
|
||||
QLowEnergyCharacteristic gattNotify2Characteristic;
|
||||
#endif
|
||||
|
||||
int8_t bikeResistanceOffset = 4;
|
||||
double bikeResistanceGain = 1.0;
|
||||
@@ -82,6 +84,7 @@ class echelonconnectsport : public bike {
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
lockscreen *h = 0;
|
||||
lockscreen* iOS_echelonConnectSport = nullptr;
|
||||
#endif
|
||||
|
||||
Q_SIGNALS:
|
||||
@@ -89,14 +92,14 @@ class echelonconnectsport : public bike {
|
||||
|
||||
public slots:
|
||||
void deviceDiscovered(const QBluetoothDeviceInfo &device);
|
||||
void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue);
|
||||
void stateChanged(QLowEnergyService::ServiceState state);
|
||||
void descriptorWritten(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue);
|
||||
void controllerStateChanged(QLowEnergyController::ControllerState state);
|
||||
|
||||
private slots:
|
||||
|
||||
void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue);
|
||||
void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue);
|
||||
void descriptorWritten(const QLowEnergyDescriptor &descriptor, const QByteArray &newValue);
|
||||
void stateChanged(QLowEnergyService::ServiceState state);
|
||||
void controllerStateChanged(QLowEnergyController::ControllerState state);
|
||||
|
||||
void serviceDiscovered(const QBluetoothUuid &gatt);
|
||||
void serviceScanDone(void);
|
||||
|
||||
23
src/ios/ios_echelonconnectsport.h
Normal file
23
src/ios/ios_echelonconnectsport.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef IOSECHELONCONNECTSPORT_H
|
||||
#define IOSECHELONCONNECTSPORT_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import "echelonconnectsport.h"
|
||||
|
||||
@interface ios_echelonconnectsport : NSObject <CBCentralManagerDelegate, CBPeripheralDelegate>
|
||||
|
||||
@property (strong, nonatomic) CBCentralManager *centralManager;
|
||||
@property (strong, nonatomic) CBPeripheral *connectedPeripheral;
|
||||
@property (strong, nonatomic) NSString *targetDeviceName;
|
||||
@property echelonconnectsport *qtDevice;
|
||||
@property (strong, nonatomic) CBCharacteristic *gattWriteCharacteristic;
|
||||
@property (strong, nonatomic) CBCharacteristic *gattNotify1Characteristic;
|
||||
@property (strong, nonatomic) CBCharacteristic *gattNotify2Characteristic;
|
||||
|
||||
- (instancetype)init:(NSString *)deviceName qtDevice:(void*)qtDevice;
|
||||
- (void)writeCharacteristc:(uint8_t *)data length:(NSUInteger)length;
|
||||
|
||||
@end
|
||||
|
||||
#endif // IOSECHELONCONNECTSPORT_H
|
||||
112
src/ios/ios_echelonconnectsport.mm
Normal file
112
src/ios/ios_echelonconnectsport.mm
Normal file
@@ -0,0 +1,112 @@
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import "ios_echelonconnectsport.h"
|
||||
|
||||
@implementation ios_echelonconnectsport
|
||||
|
||||
- (instancetype)init:(NSString *)deviceName qtDevice:(void*)qtDevice {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_targetDeviceName = [deviceName copy];
|
||||
qDebug() << _targetDeviceName;
|
||||
_qtDevice = (echelonconnectsport*)qtDevice;
|
||||
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
|
||||
if (central.state == CBManagerStatePoweredOn) {
|
||||
qDebug() << "centralManagerDidUpdateState" << central.state;
|
||||
[self.centralManager scanForPeripheralsWithServices:nil options:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI {
|
||||
if (peripheral && _targetDeviceName && peripheral.name) {
|
||||
qDebug() << _targetDeviceName;
|
||||
if ([peripheral.name isEqualToString:_targetDeviceName]) {
|
||||
self.connectedPeripheral = peripheral;
|
||||
[self.centralManager stopScan];
|
||||
[self.centralManager connectPeripheral:peripheral options:nil];
|
||||
qDebug() << "didDiscoverPeripheral";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
|
||||
peripheral.delegate = self;
|
||||
[peripheral discoverServices:nil];
|
||||
}
|
||||
|
||||
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
|
||||
qDebug() << "Peripheral disconnected:" << peripheral << error;
|
||||
if ([peripheral.name isEqualToString:self.targetDeviceName]) {
|
||||
_qtDevice->controllerStateChanged(QLowEnergyController::UnconnectedState);
|
||||
[self.centralManager connectPeripheral:peripheral options:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
|
||||
for (CBService *service in peripheral.services) {
|
||||
[peripheral discoverCharacteristics:nil forService:service];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
|
||||
if (characteristic.value) {
|
||||
qDebug() << "didUpdateValueForCharacteristic" << characteristic;
|
||||
// Extract the data from characteristic.value and process it as needed
|
||||
NSData *receivedData = characteristic.value;
|
||||
NSLog(@"UUID: %@ Received data: %@", characteristic.UUID, receivedData);
|
||||
// Your processing logic here
|
||||
//[self.qtDevice characteristicChanged:characteristic.UUID data:receivedData];
|
||||
QLowEnergyCharacteristic c;
|
||||
QByteArray b;
|
||||
const uint8_t* d = (const uint8_t*)[receivedData bytes];
|
||||
for(int i=0; i<receivedData.length; i++) {
|
||||
b.append(d[i]);
|
||||
}
|
||||
self.qtDevice->characteristicChanged(c, b);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
|
||||
CBUUID *write = [CBUUID UUIDWithString:@"0bf669f2-45f2-11e7-9598-0800200c9a66"];
|
||||
CBUUID *uuid1 = [CBUUID UUIDWithString:@"0bf669f3-45f2-11e7-9598-0800200c9a66"];
|
||||
CBUUID *uuid2 = [CBUUID UUIDWithString:@"0bf669f4-45f2-11e7-9598-0800200c9a66"];
|
||||
|
||||
for (CBCharacteristic *characteristic in service.characteristics) {
|
||||
if ([characteristic.UUID isEqual:uuid1]) {
|
||||
self.gattNotify1Characteristic = characteristic;
|
||||
[peripheral setNotifyValue:YES forCharacteristic:self.gattNotify1Characteristic];
|
||||
} else if ([characteristic.UUID isEqual:uuid2]) {
|
||||
self.gattNotify2Characteristic = characteristic;
|
||||
[peripheral setNotifyValue:YES forCharacteristic:self.gattNotify2Characteristic];
|
||||
} else if ([characteristic.UUID isEqual:write]) {
|
||||
self.gattWriteCharacteristic = characteristic;
|
||||
}
|
||||
}
|
||||
|
||||
// Verifica se entrambe le caratteristiche sono state trovate
|
||||
if (self.gattNotify1Characteristic && self.gattNotify2Characteristic && self.gattWriteCharacteristic) {
|
||||
self.qtDevice->stateChanged(QLowEnergyService::ServiceDiscovered);
|
||||
self.qtDevice->descriptorWritten(QLowEnergyDescriptor(), QByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
- (void)writeCharacteristc:(uint8_t *)data length:(NSUInteger)length {
|
||||
if (self.connectedPeripheral.state != CBPeripheralStateConnected) {
|
||||
qDebug() << "Cannot send. Peripheral is not connected.";
|
||||
return;
|
||||
}
|
||||
|
||||
NSData *dataToSend = [NSData dataWithBytes:data length:length];
|
||||
|
||||
qDebug() << "writeCharacteristc" << dataToSend;
|
||||
|
||||
if (self.gattWriteCharacteristic) {
|
||||
[self.connectedPeripheral writeValue:dataToSend forCharacteristic:self.gattWriteCharacteristic type:CBCharacteristicWriteWithResponse];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -72,6 +72,10 @@ class lockscreen {
|
||||
// Elite Aria Fan
|
||||
void eliteAriaFan();
|
||||
void eliteAriaFan_fanSpeedRequest(unsigned char speed);
|
||||
|
||||
// Echelon Connect Sport
|
||||
void echelonConnectSport(const char* Name, void* deviceClass);
|
||||
void echelonConnectSport_WriteCharacteristic(unsigned char* qdata, unsigned char length);
|
||||
|
||||
// Zwift API
|
||||
void zwift_api_decodemessage_player(const char* data, int len);
|
||||
|
||||
@@ -10,17 +10,18 @@
|
||||
#include <QDebug>
|
||||
#include "ios/AdbClient.h"
|
||||
#include "ios/ios_eliteariafan.h"
|
||||
#include "ios/ios_echelonconnectsport.h"
|
||||
|
||||
@class virtualbike_ios_swift;
|
||||
@class virtualbike_zwift;
|
||||
@class virtualrower;
|
||||
@class virtualrower_zwift;
|
||||
@class virtualtreadmill_zwift;
|
||||
@class healthkit;
|
||||
|
||||
static healthkit* h = 0;
|
||||
static virtualbike_ios_swift* _virtualbike = nil;
|
||||
static virtualbike_zwift* _virtualbike_zwift = nil;
|
||||
static virtualrower* _virtualrower = nil;
|
||||
static virtualrower_zwift* _virtualrower = nil;
|
||||
static virtualtreadmill_zwift* _virtualtreadmill_zwift = nil;
|
||||
|
||||
static GarminConnect* Garmin = 0;
|
||||
@@ -28,6 +29,7 @@ static GarminConnect* Garmin = 0;
|
||||
static AdbClient *_adb = 0;
|
||||
|
||||
static ios_eliteariafan* ios_eliteAriaFan = nil;
|
||||
static ios_echelonconnectsport* ios_echelonConnectSport = nil;
|
||||
|
||||
static zwift_protobuf_layer* zwiftProtobufLayer = nil;
|
||||
|
||||
@@ -108,7 +110,7 @@ void lockscreen::virtualbike_zwift_ios(bool disable_hr, bool garmin_bluetooth_co
|
||||
|
||||
void lockscreen::virtualrower_ios()
|
||||
{
|
||||
_virtualrower = [[virtualrower alloc] init];
|
||||
_virtualrower = [[virtualrower_zwift alloc] init];
|
||||
}
|
||||
|
||||
double lockscreen::virtualbike_getCurrentSlope()
|
||||
@@ -321,6 +323,17 @@ void lockscreen::eliteAriaFan_fanSpeedRequest(unsigned char speed) {
|
||||
}
|
||||
}
|
||||
|
||||
void lockscreen::echelonConnectSport(const char* Name, void* deviceClass) {
|
||||
NSString *deviceName = [NSString stringWithCString:Name encoding:NSASCIIStringEncoding];
|
||||
ios_echelonConnectSport = [[ios_echelonconnectsport alloc] init:deviceName qtDevice:deviceClass];
|
||||
}
|
||||
|
||||
void lockscreen::echelonConnectSport_WriteCharacteristic(unsigned char* qdata, unsigned char length) {
|
||||
if(ios_echelonConnectSport) {
|
||||
[ios_echelonConnectSport writeCharacteristc:qdata length:length ];
|
||||
}
|
||||
}
|
||||
|
||||
void lockscreen::zwift_api_decodemessage_player(const char* data, int len) {
|
||||
NSData *d = [NSData dataWithBytes:data length:len];
|
||||
[zwiftProtobufLayer getPlayerStateWithValue:d];
|
||||
|
||||
@@ -2,7 +2,7 @@ import CoreBluetooth
|
||||
|
||||
let rowerUuid = CBUUID(string: "0x2AD1");
|
||||
|
||||
@objc public class virtualrower: NSObject {
|
||||
@objc public class virtualrower_zwift: NSObject {
|
||||
private var peripheralManager: rowerBLEPeripheralManagerZwift!
|
||||
|
||||
@objc public override init() {
|
||||
|
||||
Reference in New Issue
Block a user