V 1.27.6 Persistent bluetooth connection indicator, consolidated loading of data in BLEManager. Default to mesh logging being on

This commit is contained in:
Garth Vander Houwen 2021-10-28 00:15:47 -07:00
parent 57dfbdd2e2
commit c3a9136e6c
9 changed files with 44 additions and 33 deletions

View file

@ -672,7 +672,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.27.4;
MARKETING_VERSION = 1.27.6;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
@ -699,7 +699,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.27.4;
MARKETING_VERSION = 1.27.6;
PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;

View file

@ -31,6 +31,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
@Published var lastConnectionError: String
@Published var isSwitchedOn = false
@Published var isScanning = false
@Published var peripherals = [Peripheral]()
var timeoutTimer: Timer?
@ -71,6 +72,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
if central.state == .poweredOn {
isSwitchedOn = true
startScanning()
}
else {
@ -84,6 +86,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
if isSwitchedOn {
centralManager.scanForPeripherals(withServices: [meshtasticServiceCBUUID], options: nil)
self.isScanning = self.centralManager.isScanning
print("Scanning Started")
}
}
@ -94,6 +97,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
if centralManager.isScanning {
self.centralManager.stopScan()
self.isScanning = self.centralManager.isScanning
print("Stopped Scanning")
}
}
@ -108,7 +112,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
guard let context = timer.userInfo as? [String: String] else { return }
let name = context["name", default: "Unknown"]
timeoutTimerCount += 1
self.timeoutTimerCount += 1
if timeoutTimerCount == 6 {
@ -123,8 +127,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
print("BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)")
if meshLoggingEnabled { Logger.log("BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)") }
timeoutTimer?.invalidate()
timeoutTimerCount = 0
self.timeoutTimer?.invalidate()
self.timeoutTimerCount = 0
}
else {
print("BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)")
@ -174,10 +178,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
let peripheralIndex = peripherals.firstIndex(where: { $0.id == newPeripheral.id })
if peripheralIndex != nil {
if self.meshData.nodes[peripheralIndex!].myInfo != nil {
newPeripheral.myInfo = self.meshData.nodes[peripheralIndex!].myInfo
}
newPeripheral.myInfo = peripherals.first(where: { $0.id == newPeripheral.id })?.myInfo
peripherals.remove(at: peripheralIndex!)
peripherals.append(newPeripheral)
print("Updating peripheral: \(peripheralName)");

View file

@ -1,10 +1,3 @@
//
// MeshtasticClientApp.swift
// MeshtasticClient
//
// Created by Garth Vander Houwen on 8/18/21.
//
import SwiftUI
@main

View file

@ -57,11 +57,13 @@ struct Connect: View {
Text(String(bleManager.connectedPeripheral.peripheral.name ?? "Unknown")).font(.title2)
}
Text("Model: ").font(.caption)+Text(bleManager.connectedNode?.user.hwModel ?? "(null)").font(.caption).foregroundColor(Color.gray)
if bleManager.connectedNode != nil {
Text("BLE Name: ").font(.caption)+Text(bleManager.connectedPeripheral.name).font(.caption).foregroundColor(Color.gray)
Text("Model: ").font(.caption)+Text(bleManager.connectedNode?.user.hwModel ?? "(null)").font(.caption).foregroundColor(Color.gray)
}
Text("BLE Name: ").font(.caption)+Text(bleManager.connectedPeripheral.name).font(.caption).foregroundColor(Color.gray)
if bleManager.connectedPeripheral.myInfo != nil {
Text("FW Version: ").font(.caption)+Text(bleManager.connectedPeripheral.myInfo?.firmwareVersion ?? "(null)").font(.caption).foregroundColor(Color.gray)
}
Text("FW Version: ").font(.caption)+Text(bleManager.connectedPeripheral.myInfo?.firmwareVersion ?? "(null)").font(.caption).foregroundColor(Color.gray)
}
Spacer()
@ -87,7 +89,8 @@ struct Connect: View {
} else {
if bleManager.connectedNode != nil {
if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.identifier.uuidString == userSettings.preferredPeripheralId {
userSettings.preferredPeripheralId = ""
userSettings.preferredPeripheralName = ""
}
@ -167,6 +170,7 @@ struct Connect: View {
.font(.caption)
.foregroundColor(.gray)
}
.disabled(self.bleManager.isScanning)
.padding()
.background(Color(.systemGray6))
.clipShape(Capsule())
@ -179,6 +183,7 @@ struct Connect: View {
.font(.caption)
.foregroundColor(.gray)
}
.disabled(!self.bleManager.isScanning)
.padding()
.background(Color(.systemGray6))
.clipShape(Capsule())
@ -219,8 +224,7 @@ struct Connect_Previews: PreviewProvider {
static var previews: some View {
Connect()
.environmentObject(MeshData())
.environmentObject(BLEManager())
}
}

View file

@ -8,6 +8,8 @@ import MapKit
import CoreLocation
struct NodeDetail: View {
@EnvironmentObject var bleManager :BLEManager
var node: NodeInfoModel
@ -156,6 +158,11 @@ struct NodeDetail: View {
}
}.navigationTitle(node.user.longName)
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(trailing:
ZStack {
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedNode != nil) ? bleManager.connectedNode.user.shortName : ((bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") )
})
}.ignoresSafeArea(.all, edges: [.leading, .trailing])
}
}

View file

@ -83,9 +83,6 @@ struct NodeList: View {
.navigationTitle("All Nodes")
.onAppear(
perform: {
if bleManager.meshData.nodes.count == 0 {
bleManager.meshData.load()
}
if UIDevice.current.userInterfaceIdiom == .pad {
if bleManager.meshData.nodes.count > 0 {
selection = "0"

View file

@ -56,11 +56,14 @@ struct NodeMap: View {
}
.navigationTitle("Mesh Map")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(trailing:
ZStack {
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedNode != nil) ? bleManager.connectedNode.user.shortName : ((bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") )
})
}
.navigationViewStyle(StackNavigationViewStyle())
.onAppear{
bleManager.meshData.load()
}
}
}

View file

@ -59,7 +59,7 @@ struct NodeRow: View {
}
struct NodeRow_Previews: PreviewProvider {
static var nodes = MeshData().nodes
static var nodes = BLEManager().meshData.nodes
static var previews: some View {
Group {

View file

@ -68,7 +68,7 @@ class UserSettings: ObservableObject {
self.preferredPeripheralId = UserDefaults.standard.object(forKey: "preferredPeripheralId") as? String ?? ""
self.provideLocation = UserDefaults.standard.object(forKey: "provideLocation") as? Bool ?? false
self.keyboardType = UserDefaults.standard.object(forKey: "keyboardType") as? Int ?? 0
self.meshActivityLog = UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? false
self.meshActivityLog = UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? true
}
}
@ -93,9 +93,9 @@ struct AppSettings: View {
Section(header: Text("USER DETAILS")) {
//HStack {
//Label("Name", systemImage: "person.crop.rectangle.fill")
//TextField("Username", text: $userSettings.meshtasticUsername)
//.foregroundColor(.gray)
// Label("Name", systemImage: "person.crop.rectangle.fill")
// TextField("Username", text: $userSettings.meshtasticUsername)
// .foregroundColor(.gray)
//}
//.listRowSeparator(.visible)
Toggle(isOn: $userSettings.provideLocation) {
@ -141,6 +141,11 @@ struct AppSettings: View {
}
}
.navigationTitle("App Settings")
.navigationBarItems(trailing:
ZStack {
ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedNode != nil) ? bleManager.connectedNode.user.shortName : ((bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.name : "Unknown") )
})
}
.navigationViewStyle(StackNavigationViewStyle())
}