commit 405a33acbba98a36f22c12e90d51ab7976b490df
parent 1c98ff6f38060e2dd92c0df70c4d2d9fc44142d2
Author: Jean Schurger <jean@schurger.org>
Date: Fri, 13 Nov 2026 23:53:50 -0500
Three-page dive screen (crown): ascent rate scale, countdown for stops and the safety stop, details, compass with heading; reduced display with the wrist down; depth limit, short no-stop time and missed safety stop alarms; compass from the home screen
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7deYGcjJYQu2t1EUEKgbs
Diffstat:
4 files changed, 139 insertions(+), 2 deletions(-)
diff --git a/Sources/RemoraDeco/AscentPlanner.swift b/Sources/RemoraDeco/AscentPlanner.swift
@@ -19,6 +19,14 @@ public struct DecoSettings: Sendable, Hashable {
public struct DecoStop: Sendable, Hashable {
public let depth: Double // m
public let minutes: Int
+ /// Durée du palier à 10 s près (affichage du compte à rebours ; seulement pour le premier palier).
+ public var seconds: Int?
+
+ public init(depth: Double, minutes: Int, seconds: Int? = nil) {
+ self.depth = depth
+ self.minutes = minutes
+ self.seconds = seconds
+ }
}
public struct AscentPlan: Sendable, Hashable {
@@ -121,12 +129,24 @@ public enum AscentPlanner {
}
// Palier à `depth` : l'ancre suit le premier (plus profond) palier, puis on attend minute par minute.
if anchor.map({ depth > $0 }) ?? true { anchor = depth }
+ // Premier palier : durée à 10 s près, pour le compte à rebours (sur une copie : le plan garde
+ // ses minutes entières, plus prudentes).
+ var seconds: Int?
+ if stops.isEmpty {
+ var fine = t
+ var s = 0
+ repeat {
+ fine.stay(atPressure: scale.pressure(atDepth: depth), gas: gas, minutes: 10.0 / 60)
+ s += 10
+ } while !clear(fine, at: next) && s < 999 * 60
+ seconds = s
+ }
var waited = 0
repeat {
t.stay(atPressure: scale.pressure(atDepth: depth), gas: gas, minutes: 1)
waited += 1
} while !clear(t, at: next) && waited < 999
- stops.append(DecoStop(depth: depth, minutes: waited))
+ stops.append(DecoStop(depth: depth, minutes: waited, seconds: seconds))
tts += Double(waited)
}
diff --git a/Sources/RemoraDeco/DiveComputer.swift b/Sources/RemoraDeco/DiveComputer.swift
@@ -8,6 +8,10 @@ public struct DiveComputer: Sendable {
public var deco = DecoSettings()
public var ppO2Warning: Double = 1.4
public var ppO2Alarm: Double = 1.6
+ /// Profondeur d'alerte, avant la limite de 40 m de la montre.
+ public var depthLimit: Double = 38
+ /// Alerte quand le temps sans palier passe sous cette valeur (min).
+ public var lowNoDecompression: Double = 5
public init() {}
}
@@ -16,6 +20,18 @@ public struct DiveComputer: Sendable {
case ceilingViolated
case ppO2High, ppO2Critical
case missedSafetyStop
+ case depthLimit
+ case lowNoDecompression
+ }
+
+ /// Palier de sécurité (3 min entre 3 et 6 m après être descendu sous 10 m, hors décompression).
+ public enum SafetyStop: Sendable, Hashable {
+ case notRequired
+ case pending
+ /// En cours : secondes restantes.
+ case running(remaining: Double)
+ case done
+ case missed
}
public struct Status: Sendable {
@@ -27,6 +43,7 @@ public struct DiveComputer: Sendable {
public let plan: AscentPlan
public let ceilingDepth: Double // m (0 = pas de plafond)
public let safetyStopRecommended: Bool
+ public let safetyStop: SafetyStop
public let warnings: Set<Warning>
}
@@ -38,6 +55,8 @@ public struct DiveComputer: Sendable {
private var start: Double?
private var last: (time: Double, pressure: Double)?
private var ascent = AscentRateMonitor()
+ private var safetyStopTime = 0.0 // s passées dans la zone du palier de sécurité
+ private var safetyStopState = SafetyStop.notRequired
private var plan: AscentPlan?
/// `surfacePressure` : mesurée par la montre juste avant l'immersion.
@@ -51,6 +70,7 @@ public struct DiveComputer: Sendable {
/// Nouvel échantillon : `time` en secondes (horloge monotone), `pressure` absolue en bar.
public mutating func update(time: Double, pressure: Double) {
+ let elapsedStep = last.map { max(0, time - $0.time) } ?? 0
if let last, time > last.time {
tissues.change(from: last.pressure, to: pressure, gas: configuration.gas,
minutes: (time - last.time) / 60)
@@ -67,8 +87,30 @@ public struct DiveComputer: Sendable {
// L'ancre des facteurs de gradient suit le premier palier le plus profond et reste pour la plongée.
if let anchor = newPlan.gradientAnchorDepth { gradientAnchorDepth = max(gradientAnchorDepth ?? 0, anchor) }
plan = newPlan
+ updateSafetyStop(depth: depth, seconds: elapsedStep)
+ }
+
+ /// Avance le palier de sécurité. Zone : de 3 à 6,5 m ; on repart de zéro si on redescend sous 7 m.
+ private mutating func updateSafetyStop(depth: Double, seconds: Double) {
+ let deco = configuration.deco
+ guard maxDepth >= deco.safetyStopTriggerDepth else { return }
+ if case .done = safetyStopState { return }
+ if case .missed = safetyStopState { return }
+ if plan?.inDecompression == true { safetyStopState = .pending; safetyStopTime = 0; return }
+ let required = deco.safetyStopMinutes * 60
+ if depth >= 3, depth <= deco.safetyStopDepth + 1.5 {
+ safetyStopTime += seconds
+ safetyStopState = safetyStopTime >= required ? .done : .running(remaining: required - safetyStopTime)
+ } else if depth > deco.safetyStopDepth + 2 {
+ safetyStopTime = 0
+ safetyStopState = .pending
+ } else if depth < 1 {
+ safetyStopState = .missed
+ }
}
+ public var safetyStop: SafetyStop { safetyStopState }
+
public var status: Status {
let pressure = last?.pressure ?? scale.surfacePressure
let depth = scale.depth(atPressure: pressure)
@@ -87,13 +129,17 @@ public struct DiveComputer: Sendable {
if ceiling > 0, depth < ceiling - 0.3 { warnings.insert(.ceilingViolated) }
if ppO2 > configuration.ppO2Alarm { warnings.insert(.ppO2Critical) }
else if ppO2 > configuration.ppO2Warning { warnings.insert(.ppO2High) }
+ if depth >= configuration.depthLimit { warnings.insert(.depthLimit) }
+ if !plan.inDecompression, let ndl = plan.noDecompressionLimit, ndl < configuration.lowNoDecompression,
+ depth > configuration.deco.safetyStopDepth + 2 { warnings.insert(.lowNoDecompression) }
+ if case .missed = safetyStopState { warnings.insert(.missedSafetyStop) }
let elapsed = ((last?.time ?? 0) - (start ?? 0)) / 60
return Status(elapsed: elapsed, depth: depth, maxDepth: maxDepth, ascentRate: ascent.rate,
ppO2: ppO2, plan: plan, ceilingDepth: ceiling,
safetyStopRecommended: !plan.inDecompression
&& maxDepth >= configuration.deco.safetyStopTriggerDepth,
- warnings: warnings)
+ safetyStop: safetyStopState, warnings: warnings)
}
private func currentGF(depth: Double) -> Double {
diff --git a/Sources/RemoraDeco/UDDF.swift b/Sources/RemoraDeco/UDDF.swift
@@ -73,6 +73,8 @@ public enum UDDF {
case .ceilingViolated: "deco"
case .ppO2High, .ppO2Critical: "error"
case .missedSafetyStop: "deco"
+ case .depthLimit: "depth"
+ case .lowNoDecompression: "deco"
}
}
}
diff --git a/Tests/RemoraDecoTests/DecoTests.swift b/Tests/RemoraDecoTests/DecoTests.swift
@@ -243,3 +243,72 @@ struct DiveComputerTests {
#expect(c.status.warnings.contains(.ppO2Critical))
}
}
+
+@Suite("Écran de plongée")
+struct DiveScreenEngineTests {
+ func computer() -> DiveComputer {
+ var config = DiveComputer.Configuration()
+ config.water = .salt
+ return DiveComputer(configuration: config, surfacePressure: scale.surfacePressure)
+ }
+
+ /// Profil à 1 Hz : (profondeur cible, vitesse m/min, secondes sur place).
+ func run(_ c: inout DiveComputer, _ legs: [(Double, Double, Int)]) {
+ var t = 0.0, d = 0.0
+ c.update(time: 0, pressure: scale.surfacePressure)
+ for (target, rate, hold) in legs {
+ while abs(d - target) > 1e-9 {
+ d = d < target ? min(target, d + rate / 60) : max(target, d - rate / 60)
+ t += 1; c.update(time: t, pressure: scale.pressure(atDepth: d))
+ }
+ for _ in 0..<hold { t += 1; c.update(time: t, pressure: scale.pressure(atDepth: d)) }
+ }
+ }
+
+ @Test func firstStopHasSecondsCountdown() throws {
+ let p = AscentPlanner.plan(tissues: tissues(after: 25, at: 40), pressure: scale.pressure(atDepth: 40),
+ gas: .air, scale: scale, settings: DecoSettings())
+ let first = try #require(p.stops.first)
+ let seconds = try #require(first.seconds)
+ #expect(seconds % 10 == 0)
+ #expect(seconds <= first.minutes * 60) // le compte à rebours ne dépasse pas la minute affichée
+ #expect(seconds > (first.minutes - 1) * 60)
+ #expect(p.stops.dropFirst().allSatisfy { $0.seconds == nil })
+ }
+
+ @Test func safetyStopCountsDownThenDone() {
+ var c = computer()
+ run(&c, [(18, 18, 600), (5, 9, 90)])
+ guard case .running(let remaining) = c.safetyStop else { Issue.record("attendu en cours : \(c.safetyStop)"); return }
+ #expect(abs(remaining - 90) < 15)
+ var d = c
+ let t0 = 18.0 / 18 * 60 + 600 + 13.0 / 9 * 60 + 90
+ for i in 1...120 { d.update(time: t0 + Double(i), pressure: scale.pressure(atDepth: 5)) }
+ #expect(d.safetyStop == .done)
+ }
+
+ @Test func skippingSafetyStopIsFlagged() {
+ var c = computer()
+ run(&c, [(18, 18, 600), (0, 9, 5)])
+ #expect(c.safetyStop == .missed)
+ #expect(c.status.warnings.contains(.missedSafetyStop))
+ }
+
+ @Test func shallowDiveNeedsNoSafetyStop() {
+ var c = computer()
+ run(&c, [(8, 18, 600), (0, 9, 5)])
+ #expect(c.safetyStop == .notRequired)
+ #expect(!c.status.warnings.contains(.missedSafetyStop))
+ }
+
+ @Test func depthLimitAndLowNoDecoWarnings() {
+ var c = computer()
+ run(&c, [(38.5, 18, 5)])
+ #expect(c.status.warnings.contains(.depthLimit))
+ var l = computer()
+ run(&l, [(30, 18, 360)])
+ let ndl = l.status.plan.noDecompressionLimit ?? 99
+ #expect(ndl < 5)
+ #expect(l.status.warnings.contains(.lowNoDecompression))
+ }
+}