open-remora

Open Remora, a free secondary dive computer for Apple Watch Ultra
git clone https://git.schurger.org/open-remora.git
Log | Files | Refs | README | LICENSE

commit a3bfbd879f30c2f70861aafb6118074ee8ca1a2f
parent 80b2cba4b96b62bcea58d7d085a0dc849ef69629
Author: Jean Schurger <jean@schurger.org>
Date:   Sat, 14 Nov 2026 11:00:38 -0500

Ready screen takes the GPS entry position and the Action button starts the dive from it; Action button while diving: mark (main page), stopwatch (details), bearing / way back / clear (compass); Cancel and End hidden while the screen is locked; version 0.5

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7deYJa9LG8PgUSQ5UR5LY

Diffstat:
MOpenRemoraWatch/DiveDetailView.swift | 19+++++++++++++++++++
MOpenRemoraWatch/DiveSession.swift | 101++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
MOpenRemoraWatch/DiveView.swift | 18+++++++++++++-----
AOpenRemoraWatch/EntryPosition.swift | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MOpenRemoraWatch/InfoPlist.xcstrings | 20+++++++++++++++++++-
MOpenRemoraWatch/Localizable.xcstrings | 167++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
MOpenRemoraWatch/RootView.swift | 56+++++++++++++++++++++++++++++++++++++++++---------------
Mdocs/SHARING.md | 2++
Mproject.yml | 3++-
9 files changed, 408 insertions(+), 51 deletions(-)

