diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 8cd75056..c22230c2 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -71,6 +71,8 @@ DDB2CC6E27F3EB47009C5FCC /* telemetry.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB2CC6D27F3EB47009C5FCC /* telemetry.pb.swift */; }; DDB3107228A6224100F1DE3D /* device_metadata.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB3107128A6224100F1DE3D /* device_metadata.pb.swift */; }; DDB6ABD628AE742000384BA1 /* BluetoothConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB6ABD528AE742000384BA1 /* BluetoothConfig.swift */; }; + DDB6ABD928B0A4BA00384BA1 /* BluetoothModes.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB6ABD828B0A4BA00384BA1 /* BluetoothModes.swift */; }; + DDB6ABDB28B0AC6000384BA1 /* DistanceText.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB6ABDA28B0AC6000384BA1 /* DistanceText.swift */; }; DDC2E15826CE248E0042C5E4 /* MeshtasticApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC2E15726CE248E0042C5E4 /* MeshtasticApp.swift */; }; DDC2E15C26CE248F0042C5E4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */; }; DDC2E15F26CE248F0042C5E4 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DDC2E15E26CE248F0042C5E4 /* Preview Assets.xcassets */; }; @@ -174,6 +176,8 @@ DDB3107128A6224100F1DE3D /* device_metadata.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = device_metadata.pb.swift; sourceTree = ""; }; DDB6ABD528AE742000384BA1 /* BluetoothConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BluetoothConfig.swift; sourceTree = ""; }; DDB6ABD728AE8F5D00384BA1 /* MeshtasticDataModel v 7.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModel v 7.xcdatamodel"; sourceTree = ""; }; + DDB6ABD828B0A4BA00384BA1 /* BluetoothModes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BluetoothModes.swift; sourceTree = ""; }; + DDB6ABDA28B0AC6000384BA1 /* DistanceText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DistanceText.swift; sourceTree = ""; }; DDC2E15426CE248E0042C5E4 /* Meshtastic.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Meshtastic.app; sourceTree = BUILT_PRODUCTS_DIR; }; DDC2E15726CE248E0042C5E4 /* MeshtasticApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshtasticApp.swift; sourceTree = ""; }; DDC2E15B26CE248F0042C5E4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = ../Assets.xcassets; sourceTree = ""; }; @@ -318,6 +322,7 @@ isa = PBXGroup; children = ( DD8ED9C7289CE4B900B3B0AB /* RoutingError.swift */, + DDB6ABD828B0A4BA00384BA1 /* BluetoothModes.swift */, ); path = Enums; sourceTree = ""; @@ -470,6 +475,7 @@ DDC3B273283F411B00AC321C /* LastHeardText.swift */, DDA6B2EA28420A7B003E8C16 /* NodeAnnotation.swift */, DDD94A4F2845C8F5004A87A0 /* DateTimeText.swift */, + DDB6ABDA28B0AC6000384BA1 /* DistanceText.swift */, ); path = Helpers; sourceTree = ""; @@ -687,6 +693,7 @@ DD1BF2F92776FE2E008C8D2F /* UserMessageList.swift in Sources */, DDB2CC6E27F3EB47009C5FCC /* telemetry.pb.swift in Sources */, DD23A50F26FD1B4400D9B90C /* PeripheralModel.swift in Sources */, + DDB6ABDB28B0AC6000384BA1 /* DistanceText.swift in Sources */, C9A7BC1027759A9600760B50 /* PositionAnnotationView.swift in Sources */, DD882F5D2772E4640005BF05 /* Contacts.swift in Sources */, DD47E3CE26F103C600029299 /* NodeList.swift in Sources */, @@ -695,6 +702,7 @@ DDC2E18F26CE25FE0042C5E4 /* ContentView.swift in Sources */, DD17E5DE277D49D400010EC2 /* storeforward.pb.swift in Sources */, DD2553572855B02500E55709 /* LoRaConfig.swift in Sources */, + DDB6ABD928B0A4BA00384BA1 /* BluetoothModes.swift in Sources */, DDD9E4E4284B208E003777C5 /* UserEntityExtension.swift in Sources */, C9A88B55278B503C00BD810A /* MapViewModule.swift in Sources */, DD2553592855B52700E55709 /* PositionConfig.swift in Sources */, diff --git a/Meshtastic/Enums/BluetoothModes.swift b/Meshtastic/Enums/BluetoothModes.swift new file mode 100644 index 00000000..003b0a3f --- /dev/null +++ b/Meshtastic/Enums/BluetoothModes.swift @@ -0,0 +1,39 @@ +// +// BluetoothModes.swift +// Meshtastic +// +// Copyright(c) Garth Vander Houwen 8/19/22. +// + +enum BluetoothModes: Int, CaseIterable, Identifiable { + + case randomPin = 0 + case fixedPin = 1 + case noPin = 2 + + var id: Int { self.rawValue } + var description: String { + get { + switch self { + case .randomPin: + return "Random" + case .fixedPin: + return "Fixed" + case .noPin: + return "None" + } + } + } + func protoEnumValue() -> Config.BluetoothConfig.PairingMode { + + switch self { + + case .randomPin: + return Config.BluetoothConfig.PairingMode.randomPin + case .fixedPin: + return Config.BluetoothConfig.PairingMode.fixedPin + case .noPin: + return Config.BluetoothConfig.PairingMode.noPin + } + } +} diff --git a/Meshtastic/Views/Helpers/DistanceText.swift b/Meshtastic/Views/Helpers/DistanceText.swift new file mode 100644 index 00000000..1709b5f4 --- /dev/null +++ b/Meshtastic/Views/Helpers/DistanceText.swift @@ -0,0 +1,22 @@ +// +// DistanceText.swift +// Meshtastic +// +// Copyright(c) Garth Vander Houwen 8/19/22. +// + +import SwiftUI +import CoreLocation +import MapKit + +struct DistanceText: View { + + var meters: CLLocationDistance + + var body: some View { + + let distanceFormatter = MKDistanceFormatter() + + Text("Distance: \(distanceFormatter.string(fromDistance: Double(meters)))") + } +} diff --git a/Meshtastic/Views/Nodes/NodeList.swift b/Meshtastic/Views/Nodes/NodeList.swift index 95755bd4..16009570 100644 --- a/Meshtastic/Views/Nodes/NodeList.swift +++ b/Meshtastic/Views/Nodes/NodeList.swift @@ -9,6 +9,7 @@ // A view showing a list of devices that have been seen on the mesh network from the perspective of the connected device. import SwiftUI +import CoreLocation struct NodeList: View { @@ -35,8 +36,8 @@ struct NodeList: View { if nodes.count == 0 { Text("Scan for Radios").font(.largeTitle) - Text("No LoRa Mesh Nodes Found").font(.title2) - Text("Go to the bluetooth section in the bottom right menu and click the Start Scanning button to scan for nearby radios and find your Meshtastic device. Make sure your device is powered on and near your phone or tablet.") + Text("No Meshtastic Nodes Found").font(.title2) + Text("Go to the bluetooth section in the bottom right menu and click the Start Scanning button to scan for nearby radios and find your Meshtastic device. Make sure your device is powered on and near your iPhone, iPad or Mac.") .font(.body) Text("Once the device shows under Available Devices touch the device you want to connect to and it will pull node information over BLE and populate the node list and mesh map in the Meshtastic app.") Text("Views with bluetooth functionality will show an indicator in the upper right hand corner show if bluetooth is on, and if a device is connected.") @@ -87,14 +88,43 @@ struct NodeList: View { Image(systemName: "clock.badge.checkmark.fill").font(.title3) .foregroundColor(.accentColor).symbolRenderingMode(.hierarchical) + if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac { LastHeardText(lastHeard: node.lastHeard).font(.subheadline).foregroundColor(.gray) + } else { LastHeardText(lastHeard: node.lastHeard).font(.title3).foregroundColor(.gray) } } + + if node.positions?.count ?? 0 > 0 { + + Spacer() + HStack(alignment: .bottom) { + + let lastPostion = node.positions!.reversed()[0] as! PositionEntity + + let myCoord = CLLocation(latitude: LocationHelper.currentLocation.latitude, longitude: LocationHelper.currentLocation.longitude) + + let nodeCoord = CLLocation(latitude: lastPostion.coordinate!.latitude, longitude: lastPostion.coordinate!.longitude) + + let metersAway = nodeCoord.distance(from: myCoord) + + Image(systemName: "lines.measurement.horizontal").font(.title3) + .foregroundColor(.accentColor).symbolRenderingMode(.hierarchical) + + if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac { + + DistanceText(meters: metersAway).font(.subheadline).foregroundColor(.gray) + + } else { + + DistanceText(meters: metersAway).font(.title3).foregroundColor(.gray) + } + } + } } .padding([.leading, .top, .bottom]) } @@ -109,13 +139,6 @@ struct NodeList: View { self.bleManager.userSettings = userSettings self.bleManager.context = context self.initialLoad = false - -// if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac { -// -// if nodes.count > 0 { -// selection = "0" -// } -// } } } } diff --git a/Meshtastic/Views/Settings/Config/BluetoothConfig.swift b/Meshtastic/Views/Settings/Config/BluetoothConfig.swift index 1057f1eb..5f5c7e8f 100644 --- a/Meshtastic/Views/Settings/Config/BluetoothConfig.swift +++ b/Meshtastic/Views/Settings/Config/BluetoothConfig.swift @@ -7,39 +7,6 @@ import SwiftUI -enum BluetoothModes: Int, CaseIterable, Identifiable { - - case randomPin = 0 - case fixedPin = 1 - case noPin = 2 - - var id: Int { self.rawValue } - var description: String { - get { - switch self { - case .randomPin: - return "Random" - case .fixedPin: - return "Fixed" - case .noPin: - return "None" - } - } - } - func protoEnumValue() -> Config.BluetoothConfig.PairingMode { - - switch self { - - case .randomPin: - return Config.BluetoothConfig.PairingMode.randomPin - case .fixedPin: - return Config.BluetoothConfig.PairingMode.fixedPin - case .noPin: - return Config.BluetoothConfig.PairingMode.noPin - } - } -} - struct BluetoothConfig: View { @Environment(\.managedObjectContext) var context diff --git a/Meshtastic/Views/Settings/Config/PositionConfig.swift b/Meshtastic/Views/Settings/Config/PositionConfig.swift index a2348bea..19201fda 100644 --- a/Meshtastic/Views/Settings/Config/PositionConfig.swift +++ b/Meshtastic/Views/Settings/Config/PositionConfig.swift @@ -370,6 +370,13 @@ struct PositionConfig: View { if newSmartPosition != node!.positionConfig!.smartPositionEnabled { hasChanges = true } } } + .onChange(of: positionBroadcastSeconds) { newPositionBroadcastSeconds in + + if node != nil && node!.positionConfig != nil { + + if newPositionBroadcastSeconds != node!.positionConfig!.positionBroadcastSeconds { hasChanges = true } + } + } .onChange(of: deviceGpsEnabled) { newDeviceGps in if node != nil && node!.positionConfig != nil {