Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Apps/FirmwareUpdater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 36 additions & 25 deletions Apps/FirmwareUpdater/Sources/BackupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion Apps/FirmwareUpdater/Sources/CoreMIDISend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
29 changes: 25 additions & 4 deletions Apps/FirmwareUpdater/Sources/FirmwareUpdaterApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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) }
Expand All @@ -119,10 +125,18 @@ struct UpdaterView: View {
}
}

struct SectionView: View {
struct SectionView<Extra: View>: 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 {
Expand All @@ -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)
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions Apps/FirmwareUpdater/Sources/PreviewLaunch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ import UpdaterScreen

/// Screenshots of the window (#761), in Debug builds only: `FirmwareUpdater --preview <shot>` 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
}
}

Expand Down
73 changes: 64 additions & 9 deletions Apps/FirmwareUpdater/Sources/UpdateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
}
Expand All @@ -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.")
}
}
}
3 changes: 3 additions & 0 deletions Apps/FirmwareUpdater/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Loading
Loading