mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Generate QR Code for channels
This commit is contained in:
parent
4ec161411b
commit
106069f95a
4 changed files with 54 additions and 25 deletions
|
|
@ -29,7 +29,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
|
||||
@Published var connectedPeripheral: Peripheral!
|
||||
@Published var lastConnectionError: String
|
||||
@Published var minimumVersion = "1.3.41"
|
||||
@Published var minimumVersion = "1.3.42"
|
||||
@Published var connectedVersion: String
|
||||
@Published var invalidVersion = false
|
||||
@Published var preferredPeripheral = false
|
||||
|
|
|
|||
|
|
@ -194,32 +194,31 @@ func localConfig (config: Config, meshlogging: Bool, context:NSManagedObjectCont
|
|||
let newLoRaConfig = LoRaConfigEntity(context: context)
|
||||
|
||||
newLoRaConfig.regionCode = Int32(config.lora.region.rawValue)
|
||||
newLoRaConfig.modemPreset = Int32(config.lora.modemPreset.rawValue)
|
||||
newLoRaConfig.hopLimit = Int32(config.lora.hopLimit)
|
||||
newLoRaConfig.txPower = Int32(config.lora.txPower)
|
||||
newLoRaConfig.txEnabled = config.lora.txEnabled
|
||||
newLoRaConfig.usePreset = config.lora.usePreset
|
||||
newLoRaConfig.modemPreset = Int32(config.lora.modemPreset.rawValue)
|
||||
newLoRaConfig.bandwidth = Int32(config.lora.bandwidth)
|
||||
newLoRaConfig.spreadFactor = Int32(config.lora.spreadFactor)
|
||||
newLoRaConfig.codingRate = Int32(config.lora.codingRate)
|
||||
newLoRaConfig.spreadFactor = Int32(config.lora.spreadFactor)
|
||||
newLoRaConfig.frequencyOffset = Int32(config.lora.frequencyOffset)
|
||||
|
||||
newLoRaConfig.frequencyOffset = config.lora.frequencyOffset
|
||||
newLoRaConfig.hopLimit = Int32(config.lora.hopLimit)
|
||||
newLoRaConfig.txPower = Int32(config.lora.txPower)
|
||||
newLoRaConfig.txEnabled = config.lora.txEnabled
|
||||
newLoRaConfig.channelNum = Int32(config.lora.channelNum)
|
||||
fetchedNode[0].loRaConfig = newLoRaConfig
|
||||
|
||||
} else {
|
||||
|
||||
fetchedNode[0].loRaConfig?.regionCode = Int32(config.lora.region.rawValue)
|
||||
fetchedNode[0].loRaConfig?.modemPreset = Int32(config.lora.modemPreset.rawValue)
|
||||
fetchedNode[0].loRaConfig?.hopLimit = Int32(config.lora.hopLimit)
|
||||
fetchedNode[0].loRaConfig?.txPower = Int32(config.lora.txPower)
|
||||
fetchedNode[0].loRaConfig?.txEnabled = config.lora.txEnabled
|
||||
fetchedNode[0].loRaConfig?.usePreset = config.lora.usePreset
|
||||
fetchedNode[0].loRaConfig?.modemPreset = Int32(config.lora.modemPreset.rawValue)
|
||||
fetchedNode[0].loRaConfig?.bandwidth = Int32(config.lora.bandwidth)
|
||||
fetchedNode[0].loRaConfig?.spreadFactor = Int32(config.lora.spreadFactor)
|
||||
fetchedNode[0].loRaConfig?.codingRate = Int32(config.lora.codingRate)
|
||||
fetchedNode[0].loRaConfig?.spreadFactor = Int32(config.lora.spreadFactor)
|
||||
fetchedNode[0].loRaConfig?.frequencyOffset = Int32(config.lora.frequencyOffset)
|
||||
fetchedNode[0].loRaConfig?.frequencyOffset = config.lora.frequencyOffset
|
||||
fetchedNode[0].loRaConfig?.hopLimit = Int32(config.lora.hopLimit)
|
||||
fetchedNode[0].loRaConfig?.txPower = Int32(config.lora.txPower)
|
||||
fetchedNode[0].loRaConfig?.txEnabled = config.lora.txEnabled
|
||||
fetchedNode[0].loRaConfig?.channelNum = Int32(config.lora.channelNum)
|
||||
}
|
||||
|
||||
do {
|
||||
|
|
@ -239,7 +238,6 @@ func localConfig (config: Config, meshlogging: Bool, context:NSManagedObjectCont
|
|||
print("💥 No Nodes found in local database matching node number \(nodeNum) unable to save Lora Config")
|
||||
}
|
||||
|
||||
|
||||
} catch {
|
||||
|
||||
let nsError = error as NSError
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
<attribute name="id" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="index" attributeType="Integer 32" minValueString="0" maxValueString="13" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="name" optional="YES" attributeType="String"/>
|
||||
<attribute name="psk" optional="YES" attributeType="String"/>
|
||||
<attribute name="psk" optional="YES" attributeType="Binary"/>
|
||||
<attribute name="role" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="uplinkEnabled" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<relationship name="myInfoChannel" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="MyInfoEntity" inverseName="channels" inverseEntity="MyInfoEntity"/>
|
||||
|
|
@ -60,7 +60,7 @@
|
|||
<attribute name="bandwidth" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="channelNum" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="codingRate" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="frequencyOffset" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="frequencyOffset" optional="YES" attributeType="Float" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="hopLimit" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="modemPreset" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="regionCode" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ struct QrCodeImage {
|
|||
return qrImage
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct ShareChannels: View {
|
||||
|
||||
@Environment(\.managedObjectContext) var context
|
||||
|
|
@ -50,7 +52,7 @@ struct ShareChannels: View {
|
|||
|
||||
var node: NodeInfoEntity?
|
||||
|
||||
@State private var channelsUrl = "https://meshtastic.org/e/#test"
|
||||
@State private var channelsUrl = "https://meshtastic.org/e/#"
|
||||
var qrCodeImage = QrCodeImage()
|
||||
|
||||
var body: some View {
|
||||
|
|
@ -93,7 +95,7 @@ struct ShareChannels: View {
|
|||
Toggle("Channel 0 Included", isOn: $includeChannel0)
|
||||
.toggleStyle(.switch)
|
||||
.labelsHidden()
|
||||
.disabled(true)
|
||||
.disabled(channel.role == 1)
|
||||
Text((channel.name!.isEmpty ? "Primary" : channel.name) ?? "Primary")
|
||||
|
||||
} else if channel.index == 1 {
|
||||
|
|
@ -142,10 +144,9 @@ struct ShareChannels: View {
|
|||
if channel.role > 0 {
|
||||
Image(systemName: "lock.fill")
|
||||
.foregroundColor(.green)
|
||||
} else {
|
||||
} else {
|
||||
Image(systemName: "lock.slash")
|
||||
.foregroundColor(.gray)
|
||||
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
|
|
@ -166,8 +167,7 @@ struct ShareChannels: View {
|
|||
)
|
||||
.buttonStyle(.bordered)
|
||||
.buttonBorderShape(.capsule)
|
||||
.controlSize(.small)
|
||||
.padding(.bottom)
|
||||
.controlSize(.large)
|
||||
|
||||
Image(uiImage: qrImage)
|
||||
.resizable()
|
||||
|
|
@ -192,7 +192,6 @@ struct ShareChannels: View {
|
|||
.buttonBorderShape(.capsule)
|
||||
.controlSize(.small)
|
||||
.padding(.top)
|
||||
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $isPresentingHelp) {
|
||||
|
|
@ -238,11 +237,43 @@ struct ShareChannels: View {
|
|||
self.bleManager.context = context
|
||||
|
||||
self.initialLoad = false
|
||||
channelSet = ChannelSet()
|
||||
GenerateChannelSet()
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationViewStyle(StackNavigationViewStyle())
|
||||
}
|
||||
}
|
||||
func GenerateChannelSet() {
|
||||
|
||||
var loRaConfig = Config.LoRaConfig()
|
||||
loRaConfig.region = RegionCodes(rawValue: Int(node!.loRaConfig!.regionCode))!.protoEnumValue()
|
||||
loRaConfig.modemPreset = ModemPresets(rawValue: Int(node!.loRaConfig!.modemPreset))!.protoEnumValue()
|
||||
loRaConfig.bandwidth = UInt32(node!.loRaConfig!.bandwidth)
|
||||
loRaConfig.spreadFactor = UInt32(node!.loRaConfig!.spreadFactor)
|
||||
loRaConfig.codingRate = UInt32(node!.loRaConfig!.codingRate)
|
||||
loRaConfig.frequencyOffset = node!.loRaConfig!.frequencyOffset
|
||||
loRaConfig.hopLimit = UInt32(node!.loRaConfig!.hopLimit)
|
||||
loRaConfig.txEnabled = node!.loRaConfig!.txEnabled
|
||||
loRaConfig.txPower = node!.loRaConfig!.txPower
|
||||
loRaConfig.channelNum = UInt32(node!.loRaConfig!.channelNum)
|
||||
|
||||
channelSet.loraConfig = loRaConfig
|
||||
|
||||
for ch in node!.myInfo!.channels!.array as! [ChannelEntity] {
|
||||
print(ch)
|
||||
if ch.role > 0 {
|
||||
var channelSettings = ChannelSettings()
|
||||
channelSettings.name = ch.name!
|
||||
channelSettings.psk = ch.psk ?? Data()
|
||||
channelSettings.id = UInt32(ch.id)
|
||||
channelSettings.uplinkEnabled = ch.uplinkEnabled
|
||||
channelSettings.downlinkEnabled = ch.downlinkEnabled
|
||||
channelSet.settings.append(channelSettings)
|
||||
}
|
||||
}
|
||||
|
||||
let settingsString = try! channelSet.serializedData().base64EncodedString(options: [.endLineWithLineFeed])
|
||||
channelsUrl = "https://www.meshtastic.org/e/#" + settingsString.dropLast(2)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue