Fix assorted bugs, add connected indicator to every view, simplify some code

This commit is contained in:
Garth Vander Houwen 2021-12-17 00:21:53 -08:00
parent be28e161d5
commit 0b6c316e85
5 changed files with 46 additions and 50 deletions

View file

@ -74,10 +74,10 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "822"
endingLineNumber = "822"
startingLineNumber = "826"
endingLineNumber = "826"
landmarkName = "sendMessage(message:)"
landmarkType = "9">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@ -90,10 +90,10 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "845"
endingLineNumber = "845"
startingLineNumber = "849"
endingLineNumber = "849"
landmarkName = "sendMessage(message:)"
landmarkType = "9">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@ -122,8 +122,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "395"
endingLineNumber = "395"
startingLineNumber = "398"
endingLineNumber = "398"
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
landmarkType = "7">
</BreakpointContent>
@ -138,8 +138,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "454"
endingLineNumber = "454"
startingLineNumber = "457"
endingLineNumber = "457"
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
landmarkType = "7">
</BreakpointContent>
@ -154,8 +154,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "663"
endingLineNumber = "663"
startingLineNumber = "666"
endingLineNumber = "666"
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
landmarkType = "7">
</BreakpointContent>
@ -170,8 +170,8 @@
filePath = "MeshtasticClient/Helpers/BLEManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "706"
endingLineNumber = "706"
startingLineNumber = "709"
endingLineNumber = "709"
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
landmarkType = "7">
</BreakpointContent>

View file

