diff --git a/Apps/FirmwareUpdater/README.md b/Apps/FirmwareUpdater/README.md index 74bc5d1c..9e9c8687 100644 --- a/Apps/FirmwareUpdater/README.md +++ b/Apps/FirmwareUpdater/README.md @@ -118,7 +118,7 @@ Denon's updater at hand. Note what the panel runs now (build and Wi-Fi network). 2. With DeckBridge running, try to start. - **See:** "DeckBridge is running. Quit it first: it talks to the LC6000." 3. Put one chip in update mode. Top panel chip: power off, hold BACK + FWD + VINYL while powering on. Display chip: - type UPDATE and send the update-mode message. + click "Restart the display chip in update mode…" and confirm. No word to type here: UPDATE guards the write (#762). - **See:** the chip named ("LC6000 top panel chip" or "LC6000 display chip"), and its firmware checked. 4. Back it up to a folder on this Mac, outside any git repository. - **See:** "Backup saved: read twice and the same, N files." A folder inside a repository is refused: "That folder diff --git a/Apps/FirmwareUpdater/Sources/BackupView.swift b/Apps/FirmwareUpdater/Sources/BackupView.swift index 469f1f8d..090a8e4b 100644 --- a/Apps/FirmwareUpdater/Sources/BackupView.swift +++ b/Apps/FirmwareUpdater/Sources/BackupView.swift @@ -3,15 +3,19 @@ import FirmwareCatalog import LC6000Update import SwiftUI import UnitCheck +import UpdaterScreen /// The LC6000 section's unit check and backup (#692): the owner puts one chip in update mode, picks a folder, and the /// app reads the chip twice and saves it. The backup writes nothing to the unit; an update (#693) writes only after its confirm. @MainActor @Observable final class BackupModel { private(set) var running = false - private(set) var result: String? - var typed = "" - private(set) var stepResult: String? + /// The step's and the backup's lines (#762): a step starting clears the stale ones. + private(set) var lines = LC6000Lines() + var result: String? { lines.backup } + var stepResult: String? { lines.step } + /// The update-mode step's confirm is showing (#762: a click and a confirm, no typed word). + var confirmingStep = false /// The update this session's backup allows (#693); nil until a backup is saved. private(set) var update: UpdateModel? /// A screenshot preview's model (#761): its buttons do nothing, so no MIDI message is sent and no chip is read. @@ -20,27 +24,30 @@ final class BackupModel { init() {} #if DEBUG - init(preview result: String?) { - self.result = result + init(preview result: String?, confirmingStep: Bool = false, update: UpdateModel? = nil) { + lines.backup = result + self.confirmingStep = confirmingStep + self.update = update inert = true } #endif - /// The display chip's step into update mode: only on the owner's typed UPDATE, once. - func enterUpdateMode() async { - guard !inert else { return } - let outcome = await UpdateModeStep(midi: CoreMIDISend(), apps: WorkspaceApps()).enter(typed: typed) - typed = "" + /// The display chip's step into update mode: only from the confirm's own button, once. + func enterUpdateMode(clicked button: String) async { + guard !inert, let confirmed = UpdateModeStep.Confirmed(clicked: button) else { return } + lines.stepStarts() + let outcome = await UpdateModeStep(midi: CoreMIDISend(), apps: WorkspaceApps()).enter(confirmed: confirmed) switch outcome { - case .sent: stepResult = UpdateModeStep.sentText - case .refused(let reason): stepResult = reason + case .sent: lines.step = UpdateModeStep.sentText + case .refused(let reason): lines.step = reason } } func backUp() async { guard !running, !inert else { return } + lines.backupStarts() if let stop = await Preflight(apps: WorkspaceApps()).stop() { - result = stop + lines.backup = stop return } let panel = NSOpenPanel() @@ -56,14 +63,14 @@ final class BackupModel { guard found.count == 1, let one = found.first, let usb = try? IOUSBHostDFU(service: one.service) else { let report = await UnitCheck(known: Self.known, log: FileLog.shared) .backUp(devices: found.map(\.device), transport: Unreachable(), into: folder, stamp: Self.stamp()) - result = report.refusal ?? "The chip in update mode couldn't be opened. Nothing was read." + lines.backup = report.refusal ?? "The chip in update mode couldn't be opened. Nothing was read." return } let report = await UnitCheck(known: Self.known, log: FileLog.shared) .backUp(devices: [one.device], transport: ReadOnlyTransport(usb), into: folder, stamp: Self.stamp()) - update = report.read.map { UpdateModel(read: $0) } + update = report.read.map { UpdateModel(read: $0) { [weak self] in self?.lines.writeStarts() } } // With a read, the update's view of it: a chip already running DeckBridge's firmware is said to (#748). - result = update.map { $0.flow.backupLine(files: report.files.count, identified: report.identified) } ?? Self.text(report) + lines.backup = update.map { $0.flow.backupLine(files: report.files.count, identified: report.identified) } ?? Self.text(report) } static var known: KnownFirmware { @@ -94,17 +101,14 @@ struct BackupView: View { var body: some View { VStack(alignment: .leading, spacing: 6) { Text("Back up a chip").font(.headline) - Text("Put one chip in update mode. Top panel chip: power the LC6000 off, then hold BACK + FWD + VINYL while you power it on.") - .fixedSize(horizontal: false, vertical: true) - Text("Display chip: it has no buttons. One MIDI message restarts it in update mode. It writes nothing to its firmware. Type UPDATE to send it.") - .fixedSize(horizontal: false, vertical: true) - HStack { - TextField("Type UPDATE", text: $model.typed).frame(maxWidth: 140) - Button("Send the update-mode message") { Task { await model.enterUpdateMode() } } - .disabled(model.typed != "UPDATE" || model.running) + // The steps in order (#762), DeckBridge quit first. + ForEach(Array(UpdaterScreen.lc6000Steps.prefix(3).enumerated()), id: \.offset) { _, step in + Text(step).fixedSize(horizontal: false, vertical: true) } + Button("Restart the display chip in update mode…") { model.confirmingStep = true } + .disabled(model.running) if let stepResult = model.stepResult { Text(stepResult).fixedSize(horizontal: false, vertical: true) } - Text("Then quit DeckBridge and pick a folder. The app reads the chip twice and saves it only if both reads match. Nothing is written to the LC6000.") + Text(UpdaterScreen.lc6000Steps[3]) .fixedSize(horizontal: false, vertical: true) .foregroundStyle(.secondary) HStack { @@ -116,5 +120,12 @@ struct BackupView: View { if let update = model.update { UpdateView(model: update) } } .padding(.top, 4) + // Return never fires it: Cancel is the default. + .alert(UpdateModeStep.confirmTitle, isPresented: $model.confirmingStep) { + Button(UpdateModeStep.confirmButton) { Task { await model.enterUpdateMode(clicked: UpdateModeStep.confirmButton) } } + Button("Cancel", role: .cancel) {}.keyboardShortcut(.defaultAction) + } message: { + Text(UpdateModeStep.confirmBody) + } } } diff --git a/Apps/FirmwareUpdater/Sources/CoreMIDISend.swift b/Apps/FirmwareUpdater/Sources/CoreMIDISend.swift index 936f81be..519f9f00 100644 --- a/Apps/FirmwareUpdater/Sources/CoreMIDISend.swift +++ b/Apps/FirmwareUpdater/Sources/CoreMIDISend.swift @@ -3,7 +3,7 @@ import Foundation import UnitCheck /// The update-mode step's one send (#692), as tools/lc6000-firmware/enter-update-mode.swift sends it: a SysEx as UMP -/// SysEx7 packets on a CoreMIDI output port. Used only by UpdateModeStep, after the owner typed UPDATE. +/// SysEx7 packets on a CoreMIDI output port. Used only by UpdateModeStep, after the owner's click and confirm. struct CoreMIDISend: MIDISend { func destinations() async -> [String] { Self.named().map(\.name) } diff --git a/Apps/FirmwareUpdater/Sources/FirmwareUpdaterApp.swift b/Apps/FirmwareUpdater/Sources/FirmwareUpdaterApp.swift index 7ece6e28..cfebc7b0 100644 --- a/Apps/FirmwareUpdater/Sources/FirmwareUpdaterApp.swift +++ b/Apps/FirmwareUpdater/Sources/FirmwareUpdaterApp.swift @@ -75,7 +75,11 @@ struct UpdaterView: View { static func makeBackup() -> BackupModel { #if DEBUG - if let shot = PreviewLaunch.shot { return BackupModel(preview: shot.backupResult) } + if let shot = PreviewLaunch.shot { + return BackupModel(preview: shot.backupResult, confirmingStep: shot == .stepConfirm, + update: [.writeConfirm, .writing, .details].contains(shot) + ? UpdateModel(preview: shot == .writing, details: shot == .details) : nil) + } #endif return BackupModel() } @@ -106,8 +110,10 @@ struct UpdaterView: View { SectionView(title: "Deck panel", section: model.screen.panel, accept: nil) FirmwareRow(line: model.firmware) PanelUpdateView(model: model) - SectionView(title: "LC6000", section: model.screen.lc6000, accept: model.acceptLC6000Warning) - if model.screen.lc6000.warning == nil { BackupView(model: backup) } + // The LC6000's steps inside its box, only once one is found (#762). + SectionView(title: "LC6000", section: model.screen.lc6000, accept: model.acceptLC6000Warning) { + if model.screen.showsLC6000Steps { BackupView(model: backup) } + } HStack { Spacer() if model.looking { ProgressView().controlSize(.small) } @@ -119,10 +125,18 @@ struct UpdaterView: View { } } -struct SectionView: View { +struct SectionView: View { let title: String let section: DeviceSection let accept: (() -> Void)? + let extra: Extra + + init(title: String, section: DeviceSection, accept: (() -> Void)?, @ViewBuilder extra: () -> Extra) { + self.title = title + self.section = section + self.accept = accept + self.extra = extra() + } var body: some View { GroupBox { @@ -134,6 +148,7 @@ struct SectionView: View { Text(section.status).font(.headline) if let detail = section.detail { Text(detail).foregroundStyle(.secondary) } if let guide = section.guide { GuideView(guide: guide) } + extra } } .frame(maxWidth: .infinity, alignment: .leading) @@ -144,6 +159,12 @@ struct SectionView: View { } } +extension SectionView where Extra == EmptyView { + init(title: String, section: DeviceSection, accept: (() -> Void)?) { + self.init(title: title, section: section, accept: accept) { EmptyView() } + } +} + /// A driver's install steps, as plain numbered text, and the maker's download page (#688). No Settings button. struct GuideView: View { let guide: DriverGuide diff --git a/Apps/FirmwareUpdater/Sources/PreviewLaunch.swift b/Apps/FirmwareUpdater/Sources/PreviewLaunch.swift index 61d78b48..520a955d 100644 --- a/Apps/FirmwareUpdater/Sources/PreviewLaunch.swift +++ b/Apps/FirmwareUpdater/Sources/PreviewLaunch.swift @@ -4,22 +4,25 @@ import UpdaterScreen /// Screenshots of the window (#761), in Debug builds only: `FirmwareUpdater --preview ` opens it in a fixed state /// on fake ports (Updater.preview). No IOKit, CoreMIDI or serial object is made, no DeckBridge signal is sent, and its -/// buttons reach only the fakes. Shots: nothing, found, backup, updating. +/// buttons reach only the fakes. Shots: nothing, found, backup, updating; #762's stepConfirm, writeConfirm, writing. enum PreviewLaunch { enum Shot: String { case nothing, found, backup, updating + /// #762: the update-mode step's confirm; the write's confirm with its typed-word field; the write running; the + /// sectors under Details. + case stepConfirm, writeConfirm, writing, details var state: PreviewState { switch self { case .nothing: .nothing - case .found, .backup: .found + case .found, .backup, .stepConfirm, .writeConfirm, .writing, .details: .found case .updating: .updating } } /// The backup line shown in the LC6000 section, after a backup. var backupResult: String? { - self == .backup ? "Backup saved: read twice and the same, 2 files.\nTop panel chip: firmware 1.0.0." : nil + [.backup, .writeConfirm, .writing, .details].contains(self) ? "Backup saved: read twice and the same, 2 files.\nTop panel chip: firmware 1.0.0." : nil } } diff --git a/Apps/FirmwareUpdater/Sources/UpdateView.swift b/Apps/FirmwareUpdater/Sources/UpdateView.swift index 1d60375e..f7f20a76 100644 --- a/Apps/FirmwareUpdater/Sources/UpdateView.swift +++ b/Apps/FirmwareUpdater/Sources/UpdateView.swift @@ -13,9 +13,20 @@ final class UpdateModel { /// Why a write didn't start (DeckBridge running, the chip not found): nothing was sent. private(set) var stop: String? var confirming = false + var confirmingRestore = false + /// The confirm's Details disclosure is open. + var detailsOpen = false + /// The word typed in the write's confirm (#762): the write's button stays off until it's UPDATE. + var typed = "" + + /// Called as a write or restore starts: the backup's line goes (#762). + private let writeStarts: () -> Void + /// A screenshot preview (#762): write and restore do nothing, so no IOKit object is made and no chip is reached. + private var inert = false /// `read`: the backup read just taken, in this run of the app. - init(read: ChipRead) { + init(read: ChipRead, writeStarts: @escaping () -> Void = {}) { + self.writeStarts = writeStarts let catalog = try? Catalog.builtIn() let chip: Chip = read.kind == .display ? .wd : .tp let edits = catalog.map { catalog in @@ -26,12 +37,38 @@ final class UpdateModel { known: catalog?.knownNumbers ?? .none) } - func write() async { await run(flow.plan) } - func restore() async { await run(flow.restorePlan) } + /// The write's confirmation, only with the typed word; the button is off without it. + var writeConfirmation: Confirmation? { flow.plan.flatMap { Confirmation(typed: typed, for: $0) } } + + #if DEBUG + /// A screenshot preview (#762): a made-up plan, its confirm open or a write showing as running. Nothing reaches a + /// chip: the preview's buttons are inert (BackupModel), and no IOKit object is made. + init(preview writing: Bool, details: Bool = false) { + writeStarts = {} + // Made-up bytes: the top panel chip's app area as 0xFF, with one byte changed in its 64 KB sector. + let backup = [UInt8](repeating: 0xFF, count: ChipKind.topPanel.app.length) + var patched = backup + patched[0x8000] = 0x00 + flow = UpdateFlow(preview: WritePlan(chip: .topPanel, backup: backup, patched: patched), version: "00.31") + running = writing + confirming = !writing && !details + detailsOpen = details + inert = true + } + #endif + + func write() async { + let confirmed = writeConfirmation + typed = "" + await run(flow.plan, confirmed) + } + + func restore() async { await run(flow.restorePlan, flow.restorePlan.flatMap(Confirmation.init(restoring:))) } - private func run(_ plan: WritePlan?) async { - guard let plan, !running else { return } + private func run(_ plan: WritePlan?, _ confirmed: Confirmation?) async { + guard !inert, let plan, let confirmed, !running else { return } stop = nil + writeStarts() if let reason = await Preflight(apps: WorkspaceApps()).stop() { stop = reason return @@ -44,7 +81,7 @@ final class UpdateModel { } running = true defer { running = false } - let outcome = await ChipWriter(transport: usb).write(plan, confirmed: Confirmation(plan)) + let outcome = await ChipWriter(transport: usb).write(plan, confirmed: confirmed) flow.finished(outcome) FileLog.shared.log(flow.logLine(outcome)) } @@ -58,23 +95,41 @@ struct UpdateView: View { Text("Update the chip").font(.headline) if let status = model.flow.status { Text(status).fixedSize(horizontal: false, vertical: true) } if let stop = model.stop { Text(stop).fixedSize(horizontal: false, vertical: true) } + if model.running { Text(model.flow.writingText).fixedSize(horizontal: false, vertical: true) } + // The sectors and addresses, out of the way (#762): an alert can't hold a disclosure, so it sits by the button. + if model.flow.canConfirm { + DisclosureGroup("Details", isExpanded: $model.detailsOpen) { + Text(model.flow.confirmDetails).font(.callout).fixedSize(horizontal: false, vertical: true) + } + } HStack { if model.flow.canConfirm { Button(model.flow.confirmButton + "…") { model.confirming = true }.disabled(model.running) } if model.flow.canRestore { - Button(model.flow.restoreButton) { Task { await model.restore() } }.disabled(model.running) + Button(model.flow.restoreButton + "…") { model.confirmingRestore = true }.disabled(model.running) + } + if let guide = model.flow.recoveryGuide(bundled: Bundle.main.url(forResource: "LC6000-RECOVERY", withExtension: "md")) { + Link("Recovery guide", destination: guide) } - if let guide = model.flow.recoveryGuide { Link("Recovery guide", destination: guide) } if model.running { ProgressView().controlSize(.small) } } } .padding(.top, 4) + // Return never fires a destructive button: Cancel is the default in both, and the write needs the typed word. .alert(model.flow.confirmTitle, isPresented: $model.confirming) { + TextField("Type \(Confirmation.word)", text: $model.typed) Button(model.flow.confirmButton, role: .destructive) { Task { await model.write() } } - Button("Cancel", role: .cancel) {} + .disabled(model.writeConfirmation == nil) + Button("Cancel", role: .cancel) { model.typed = "" }.keyboardShortcut(.defaultAction) } message: { Text(model.flow.confirmBody) } + .alert("Restore your backup?", isPresented: $model.confirmingRestore) { + Button(model.flow.restoreButton, role: .destructive) { Task { await model.restore() } } + Button("Cancel", role: .cancel) {}.keyboardShortcut(.defaultAction) + } message: { + Text("This writes your backup's bytes back to the same sectors, then reads them back. Keep the LC6000 on and plugged in until it's done.") + } } } diff --git a/Apps/FirmwareUpdater/project.yml b/Apps/FirmwareUpdater/project.yml index 3ce2a17f..a11c9400 100644 --- a/Apps/FirmwareUpdater/project.yml +++ b/Apps/FirmwareUpdater/project.yml @@ -26,6 +26,9 @@ targets: - path: Sources # Its own icon (#733), rendered from design/icon/updater-download.svg by scripts/render_app_icon.swift. - path: Assets.xcassets + # The LC6000 recovery guide, opened from the app with no network (#762). Never site text. + - path: ../../docs/LC6000-RECOVERY.md + buildPhase: resources dependencies: - package: FirmwareUpdaterKit product: DeviceFinder diff --git a/Packages/FirmwareUpdaterKit/Sources/LC6000Update/ChipWriter.swift b/Packages/FirmwareUpdaterKit/Sources/LC6000Update/ChipWriter.swift index 62665a15..fdc4dbd1 100644 --- a/Packages/FirmwareUpdaterKit/Sources/LC6000Update/ChipWriter.swift +++ b/Packages/FirmwareUpdaterKit/Sources/LC6000Update/ChipWriter.swift @@ -1,12 +1,29 @@ +import Foundation // Writing an LC6000 chip in ST's update mode (#693): only after the owner confirms this very plan, only the plan's // sectors, erased and written as dfu-util's DfuSe download does it (erase 0x41, set address 0x21, DNLOAD blocks from // 2), then read back and compared. Tested on a fake chip; on a unit, the owner runs every write. import UnitCheck /// The owner's confirm of one plan: the confirm sheet's button makes it, for the plan it showed. +/// The owner's go-ahead for one plan. The update's write needs the typed word UPDATE (#762, the owner's decision of +/// 2026-11-22); a restore after a mismatch needs only its confirm. Nothing else makes one, so nothing else can write. public struct Confirmation: Sendable { let plan: WritePlan - public init(_ plan: WritePlan) { self.plan = plan } + + /// The word the owner types before the write. + public static let word = "UPDATE" + + /// For the update's write: only when `typed` is UPDATE, in any case, spaces around it allowed. + public init?(typed: String, for plan: WritePlan) { + guard !plan.isRestore, typed.trimmingCharacters(in: .whitespaces).uppercased() == Self.word else { return nil } + self.plan = plan + } + + /// For Restore backup: only for a restore plan, never the update's own write. + public init?(restoring plan: WritePlan) { + guard plan.isRestore else { return nil } + self.plan = plan + } } public enum WriteOutcome: Sendable, Equatable { diff --git a/Packages/FirmwareUpdaterKit/Sources/LC6000Update/UpdateFlow.swift b/Packages/FirmwareUpdaterKit/Sources/LC6000Update/UpdateFlow.swift index 42e2d5d3..0fffc88f 100644 --- a/Packages/FirmwareUpdaterKit/Sources/LC6000Update/UpdateFlow.swift +++ b/Packages/FirmwareUpdaterKit/Sources/LC6000Update/UpdateFlow.swift @@ -15,7 +15,7 @@ public struct UpdateFlow: Sendable { enum Phase: Equatable { case ready, mismatch(UInt32), done(String), recovery } - /// The written recovery guide, in the repo. + /// The written recovery guide, in the repo: the fallback when the app's own copy is missing. public static let recoveryGuideURL = URL(string: "https://github.com/ericdahl-dev/deckbridge/blob/main/docs/LC6000-RECOVERY.md")! /// `backup`: the read the plan is built from. `backupTakenThisSession`: it was read in this run of the app. @@ -36,25 +36,44 @@ public struct UpdateFlow: Sendable { } } + #if DEBUG + /// A screenshot preview's flow (#762): a made-up plan on a made-up backup, never from a chip. Debug builds only. + public init(preview plan: WritePlan, version: String) { + chip = plan.chip + fresh = true + state = .stock(version) + self.plan = plan + } + #endif + var name: String { chip == .display ? "display chip" : "top panel chip" } /// The confirm can be pressed: a plan from this session's backup, and nothing written yet. public var canConfirm: Bool { phase == .ready && fresh && plan.map { !$0.sectors.isEmpty } == true } public var confirmTitle: String { "Write to the LC6000's \(name)?" } public var confirmButton: String { "Write to the \(name)" } + /// The risk first, in plain words (#762), and the word to type. No addresses: those are `confirmDetails`. public var confirmBody: String { - (plan?.text ?? "") + "\n\n" + "If this goes wrong, the unit may not start, and the worst case needs a hardware " - + "debug probe to recover it. Your backup stays on this Mac. Quit DeckBridge first, and keep the LC6000 " - + "powered and plugged in until it's done." + "If it goes wrong, the LC6000 may not start, and the worst case needs a hardware probe. Your backup stays on " + + "this Mac. Keep it on and plugged in until it's done.\n\nType \(Confirmation.word) to write." } + /// While a write or restore runs (#762). The top panel chip's time is the owner's write (2026-11-22, about 30 s); + /// the display chip's isn't measured yet. + public var writingText: String { + "Writing the \(name). Don't unplug or switch off the LC6000. " + + (chip == .topPanel ? "This takes about 30 seconds." : "This takes under a minute.") + } + + /// Exactly what is written where, behind the confirm's Details. + public var confirmDetails: String { plan?.text ?? "" } /// After a mismatch: the backup's bytes back in the same sectors. public var canRestore: Bool { if case .mismatch = phase { true } else { false } } public var restoreButton: String { "Restore backup" } public var restorePlan: WritePlan? { plan?.restore } - /// The guide, when the chip may not start. - public var recoveryGuide: URL? { phase == .recovery ? Self.recoveryGuideURL : nil } + /// The guide, when the chip may not start: the app's own copy (`bundled`, #762: no network needed), else GitHub's. + public func recoveryGuide(bundled: URL?) -> URL? { phase == .recovery ? bundled ?? Self.recoveryGuideURL : nil } public var status: String? { switch phase { diff --git a/Packages/FirmwareUpdaterKit/Sources/LC6000Update/WritePlan.swift b/Packages/FirmwareUpdaterKit/Sources/LC6000Update/WritePlan.swift index d35c8018..e6713e05 100644 --- a/Packages/FirmwareUpdaterKit/Sources/LC6000Update/WritePlan.swift +++ b/Packages/FirmwareUpdaterKit/Sources/LC6000Update/WritePlan.swift @@ -14,6 +14,8 @@ public struct WritePlan: Sendable, Equatable { /// How many bytes differ from the backup. public let changedBytes: Int private let backup: [UInt8] + /// The backup's bytes going back (Restore backup), not the update's write. + public let isRestore: Bool /// `backup` and `patched`: the chip's app area, as the unit check reads it and as the patch makes it. public init(chip: ChipKind, backup: [UInt8], patched: [UInt8]) { @@ -33,6 +35,7 @@ public struct WritePlan: Sendable, Equatable { } self.sectors = sectors changedBytes = changed + isRestore = false } private init(chip: ChipKind, sectors: [Sector], changedBytes: Int, backup: [UInt8]) { @@ -40,6 +43,7 @@ public struct WritePlan: Sendable, Equatable { self.sectors = sectors self.changedBytes = changedBytes self.backup = backup + isRestore = true } /// The same sectors with the backup's bytes: what the restore button writes. diff --git a/Packages/FirmwareUpdaterKit/Sources/UnitCheck/LC6000Lines.swift b/Packages/FirmwareUpdaterKit/Sources/UnitCheck/LC6000Lines.swift new file mode 100644 index 00000000..82c04c6a --- /dev/null +++ b/Packages/FirmwareUpdaterKit/Sources/UnitCheck/LC6000Lines.swift @@ -0,0 +1,18 @@ +/// The LC6000 section's status lines (#762): one per step, and a step starting clears the ones it makes stale. +public struct LC6000Lines: Sendable, Equatable { + /// The update-mode step's result. + public var step: String? + /// The backup's result. + public var backup: String? + + public init() {} + + public mutating func stepStarts() { step = nil } + + public mutating func backupStarts() { + step = nil + backup = nil + } + + public mutating func writeStarts() { backup = nil } +} diff --git a/Packages/FirmwareUpdaterKit/Sources/UnitCheck/UpdateModeStep.swift b/Packages/FirmwareUpdaterKit/Sources/UnitCheck/UpdateModeStep.swift index 1903df5b..360dec10 100644 --- a/Packages/FirmwareUpdaterKit/Sources/UnitCheck/UpdateModeStep.swift +++ b/Packages/FirmwareUpdaterKit/Sources/UnitCheck/UpdateModeStep.swift @@ -5,7 +5,8 @@ public protocol MIDISend: Sendable { func send(_ bytes: [UInt8], to port: String) async -> Bool } -/// The display chip's step into update mode (#692): one message on its WD port, only when the owner typed UPDATE. +/// The display chip's step into update mode (#692): one message on its WD port, only after the owner's click and confirm +/// (#762: the typed UPDATE moved to the write). /// A port of tools/lc6000-firmware/enter-update-mode.swift. It writes nothing to flash, but the chip stays in update /// mode until it is flashed or power-cycled. public struct UpdateModeStep: Sendable { @@ -13,6 +14,17 @@ public struct UpdateModeStep: Sendable { public static let sentText = "Sent. The display chip restarts in update mode: give it a few seconds, then back it up. " + "A power cycle ends update mode, and the chip starts its own firmware again." + public static let confirmTitle = "Restart the display chip in update mode?" + public static let confirmBody = "This restarts the display chip into update mode. Nothing is written. A power cycle ends it." + public static let confirmButton = "Restart in update mode" + + /// The owner's go-ahead: only the confirm's own button makes one. + public struct Confirmed: Sendable, Equatable { + public init?(clicked button: String) { + guard button == UpdateModeStep.confirmButton else { return nil } + } + } + public enum Outcome: Sendable, Hashable { case sent case refused(String) @@ -31,8 +43,7 @@ public struct UpdateModeStep: Sendable { static let portHint = "LC6000 PRIME WD" /// Sends the message once, or nothing. Never retried. - public func enter(typed: String) async -> Outcome { - guard typed == "UPDATE" else { return .refused("You didn't type UPDATE, so nothing was sent.") } + public func enter(confirmed: Confirmed) async -> Outcome { if let stop = await Preflight(apps: apps).stop() { return .refused(stop) } let ports = await midi.destinations().filter { $0.contains(Self.portHint) } guard let port = ports.first else { diff --git a/Packages/FirmwareUpdaterKit/Sources/UpdaterScreen/Updater.swift b/Packages/FirmwareUpdaterKit/Sources/UpdaterScreen/Updater.swift index e7ba065b..3ac54d8e 100644 --- a/Packages/FirmwareUpdaterKit/Sources/UpdaterScreen/Updater.swift +++ b/Packages/FirmwareUpdaterKit/Sources/UpdaterScreen/Updater.swift @@ -138,11 +138,15 @@ public final class Updater { flashing = nil canCancel = false updating = false - // The panel restarted into its new build: look again so the section shows it. - await refresh() + // The panel restarted into its new build: look again so the section shows it, keeping the result on screen. + await look(keepingResult: true) } - public func refresh() async { + /// A look the owner asked for (Look again) or launch's: the last update's result goes (#762: one status line per + /// step). A USB change keeps it: the panel's port comes back seconds after an update, and the result must stay. + public func refresh() async { await look(keepingResult: false) } + + private func look(keepingResult: Bool) async { // During an update the panel restarts (a USB change), and a look would open the port the flasher holds. The // update looks once when it's done. guard !updating else { return } @@ -151,6 +155,7 @@ public final class Updater { return } looking = true + if !keepingResult { updateText = nil } repeat { lookAgain = false found = await finder.find() @@ -170,7 +175,7 @@ public final class Updater { /// Looks again on every USB change, until the stream ends. public func watch() async { - for await _ in changes { await refresh() } + for await _ in changes { await look(keepingResult: true) } } public func acceptLC6000Warning() { diff --git a/Packages/FirmwareUpdaterKit/Sources/UpdaterScreen/UpdaterScreen.swift b/Packages/FirmwareUpdaterKit/Sources/UpdaterScreen/UpdaterScreen.swift index afbc1f41..fb28f711 100644 --- a/Packages/FirmwareUpdaterKit/Sources/UpdaterScreen/UpdaterScreen.swift +++ b/Packages/FirmwareUpdaterKit/Sources/UpdaterScreen/UpdaterScreen.swift @@ -40,6 +40,16 @@ public struct DeviceSection: Sendable, Equatable { public struct UpdaterScreen: Sendable, Equatable { public let panel: DeviceSection public let lc6000: DeviceSection + /// The LC6000's steps (update mode, backup) show: its warning accepted and an LC6000 found (#762). + public let showsLC6000Steps: Bool + + /// The LC6000's steps, in order (#762): DeckBridge quit first, since it talks to the LC6000. + public static let lc6000Steps = [ + "Quit DeckBridge first. It talks to the LC6000.", + "Put one chip in update mode. Top panel chip: power the LC6000 off, then hold BACK + FWD + VINYL while you power it on.", + "Display chip: it has no buttons. One MIDI message restarts it in update mode. It writes nothing to its firmware.", + "Then pick a folder. The app reads the chip twice and saves it only if both reads match. Nothing is written to the LC6000.", + ] /// The app's name wherever the owner sees it (#763): the window title here; project.yml names the rest. public static let appName = "DeckBridge Firmware Updater" @@ -78,14 +88,16 @@ public struct UpdaterScreen: Sendable, Equatable { panel = DeviceSection(status: "Deck panel found", detail: "Build not read") } + showsLC6000Steps = lc6000WarningAccepted && found.lc6000 != nil guard lc6000WarningAccepted else { lc6000 = DeviceSection(status: "Read the warning first", warning: Self.lc6000Warning) return } switch found.lc6000 { - case nil: lc6000 = DeviceSection(status: "Nothing connected") + case nil: lc6000 = DeviceSection(status: "Nothing connected", detail: "Plug in the LC6000 and switch it on.") case .onMIDI: lc6000 = DeviceSection(status: "LC6000 found", detail: "Firmware not checked yet") - case .updateMode: lc6000 = DeviceSection(status: "A device in update mode, maybe an LC6000") + // Not which chip: naming it would mean a new request at every look (#762). The backup names it. + case .updateMode: lc6000 = DeviceSection(status: "An LC6000 chip in update mode") } } diff --git a/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/ChipWriterTests.swift b/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/ChipWriterTests.swift index 835f80b5..c8caed2b 100644 --- a/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/ChipWriterTests.swift +++ b/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/ChipWriterTests.swift @@ -25,7 +25,7 @@ struct ChipWriterTests { func confirmIsForThisPlan() async throws { let (chip, plan, stock, _) = try Self.display() let other = WritePlan(chip: .display, backup: stock, patched: stock.enumerated().map { $0.offset == 0x10 ? 0 : $0.element }) - let outcome = await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(other)) + let outcome = await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(typed: "UPDATE", for: other)!) #expect(outcome == .refused) #expect(chip.log.isEmpty) } @@ -34,7 +34,7 @@ struct ChipWriterTests { func writesAndVerifies() async throws { let (chip, plan, _, patched) = try Self.display() let before = chip.bytes(0x0800_0000, 0x10_0000) - #expect(await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(plan)) == .written) + #expect(await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(typed: "UPDATE", for: plan)!) == .written) #expect(Self.app(chip) == patched) let after = chip.bytes(0x0800_0000, 0x10_0000) let changed = zip(before, after).enumerated().filter { $0.element.0 != $0.element.1 }.map { 0x0800_0000 + UInt32($0.offset) } @@ -47,17 +47,17 @@ struct ChipWriterTests { func mismatch() async throws { let (chip, plan, stock, _) = try Self.display() chip.stuckAt = 0x0800_BDA4 - #expect(await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(plan)) == .mismatch(at: 0x0800_BDA4)) + #expect(await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(typed: "UPDATE", for: plan)!) == .mismatch(at: 0x0800_BDA4)) chip.stuckAt = nil - #expect(await ChipWriter(transport: chip).write(plan.restore, confirmed: Confirmation(plan.restore)) == .written) + #expect(await ChipWriter(transport: chip).write(plan.restore, confirmed: Confirmation(restoring: plan.restore)!) == .written) #expect(Self.app(chip) == stock) } @Test("Restore after a good write: the backup's bytes again in the same sectors") func restore() async throws { let (chip, plan, stock, _) = try Self.display() - _ = await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(plan)) - #expect(await ChipWriter(transport: chip).write(plan.restore, confirmed: Confirmation(plan.restore)) == .written) + _ = await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(typed: "UPDATE", for: plan)!) + #expect(await ChipWriter(transport: chip).write(plan.restore, confirmed: Confirmation(restoring: plan.restore)!) == .written) #expect(Self.app(chip) == stock) } @@ -65,7 +65,7 @@ struct ChipWriterTests { func noAnswer() async throws { let (chip, plan, _, _) = try Self.display() chip.goneAfterErases = 1 - #expect(await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(plan)) == .noAnswer) + #expect(await ChipWriter(transport: chip).write(plan, confirmed: Confirmation(typed: "UPDATE", for: plan)!) == .noAnswer) } @Test("The write guard: another sector's erase, a block that isn't the plan's, or one past its sector never reach the chip") diff --git a/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/UpdateFlowTests.swift b/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/UpdateFlowTests.swift index 1939f819..7e8e46f0 100644 --- a/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/UpdateFlowTests.swift +++ b/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/UpdateFlowTests.swift @@ -21,18 +21,22 @@ struct UpdateFlowTests { return UpdateFlow(chip: .display, backup: backup, backupTakenThisSession: fresh, edits: edits, known: known) } - @Test("Stock, with this session's backup: the confirm names the chip and the risk, and lists what is written") + @Test("Stock, with this session's backup: the confirm says the risk first in plain words; the sectors are its Details") func confirm() throws { let flow = try Self.flow() #expect(flow.canConfirm) #expect(flow.confirmTitle == "Write to the LC6000's display chip?") #expect(flow.confirmButton == "Write to the display chip") #expect(flow.confirmBody == """ + If it goes wrong, the LC6000 may not start, and the worst case needs a hardware probe. Your backup stays on \ + this Mac. Keep it on and plugged in until it's done. + + Type UPDATE to write. + """) + #expect(!flow.confirmBody.contains("0x")) + #expect(flow.confirmDetails == """ The display chip: 2 flash sectors are erased and written with the patched image, 0x08008000-0x0800BFFF \ (16 KB) and 0x08060000-0x0807FFFF (128 KB). 5 bytes differ from your backup. Every other sector is untouched. - - If this goes wrong, the unit may not start, and the worst case needs a hardware debug probe to recover it. \ - Your backup stays on this Mac. Quit DeckBridge first, and keep the LC6000 powered and plugged in until it's done. """) } @@ -57,7 +61,7 @@ struct UpdateFlowTests { var flow = try Self.flow() flow.finished(.written) #expect(flow.status == "Written and checked. Turn the LC6000 off and on again.") - #expect(!flow.canConfirm && !flow.canRestore && flow.recoveryGuide == nil) + #expect(!flow.canConfirm && !flow.canRestore && flow.recoveryGuide(bundled: URL(filePath: "/x.md")) == nil) } @Test("A mismatch offers Restore backup; restored and checked, power-cycle") @@ -80,10 +84,13 @@ struct UpdateFlowTests { let noAnswer = "The chip stopped answering during the update, so the LC6000 may not start. Leave it plugged in and follow the recovery guide." #expect(flow.status == noAnswer) #expect(!flow.canRestore && !flow.canConfirm) - #expect(flow.recoveryGuide == URL(string: "https://github.com/ericdahl-dev/deckbridge/blob/main/docs/LC6000-RECOVERY.md")) + #expect(flow.recoveryGuide(bundled: nil) == URL(string: "https://github.com/ericdahl-dev/deckbridge/blob/main/docs/LC6000-RECOVERY.md")) + // The app's own copy first (#762): it opens with no network, when the unit may need it most. + let local = URL(filePath: "/Applications/DeckBridge Firmware Updater.app/Contents/Resources/LC6000-RECOVERY.md") + #expect(flow.recoveryGuide(bundled: local) == local) var gone = try Self.flow() gone.finished(.noAnswer) - #expect(gone.status == noAnswer && !gone.canRestore && gone.recoveryGuide != nil) + #expect(gone.status == noAnswer && !gone.canRestore && gone.recoveryGuide(bundled: nil) != nil) } @Test("The owner's top panel chip after #748's run: patched, so its hash isn't stock's, and it shows up to date") @@ -117,6 +124,16 @@ struct UpdateFlowTests { == "Backup saved: read twice and the same, 2 files.\nTop panel chip: firmware 00.31.") } + /// While a write runs (#762): which chip, not to unplug, and how long. The top panel chip's time is the owner's + /// write of 2026-11-22 (about 30 s, confirm to read back); the display chip's isn't measured yet. + @Test("While writing: the chip, don't unplug or switch off, and how long") + func writingLine() throws { + #expect(try Self.flow().writingText + == "Writing the display chip. Don't unplug or switch off the LC6000. This takes under a minute.") + #expect(UpdateFlow(chip: .topPanel, backup: nil, backupTakenThisSession: true, edits: [], known: .none).writingText + == "Writing the top panel chip. Don't unplug or switch off the LC6000. This takes about 30 seconds.") + } + @Test("The log line for each outcome: fixed words, and where a read-back differed (#763: the address is log only)") func logLines() throws { let flow = try Self.flow() diff --git a/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/WriteGateTests.swift b/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/WriteGateTests.swift new file mode 100644 index 00000000..9473f167 --- /dev/null +++ b/Packages/FirmwareUpdaterKit/Tests/LC6000UpdateTests/WriteGateTests.swift @@ -0,0 +1,39 @@ +import LC6000Update +import Testing +import UnitCheck + +/// The owner's decision (#762, 2026-11-22): the typed word UPDATE guards the flash write, not the update-mode step. +/// Without it there's no confirmation, so the writer can't be asked. Restore after a mismatch is a click and confirm. +@Suite("LC6000 update: the typed UPDATE guards the write") +struct WriteGateTests { + typealias W = ChipWriterTests + + @Test("UPDATE in any case gives the write's confirmation", arguments: ["UPDATE", "update", "Update", " UPDATE "]) + func typed(word: String) throws { + let (_, plan, _, _) = try W.display() + #expect(Confirmation(typed: word, for: plan) != nil) + } + + @Test("Anything else gives none", arguments: ["", "UPDAT", "UPDATES", "yes", "U P D A T E"]) + func notTyped(word: String) throws { + let (_, plan, _, _) = try W.display() + #expect(Confirmation(typed: word, for: plan) == nil) + } + + @Test("Restore's confirmation is only for a restore plan: never for the update's own write") + func restoreOnly() throws { + let (_, plan, _, _) = try W.display() + #expect(Confirmation(restoring: plan) == nil) + #expect(Confirmation(restoring: plan.restore) != nil) + #expect(Confirmation(typed: "UPDATE", for: plan.restore) == nil) + } + + @Test("With the word: written. Without it the flow offers no confirmation, and not one request reaches the chip") + func endToEnd() async throws { + let (chip, plan, _, _) = try W.display() + if let confirmed = Confirmation(typed: "", for: plan) { _ = await ChipWriter(transport: chip).write(plan, confirmed: confirmed) } + #expect(chip.log.isEmpty) + let confirmed = try #require(Confirmation(typed: "update", for: plan)) + #expect(await ChipWriter(transport: chip).write(plan, confirmed: confirmed) == .written) + } +} diff --git a/Packages/FirmwareUpdaterKit/Tests/UnitCheckTests/LC6000LinesTests.swift b/Packages/FirmwareUpdaterKit/Tests/UnitCheckTests/LC6000LinesTests.swift new file mode 100644 index 00000000..d41ba54e --- /dev/null +++ b/Packages/FirmwareUpdaterKit/Tests/UnitCheckTests/LC6000LinesTests.swift @@ -0,0 +1,37 @@ +import Testing +import UnitCheck + +/// One status line per step in the LC6000 section (#762): starting a step clears the lines it makes stale, so the +/// owner never reads an old result under a new step. +@Suite("Unit check: the LC6000 section's status lines") +struct LC6000LinesTests { + static func both() -> LC6000Lines { + var lines = LC6000Lines() + lines.step = "Sent." + lines.backup = "Backup saved." + return lines + } + + @Test("A backup starting clears the update-mode step's line and the last backup's") + func backupStarts() { + var lines = Self.both() + lines.backupStarts() + #expect(lines.step == nil && lines.backup == nil) + } + + @Test("A write starting clears the backup's line, and leaves the step's alone") + func writeStarts() { + var lines = Self.both() + lines.writeStarts() + #expect(lines.backup == nil) + #expect(lines.step == "Sent.") + } + + @Test("The update-mode step starting clears its own last line only") + func stepStarts() { + var lines = Self.both() + lines.stepStarts() + #expect(lines.step == nil) + #expect(lines.backup == "Backup saved.") + } +} diff --git a/Packages/FirmwareUpdaterKit/Tests/UnitCheckTests/UpdateModeStepTests.swift b/Packages/FirmwareUpdaterKit/Tests/UnitCheckTests/UpdateModeStepTests.swift index 0558b19f..26085e11 100644 --- a/Packages/FirmwareUpdaterKit/Tests/UnitCheckTests/UpdateModeStepTests.swift +++ b/Packages/FirmwareUpdaterKit/Tests/UnitCheckTests/UpdateModeStepTests.swift @@ -27,31 +27,42 @@ let lc6000Ports = ["LC6000 PRIME Controller", "LC6000 PRIME WD"] @Suite("Unit check: the display chip's update-mode step") struct UpdateModeStepTests { - @Test("The owner typed UPDATE: the kit's one message, sent once, to the WD port only") + static let confirmed = UpdateModeStep.Confirmed(clicked: UpdateModeStep.confirmButton)! + + @Test("The owner confirmed: the kit's one message, sent once, to the WD port only") func sentOnUpdate() async throws { let midi = FakeMIDISend(ports: ["IAC Driver Bus 1"] + lc6000Ports) - let outcome = await UpdateModeStep(midi: midi, apps: FakeApps(running: [])).enter(typed: "UPDATE") + let outcome = await UpdateModeStep(midi: midi, apps: FakeApps(running: [])).enter(confirmed: Self.confirmed) #expect(outcome == .sent) #expect(midi.sent.count == 1) #expect(midi.sent.first?.port == "LC6000 PRIME WD") #expect(midi.sent.first?.bytes == (try kitUpdateModeMessage())) } - @Test("Anything but UPDATE typed: nothing is sent", arguments: ["", "update", "UPDATE ", "yes", "UPDATE\n"]) - func notSentOtherwise(typed: String) async { - let midi = FakeMIDISend(ports: lc6000Ports) - let outcome = await UpdateModeStep(midi: midi, apps: FakeApps(running: [])).enter(typed: typed) - #expect(outcome == .refused("You didn't type UPDATE, so nothing was sent.")) - #expect(midi.sent.isEmpty) + @Test("Only the confirm's own button confirms: Cancel or any other button gives no go-ahead, so nothing is sent") + func onlyTheConfirmButton() { + #expect(UpdateModeStep.Confirmed(clicked: UpdateModeStep.confirmButton) != nil) + for other in ["Cancel", "", "OK", "Write to the display chip"] { + #expect(UpdateModeStep.Confirmed(clicked: other) == nil) + } + } + + /// The owner's decision (#762, 2026-11-22): no typed word here any more (it guards the write); a click, then a confirm + /// that says what it does. + @Test("The confirm says it restarts the chip into update mode, writes nothing, and a power cycle ends it") + func confirmText() { + #expect(UpdateModeStep.confirmTitle == "Restart the display chip in update mode?") + #expect(UpdateModeStep.confirmBody == "This restarts the display chip into update mode. Nothing is written. A power cycle ends it.") + #expect(UpdateModeStep.confirmButton == "Restart in update mode") } @Test("No WD port, or two: nothing is sent, with a plain reason") func needsExactlyOneWDPort() async { let none = FakeMIDISend(ports: ["LC6000 PRIME Controller"]) - #expect(await UpdateModeStep(midi: none, apps: FakeApps(running: [])).enter(typed: "UPDATE") + #expect(await UpdateModeStep(midi: none, apps: FakeApps(running: [])).enter(confirmed: Self.confirmed) == .refused("The LC6000's display port isn't there. Is the LC6000 on, on a direct cable? Nothing was sent.")) let two = FakeMIDISend(ports: lc6000Ports + ["LC6000 PRIME WD #2"]) - #expect(await UpdateModeStep(midi: two, apps: FakeApps(running: [])).enter(typed: "UPDATE") + #expect(await UpdateModeStep(midi: two, apps: FakeApps(running: [])).enter(confirmed: Self.confirmed) == .refused("There are two LC6000 display ports. Connect one LC6000 only. Nothing was sent.")) #expect(none.sent.isEmpty && two.sent.isEmpty) } @@ -59,7 +70,7 @@ struct UpdateModeStepTests { @Test("DeckBridge running: nothing is sent") func notWithDeckBridge() async { let midi = FakeMIDISend(ports: lc6000Ports) - let outcome = await UpdateModeStep(midi: midi, apps: FakeApps(running: ["dev.ericdahl.ControllerBridge"])).enter(typed: "UPDATE") + let outcome = await UpdateModeStep(midi: midi, apps: FakeApps(running: ["dev.ericdahl.ControllerBridge"])).enter(confirmed: Self.confirmed) #expect(outcome == .refused("DeckBridge is running. Quit it first: it talks to the LC6000.")) #expect(midi.sent.isEmpty) } diff --git a/Packages/FirmwareUpdaterKit/Tests/UpdaterScreenTests/PanelUpdateFlowTests.swift b/Packages/FirmwareUpdaterKit/Tests/UpdaterScreenTests/PanelUpdateFlowTests.swift index 49c776f5..b7b2b6b2 100644 --- a/Packages/FirmwareUpdaterKit/Tests/UpdaterScreenTests/PanelUpdateFlowTests.swift +++ b/Packages/FirmwareUpdaterKit/Tests/UpdaterScreenTests/PanelUpdateFlowTests.swift @@ -126,6 +126,28 @@ struct PanelUpdateFlowTests { #expect(updater.screen.panel.detail == "Build 2b7e9c1") } + /// One status line per step (#762): the update's result stays through its own closing look, and goes at the next. + @Test("The update's result stays after its own look; Look again clears it") + func resultClearsAtNextLook() async { + let updater = Self.updater(StubDeckBridge(answers: false), StubFlasher([.connecting, .restarting, Self.updated])) + await updater.updatePanel() + #expect(updater.screen.update == "Updated: the panel now runs build 2b7e9c1") + await updater.refresh() + #expect(updater.screen.update == nil) + } + + @Test("A USB change after an update (the panel's port coming back) keeps the result on screen") + func resultStaysThroughUSBChange() async { + let (changes, change) = AsyncStream.makeStream() + let updater = Updater(finder: Rig().finder, changes: changes, borrow: StubDeckBridge(answers: false).borrow, + flasher: StubFlasher([.connecting, .restarting, Self.updated])) + await updater.updatePanel() + change.yield() + change.finish() + await updater.watch() + #expect(updater.screen.update == "Updated: the panel now runs build 2b7e9c1") + } + @Test("A write that stops partway: the screen has no address, the log has it (#763)") func writeFailedAddressInLogOnly() async { let rig = Rig() diff --git a/Packages/FirmwareUpdaterKit/Tests/UpdaterScreenTests/UpdaterScreenTests.swift b/Packages/FirmwareUpdaterKit/Tests/UpdaterScreenTests/UpdaterScreenTests.swift index 47cfc970..44b59662 100644 --- a/Packages/FirmwareUpdaterKit/Tests/UpdaterScreenTests/UpdaterScreenTests.swift +++ b/Packages/FirmwareUpdaterKit/Tests/UpdaterScreenTests/UpdaterScreenTests.swift @@ -157,15 +157,41 @@ struct UpdaterScreenTests { #expect(screen.panel.status == "Nothing connected") } - @Test("ST's ROM bootloader on USB (0483:DF11): a device in update mode, maybe an LC6000") + /// The look only sees ST's bootloader on USB, not which chip: naming it would need a new request at every look + /// (#762, cos: option 1). The backup names it. + @Test("ST's ROM bootloader on USB (0483:DF11): an LC6000 chip in update mode") func deviceInUpdateMode() async { let rig = Rig() rig.usb.plugged = [USBDevice(vendor: 0x0483, product: 0xDF11, name: "STM32 BOOTLOADER")] let screen = await rig.screen() - #expect(screen.lc6000.status == "A device in update mode, maybe an LC6000") + #expect(screen.lc6000.status == "An LC6000 chip in update mode") #expect(screen.lc6000.detail == nil) } + /// #762: the LC6000's steps show only when an LC6000 is there, and quitting DeckBridge is the first of them. + @Test("LC6000 steps: quit DeckBridge first, then update mode, then the backup") + func lc6000StepOrder() { + #expect(UpdaterScreen.lc6000Steps.first == "Quit DeckBridge first. It talks to the LC6000.") + #expect(UpdaterScreen.lc6000Steps.count == 4) + #expect(UpdaterScreen.lc6000Steps[1].hasPrefix("Put one chip in update mode.")) + #expect(UpdaterScreen.lc6000Steps.last?.hasPrefix("Then pick a folder.") == true) + #expect(!UpdaterScreen.lc6000Steps.joined().contains("quit DeckBridge")) + } + + @Test("No LC6000: no steps, and the section says to plug it in; found on MIDI or in update mode: the steps") + func lc6000StepsOnlyWhenFound() async { + let rig = Rig() + let none = await rig.screen() + #expect(!none.showsLC6000Steps) + #expect(none.lc6000.detail == "Plug in the LC6000 and switch it on.") + rig.midi.ports = ["LC6000 PRIME Controller"] + #expect(await rig.screen().showsLC6000Steps) + rig.midi.ports = [] + rig.usb.plugged = [USBDevice(vendor: 0x0483, product: 0xDF11, name: "STM32 BOOTLOADER")] + #expect(await rig.screen().showsLC6000Steps) + #expect(!(await rig.screen(lc6000WarningAccepted: false).showsLC6000Steps)) + } + @Test("Finding opens no serial port but the panel's own: another device's port is never touched, and opening resets some boards") func opensOnlyThePanelsPort() async { let rig = Rig()