VacuumView.swift (4393B)
1 // SPDX-License-Identifier: GPL-2.0-only 2 import SwiftUI 3 4 /// Card of the vacuum sequence: an instruction, the pressure, and the housing button to use. 5 struct VacuumView: View { 6 let vacuum: VacuumSequence 7 8 var body: some View { 9 VStack(alignment: .leading, spacing: 8) { 10 Text(title).font(.title3.bold()).foregroundStyle(color) 11 if let detail { Text(detail) } 12 if case .testing = vacuum.step { 13 TimelineView(.periodic(from: .now, by: 1)) { context in 14 let left = Int((vacuum.testRemaining(now: context.date) ?? 0).rounded(.up)) 15 Text(String(format: "%d:%02d", left / 60, left % 60)) 16 .font(.system(size: 44, weight: .bold, design: .rounded)).monospacedDigit() 17 } 18 } 19 if let p = vacuum.pressurePa { 20 Text("Internal pressure: \(String(format: "%.1f", p / 100)) hPa").monospacedDigit() 21 } 22 if let rise { Text("Corrected rise: \(String(format: "%+.0f", rise)) Pa").monospacedDigit() } 23 if let hint { Text(hint).font(.footnote).foregroundStyle(.secondary) } 24 } 25 .sensoryFeedback(trigger: vacuum.step) { _, new in 26 switch new { 27 case .failed: .error 28 case .sealed: .success 29 default: .impact 30 } 31 } 32 } 33 34 private var rise: Double? { 35 switch vacuum.step { 36 case .testing(let b), .sealed(let b): vacuum.correctedRise(since: b) 37 default: nil 38 } 39 } 40 41 private var color: Color { 42 switch vacuum.step { 43 case .failed: .red 44 case .sealed: .green 45 case .testing: .orange 46 default: .primary 47 } 48 } 49 50 private var title: LocalizedStringKey { 51 switch vacuum.step { 52 case .prepare: "1. Close and lock the housing" 53 case .openPlug: "2. Open the plug" 54 case .pumping: "3. Pumping…" 55 case .closePlug: "4. Close the plug" 56 case .testing: "Leak test" 57 case .sealed: "Sealed, have a good dive" 58 case .failed(.vacuumNotReached): "Vacuum not reached" 59 case .failed(.leak): "Leak: do not dive" 60 case .failed(.connectionLost): "Housing disconnected" 61 case .opening: "Open the plug" 62 case .opened: "Housing vented" 63 case .bypassed: "Dry run" 64 } 65 } 66 67 private var detail: LocalizedStringKey? { 68 switch vacuum.step { 69 case .prepare: 70 if let p = vacuum.pressurePa, p < VacuumSequence.alreadyUnderVacuumPa { 71 "The housing is already under vacuum: the leak test will start right away." 72 } else { 73 "iPhone in place (airplane mode recommended, Bluetooth on), housing closed, latch locked." 74 } 75 case .openPlug: "The plug must be open before the pump starts." 76 case .pumping: "The pump stops by itself below 800 hPa." 77 case .closePlug: "Vacuum reached. Close the plug, then confirm." 78 case .testing: "The seal is not verified yet." 79 case .sealed: "Pressure is monitored throughout the dive." 80 case .failed(.vacuumNotReached): "Check the plug, the O-ring and the latch." 81 case .failed(.leak(let rise)): "Pressure rose by \(String(format: "%.0f", rise)) Pa. Get out of the water and check the O-ring." 82 case .failed(.connectionLost): "Without the housing, the seal is no longer monitored." 83 case .opening: "Pressure will return to normal." 84 case .opened: "You can open the housing. Remember to turn airplane mode off." 85 case .bypassed: "No vacuum: do not put the housing in the water." 86 } 87 } 88 89 private var hint: LocalizedStringKey? { 90 switch vacuum.step { 91 case .prepare: "Right button: continue" 92 case .openPlug: "Right button: start the pump · left: back" 93 case .pumping: "Left button: stop" 94 case .closePlug: "Right button: start the test · left: back" 95 case .testing, .sealed: "Long press right: open the housing" 96 case .failed: "Right button: start over · long press right: open the housing" 97 case .opening: "Right button: done · left: cancel" 98 case .bypassed: "Long press right: back to the vacuum sequence" 99 case .opened: "Right button: disconnect, then hold it for 2 s to turn the housing off" 100 } 101 } 102 }