diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 0e7e4ae8..2f262eb4 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -1107,6 +1107,26 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate return false } + public func sendEnterDfuMode(fromUser: UserEntity, toUser: UserEntity) -> Bool { + var adminPacket = AdminMessage() + adminPacket.enterDfuModeRequest = true + var meshPacket: MeshPacket = MeshPacket() + meshPacket.to = UInt32(toUser.num) + meshPacket.from = UInt32(fromUser.num) + meshPacket.id = UInt32.random(in: UInt32(UInt8.max).. Bool { var adminPacket = AdminMessage() adminPacket.factoryReset = 5 diff --git a/Meshtastic/Views/Settings/Firmware.swift b/Meshtastic/Views/Settings/Firmware.swift index 0e929dca..3e6a56ef 100644 --- a/Meshtastic/Views/Settings/Firmware.swift +++ b/Meshtastic/Views/Settings/Firmware.swift @@ -12,17 +12,17 @@ struct Firmware: View { @Environment(\.managedObjectContext) var context @EnvironmentObject var bleManager: BLEManager var node: NodeInfoEntity? - @State var minimumVersion = "2.2.16" + @State var minimumVersion = "2.2.17" @State var version = "" @State private var currentDevice: DeviceHardware? - + var body: some View { let supportedVersion = bleManager.connectedVersion == "0.0.0" || self.minimumVersion.compare(bleManager.connectedVersion, options: .numeric) == .orderedAscending || minimumVersion.compare(bleManager.connectedVersion, options: .numeric) == .orderedSame - VStack { + ScrollView { VStack(alignment: .leading) { let deviceString = currentDevice?.hwModelSlug.replacingOccurrences(of: "_", with: "") - + HStack { VStack { Image(systemName: currentDevice?.activelySupported ?? false ? "checkmark.seal.fill" : "x.circle") @@ -34,6 +34,7 @@ struct Firmware: View { } Text("Device Model: \(currentDevice?.displayName ?? "Unknown")") .font(.largeTitle) + .fixedSize(horizontal: false, vertical: true) } VStack { Image(deviceString ?? "UNSET") @@ -42,6 +43,7 @@ struct Firmware: View { .frame(width: 300, height: 300) .cornerRadius(5) } + if supportedVersion { Text("Your Firmware is up to date") .font(.title) @@ -49,20 +51,44 @@ struct Firmware: View { .font(.title2) } else { Text("Your Firmware is out of date") - .font(.title) - Text("Current Firmware Version: \(bleManager.connectedVersion), Minimium Firmware Version: \(minimumVersion)") + .fixedSize(horizontal: false, vertical: true) + .foregroundStyle(.red) .font(.title2) + .padding(.bottom) + Text("Current Firmware Version: \(bleManager.connectedVersion), Minimium Firmware Version: \(minimumVersion)") + .fixedSize(horizontal: false, vertical: true) + .font(.title3) + .padding(.bottom) } + if currentDevice?.architecture == Meshtastic.Architecture.nrf52840 { VStack(alignment: .leading) { /// RAK 4631 if currentDevice?.hwModel == 9 { - Text("nRF OTA Device Firmware Update App") - .font(.title3) - Text("You can update your Meshtastic device over bluetooth using the Nordic DFU app. This currently works for RAK NRF devices.") - .font(.caption) + Text("You can update your Meshtastic device over bluetooth using the Nordic DFU app.") + .fixedSize(horizontal: false, vertical: true) + .font(.callout) Link("Get NRF DFU from the App Store", destination: URL(string: "https://apps.apple.com/us/app/nrf-device-firmware-update/id1624454660")!) .font(.callout) + .padding(.bottom) + Link("Drag & Drop Firmware Update", destination: URL(string: "https://meshtastic.org/docs/getting-started/flashing-firmware/nrf52/drag-n-drop")!) + .font(.callout) + + Button { + let connectedNode = getNodeInfo(id: bleManager.connectedPeripheral?.num ?? 0, context: context) + if connectedNode != nil { + if !bleManager.sendEnterDfuMode(fromUser: connectedNode!.user!, toUser: node!.user!) { + print("Enter DFU Failed") + } + } + } label: { + Label("Enter DFU Mode", systemImage: "square.and.arrow.down") + } + .buttonStyle(.bordered) + .buttonBorderShape(.capsule) + .controlSize(.regular) + .padding(5) + Spacer() } else { Text("OTA Updates are not supported on the this NRF Device.") .font(.title3) @@ -105,56 +131,56 @@ struct Firmware: View { .font(.title3) Text(node?.user?.hwModel ?? "UNSET") .font(.title3) - // Text(hwModel.platform().description) - // .font(.title3) + Text ( currentDevice?.architecture.rawValue ?? "UNKNOWN") + .font(.title3) } } - .padding() + .padding() VStack(alignment: .leading) { - Text("Firmware Releases") - .font(.title3) - .padding([.leading, .trailing]) -// List { -// Section(header: Text("Stable")) { -// ForEach(firmwareReleaseData.releases?.stable ?? [], id: \.id) { fr in -// Link(destination: URL(string: fr.zipUrl ?? "")!) { -// HStack { -// Text(fr.title ?? "Unknown") -// .font(.caption) -// Spacer() -// Image(systemName: "square.and.arrow.down") -// .font(.title3) -// } -// } -// } -// } -// Section("Alpha") { -// ForEach(firmwareReleaseData.releases?.alpha ?? [], id: \.id) { fr in -// Link(destination: URL(string: fr.zipUrl ?? "")!) { -// HStack { -// Text(fr.title ?? "Unknown") -// .font(.caption) -// Spacer() -// Image(systemName: "square.and.arrow.down") -// .font(.title3) -// } -// } -// } -// } -// Section("Pull Requests") { -// ForEach(firmwareReleaseData.pullRequests ?? [], id: \.id) { fr in -// Link(destination: URL(string: fr.zipUrl ?? "")!) { -// HStack { -// Text(fr.title ?? "Unknown") -// .font(.caption) -// Spacer() -// Image(systemName: "square.and.arrow.down") -// .font(.title3) -// } -// } -// } -// } -// } + // Text("Firmware Releases") + // .font(.title3) + // .padding([.leading, .trailing]) + // List { + // Section(header: Text("Stable")) { + // ForEach(firmwareReleaseData.releases?.stable ?? [], id: \.id) { fr in + // Link(destination: URL(string: fr.zipUrl ?? "")!) { + // HStack { + // Text(fr.title ?? "Unknown") + // .font(.caption) + // Spacer() + // Image(systemName: "square.and.arrow.down") + // .font(.title3) + // } + // } + // } + // } + // Section("Alpha") { + // ForEach(firmwareReleaseData.releases?.alpha ?? [], id: \.id) { fr in + // Link(destination: URL(string: fr.zipUrl ?? "")!) { + // HStack { + // Text(fr.title ?? "Unknown") + // .font(.caption) + // Spacer() + // Image(systemName: "square.and.arrow.down") + // .font(.title3) + // } + // } + // } + // } + // Section("Pull Requests") { + // ForEach(firmwareReleaseData.pullRequests ?? [], id: \.id) { fr in + // Link(destination: URL(string: fr.zipUrl ?? "")!) { + // HStack { + // Text(fr.title ?? "Unknown") + // .font(.caption) + // Spacer() + // Image(systemName: "square.and.arrow.down") + // .font(.title3) + // } + // } + // } + // } + // } } .padding(.bottom, 5) .onAppear() { @@ -167,9 +193,9 @@ struct Firmware: View { } } } - Api().loadFirmwareReleaseData { (bks) in - //sel = bks - } + //Api().loadFirmwareReleaseData { (bks) in + //sel = bks + //} } .navigationTitle("Firmware Updates") .navigationBarTitleDisplayMode(.inline)