From dba78896663528cbc564af6e68e8a68eeef1ca1f Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Wed, 22 Feb 2023 20:31:08 -0800 Subject: [PATCH] Cleanup Client tracking mode some --- Meshtastic/Enums/IntervalEnums.swift | 6 ++ Meshtastic/Helpers/BLEManager.swift | 68 +++++++++---------- .../Views/Map/Custom/MapViewSwiftUI.swift | 9 ++- .../Views/Settings/Config/DeviceConfig.swift | 2 +- .../Module/ExternalNotificationConfig.swift | 2 +- .../Settings/Config/Module/MQTTConfig.swift | 2 +- .../Config/Module/TelemetryConfig.swift | 2 +- 7 files changed, 48 insertions(+), 43 deletions(-) diff --git a/Meshtastic/Enums/IntervalEnums.swift b/Meshtastic/Enums/IntervalEnums.swift index 5fc0dc20..93493767 100644 --- a/Meshtastic/Enums/IntervalEnums.swift +++ b/Meshtastic/Enums/IntervalEnums.swift @@ -93,6 +93,8 @@ enum SenderIntervals: Int, CaseIterable, Identifiable { enum UpdateIntervals: Int, CaseIterable, Identifiable { + case fiveSeconds = 5 + case tenSeconds = 10 case fifteenSeconds = 15 case thirtySeconds = 30 case oneMinute = 60 @@ -118,6 +120,10 @@ enum UpdateIntervals: Int, CaseIterable, Identifiable { get { switch self { + case .fiveSeconds: + return NSLocalizedString("interval.five.seconds", comment: "Five Seconds") + case .tenSeconds: + return NSLocalizedString("interval.ten.seconds", comment: "Ten Seconds") case .fifteenSeconds: return NSLocalizedString("interval.fifteen.seconds", comment: "Fifteen Seconds") case .thirtySeconds: diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 167e1c0f..1082a22b 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -2011,38 +2011,38 @@ extension BLEManager: CBCentralManagerDelegate { self.peripherals.removeAll(where: { $0.lastUpdate < visibleDuration}) } -// func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) { -// -// guard let peripherals = dict[CBCentralManagerRestoredStatePeripheralsKey] as? [CBPeripheral] else { -// return -// } -// print(peripherals) -// if peripherals.count > 0 { -// //connectedPeripheral.peripheral = peripherals[0] -// // 5 -// //connectedPeripheral.peripheral.delegate = self -// -// for peripheral in peripherals { -// -// switch peripheral.state { -// case .connecting: // I've only seen this happen when -// // re-launching attached to Xcode. -// print("Xcode Restore") -// -// case .connected: // Store for connection / requesting -// // notifications when BT starts. -// print("Actual restore") -// //centralManager.connect(peripheral) -// default: break -// } -// -// -// -// // connectedPeripheral.peripheral -// //connectedPeripheral.peripheral = peripheral -// //connectedPeripheral.peripheral.delegate = self -// } -// } -// print("willRestoreState Hit!") -// } + func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) { + + guard let peripherals = dict[CBCentralManagerRestoredStatePeripheralsKey] as? [CBPeripheral] else { + return + } + print(peripherals) + if peripherals.count > 0 { + //connectedPeripheral.peripheral = peripherals[0] + // 5 + //connectedPeripheral.peripheral.delegate = self + + for peripheral in peripherals { + + switch peripheral.state { + case .connecting: // I've only seen this happen when + // re-launching attached to Xcode. + print("Xcode Restore") + + case .connected: // Store for connection / requesting + // notifications when BT starts. + print("Actual restore") + //centralManager.connect(peripheral) + default: break + } + + + + // connectedPeripheral.peripheral + //connectedPeripheral.peripheral = peripheral + //connectedPeripheral.peripheral.delegate = self + } + } + print("willRestoreState Hit!") + } } diff --git a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift index 4cc5ef0b..55f707a2 100644 --- a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift +++ b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift @@ -50,12 +50,11 @@ struct MapViewSwiftUI: UIViewRepresentable { let center = CLLocationCoordinate2D(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude) let region = MKCoordinateRegion(center: center, span: span) mapView.setRegion(region, animated: true) - mapView.setUserTrackingMode(.followWithHeading, animated: true) mapView.addAnnotations(positions) } // Other MKMapView Settings - mapView.showsUserLocation = true + mapView.showsUserLocation = false mapView.preferredConfiguration.elevationStyle = .realistic mapView.isPitchEnabled = true mapView.isRotateEnabled = true @@ -130,10 +129,10 @@ struct MapViewSwiftUI: UIViewRepresentable { } case .clientGps: mapView.addAnnotations(positions) + mapView.showsUserLocation = true + mapView.setUserTrackingMode(.followWithHeading, animated: true) if recenter { - let span = MKCoordinateSpan(latitudeDelta: 0.003, longitudeDelta: 0.003) - let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude), span: span) - mapView.setRegion(region, animated: true) + mapView.centerCoordinate = LocationHelper.currentLocation } } } diff --git a/Meshtastic/Views/Settings/Config/DeviceConfig.swift b/Meshtastic/Views/Settings/Config/DeviceConfig.swift index b979464d..67f87bca 100644 --- a/Meshtastic/Views/Settings/Config/DeviceConfig.swift +++ b/Meshtastic/Views/Settings/Config/DeviceConfig.swift @@ -204,7 +204,7 @@ struct DeviceConfig: View { // Need to request a LoRaConfig from the remote node before allowing changes if bleManager.connectedPeripheral != nil && node?.deviceConfig == nil { print("empty device config") - let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral.num, context: context) + let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral?.num ?? -1, context: context) if connectedNode != nil && connectedNode!.num > 0 { _ = bleManager.requestDeviceConfig(fromUser: connectedNode!.user!, toUser: node!.user!, adminIndex: connectedNode?.myInfo?.adminIndex ?? 0) } diff --git a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift index f7255fdd..b1dcdf60 100644 --- a/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/ExternalNotificationConfig.swift @@ -154,7 +154,7 @@ struct ExternalNotificationConfig: View { isPresented: $isPresentingSaveConfirm, titleVisibility: .visible ) { - let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral.num, context: context) + let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral?.num ?? -1, context: context) if connectedNode != nil { let nodeName = node?.user?.longName ?? NSLocalizedString("unknown", comment: "Unknown") let buttonText = String.localizedStringWithFormat(NSLocalizedString("save.config %@", comment: "Save Config for %@"), nodeName) diff --git a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift index ec2d9735..7872d90a 100644 --- a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift @@ -143,7 +143,7 @@ struct MQTTConfig: View { isPresented: $isPresentingSaveConfirm, titleVisibility: .visible ) { - let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral.num, context: context) + let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral?.num ?? -1, context: context) if connectedNode != nil { let nodeName = node?.user?.longName ?? NSLocalizedString("unknown", comment: "Unknown") let buttonText = String.localizedStringWithFormat(NSLocalizedString("save.config %@", comment: "Save Config for %@"), nodeName) diff --git a/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift b/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift index fad65cd7..bbcda4e0 100644 --- a/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/TelemetryConfig.swift @@ -77,7 +77,7 @@ struct TelemetryConfig: View { isPresented: $isPresentingSaveConfirm, titleVisibility: .visible ) { - let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral.num, context: context) + let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral?.num ?? -1, context: context) if connectedNode != nil { let nodeName = node?.user?.longName ?? NSLocalizedString("unknown", comment: "Unknown") let buttonText = String.localizedStringWithFormat(NSLocalizedString("save.config %@", comment: "Save Config for %@"), nodeName)