mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Add enter dfu mode button for rak devices on firmware view
This commit is contained in:
parent
2f9351c653
commit
ca423e614e
2 changed files with 106 additions and 60 deletions
|
|
@ -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)..<UInt32.max)
|
||||
meshPacket.priority = MeshPacket.Priority.reliable
|
||||
meshPacket.wantAck = true
|
||||
var dataMessage = DataMessage()
|
||||
dataMessage.payload = try! adminPacket.serializedData()
|
||||
dataMessage.portnum = PortNum.adminApp
|
||||
meshPacket.decoded = dataMessage
|
||||
let messageDescription = "🚀 Sent enter DFU mode Admin Message to: \(toUser.longName ?? "unknown".localized) from: \(fromUser.longName ?? "unknown".localized)"
|
||||
if sendAdminMessageToRadio(meshPacket: meshPacket, adminDescription: messageDescription, fromUser: fromUser, toUser: toUser) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public func sendFactoryReset(fromUser: UserEntity, toUser: UserEntity) -> Bool {
|
||||
var adminPacket = AdminMessage()
|
||||
adminPacket.factoryReset = 5
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue