V 1.25.6 Re-implement last connected node functionality clean up notification with title, subtitle and content body

This commit is contained in:
Garth Vander Houwen 2021-10-14 22:51:09 -07:00
parent d2587e7ff0
commit df4a70b672
4 changed files with 25 additions and 22 deletions

View file

@ -659,7 +659,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.25.5;
MARKETING_VERSION = 1.25.6;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = NO;
@ -686,7 +686,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.25.5;
MARKETING_VERSION = 1.25.6;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = NO;

View file

@ -15,6 +15,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
@Published var connectedPeripheral: Peripheral!
@Published var connectedNode: NodeInfoModel!
@Published var lastConnectedPeripheral: String
@Published var lastConnectionError: String
@Published var isSwitchedOn = false
@ -37,6 +38,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
self.meshData = MeshData()
self.messageData = MessageData()
self.lastConnectedPeripheral = ""
self.lastConnectionError = ""
super.init()
centralManager = CBCentralManager(delegate: self, queue: nil)
@ -92,8 +94,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Disconnect Device function
func disconnectDevice(){
if connectedPeripheral != nil && connectedPeripheral.peripheral.state == CBPeripheralState.connected {
if connectedPeripheral != nil {
self.centralManager?.cancelPeripheralConnection(connectedPeripheral.peripheral)
}
}
@ -118,11 +119,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
peripheral.delegate = self
connectedPeripheral = peripherals.filter({ $0.peripheral.identifier == peripheral.identifier }).first
if connectedPeripheral != nil {
connectedPeripheral.peripheral.discoverServices([meshtasticServiceCBUUID])
print("Peripheral connected: " + peripheral.name!)
}
lastConnectedPeripheral = peripheral.identifier.uuidString
peripheral.discoverServices([meshtasticServiceCBUUID])
print("Peripheral connected: " + peripheral.name!)
}
// Send Broadcast Message
@ -133,6 +132,13 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Return false if we are not properly connected to a device, handle retry logic in the view for now
if connectedPeripheral == nil || connectedPeripheral!.peripheral.state != CBPeripheralState.connected || self.connectedNode == nil {
// Try and connect to the last connected device
self.disconnectDevice()
let lastConnectedPeripheral = peripherals.filter({ $0.peripheral.identifier.uuidString == self.lastConnectedPeripheral }).first
if lastConnectedPeripheral != nil && lastConnectedPeripheral?.peripheral != nil {
connectTo(peripheral: lastConnectedPeripheral!.peripheral)
}
success = false
success = false
}
else if message.count < 1 {
@ -292,9 +298,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
{
case FROMNUM_UUID:
peripheral.readValue(for: FROMNUM_characteristic)
let byteArrayFromData: [UInt8] = [UInt8](characteristic.value!)
let stringFromByteArray = String(data: Data(_: byteArrayFromData), encoding: .utf8)
print("string array data \(stringFromByteArray!)")
//let byteArrayFromData: [UInt8] = [UInt8](characteristic.value!)
//let stringFromByteArray = String(data: Data(_: byteArrayFromData), encoding: .utf8)
//print("string array data \(stringFromByteArray!)")
//print(characteristic.value?. ?? "no value")
@ -316,7 +322,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
// Create a MyInfoModel
let myInfoModel = MyInfoModel(
id: connectedPeripheral.peripheral.identifier,
myNodeNum: decodedInfo.myInfo.myNodeNum,
hasGps: decodedInfo.myInfo.hasGps_p,
numBands: decodedInfo.myInfo.numBands,

View file

@ -4,7 +4,7 @@ struct MyInfoModel: Identifiable, Codable {
// Uses the BLE Peripheral identifier as the ID
// So myInfo can map between Peripherals and Nodes
var id: UUID
var id: UInt32
var myNodeNum: UInt32
var hasGps: Bool
var numBands: UInt32
@ -13,9 +13,9 @@ struct MyInfoModel: Identifiable, Codable {
var messageTimeoutMsec: UInt32
var minAppVersion: UInt32
init(id: UUID, myNodeNum: UInt32, hasGps: Bool, numBands: UInt32, maxChannels: UInt32, firmwareVersion: String, messageTimeoutMsec: UInt32, minAppVersion: UInt32) {
init(myNodeNum: UInt32, hasGps: Bool, numBands: UInt32, maxChannels: UInt32, firmwareVersion: String, messageTimeoutMsec: UInt32, minAppVersion: UInt32) {
self.id = id
self.id = myNodeNum
self.myNodeNum = myNodeNum
self.hasGps = hasGps
self.numBands = numBands

View file

@ -92,12 +92,10 @@ struct Messages: View {
}
else {
if bleManager.connectedPeripheral != nil {
let timer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { (timer) in
if bleManager.sendMessage(message: typingMessage) {
typingMessage = ""
}
let _ = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { (timer) in
if bleManager.sendMessage(message: typingMessage) {
typingMessage = ""
}
}
}