commit 1495d1360b16578291e02027e0931de1bb677f87
parent 74a16343a31af2284dab4225dd36dea8ec358c55
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:
11 files changed, 137 insertions(+), 31 deletions(-)
diff --git a/OpenRemora/HomeView.swift b/OpenRemora/HomeView.swift
@@ -66,6 +66,7 @@ struct HomeView: View {
row("Mélange", s.gas.description)
row("Profondeur maximale du mélange", "\(Format.depth(s.maximumOperatingDepth())) m")
row("Eau", s.water.label)
+ row("Alarme de NDL", s.ndlAlarmMinutes == 0 ? "Désactivée" : "Sous \(s.ndlAlarmMinutes) min")
row("Prudence", s.conservatism == .custom ? "Personnalisée (\(s.gradientFactors.description))" : s.conservatism.label)
row("ppO2 maximale", String(format: "%.1f bar", s.ppO2Max).replacingOccurrences(of: ".", with: ","))
} header: {
@@ -141,16 +142,17 @@ struct HelpView: View {
Text("Sans cela, la plongée démarre quand même toute seule dès l'immersion.")
}
Section("Pendant la plongée") {
- Text("La profondeur est en grand. Dessous : le temps restant sans palier, ou le palier à faire (profondeur et durée).")
+ Text("La profondeur est en grand. Dessous : le NDL (temps restant sans palier obligatoire), ou le palier à faire avec son compte à rebours.")
Text("Les flèches en bas à droite montrent la vitesse de remontée. Au-delà de 10 m/min : orange ; au-delà de 12 m/min : rouge et vibration.")
- Text("Fond rouge : plafond franchi, remontée trop rapide ou pression d'oxygène critique. Redescendez au palier ou ralentissez.")
+ Text("Alarme : tout l'écran clignote en rouge et la montre vibre sans arrêt (plafond ou palier franchi, remontée trop rapide, pression d'oxygène critique, profondeur inconnue). Redescendez au palier ou ralentissez.")
+ Text("Avertissement : seule la valeur concernée clignote, avec une vibration (NDL bas, profondeur limite, remontée rapide).")
}
Section("Après la plongée") {
Text("La plongée se termine après une minute en surface. Elle arrive dans cette app, puis dans Sub Rascasse, et dans Santé comme entraînement de plongée.")
Text("Sur la montre, le carnet garde vos plongées : touchez une plongée, puis le profil, et tournez la couronne pour le parcourir.")
}
Section("Réglages (sur la montre)") {
- Text("Oxygène : 21 % (air) à 40 % (nitrox). Eau : douce, salée ou standard.")
+ Text("Oxygène : 21 % (air) à 40 % (nitrox). Eau : douce, salée ou standard. Alarme de NDL : seuil au choix, ou désactivée.")
Text("Réglages avancés : prudence (facteurs de gradient) et pression d'oxygène maximale.")
}
}
diff --git a/OpenRemoraWatch/DiveDetailView.swift b/OpenRemoraWatch/DiveDetailView.swift
@@ -117,7 +117,7 @@ struct ProfileView: View {
if let stop = s.stopDepth, let minutes = s.stopMinutes {
parts.append("palier \(Int(stop)) m · \(minutes) min")
} else if dive.source != .subsurface || s.noDecompressionLimit != nil {
- parts.append("sans palier \(Format.ndl(s.noDecompressionLimit)) min")
+ parts.append("NDL \(Format.ndl(s.noDecompressionLimit)) min")
}
return parts.joined(separator: " · ")
}
diff --git a/OpenRemoraWatch/DiveSession.swift b/OpenRemoraWatch/DiveSession.swift
@@ -23,7 +23,7 @@ final class DiveSession {
private var recorder: DiveRecorder?
private var surfacedAt: Double?
private var wentUnder = false
- private var warnings = Set<DiveComputer.Warning>()
+ private(set) var warnings = Set<DiveComputer.Warning>()
private var safetyStop = DiveComputer.SafetyStop.notRequired
private var sensor: SubmersionSource?
private var simulation: Task<Void, Never>?
@@ -32,6 +32,14 @@ final class DiveSession {
private var lastPressure: Double?
private var surfacePressure = standardSurfacePressure
private var lastHaptic: [DiveComputer.Warning: Date] = [:]
+ private var lastAlarmHaptic: Date?
+
+ /// Alarme en cours : une violation, ou la profondeur inconnue. L'écran entier clignote en rouge.
+ var isAlarming: Bool { depthUnknown || warnings.contains(where: \.isViolation) || Self.forcedAlarm }
+ /// Captures d'écran seulement (`-testAlarm`).
+ private static let forcedAlarm = CommandLine.arguments.contains("-testAlarm")
+ /// Avertissements en cours (sans les violations) : seule la valeur concernée clignote.
+ var activeWarnings: Set<DiveComputer.Warning> { warnings.filter { !$0.isViolation } }
let workout = DiveWorkout()
/// Appelé après chaque plongée enregistrée (envoi vers l'iPhone).
var onDiveSaved: (() -> Void)?
@@ -134,6 +142,7 @@ final class DiveSession {
lastReadingAt = Date()
depthUnknown = false
lastHaptic = [:]
+ lastAlarmHaptic = nil
if !simulation { startWatchdog() }
surfacedAt = nil
wentUnder = false
@@ -156,18 +165,26 @@ final class DiveSession {
}
safetyStop = s.safetyStop
- // Vibration à l'apparition d'une alarme, au plus une fois toutes les 20 s pour la même
- // (une valeur qui oscille autour d'un seuil ne doit pas faire vibrer en continu).
+ // Vibrations (horloge réelle, pas celle de la plongée).
+ // Alarme (violation, profondeur inconnue) : vibration forte toutes les 2 s tant qu'elle dure.
+ // Avertissement : une vibration à l'apparition, rappelée toutes les 15 s tant qu'il dure.
let now = Date()
- let fresh = s.warnings.subtracting(warnings).filter { w in
- lastHaptic[w].map { now.timeIntervalSince($0) > 20 } ?? true
- }
warnings = s.warnings
- if !fresh.isEmpty {
- for w in fresh { lastHaptic[w] = now }
- let serious = fresh.contains(where: \.isViolation)
- WKInterfaceDevice.current().play(serious ? .failure : .notification)
+ if isAlarming {
+ if lastAlarmHaptic.map({ now.timeIntervalSince($0) >= 2 }) ?? true {
+ lastAlarmHaptic = now
+ WKInterfaceDevice.current().play(.failure)
+ }
+ } else {
+ lastAlarmHaptic = nil
+ let due = s.warnings.filter { w in lastHaptic[w].map { now.timeIntervalSince($0) >= 15 } ?? true }
+ if !due.isEmpty {
+ for w in due { lastHaptic[w] = now }
+ WKInterfaceDevice.current().play(.notification)
+ }
}
+ // Un avertissement disparu puis revenu vibre de nouveau, mais pas plus d'une fois toutes les 15 s.
+ lastHaptic = lastHaptic.filter { now.timeIntervalSince($0.value) < 15 || s.warnings.contains($0.key) }
// Fin automatique : une minute en surface après être descendu sous 1 m.
if s.depth > 1 { wentUnder = true }
diff --git a/OpenRemoraWatch/DiveView.swift b/OpenRemoraWatch/DiveView.swift
@@ -2,8 +2,9 @@ import SwiftUI
import RemoraDeco
/// Écran de plongée. Sous l'eau l'écran tactile est verrouillé : on passe d'une page à l'autre à la couronne.
-/// Page 1 : profondeur, vitesse de remontée, sans palier ou palier ; page 2 : détails ; page 3 : boussole.
-/// Poignet baissé (luminosité réduite) : seulement la profondeur et le sans palier ou palier, en très gros.
+/// Page 1 : profondeur, vitesse de remontée, NDL ou palier ; page 2 : détails ; page 3 : boussole.
+/// Poignet baissé (luminosité réduite) : seulement la profondeur et le NDL ou le palier, en très gros.
+/// Alarme : tout l'écran clignote en rouge ; avertissement : seule la valeur concernée clignote.
struct DiveView: View {
@Environment(DiveSession.self) private var session
@Environment(\.isLuminanceReduced) private var dimmed
@@ -23,7 +24,7 @@ struct DiveView: View {
.tabViewStyle(.verticalPage)
}
}
- .background(alarmColor(s).opacity(dimmed ? 0 : 0.35))
+ .background { if session.isAlarming && !dimmed { AlarmFlash() } }
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Fin", role: .destructive) { session.end() }
@@ -50,10 +51,29 @@ struct DiveView: View {
}
}
- private func alarmColor(_ s: DiveComputer.Status?) -> Color {
- guard let s else { return .clear }
- if s.warnings.contains(where: \.isViolation) { return .red }
- return s.warnings.isEmpty ? .clear : .orange
+}
+
+/// Alarme : tout l'écran clignote en rouge.
+private struct AlarmFlash: View {
+ var body: some View {
+ TimelineView(.periodic(from: .now, by: 0.4)) { context in
+ let on = Int(context.date.timeIntervalSinceReferenceDate / 0.4) % 2 == 0
+ Color.red.opacity(on ? 0.85 : 0.15).ignoresSafeArea()
+ }
+ }
+}
+
+extension View {
+ /// Avertissement : la valeur concernée clignote (rien ne bouge si `active` est faux).
+ @ViewBuilder func blinking(_ active: Bool) -> some View {
+ if active {
+ TimelineView(.periodic(from: .now, by: 0.4)) { context in
+ let on = Int(context.date.timeIntervalSinceReferenceDate / 0.4) % 2 == 0
+ self.opacity(on ? 1 : 0.15)
+ }
+ } else {
+ self
+ }
}
}
@@ -76,12 +96,15 @@ private struct MainDivePage: View {
HStack(alignment: .center, spacing: 6) {
AscentScale(rate: s?.ascentRate ?? 0)
+ .blinking(session.activeWarnings.contains(.ascentFast))
VStack(spacing: 2) {
HStack(alignment: .firstTextBaseline, spacing: 2) {
Text(Format.depth(s?.depth ?? 0))
.font(.system(size: 56, weight: .semibold, design: .rounded))
.monospacedDigit()
.minimumScaleFactor(0.6)
+ .foregroundStyle(session.activeWarnings.contains(.depthLimit) ? .orange : .primary)
+ .blinking(session.activeWarnings.contains(.depthLimit))
Text("m").font(.title3).foregroundStyle(.secondary)
}
if let s { Instruction(status: s) }
@@ -113,9 +136,10 @@ private struct Instruction: View {
if let warning = s.warnings.sorted(by: { $0.rank < $1.rank }).first {
Text(warning.label.uppercased())
.font(.system(size: 14, weight: .bold, design: .rounded))
- .foregroundStyle(warning.color)
+ .foregroundStyle(warning.isViolation ? .white : warning.color)
.minimumScaleFactor(0.6)
.lineLimit(1)
+ .blinking([.ppO2High, .missedSafetyStop].contains(warning))
}
if let stop = s.plan.stops.first {
HStack(alignment: .firstTextBaseline, spacing: 4) {
@@ -135,11 +159,14 @@ private struct Instruction: View {
.monospacedDigit()
.foregroundStyle(.cyan)
} else {
+ let low = s.warnings.contains(.lowNoDecompression)
HStack(alignment: .firstTextBaseline, spacing: 4) {
- Text("sans palier").font(.caption).foregroundStyle(.secondary)
+ Text("NDL").font(.system(size: 15, weight: .semibold, design: .rounded)).foregroundStyle(.secondary)
Text(Format.ndl(s.plan.noDecompressionLimit))
- .font(.system(size: 24, weight: .semibold, design: .rounded))
- .foregroundStyle((s.plan.noDecompressionLimit ?? 99) < 5 ? .orange : .green)
+ .font(.system(size: 26, weight: .bold, design: .rounded))
+ .monospacedDigit()
+ .foregroundStyle(low ? .orange : .green)
+ .blinking(low)
Text("min").font(.caption).foregroundStyle(.secondary)
}
switch s.safetyStop {
@@ -238,7 +265,7 @@ private struct DimmedDivePage: View {
} else if case .running(let remaining) = s.safetyStop {
Text("SÉCURITÉ \(Format.clock(remaining))").font(.system(size: 20, weight: .bold, design: .rounded))
} else {
- Text("sans palier \(Format.ndl(s.plan.noDecompressionLimit)) min")
+ Text("NDL \(Format.ndl(s.plan.noDecompressionLimit)) min")
.font(.system(size: 20, weight: .bold, design: .rounded))
}
if let warning = s.warnings.sorted(by: { $0.rank < $1.rank }).first {
diff --git a/OpenRemoraWatch/SettingsView.swift b/OpenRemoraWatch/SettingsView.swift
@@ -21,6 +21,16 @@ struct SettingsView: View {
}
Section {
+ Picker("Alarme de NDL", selection: $store.settings.ndlAlarmMinutes) {
+ ForEach(UserSettings.Limits.ndlAlarmMinutes, id: \.self) { m in
+ Text(m == 0 ? "Désactivée" : "Sous \(m) min").tag(m)
+ }
+ }
+ } footer: {
+ Text("NDL : temps restant sans palier obligatoire. La montre vibre et la valeur clignote sous ce seuil.")
+ }
+
+ Section {
NavigationLink("Réglages avancés") { AdvancedSettingsView() }
} footer: {
Text("L'altitude est mesurée par la montre : rien à régler.")
diff --git a/Packages/RemoraDeco/Sources/RemoraDeco/DiveComputer.swift b/Packages/RemoraDeco/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/Packages/RemoraDeco/Sources/RemoraDeco/UserSettings.swift b/Packages/RemoraDeco/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/Packages/RemoraDeco/Tests/RemoraDecoTests/SettingsTests.swift b/Packages/RemoraDeco/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)
+ }
}
diff --git a/Shared/Format.swift b/Shared/Format.swift
@@ -37,7 +37,7 @@ extension DiveComputer.Warning {
case .ppO2Critical: "ppO2 critique"
case .missedSafetyStop: "Palier de sécurité sauté"
case .depthLimit: "Profondeur limite"
- case .lowNoDecompression: "Moins de 5 min sans palier"
+ case .lowNoDecompression: "NDL bas"
}
}
diff --git a/fastlane/Fastfile b/fastlane/Fastfile
@@ -68,9 +68,9 @@ platform :ios do
end
texts = {
"fr-CA" => ["Ordinateur de plongée secondaire, libre et gratuit, pour Apple Watch Ultra. Non certifié : à porter avec un ordinateur principal.",
- "0.2 : nouvel écran de plongée en trois pages à la couronne (échelle de vitesse de remontée, compte à rebours des paliers et du palier de sécurité ; détails ; boussole avec cap) ; boussole depuis l'accueil ; alarmes profondeur limite, moins de 5 min sans palier, palier de sécurité sauté, au-dessus du palier ; « profondeur inconnue » si le capteur ne mesure plus sous l'eau. À essayer à sec : plongée de démonstration, tourner la couronne pendant la plongée, Boussole → Fixer le cap."],
+ "0.3 : le temps sans palier s'appelle NDL à l'écran ; alarme de NDL réglable (Réglages → Alarme de NDL : désactivée, 3, 5, 10 ou 15 min) ; alarme = tout l'écran clignote en rouge et la montre vibre toutes les 2 s ; avertissement = seule la valeur concernée clignote, vibration rappelée toutes les 15 s. À essayer à sec : régler l'alarme de NDL sur 15 min puis lancer la plongée de démonstration."],
"en-CA" => ["Free, open-source backup dive computer for Apple Watch Ultra. Not certified: wear it with a primary dive computer.",
- "0.2: new three-page dive screen on the Digital Crown (ascent rate scale, stop and safety stop countdowns; details; compass with bearing); compass from the home screen; new alarms (depth limit, low no-stop time, missed safety stop, above the stop); \"depth unknown\" if the sensor stops measuring under water. Try it dry: demo dive, turn the crown during the dive, Boussole → Fixer le cap."],
+ "0.3: no-stop time is labelled NDL; adjustable NDL alarm (Réglages → Alarme de NDL: off, 3, 5, 10 or 15 min); alarm = the whole screen flashes red and the watch vibrates every 2 s; warning = only the affected value blinks, with a vibration repeated every 15 s. Try it dry: set the NDL alarm to 15 min, then run the demo dive."],
}
_, locs = asc(:get, "/v1/apps/#{app.id}/betaAppLocalizations")
texts.each do |locale, (description, _)|
diff --git a/project.yml b/project.yml
@@ -13,7 +13,7 @@ settings:
base:
DEVELOPMENT_TEAM: CM5RQKJH56
CODE_SIGN_STYLE: Automatic
- MARKETING_VERSION: "0.2"
+ MARKETING_VERSION: "0.3"
CURRENT_PROJECT_VERSION: "1"
SWIFT_VERSION: "6.0"
targets: