BLE Cleanup

This commit is contained in:
Garth Vander Houwen 2021-11-17 07:34:37 -08:00
parent 8de9c62519
commit 7bbfb38c3f
4 changed files with 19 additions and 15 deletions

View file

@ -682,7 +682,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.27.9;
MARKETING_VERSION = 1.28.1;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
@ -709,7 +709,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.27.9;
MARKETING_VERSION = 1.28.1;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;

View file

@ -42,8 +42,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "475"
endingLineNumber = "475"
startingLineNumber = "476"
endingLineNumber = "476"
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
landmarkType = "7">
</BreakpointContent>
@ -58,8 +58,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "354"
endingLineNumber = "354"
startingLineNumber = "355"
endingLineNumber = "355"
landmarkName = "peripheral(_:didUpdateNotificationStateFor:error:)"
landmarkType = "7">
</BreakpointContent>
@ -74,8 +74,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "432"
endingLineNumber = "432"
startingLineNumber = "433"
endingLineNumber = "433"
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
landmarkType = "7">
</BreakpointContent>

View file

@ -196,7 +196,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// called when a peripheral is connected
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
peripheral.delegate = self
//peripheral.delegate = self
// Invalidate and reset connection timer count, remove any connection errors
lastConnectionError = ""
self.timeoutTimer!.invalidate()
@ -204,6 +204,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Map the peripheral to the connectedNode and connectedPeripheral ObservedObjects
connectedPeripheral = peripherals.filter({ $0.peripheral.identifier == peripheral.identifier }).first
connectedPeripheral.peripheral.delegate = self
let deviceName = peripheral.name ?? ""
let peripheralLast4: String = String(deviceName.suffix(4))
connectedNode = self.meshData.nodes.first(where: { $0.user.id.contains(peripheralLast4) })
@ -219,7 +220,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Disconnect Peripheral Event
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?)
{
peripheral.delegate = self
connectedPeripheral.peripheral.delegate = self
// Start a scan so the disconnected peripheral is moved to the peripherals[] if it is awake
self.startScanning()
self.connectedPeripheral = nil
@ -276,7 +277,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Discover Services Event
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
peripheral.delegate = self
connectedPeripheral.peripheral.delegate = self
if let e = error {
print("Discover Services error \(e)")
@ -300,7 +301,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Discover Characteristics Event
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
{
peripheral.delegate = self
connectedPeripheral.peripheral.delegate = self
if let e = error {
print("Discover Characteristics error \(e)")
@ -346,7 +347,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {
peripheral.delegate = self
connectedPeripheral.peripheral.delegate = self
print("didUpdateNotificationStateFor char: \(characteristic.uuid.uuidString) \(characteristic.isNotifying)")
if meshLoggingEnabled { MeshLogger.log("didUpdateNotificationStateFor char: \(characteristic.uuid.uuidString) \(characteristic.isNotifying)") }
if let errorText = error?.localizedDescription
@ -377,7 +378,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Data Read / Update Characteristic Event
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)
{
peripheral.delegate = self
connectedPeripheral.peripheral.delegate = self
if let e = error {
print("didUpdateValueFor Characteristic error \(e)")
@ -629,7 +630,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
if decodedInfo.configCompleteID != 0 {
if meshLoggingEnabled { MeshLogger.log("BLE Config Complete Packet Id: \(decodedInfo.configCompleteID)") }
print("BLE Config Complete Packet Id: \(decodedInfo.configCompleteID)")
self.connectedPeripheral.subscribed = true
}
default:

View file

@ -64,6 +64,9 @@ struct Connect: View {
if bleManager.connectedPeripheral.myInfo != nil {
Text("FW Version: ").font(.caption)+Text(bleManager.connectedPeripheral.myInfo?.firmwareVersion ?? "(null)").font(.caption).foregroundColor(Color.gray)
}
if bleManager.connectedPeripheral.subscribed {
Text("Properly Subscribed").font(.caption)
}
}
Spacer()