remora-kit

RemoraKit, shared dive computer engine (Buhlmann ZHL-16C + GF) and SwiftUI components for Open Remora and Open Merou
git clone https://git.schurger.org/remora-kit.git
Log | Files | Refs | README | LICENSE

README.md (4803B)


      1 # RemoraKit
      2 
      3 The dive computer shared by Open Rémora (Apple Watch Ultra) and other apps: decompression
      4 engine, dive logic and the common parts of the interface, as one Swift package with two libraries.
      5 
      6 **This is not a certified dive computer.** Apps built on it are secondary instruments: always dive with a
      7 primary dive computer and follow it when the two disagree.
      8 
      9 ## RemoraDeco
     10 
     11 No user interface, no platform framework (Foundation and Observation only); runs on iOS, watchOS and macOS.
     12 
     13 - **Engine**: Bühlmann ZHL-16C with gradient factors (`TissueState`, `AscentPlanner`), `DiveComputer` (no-stop
     14   time, stops, ceiling, safety stop, ascent rate, warnings), air or nitrox up to EAN40.
     15 - **Logbook**: `DiveRecorder`, `DiveLog`, `Logbook` (tissues carried over to repetitive dives), `SurfaceAdvice`
     16   (no-fly and altitude waiting times), `UserSettings`, UDDF export, Subsurface import.
     17 - **Dive logic**: `DiveTracker` and `DiveMonitor`, described below.
     18 
     19 ### Plugging in a depth source
     20 
     21 The app owns the sensor. It turns what the sensor says into `DiveReading` values and hands them to a
     22 `DiveMonitor`:
     23 
     24 ```swift
     25 let monitor = DiveMonitor(store: store) { cue in
     26     // DiveCue: .depthLost, .safetyStopStarted, .safetyStopDone, .alarm, .warning, .diveSaved
     27     // → a vibration, a sound, a flash…
     28 }
     29 monitor.onDiveStarted = { simulation in /* keep the app awake, start a workout… */ }
     30 monitor.onDiveEnded = { saved, simulation in /* saved == nil: the diver never went down */ }
     31 
     32 // For every sample of the sensor:
     33 monitor.receive(.pressure(time: seconds, surface: surfaceBar, absolute: ambientBar, submerged: true))
     34 monitor.receive(.temperature(celsius))
     35 ```
     36 
     37 - `store` is a `DiveLogStore`: the diver's `UserSettings`, the `Logbook`, and `add(_:)` to save a dive.
     38 - `absolute` is the ambient pressure in bar and `surface` the pressure measured at the surface before the dive.
     39   Pass `absolute: nil` when the sensor has no measurement: with `submerged: true` the last known depth is held
     40   and `depthUnknown` is raised (an alarm); with `submerged: false` the diver is at the surface.
     41 - The dive starts by itself when `absolute` exceeds `surface` by 0.03 bar, and ends after a minute at the
     42   surface (or with `end()`). A source that goes completely silent for more than 5 s is handled by a watchdog:
     43   near the surface the dive ends, deeper the depth is held and flagged. These thresholds are in
     44   `DiveTracker.Tuning` (`monitor.tuning`).
     45 - The monitor is `@Observable` and `@MainActor`: views read `status` (`DiveComputer.Status`), `warnings`,
     46   `isAlarming`, `activeWarnings`, `depthUnknown`, `temperature`, `sourceMessage`, `finishedDive`.
     47 - `startSimulation(_:speed:)` runs a dry demo dive from a `DemoProfile`.
     48 - What depends on the device rather than on the diver is set on the monitor: `computerModel` (the name written
     49   in the recorded dives, "Open Rémora" by default) and `configure`, a closure that adjusts the
     50   `DiveComputer.Configuration` after the diver's settings (`depthLimit`, the warning depth, 38 m by default;
     51   `ascentRateWindow`, 5 s by default).
     52 
     53 `DiveTracker` is the same logic as a plain value type, with no clock and no timer: every call takes the
     54 wall-clock time and returns the events (`diveStarted`, `cue`, `diveEnded`). The tests script dives with it.
     55 
     56 ## RemoraUI
     57 
     58 SwiftUI, for watchOS and iOS. Its texts are in its own String Catalog
     59 (`Sources/RemoraUI/Resources/Localizable.xcstrings`): English is the source language, French is translated.
     60 
     61 - `Format`: depths, durations, percentages, dates.
     62 - Labels and colours: `DiveComputer.Warning.label` / `.color`, `Water.label`, `UserSettings.Conservatism.label`,
     63   `SettingsText` (every setting value as text).
     64 - Alarm styling: `AlarmFlash` (the whole screen flashes red), `.blinking(_:)` (a value blinks),
     65   `DepthUnknownBanner`.
     66 - Dive read-outs: `DiveInstruction` (warning, stop with its countdown, safety stop or NDL) and `AscentScale`,
     67   with a `scale` factor for screens larger than a watch.
     68 - Settings: `DiveSettingsView` (oxygen, water, NDL alarm) and `AdvancedDiveSettingsView` (conservatism, custom
     69   gradient factors, maximum ppO2) on a binding to `UserSettings`; `SettingsSummary` for read-only rows.
     70 - `Terms`, `TermsView` and `.requiresTerms(_:)`: the warning to accept at first launch.
     71 
     72 ## Tests
     73 
     74     swift test
     75 
     76 runs on macOS (Swift 6). Two tests only run when given data:
     77 
     78 - `SHEARWATER_JSON=/path/to/dives.json swift test`: replays real dives and compares with what a Shearwater
     79   displayed (see `docs/VALIDATION.md` in Open Rémora).
     80 - `SAMPLE_DIVE_DIR=/some/dir swift test`: writes a sample dive in the format shared with Sub Rascasse.
     81 
     82 `make test` does the same from a Linux host by syncing the sources to a Mac over SSH (`CHUNGA`, `REMOTE`).
     83 
     84 ## License
     85 
     86 GPL-2.0-only. See [LICENSE](LICENSE).