commit 7d72f0b07984f2140e3640847e8149f62c1dd377
parent 076704881a8ff22741a33446b629ff2e88e0592f
Author: Jean Schurger <jean@schurger.org>
Date: Sat, 14 Nov 2026 00:10:18 -0500
NDL on screen, adjustable NDL alarm, alarms flash the whole screen red with a vibration every 2 s, warnings flash the value; settings read even when a field is missing; version 0.3
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7deYGcjJYQu2t1EUEKgbs
Diffstat:
3 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/Sources/RemoraDeco/DiveComputer.swift b/Sources/RemoraDeco/DiveComputer.swift
@@ -10,7 +10,7 @@ public struct DiveComputer: Sendable {
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).
+ /// Alerte quand le NDL (temps sans palier) passe sous cette valeur (min) ; 0 = désactivée.
public var lowNoDecompression: Double = 5
public init() {}
}
diff --git a/Sources/RemoraDeco/UserSettings.swift b/Sources/RemoraDeco/UserSettings.swift
@@ -27,11 +27,15 @@ public struct UserSettings: Sendable, Hashable, Codable {
public static let gfLowPercent = 10...100
public static let gfHighPercent = 50...100
public static let ppO2Max = 1.2...1.6
+ /// Alarme de NDL : seuils proposés, en minutes (0 = désactivée).
+ public static let ndlAlarmMinutes = [0, 3, 5, 10, 15]
}
// Réglages
public var oxygenPercent: Int = 21
public var water: Water = .en13319
+ /// Alarme quand le NDL (temps restant sans palier) passe sous ce nombre de minutes ; 0 = désactivée.
+ public var ndlAlarmMinutes: Int = 5
// Réglages avancés
public var conservatism: Conservatism = .high
@@ -42,10 +46,25 @@ public struct UserSettings: Sendable, Hashable, Codable {
public init() {}
+ /// Lecture tolérante : un réglage absent (enregistré par une version plus ancienne, ou envoyé par une
+ /// montre pas encore à jour) prend sa valeur par défaut au lieu de faire échouer toute la lecture.
+ public init(from decoder: Decoder) throws {
+ let v = try decoder.container(keyedBy: CodingKeys.self)
+ let d = UserSettings()
+ oxygenPercent = try v.decodeIfPresent(Int.self, forKey: .oxygenPercent) ?? d.oxygenPercent
+ water = try v.decodeIfPresent(Water.self, forKey: .water) ?? d.water
+ ndlAlarmMinutes = try v.decodeIfPresent(Int.self, forKey: .ndlAlarmMinutes) ?? d.ndlAlarmMinutes
+ conservatism = try v.decodeIfPresent(Conservatism.self, forKey: .conservatism) ?? d.conservatism
+ customGFLowPercent = try v.decodeIfPresent(Int.self, forKey: .customGFLowPercent) ?? d.customGFLowPercent
+ customGFHighPercent = try v.decodeIfPresent(Int.self, forKey: .customGFHighPercent) ?? d.customGFHighPercent
+ ppO2Max = try v.decodeIfPresent(Double.self, forKey: .ppO2Max) ?? d.ppO2Max
+ }
+
public enum Problem: Error, Hashable, Sendable {
case oxygenOutOfRange
case gfLowOutOfRange, gfHighOutOfRange, gfLowAboveHigh
case ppO2OutOfRange
+ case ndlAlarmOutOfRange
}
/// Ce qui empêche d'appliquer les réglages (vide = valides).
@@ -58,6 +77,7 @@ public struct UserSettings: Sendable, Hashable, Codable {
if customGFLowPercent > customGFHighPercent { p.append(.gfLowAboveHigh) }
}
if !Limits.ppO2Max.contains(ppO2Max) { p.append(.ppO2OutOfRange) }
+ if !(0...30).contains(ndlAlarmMinutes) { p.append(.ndlAlarmOutOfRange) }
return p
}
@@ -83,6 +103,7 @@ public struct UserSettings: Sendable, Hashable, Codable {
c.deco.gradientFactors = gradientFactors
c.ppO2Warning = ppO2Max
c.ppO2Alarm = max(1.6, ppO2Max)
+ c.lowNoDecompression = Double(ndlAlarmMinutes) // 0 : jamais sous le seuil, alarme désactivée
return c
}
}
diff --git a/Tests/RemoraDecoTests/SettingsTests.swift b/Tests/RemoraDecoTests/SettingsTests.swift
@@ -61,4 +61,33 @@ struct SettingsTests {
}
#expect(try tts(32) < tts(21))
}
+
+ @Test func ndlAlarmIsAdjustableAndCanBeOff() throws {
+ var s = UserSettings()
+ #expect(try s.configuration().lowNoDecompression == 5)
+ s.ndlAlarmMinutes = 10
+ #expect(try s.configuration().lowNoDecompression == 10)
+
+ func warns(_ minutes: Int) throws -> Bool {
+ var u = UserSettings(); u.ndlAlarmMinutes = minutes; u.water = .salt
+ var c = DiveComputer(configuration: try u.configuration(), surfacePressure: standardSurfacePressure)
+ let scale = c.scale
+ c.update(time: 0, pressure: scale.surfacePressure)
+ for t in 1...300 { c.update(time: Double(t), pressure: scale.pressure(atDepth: 30)) } // NDL ≈ 4 min
+ return c.status.warnings.contains(.lowNoDecompression)
+ }
+ #expect(try warns(5))
+ #expect(try !warns(3))
+ #expect(try !warns(0))
+ }
+
+ @Test func olderSavedSettingsStillLoad() throws {
+ // Réglages enregistrés par la 0.2 (sans l'alarme de NDL) : ils ne doivent pas être perdus.
+ let old = #"{"oxygenPercent":32,"water":"salt","conservatism":"medium","customGFLowPercent":30,"customGFHighPercent":70,"ppO2Max":1.4}"#
+ let s = try JSONDecoder().decode(UserSettings.self, from: Data(old.utf8))
+ #expect(s.oxygenPercent == 32)
+ #expect(s.water == .salt)
+ #expect(s.conservatism == .medium)
+ #expect(s.ndlAlarmMinutes == 5)
+ }
}