diff --git a/OpenRemoraWatch/DiveDetailView.swift b/OpenRemoraWatch/DiveDetailView.swift @@ -54,8 +54,27 @@ struct DiveDetailView: View { } } + if let marks = dive.marks, !marks.isEmpty { + Section("Marks") { + ForEach(Array(marks.enumerated()), id: \.offset) { i, mark in + HStack { + Image(systemName: "mappin").foregroundStyle(.cyan) + Text("\(i + 1) · \(Format.depth(mark.depth)) m").font(.footnote) + if let heading = mark.heading { + Text("\(Int(heading.rounded()) % 360)°").font(.footnote).foregroundStyle(.secondary) + } + Spacer() + Text(Format.clock(mark.time)).font(.footnote).foregroundStyle(.secondary).monospacedDigit() + } + } + } + } + Section { row("Start", Format.dayTime(dive.start)) + if let latitude = dive.latitude, let longitude = dive.longitude { + row("Position", String(format: "%.5f, %.5f", latitude, longitude)) + } if let site = dive.site { row("Site", site) } if let gf = dive.gradientFactors { row("Conservatism", gf.description) } row("Water", dive.water.label) diff --git a/OpenRemoraWatch/DiveSession.swift b/OpenRemoraWatch/DiveSession.swift @@ -3,6 +3,7 @@ import Foundation import Observation import WatchKit import RemoraDeco +import RemoraUI /// The dive in progress on the watch. The dive logic itself (start on submersion, depth held when the reading /// is missing, alarms, end at the surface, demo dives) is `DiveMonitor` from RemoraDeco, shared with other @@ -45,6 +46,13 @@ final class DiveSession { private var actionMessageTask: Task<Void, Never>? /// Compass (the Action button sets the bearing there). var compass: Compass? + /// Position of the entry point, taken while the "Ready" screen is shown. + let position = EntryPosition() + /// Stopwatch of the details page (Action button: start, stop, reset). + private(set) var stopwatch = Stopwatch() + /// Bearing set by the Action button during this dive: the next press turns it around (way back). + private var bearingIsReciprocal = false + private var bearingSetInDive = false let diagnostics = Diagnostics() /// The session of the app, for the Action button intents and the app delegate. static weak var current: DiveSession? @@ -91,6 +99,13 @@ final class DiveSession { diagnostics.reset() workout.start() startDiveSession() + position.start() + } + + /// From the "Ready" screen: starts the dive now, before getting in the water (Action button). + func startDiveNow() { + guard isReady, !isDiving else { return } + monitor.startManually() } /// Apple's dive session (screen locked) and Action button wired to the app. @@ -102,20 +117,47 @@ final class DiveSession { } } - /// Action button during the session. On the compass page: sets the bearing; elsewhere: next page. - /// Every press vibrates, is displayed and is counted (trial: does the button reach the app underwater?). + /// Action button during the session; the touch screen is locked, the crown changes page. + /// "Ready" screen: starts the dive now. During the dive, it acts on the page shown: + /// main page: marks the point in the dive log; details page: stopwatch (start, stop, reset); + /// compass page: sets the bearing, then turns it around for the way back, then clears it. func actionPressed() { guard isReady || isDiving else { return } WKInterfaceDevice.current().play(.click) diagnostics.notePress(depth: isDiving ? status?.depth : nil) - var text = String(localized: "ACTION BUTTON \(diagnostics.presses)") - if isDiving { - if divePage == 2, let compass, let heading = compass.heading { + guard isDiving else { + startDiveNow() + return + } + let text: String + switch divePage { + case 1: + switch stopwatch.press() { + case .running: text = String(localized: "STOPWATCH STARTED") + case .stopped: text = String(localized: "STOPWATCH STOPPED") + case .idle: text = String(localized: "STOPWATCH RESET") + } + case 2: + guard let compass, let heading = compass.heading else { return } + if !bearingSetInDive || compass.bearing == nil { compass.setBearing() + bearingSetInDive = true + bearingIsReciprocal = false text = String(localized: "BEARING SET \(Int(heading.rounded()) % 360)°") + } else if !bearingIsReciprocal, let bearing = compass.bearing { + let back = (bearing + 180).truncatingRemainder(dividingBy: 360) + compass.bearing = back + bearingIsReciprocal = true + text = String(localized: "WAY BACK \(Int(back.rounded()) % 360)°") } else { - divePage = (divePage + 1) % 3 + compass.clearBearing() + bearingSetInDive = false + bearingIsReciprocal = false + text = String(localized: "BEARING CLEARED") } + default: + guard let mark = monitor.mark(heading: compass?.heading) else { return } + text = String(localized: "MARK \(monitor.markCount) · \(Format.depth(mark.depth)) m") } actionMessage = text actionMessageTask?.cancel() @@ -129,6 +171,7 @@ final class DiveSession { guard isReady, !isDiving else { return } isReady = false runtime.stop() + position.stop() Task { await workout.finish(with: nil) } } @@ -149,12 +192,26 @@ final class DiveSession { } isReady = false divePage = 0 + stopwatch = Stopwatch() + bearingSetInDive = false + bearingIsReciprocal = false + if !simulation { + // The entry point: the best fix taken on the "Ready" screen (none without "Ready to dive"). + if let fix = position.fix { + monitor.entryPosition = (fix.coordinate.latitude, fix.coordinate.longitude) + } + position.stop() + // The compass runs for the whole dive, so that a mark knows its heading. + compass?.start() + } } /// `saved` is nil when nothing was kept (the diver never went down). private func diveEnded(_ saved: DiveLog?, simulation: Bool) { if !simulation { runtime.stop() + compass?.stop() + monitor.entryPosition = nil Task { await workout.finish(with: saved) } } if saved != nil { onDiveSaved?() } @@ -170,6 +227,38 @@ final class DiveSession { } } +/// Stopwatch driven by a single button: start, stop, reset. +struct Stopwatch { + enum State { case idle, running, stopped } + private(set) var state = State.idle + private var startedAt: Date? + private var frozen = 0.0 + + /// Seconds shown at `date`. + func elapsed(at date: Date = Date()) -> Double { + switch state { + case .idle: 0 + case .running: max(0, date.timeIntervalSince(startedAt ?? date)) + case .stopped: frozen + } + } + + /// One press; returns the new state. + mutating func press(at date: Date = Date()) -> State { + switch state { + case .idle: + startedAt = date + state = .running + case .running: + frozen = elapsed(at: date) + state = .stopped + case .stopped: + state = .idle + } + return state + } +} + /// What we want to know after a trial in the water: did the Action button reach the app, and did Apple's /// dive session (screen locked) run. Kept from one launch to the next (the texts are stored as displayed). @MainActor @Observable diff --git a/OpenRemoraWatch/DiveView.swift b/OpenRemoraWatch/DiveView.swift @@ -3,8 +3,10 @@ import SwiftUI import RemoraDeco import RemoraUI -/// Dive screen. Underwater the touch screen is locked: the crown moves from one page to the next. -/// Page 1: depth, ascent rate, NDL or stop; page 2: details; page 3: compass. +/// Dive screen. Underwater the touch screen is locked: the crown moves from one page to the next and the +/// Action button acts on the page shown. +/// Page 1: depth, ascent rate, NDL or stop (Action: mark the point); page 2: details (Action: stopwatch); +/// page 3: compass (Action: set the bearing, way back, clear). /// Wrist down (reduced luminance): only the depth and the NDL or the stop, in very large type. /// Alarm: the whole screen flashes red; warning: only the value concerned blinks. struct DiveView: View { @@ -28,8 +30,11 @@ struct DiveView: View { } .background { if session.isAlarming && !dimmed { AlarmFlash() } } .toolbar { - ToolbarItem(placement: .cancellationAction) { - Button("End", role: .destructive) { session.end() } + // Useless while the touch screen is locked (long press on the crown unlocks it). + if !session.screenLocked { + ToolbarItem(placement: .cancellationAction) { + Button("End", role: .destructive) { session.end() } + } } } .overlay(alignment: .bottom) { @@ -123,7 +128,10 @@ private struct DetailsDivePage: View { cell("Gas", store.settings.gas.description) } GridRow { - cell("Clock", Date().formatted(date: .omitted, time: .shortened)) + TimelineView(.periodic(from: .now, by: 1)) { context in + cell("Stopwatch", Format.clock(session.stopwatch.elapsed(at: context.date)), + color: session.stopwatch.state == .running ? .cyan : .primary) + } if let level = session.batteryLevel { cell("Battery", Format.percent(Int((level * 100).rounded())), color: level < 0.3 ? .red : .primary) } else { diff --git a/OpenRemoraWatch/EntryPosition.swift b/OpenRemoraWatch/EntryPosition.swift @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-only +import Foundation +import Observation +@preconcurrency import CoreLocation + +/// Position of the entry point, taken on the "Ready" screen: GPS does not work underwater, so the fix has to +/// be taken before the dive. The best fix (smallest uncertainty) is kept and written into the dive log. +@MainActor @Observable +final class EntryPosition: NSObject, CLLocationManagerDelegate { + enum State: Equatable { case idle, searching, denied, unavailable } + + private(set) var state = State.idle + /// Best fix so far. + private(set) var fix: CLLocation? + + private let manager = CLLocationManager() + + override init() { + super.init() + manager.delegate = self + manager.desiredAccuracy = kCLLocationAccuracyBest + } + + func start() { + fix = nil + switch manager.authorizationStatus { + case .denied, .restricted: + state = .denied + case .notDetermined: + state = .searching + manager.requestWhenInUseAuthorization() + default: + state = .searching + manager.startUpdatingLocation() + } + } + + func stop() { + manager.stopUpdatingLocation() + if state == .searching { state = .idle } + } + + nonisolated func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) { + let status = manager.authorizationStatus + Task { @MainActor in + guard self.state == .searching || self.state == .denied else { return } + switch status { + case .denied, .restricted: self.state = .denied + case .notDetermined: break + default: + self.state = .searching + self.manager.startUpdatingLocation() + } + } + } + + nonisolated func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + // Recent and plausible fixes only. + let usable = locations.filter { $0.horizontalAccuracy >= 0 && $0.timestamp.timeIntervalSinceNow > -120 } + guard let best = usable.min(by: { $0.horizontalAccuracy < $1.horizontalAccuracy }) else { return } + Task { @MainActor in + guard self.state == .searching else { return } + if self.fix.map({ best.horizontalAccuracy <= $0.horizontalAccuracy }) ?? true { self.fix = best } + } + } + + nonisolated func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error) { + let denied = (error as? CLError)?.code == .denied + Task { @MainActor in + if denied { self.state = .denied } + } + } +} diff --git a/OpenRemoraWatch/InfoPlist.xcstrings b/OpenRemoraWatch/InfoPlist.xcstrings @@ -51,7 +51,24 @@ } } } + }, + "NSLocationWhenInUseUsageDescription": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Open Rémora notes the position of the entry point before the dive; it stays in your logbook." + } + }, + "fr": { + "stringUnit": { + "state": "translated", + "value": "Open Rémora note la position de la mise à l'eau avant la plongée ; elle reste dans votre carnet." + } + } + } } }, "version": "1.0" -} +} +\ No newline at end of file diff --git a/OpenRemoraWatch/Localizable.xcstrings b/OpenRemoraWatch/Localizable.xcstrings @@ -51,22 +51,22 @@ } } }, - "%lld°": { + "%lld · %@ m": { "localizations": { "fr": { "stringUnit": { "state": "translated", - "value": "%lld°" + "value": "%lld · %@ m" } } } }, - "ACTION BUTTON %lld": { + "%lld°": { "localizations": { "fr": { "stringUnit": { "state": "translated", - "value": "BOUTON ACTION %lld" + "value": "%lld°" } } } @@ -141,6 +141,16 @@ } } }, + "BEARING CLEARED": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "CAP EFFACÉ" + } + } + } + }, "BEARING SET %lld°": { "localizations": { "fr": { @@ -201,16 +211,6 @@ } } }, - "Clock": { - "localizations": { - "fr": { - "stringUnit": { - "state": "translated", - "value": "Heure" - } - } - } - }, "Close to the sensor limit": { "localizations": { "fr": { @@ -421,6 +421,16 @@ } } }, + "Looking for the GPS position…": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Recherche de la position GPS…" + } + } + } + }, "Low accuracy: draw a figure 8 with your wrist": { "localizations": { "fr": { @@ -441,6 +451,16 @@ } } }, + "MARK %lld · %@ m": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "REPÈRE %lld · %@ m" + } + } + } + }, "Mandatory stops": { "localizations": { "fr": { @@ -451,6 +471,16 @@ } } }, + "Marks": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Repères" + } + } + } + }, "Max": { "localizations": { "fr": { @@ -591,6 +621,26 @@ } } }, + "No position": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Pas de position" + } + } + } + }, + "No position: location not allowed": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Pas de position : localisation refusée" + } + } + } + }, "No. %lld · %@": { "localizations": { "fr": { @@ -621,6 +671,26 @@ } } }, + "Position": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Position" + } + } + } + }, + "Position taken (±%lld m)": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Position prise (±%lld m)" + } + } + } + }, "Profile": { "localizations": { "fr": { @@ -701,6 +771,36 @@ } } }, + "STOPWATCH RESET": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "CHRONO À ZÉRO" + } + } + } + }, + "STOPWATCH STARTED": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "CHRONO LANCÉ" + } + } + } + }, + "STOPWATCH STOPPED": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "CHRONO ARRÊTÉ" + } + } + } + }, "SW": { "localizations": { "fr": { @@ -791,12 +891,22 @@ } } }, - "Starts the dive session and locks the screen (long press on the crown to unlock). Without it, the dive still starts on submersion.": { + "Starts on submersion or with the Action button": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Départ à l'immersion ou au bouton Action" + } + } + } + }, + "Stopwatch": { "localizations": { "fr": { "stringUnit": { "state": "translated", - "value": "Démarre la séance de plongée et verrouille l'écran (appui long sur la couronne pour déverrouiller). Sans ça, la plongée démarre quand même à l'immersion." + "value": "Chrono" } } } @@ -821,32 +931,32 @@ } } }, - "Tap to browse the profile": { + "Takes the GPS position, starts the dive session and locks the screen (long press on the crown to unlock). Without it, the dive still starts on submersion.": { "localizations": { "fr": { "stringUnit": { "state": "translated", - "value": "Toucher pour parcourir le profil" + "value": "Prend la position GPS, démarre la séance de plongée et verrouille l'écran (appui long sur la couronne pour déverrouiller). Sans ça, la plongée démarre quand même à l'immersion." } } } }, - "The bearing set here stays displayed during the dive (compass page, two crown clicks).": { + "Tap to browse the profile": { "localizations": { "fr": { "stringUnit": { "state": "translated", - "value": "Le cap posé ici reste affiché pendant la plongée (page boussole, deux crans de couronne)." + "value": "Toucher pour parcourir le profil" } } } }, - "The dive starts on submersion": { + "The bearing set here stays displayed during the dive (compass page, two crown clicks).": { "localizations": { "fr": { "stringUnit": { "state": "translated", - "value": "La plongée démarre à l'immersion" + "value": "Le cap posé ici reste affiché pendant la plongée (page boussole, deux crans de couronne)." } } } @@ -881,6 +991,16 @@ } } }, + "WAY BACK %lld°": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "CAP RETOUR %lld°" + } + } + } + }, "Waiting for the iPhone": { "localizations": { "fr": { @@ -1133,4 +1253,4 @@ } }, "version": "1.0" -} +} +\ No newline at end of file diff --git a/OpenRemoraWatch/RootView.swift b/OpenRemoraWatch/RootView.swift @@ -20,7 +20,7 @@ struct RootView: View { } .listItemTint(.cyan) } footer: { - Text("Starts the dive session and locks the screen (long press on the crown to unlock). Without it, the dive still starts on submersion.") + Text("Takes the GPS position, starts the dive session and locks the screen (long press on the crown to unlock). Without it, the dive still starts on submersion.") } } @@ -114,22 +114,20 @@ struct DiveRow: View { } } -/// Waiting for submersion: the session is running, the screen recalls the gas, the conservatism and the battery. +/// Waiting for submersion: the session is running, the entry position is being taken, the screen recalls the +/// gas, the conservatism and the battery. The Action button starts the dive without waiting for the water. struct ReadyView: View { @Environment(LogStore.self) private var store @Environment(DiveSession.self) private var session var body: some View { - VStack(spacing: 6) { - Image(systemName: "water.waves").font(.title2).foregroundStyle(.cyan) - Text("Ready").font(.title3.bold()) - Text("The dive starts on submersion").font(.footnote).foregroundStyle(.secondary) - .multilineTextAlignment(.center) - if let action = session.actionMessage { - Text(action).font(.system(size: 14, weight: .heavy, design: .rounded)) - .padding(.horizontal, 8).padding(.vertical, 2) - .background(.cyan, in: Capsule()).foregroundStyle(.black) - } else if session.screenLocked { + VStack(spacing: 4) { + Label("Ready", systemImage: "water.waves").font(.title3.bold()).foregroundStyle(.cyan) + Text("Starts on submersion or with the Action button").font(.caption2) + .foregroundStyle(.secondary).multilineTextAlignment(.center) + .lineLimit(2).minimumScaleFactor(0.7).fixedSize(horizontal: false, vertical: true) + PositionLine(position: session.position) + if session.screenLocked { Label("Screen locked: long press on the crown", systemImage: "lock.fill") .font(.caption2).foregroundStyle(.cyan).multilineTextAlignment(.center) } @@ -137,7 +135,7 @@ struct ReadyView: View { .font(.footnote) let mod = store.settings.maximumOperatingDepth() Text(mod > 40 ? "max 40 m (watch limit)" : "max \(Format.depth(mod)) m for this gas") - .font(.caption2).foregroundStyle(.secondary) + .font(.caption2).foregroundStyle(.secondary).lineLimit(1).minimumScaleFactor(0.7) if let level = session.batteryLevel { Label(Format.percent(Int((level * 100).rounded())), systemImage: level < 0.3 ? "battery.25" : "battery.100") .font(.footnote) @@ -146,10 +144,38 @@ struct ReadyView: View { } } .toolbar { - ToolbarItem(placement: .cancellationAction) { - Button("Cancel") { session.cancelReady() } + // Useless while the touch screen is locked: it comes back once unlocked (long press on the crown). + if !session.screenLocked { + ToolbarItem(placement: .cancellationAction) { + Button("Cancel") { session.cancelReady() } + } + } + } + } +} + +/// Entry position on the "Ready" screen: searching, taken (with its uncertainty), or not allowed. +private struct PositionLine: View { + let position: EntryPosition + + var body: some View { + Group { + if let fix = position.fix { + Label("Position taken (±\(Int(fix.horizontalAccuracy.rounded())) m)", systemImage: "location.fill") + .foregroundStyle(.green) + } else { + switch position.state { + case .denied: + Label("No position: location not allowed", systemImage: "location.slash").foregroundStyle(.orange) + case .unavailable: + Label("No position", systemImage: "location.slash").foregroundStyle(.orange) + default: + Label("Looking for the GPS position…", systemImage: "location").foregroundStyle(.secondary) + } } } + .font(.caption2) + .multilineTextAlignment(.center) } } diff --git a/docs/SHARING.md b/docs/SHARING.md @@ -24,3 +24,5 @@ Jean's decision (2026-11-13): Sub Rascasse is the logbook. Open Rémora (watch) `water`, `samples[]` (`time` s, `depth` m, `temperature` °C, `ceiling` m, `noDecompressionLimit` min, `stopDepth`, `stopMinutes`), `events[]` (`time`, `warning`: ascentFast, ascentTooFast, ceilingViolated, ppO2High, ppO2Critical), `tissuesAfter` (16 nitrogen pressures, bar), `computerModel` = "Open Rémora". +Optional, absent when empty: `latitude`, `longitude` (entry point, GPS fix taken on the "Ready" screen before the dive) and +`marks[]` (points marked by the diver with the Action button: `time` s, `depth` m, `heading` magnetic degrees or absent). diff --git a/project.yml b/project.yml @@ -15,7 +15,7 @@ settings: base: DEVELOPMENT_TEAM: CM5RQKJH56 CODE_SIGN_STYLE: Automatic - MARKETING_VERSION: "0.4" + MARKETING_VERSION: "0.5" CURRENT_PROJECT_VERSION: "1" SWIFT_VERSION: "6.0" SWIFT_EMIT_LOC_STRINGS: YES @@ -114,6 +114,7 @@ targets: WKRunsIndependentlyOfCompanionApp: true WKBackgroundModes: [underwater-depth, workout-processing] # French translations in OpenRemoraWatch/InfoPlist.xcstrings. + NSLocationWhenInUseUsageDescription: Open Rémora notes the position of the entry point before the dive; it stays in your logbook. NSMotionUsageDescription: Open Rémora reads the depth and the water temperature during the dive. NSHealthUpdateUsageDescription: Open Rémora saves every dive in Health, with the depth and the water temperature. NSHealthShareUsageDescription: Open Rémora reads no Health data; it only saves your dives there.