From 2bac0a28bf1d253f86923380bc86dd2def967a73 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 27 Sep 2022 08:09:35 -0700 Subject: [PATCH 1/2] Add share channels view back --- Meshtastic.xcodeproj/project.pbxproj | 4 + Meshtastic/Views/Settings/ShareChannels.swift | 110 ++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 Meshtastic/Views/Settings/ShareChannels.swift diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index dd421685..0fd5e1aa 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ DD2E65262767A01F00E45FC5 /* NodeDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2E65252767A01F00E45FC5 /* NodeDetail.swift */; }; DD3501892852FC3B000FC853 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3501882852FC3B000FC853 /* Settings.swift */; }; DD35018B2852FC79000FC853 /* UserSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD35018A2852FC79000FC853 /* UserSettings.swift */; }; + DD3CC6B528E33FD100FA9159 /* ShareChannels.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */; }; DD4033C228B286B70096A444 /* Onboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD4033C128B286B70096A444 /* Onboarding.swift */; }; DD41582628582E9B009B0E59 /* DeviceConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD41582528582E9B009B0E59 /* DeviceConfig.swift */; }; DD415828285859C4009B0E59 /* TelemetryConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD415827285859C4009B0E59 /* TelemetryConfig.swift */; }; @@ -135,6 +136,7 @@ DD2E65252767A01F00E45FC5 /* NodeDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeDetail.swift; sourceTree = ""; }; DD3501882852FC3B000FC853 /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; }; DD35018A2852FC79000FC853 /* UserSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettings.swift; sourceTree = ""; }; + DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareChannels.swift; sourceTree = ""; }; DD4033C128B286B70096A444 /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = ""; }; DD4033C328B405A60096A444 /* MeshtasticDataModel v 8.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModel v 8.xcdatamodel"; sourceTree = ""; }; DD41582528582E9B009B0E59 /* DeviceConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceConfig.swift; sourceTree = ""; }; @@ -302,6 +304,7 @@ DDCE4E2B2869F92900BE9F8F /* UserConfig.swift */, DD0F791A28713C8A00A6FDAD /* AdminMessageList.swift */, DD61937A2863876A00E59241 /* Config */, + DD3CC6B428E33FD100FA9159 /* ShareChannels.swift */, ); path = Settings; sourceTree = ""; @@ -725,6 +728,7 @@ DD9D8F2F2764403B00080993 /* Meshtastic.xcdatamodeld in Sources */, DD6193772862F90F00E59241 /* CannedMessagesConfig.swift in Sources */, DD41582628582E9B009B0E59 /* DeviceConfig.swift in Sources */, + DD3CC6B528E33FD100FA9159 /* ShareChannels.swift in Sources */, DD1BF2F92776FE2E008C8D2F /* UserMessageList.swift in Sources */, DDB6ABE628B1406100384BA1 /* LoraConfigEnums.swift in Sources */, DDB2CC6E27F3EB47009C5FCC /* telemetry.pb.swift in Sources */, diff --git a/Meshtastic/Views/Settings/ShareChannels.swift b/Meshtastic/Views/Settings/ShareChannels.swift new file mode 100644 index 00000000..03dca338 --- /dev/null +++ b/Meshtastic/Views/Settings/ShareChannels.swift @@ -0,0 +1,110 @@ +// +// ShareChannel.swift +// MeshtasticApple +// +// Created by Garth Vander Houwen on 4/8/22. +// +import SwiftUI +import CoreData +import CoreImage.CIFilterBuiltins + + +struct QrCodeImage { + let context = CIContext() + + func generateQRCode(from text: String) -> UIImage { + var qrImage = UIImage(systemName: "xmark.circle") ?? UIImage() + let data = Data(text.utf8) + let filter = CIFilter.qrCodeGenerator() + filter.setValue(data, forKey: "inputMessage") + + let transform = CGAffineTransform(scaleX: 20, y: 20) + if let outputImage = filter.outputImage?.transformed(by: transform) { + if let image = context.createCGImage( + outputImage, + from: outputImage.extent) { + qrImage = UIImage(cgImage: image) + } + } + return qrImage + } +} +struct ShareChannels: View { + + @Environment(\.managedObjectContext) var context + @EnvironmentObject var bleManager: BLEManager + @EnvironmentObject var userSettings: UserSettings + + var node: NodeInfoEntity? + + @State private var text = "https://meshtastic.org/E/#test" + var qrCodeImage = QrCodeImage() + + var body: some View { + + VStack { + + GeometryReader { bounds in + + let smallest = min(bounds.size.width, bounds.size.height) + + ScrollView { + + VStack { + Text("Scan the QR code below with the Apple or Android device you would like to share your channel settings with.") + .fixedSize(horizontal: false, vertical: true) + .font(.callout) + + let image = qrCodeImage.generateQRCode(from: text) + Image(uiImage: image) + .resizable() + .scaledToFit() + .frame( + minWidth: smallest * 0.8, + maxWidth: smallest * 0.8, + minHeight: smallest * 0.8, + maxHeight: smallest * 0.8, + alignment: .center + ) + + if node != nil && node!.loRaConfig != nil { + + HStack { + + let preset = ModemPresets(rawValue: Int(node!.loRaConfig!.modemPreset)) + Text("Modem Preset \(preset!.description)").font(.title3) + } + } + VStack { + + Text("Number of Channels: \(node!.myInfo!.maxChannels)").font(.title2) + + ForEach(node!.myInfo!.channels?.array.sorted(by: { ($0 as! ChannelEntity).index < ($1 as! ChannelEntity).index }) as! [ChannelEntity], id: \.self) { (channel: ChannelEntity) in + + VStack { + + + Text("Channel: \(channel.index) Name: \(channel.name ?? "")") + } + } + } + .frame(width: bounds.size.width, height: bounds.size.height) + } + } + .navigationTitle("Share Channel") + .navigationBarTitleDisplayMode(.automatic) + .navigationBarItems(trailing: + + ZStack { + + ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "????") + }) + .onAppear { + + self.bleManager.context = context + } + } + .navigationViewStyle(StackNavigationViewStyle()) + } + } +} From e2e8eb0faa228c8f2e079521cca3536f60c6a92b Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 27 Sep 2022 08:14:12 -0700 Subject: [PATCH 2/2] Add back link to share channels --- Meshtastic/Views/Settings/Settings.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Meshtastic/Views/Settings/Settings.swift b/Meshtastic/Views/Settings/Settings.swift index 81e29b1e..b998e532 100644 --- a/Meshtastic/Views/Settings/Settings.swift +++ b/Meshtastic/Views/Settings/Settings.swift @@ -37,6 +37,15 @@ struct Settings: View { Section("Radio Configuration") { + NavigationLink { + ShareChannels(node: nodes.first(where: { $0.num == connectedNodeNum })) + } label: { + Image(systemName: "qrcode") + .symbolRenderingMode(.hierarchical) + Text("Share Channels QR Code") + } + .disabled(bleManager.connectedPeripheral == nil) + NavigationLink { UserConfig(node: nodes.first(where: { $0.num == connectedNodeNum })) } label: {