diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index ca5981b1..a2756562 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -660,7 +660,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.25.10; + MARKETING_VERSION = 1.26.0; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; @@ -687,7 +687,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.25.10; + MARKETING_VERSION = 1.26.0; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index 69111785..d2b1690a 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -107,11 +107,10 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph if let name = advertisementData[CBAdvertisementDataLocalNameKey] as? String { peripheralName = name } - - let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, name: peripheralName, rssi: RSSI.intValue, peripheral: peripheral, myInfo: nil) - - peripherals.append(newPeripheral) - print("Adding peripheral: \(peripheralName)"); + + let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, name: peripheralName, rssi: RSSI.intValue, peripheral: peripheral, myInfo: nil) + peripherals.append(newPeripheral) + print("Adding peripheral: \(peripheralName)"); } // called when a peripheral is connected diff --git a/MeshtasticClient/Views/Bluetooth/Connect.swift b/MeshtasticClient/Views/Bluetooth/Connect.swift index a1311e5d..46e5c1ae 100644 --- a/MeshtasticClient/Views/Bluetooth/Connect.swift +++ b/MeshtasticClient/Views/Bluetooth/Connect.swift @@ -18,9 +18,13 @@ struct Connect: View { @EnvironmentObject var meshData: MeshData @EnvironmentObject var bleManager: BLEManager - + @ObservedObject var userSettings = UserSettings() + @State var isPreferredRadio: Bool = false + + var body: some View { - NavigationView { + + NavigationView { VStack { if bleManager.isSwitchedOn { @@ -46,24 +50,51 @@ struct Connect: View { } Text("FW Version: ").font(.caption)+Text(bleManager.connectedPeripheral.myInfo?.firmwareVersion ?? "(null)").font(.caption).foregroundColor(Color.gray) } + Spacer() + VStack (alignment: .center) { + Text("Preferred").font(.caption2) + Text("Radio").font(.caption2) + Toggle("Preferred Radio", isOn: $isPreferredRadio) + .toggleStyle(SwitchToggleStyle(tint: .green)) + .labelsHidden() + .onChange(of: isPreferredRadio) { value in + if value { + if bleManager.connectedNode != nil { + userSettings.preferredPeripheralName = "\(bleManager.connectedNode.user.longName) / \(bleManager.connectedPeripheral.peripheral.name ?? "")" + } + else { + + userSettings.preferredPeripheralName = bleManager.connectedPeripheral.peripheral.name ?? "Unknown Device" + } + + userSettings.preferredPeripheralId = bleManager.connectedPeripheral!.peripheral.identifier.uuidString + + } else { + + userSettings.preferredPeripheralId = "" + userSettings.preferredPeripheralName = "" + } + } + } } else { Text((bleManager.connectedPeripheral!.peripheral.name != nil) ? bleManager.connectedPeripheral!.peripheral.name! : "Unknown").font(.title2) } } - .swipeActions { - - Button(role: .destructive) { - if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.state == CBPeripheralState.connected - { - - bleManager.disconnectDevice() - } - } label: { - Label("Delete", systemImage: "antenna.radiowaves.left.and.right.slash") - } - } - .padding() + .padding([.top, .bottom]) + .swipeActions { + + Button(role: .destructive) { + if bleManager.connectedPeripheral != nil && bleManager.connectedPeripheral.peripheral.state == CBPeripheralState.connected + { + + bleManager.disconnectDevice() + } + } label: { + Label("Delete", systemImage: "antenna.radiowaves.left.and.right.slash") + } + } + //.padding() } else { HStack{ @@ -91,6 +122,10 @@ struct Connect: View { self.bleManager.disconnectDevice() } self.bleManager.connectTo(peripheral: peripheral.peripheral) + if userSettings.preferredPeripheralId == peripheral.peripheral.identifier.uuidString { + + isPreferredRadio = true + } }) { Text(peripheral.name).font(.title3) } @@ -147,7 +182,15 @@ struct Connect: View { ) } .navigationViewStyle(StackNavigationViewStyle()) - .onAppear(perform: { bleManager.startScanning() } ) + .onAppear(perform: { + + if bleManager.connectedPeripheral != nil && userSettings.preferredPeripheralId == bleManager.connectedPeripheral.peripheral.identifier.uuidString { + isPreferredRadio = true + } + else { + bleManager.startScanning() + } + } ) } } diff --git a/MeshtasticClient/Views/Settings/AppSettings.swift b/MeshtasticClient/Views/Settings/AppSettings.swift index 81573d01..17038e6d 100644 --- a/MeshtasticClient/Views/Settings/AppSettings.swift +++ b/MeshtasticClient/Views/Settings/AppSettings.swift @@ -68,15 +68,19 @@ class UserSettings: ObservableObject { struct AppSettings: View { + @State private var preferredDeviceConnected = false + @EnvironmentObject var bleManager: BLEManager @ObservedObject var userSettings = UserSettings() var body: some View { + NavigationView { GeometryReader { bounds in Form { Section(header: Text("USER DETAILS")) { + HStack{ Text("User Name") @@ -87,10 +91,12 @@ struct AppSettings: View { Text("Provide location to mesh") } - } - Section(header: Text("PREFERRED PERIPHERAL")) { - Text("The preferred peripheral will automatically reconnect if it becomes disconnected and is still within range. This device is assumed to be the primary messaging device for the app.").font(.caption).foregroundColor(.gray) + .listRowSeparator(.visible) + Text("Preferred Radio") + .listRowSeparator(.hidden) Text(userSettings.preferredPeripheralName) + .foregroundColor(.gray) + Text("The preferred radio will automatically reconnect if it becomes disconnected and is still within range. This device is assumed to be the primary radio used for messaging.").font(.caption2).foregroundColor(.gray) } Section(header: Text("MESSAGING OPTIONS")) {