@ -79,9 +79,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
func startScanning() {
if isSwitchedOn {
self.peripherals.removeAll()
centralManager.scanForPeripherals(withServices: [meshtasticServiceCBUUID], options: nil)
self.isScanning = self.centralManager.isScanning
print("Scanning Started")
}
}
@ -93,6 +95,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
self.centralManager.stopScan()
self.isScanning = self.centralManager.isScanning
print("Stopped Scanning")
}
}
@ -167,7 +170,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
peripheralName = name
}
let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, num: 0, name: peripheralName, shortName: "", longName: "", firmwareVersion: "Unknown", rssi: RSSI.intValue, subscribed: false, peripheral: peripheral)
let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, num: 0, name: peripheralName, shortName: String(peripheralName.suffix(3)), longName: peripheralName, firmwareVersion: "Unknown", rssi: RSSI.intValue, subscribed: false, peripheral: peripheral)
let peripheralIndex = peripherals.firstIndex(where: { $0.id == newPeripheral.id })
if peripheralIndex != nil && newPeripheral.peripheral.state != CBPeripheralState.connected {
@ -485,7 +488,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
position.longitudeI = decodedInfo.nodeInfo.position.longitudeI
position.altitude = decodedInfo.nodeInfo.position.altitude
position.batteryLevel = decodedInfo.nodeInfo.position.batteryLevel
position.time = Int32(bitPattern: decodedInfo.nodeInfo.position.time)
position.time = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.nodeInfo.position.time)))
var newPostions = [PositionEntity]()
newPostions.append(position)
@ -522,14 +525,14 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
fetchedNode[0].user!.shortName = decodedInfo.nodeInfo.user.shortName
fetchedNode[0].user!.hwModel = String(describing: decodedInfo.nodeInfo.user.hwModel).uppercased()
}
if decodedInfo.nodeInfo.hasPosition {
if decodedInfo.nodeInfo.hasPosition && decodedInfo.nodeInfo.position.latitudeI != 0 && decodedInfo.nodeInfo.position.longitudeI != 0 {
let position = PositionEntity(context: context!)
position.latitudeI = decodedInfo.nodeInfo.position.latitudeI
position.longitudeI = decodedInfo.nodeInfo.position.longitudeI
position.altitude = decodedInfo.nodeInfo.position.altitude
position.batteryLevel = decodedInfo.nodeInfo.position.batteryLevel
position.time = Int32(bitPattern: decodedInfo.nodeInfo.position.time)
position.time = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.nodeInfo.position.time)))
if position.latitudeI != 0 {
let mutablePositions = fetchedNode[0].positions!.mutableCopy() as! NSMutableSet
@ -671,7 +674,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
if fetchedNode.count == 1 {
fetchedNode[0].id = Int64(decodedInfo.packet.from)
fetchedNode[0].num = Int64(decodedInfo.packet.from)
fetchedNode[0].lastHeard = Date()//Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.packet.rxTime)))
fetchedNode[0].lastHeard = Date(timeIntervalSince1970: TimeInterval(Int64(decodedInfo.packet.rxTime)))
fetchedNode[0].snr = decodedInfo.packet.rxSnr
}
else {
@ -766,6 +769,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
if meshLoggingEnabled { MeshLogger.log("BLE Config Complete Packet Id: \(decodedInfo.configCompleteID)") }
print("BLE Config Complete Packet Id: \(decodedInfo.configCompleteID)")
self.connectedPeripheral.subscribed = true
self.peripherals.removeAll()
}
default:

View file

@ -48,10 +48,10 @@ struct Messages: View {
ForEach(messages) { message in
HStack(alignment: .top) {
//let currentUser: true//(message.fromUser != nil && bleManager.connectedPeripheral.num == message.fromUser!.num)
let currentUser: Bool = (message.fromUser != nil && bleManager.connectedPeripheral.num == message.fromUser!.num)
CircleText(text: (message.fromUser?.longName ?? "???"), color: true ? .accentColor : Color(.darkGray)).padding(.all, 5)
CircleText(text: (message.fromUser?.longName ?? "???"), color: currentUser ? .accentColor : Color(.darkGray)).padding(.all, 5)
.gesture(LongPressGesture(minimumDuration: 2)
.onEnded {_ in
print("I want to delete message: \(message.messageId)")
@ -66,7 +66,7 @@ struct Messages: View {
.textSelection(.enabled)
.padding(10)
.foregroundColor(.white)
.background(true ? Color.blue : Color(.darkGray))
.background(currentUser ? Color.blue : Color(.darkGray))
.cornerRadius(10)
HStack(spacing: 4) {

View file

@ -29,7 +29,10 @@ struct NodeDetail: View {
if node.positions != nil && node.positions!.count > 0 {
// let nodeCoordinatePosition = CLLocationCoordinate2D(latitude: node.position.latitude!, longitude: node.position.longitude!)
// let mostRecentPositions = node.positions.max(by: {
// $0. < $1.timeIntervalSinceReferenceDate
// })
// let nodeCoordinatePosition = CLLocationCoordinate2D(latitude: node.positions.latitude!, longitude: node.position.longitude!)
//
// let regionBinding = Binding<MKCoordinateRegion>(
// get: {
@ -37,7 +40,7 @@ struct NodeDetail: View {
// },
// set: { _ in }
// )
// let annotations = [MapLocation(name: node.user.shortName, coordinate: node.position.coordinate!)]
// let annotations = [MapLocation(name: node.user!.shortName, coordinate: node.positions?.first(where: <#T##(Any) throws -> Bool#>).coordinate!)]
//
// Map(coordinateRegion: regionBinding, showsUserLocation: true, userTrackingMode: .none, annotationItems: annotations) { location in
// MapAnnotation(

View file

@ -43,32 +43,21 @@ struct NodeMap: View {
NavigationView {
ZStack {
Map(coordinateRegion: regionBinding, showsUserLocation: true, userTrackingMode: .none)
.frame(maxHeight: .infinity)
//, annotationItems: locationNodes[0].positions?) { location in
// MapAnnotation(
// coordinate: location.coordinate,
// content: {
// CircleText(text: location.latitude, color: .accentColor)
// }
// )
// }.frame(maxHeight: .infinity)
//Map(coordinateRegion: regionBinding,
// interactionModes: [.all],
// showsUserLocation: true,
// userTrackingMode: .constant(.follow), annotationItems: locationNodes) { node in
//MapAnnotation(
//coordinate: node.positions[0].coordinate,
//content: {
// CircleText(text: node.user!.shortName, color: .accentColor)
//}
// )
//}
//.frame(maxHeight: .infinity)
//.ignoresSafeArea(.all, edges: [.leading, .trailing])
// Map(coordinateRegion: regionBinding,
// interactionModes: [.all],
// showsUserLocation: true,
// userTrackingMode: .constant(.follow), annotationItems: $locationNodes) { node in
//
// MapAnnotation(
// coordinate: node.positions[0].coordinate,
// content: {
// CircleText(text: node.user!.shortName, color: .accentColor)
// }
// )
// }
// .frame(maxHeight: .infinity)
// .ignoresSafeArea(.all, edges: [.leading, .trailing])
}
.navigationTitle("Mesh Map")
.navigationBarTitleDisplayMode(.inline)