commit 647a4e002f309065f6d3e096eb2060256dc83d07
parent deec6ffd34c1594087772fa31f7d805835e972a6
Author: Jean Schurger <jean@schurger.org>
Date: Fri, 13 Nov 2026 14:56:43 -0500
0.7: simulated housing (on-screen buttons, simulated sensors and pump, shortened test), -simulation argument
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7deYGSNhtY1AmBH7DQGNs
Diffstat:
6 files changed, 174 insertions(+), 33 deletions(-)
diff --git a/OpenMerou/App/AppModel.swift b/OpenMerou/App/AppModel.swift
@@ -36,6 +36,8 @@ final class AppModel {
}
engine.start(settings)
housing.cameraButton = { [weak self] event in self?.button(event) }
+ // Lancement avec « -simulation » : boîtier simulé d'emblée (captures d'écran, démonstrations).
+ if ProcessInfo.processInfo.arguments.contains("-simulation") { housing.startSimulation() }
sleepTask = Task { [weak self] in
while !Task.isCancelled {
try? await Task.sleep(for: .seconds(1))
diff --git a/OpenMerou/Housing/HousingClient.swift b/OpenMerou/Housing/HousingClient.swift
@@ -49,7 +49,7 @@ final class HousingClient: NSObject {
/// Vrai entre notre ordre de marche et notre ordre d'arrêt.
private(set) var pumpRequested = false
- var canPump: Bool { pumpCharacteristic != nil }
+ var canPump: Bool { pumpCharacteristic != nil || simulation != nil }
/// Seuil d'arrêt observé avec l'app officielle : premier échantillon sous 80 kPa.
static let vacuumTargetPa = 80_000.0
@@ -61,7 +61,84 @@ final class HousingClient: NSObject {
/// Dans la capture, l'app officielle n'envoie aucun ordre d'extinction : elle coupe la connexion
/// (HCI 0x16) et le boîtier s'éteint. On fait pareil.
+ // MARK: Boîtier simulé (démonstration, revue de l'interface, réviseurs sans boîtier)
+
+ private struct Simulation {
+ var pressurePa = 100_960.0
+ var temperatureC = 21.0
+ var pumpOn = false
+ var battery = 92.0
+ }
+
+ @ObservationIgnored private var simulation: Simulation?
+ @ObservationIgnored private var simulationTask: Task<Void, Never>?
+ private(set) var simulated = false
+
+ func startSimulation() {
+ guard simulation == nil else { return }
+ central.stopScan()
+ if let peripheral { central.cancelPeripheralConnection(peripheral) }
+ peripheral = nil
+ released = true // ne pas reprendre un vrai boîtier pendant la démonstration
+ simulation = Simulation()
+ simulated = true
+ vacuum = VacuumSequence()
+ vacuum.testDuration = 20 // démonstration : test raccourci
+ readings = HousingReadings()
+ status = .connected("boîtier simulé")
+ deviceInfo = ["Modèle": "Boîtier simulé"]
+ note("Simulation démarrée")
+ ingest(HousingUUID.alarm, Data([0x00]))
+ ingest(HousingUUID.pumpState, Data([0x02]))
+ simulationTask = Task { [weak self] in
+ while !Task.isCancelled {
+ try? await Task.sleep(for: .milliseconds(350))
+ self?.simulationTick()
+ }
+ }
+ }
+
+ func stopSimulation() {
+ guard simulation != nil else { return }
+ simulationTask?.cancel()
+ pumpTimeout?.cancel()
+ simulation = nil
+ simulated = false
+ pumpRequested = false
+ readings = HousingReadings()
+ deviceInfo = [:]
+ note("Simulation arrêtée")
+ reconnect()
+ }
+
+ /// Appui sur un bouton du boîtier simulé (boutons affichés à l'écran).
+ func simulatedPress(_ button: HousingButton, long: Bool = false) {
+ guard simulation != nil else { return }
+ ingest(HousingUUID.button, Data([button.rawValue << 4 | (long ? 1 : 0)]))
+ }
+
+ private func simulationTick() {
+ guard var sim = simulation else { return }
+ if sim.pumpOn {
+ sim.pressurePa -= 2_100 * 0.35 // ~2 kPa/s, comme le vrai boîtier
+ sim.battery = max(5, sim.battery - 0.15)
+ } else if case .opening = vacuum.step {
+ sim.pressurePa = min(99_300, sim.pressurePa + 6_000) // bouchon ouvert : retour à l'air
+ } else if sim.pressurePa < 90_000 {
+ sim.pressurePa += 30.0 / 60 * 0.35 // ~30 Pa/min, fuite résiduelle normale
+ sim.temperatureC = min(26, sim.temperatureC + 0.002)
+ }
+ sim.pressurePa += Double.random(in: -8...8)
+ simulation = sim
+ func le(_ value: UInt32) -> Data { Data([UInt8(value & 0xFF), UInt8(value >> 8 & 0xFF), UInt8(value >> 16 & 0xFF), UInt8(value >> 24)]) }
+ ingest(HousingUUID.externalPressure, le(9_940))
+ ingest(HousingUUID.temperature, le(UInt32(sim.temperatureC * 100)))
+ ingest(HousingUUID.internalPressure, le(UInt32(sim.pressurePa)))
+ if Int(sim.battery) != readings.batteryPercent { ingest(HousingUUID.batteryLevel, Data([UInt8(sim.battery)])) }
+ }
+
func release() {
+ if simulation != nil { stopSimulation(); return }
guard let peripheral else { return }
if pumpRequested { stopPump(reason: "déconnexion") }
released = true
@@ -70,6 +147,33 @@ final class HousingClient: NSObject {
note("Déconnexion demandée")
}
+ /// Traite une valeur du boîtier, réel ou simulé.
+ private func ingest(_ uuid: CBUUID, _ data: Data) {
+ if let label = HousingUUID.deviceInfoStrings[uuid] {
+ deviceInfo[label] = String(decoding: data, as: UTF8.self)
+ return
+ }
+ let before = vacuum.step
+ if let line = readings.apply(uuid, data) { note(line) }
+ if uuid == HousingUUID.button, let event = ButtonEvent(data) {
+ let forCamera = vacuum.cameraHasButtons && !(event.button == .right && event.isLong)
+ run(vacuum.button(event, now: .now))
+ if forCamera { cameraButton?(event) }
+ }
+ if uuid == HousingUUID.internalPressure || uuid == HousingUUID.temperature {
+ run(vacuum.sensors(pressurePa: readings.internalPressurePa, temperatureC: readings.temperatureC, now: .now))
+ }
+ if uuid == HousingUUID.internalPressure { DevLog.shared.sensors(readings, vacuum) }
+ if vacuum.step != before { note("Séquence : \(vacuum.step)") }
+ if uuid == HousingUUID.internalPressure, pumpRequested,
+ let p = readings.internalPressurePa, p < Self.vacuumTargetPa {
+ stopPump(reason: "vide atteint, \(Int(p)) Pa")
+ }
+ if [HousingUUID.internalPressure, HousingUUID.externalPressure, HousingUUID.temperature].contains(uuid) {
+ lastSensorUpdate = .now
+ }
+ }
+
private func run(_ effects: [VacuumSequence.Effect]) {
for effect in effects {
switch effect {
@@ -88,13 +192,18 @@ final class HousingClient: NSObject {
}
func startPump() {
- guard let peripheral, let pumpCharacteristic, !pumpRequested else { return }
+ guard !pumpRequested, simulation != nil || (peripheral != nil && pumpCharacteristic != nil) else { return }
if let p = readings.internalPressurePa, p < Self.vacuumTargetPa {
note("Pompe : vide déjà atteint (\(Int(p)) Pa)")
return
}
pumpRequested = true
- peripheral.writeValue(Data([0x01]), for: pumpCharacteristic, type: .withResponse)
+ if simulation != nil {
+ simulation?.pumpOn = true
+ ingest(HousingUUID.pumpState, Data([0x01]))
+ } else if let peripheral, let pumpCharacteristic {
+ peripheral.writeValue(Data([0x01]), for: pumpCharacteristic, type: .withResponse)
+ }
note("Pompe : marche demandée")
pumpTimeout = Task { [weak self] in
try? await Task.sleep(for: .seconds(Self.pumpMaxSeconds))
@@ -106,6 +215,13 @@ final class HousingClient: NSObject {
func stopPump(reason: String) {
pumpTimeout?.cancel()
pumpTimeout = nil
+ if simulation != nil {
+ simulation?.pumpOn = false
+ pumpRequested = false
+ ingest(HousingUUID.pumpState, Data([0x02]))
+ note("Pompe : arrêt demandé (\(reason))")
+ return
+ }
guard let peripheral, let pumpCharacteristic else { pumpRequested = false; return }
// Toujours envoyer l'arrêt, même si on ne pense pas l'avoir démarrée.
peripheral.writeValue(Data([0x00]), for: pumpCharacteristic, type: .withResponse)
@@ -147,6 +263,7 @@ final class HousingClient: NSObject {
extension HousingClient: CBCentralManagerDelegate {
nonisolated func centralManagerDidUpdateState(_ central: CBCentralManager) {
MainActor.assumeIsolated {
+ guard simulation == nil else { return } // la démonstration garde son état
switch central.state {
case .poweredOn:
note("Bluetooth prêt")
@@ -237,30 +354,6 @@ extension HousingClient: CBPeripheralDelegate {
error: Error?) {
guard let data = characteristic.value else { return }
let uuid = characteristic.uuid
- MainActor.assumeIsolated {
- if let label = HousingUUID.deviceInfoStrings[uuid] {
- deviceInfo[label] = String(decoding: data, as: UTF8.self)
- return
- }
- let before = vacuum.step
- if let line = readings.apply(uuid, data) { note(line) }
- if uuid == HousingUUID.button, let event = ButtonEvent(data) {
- let forCamera = vacuum.cameraHasButtons && !(event.button == .right && event.isLong)
- run(vacuum.button(event, now: .now))
- if forCamera { cameraButton?(event) }
- }
- if uuid == HousingUUID.internalPressure || uuid == HousingUUID.temperature {
- run(vacuum.sensors(pressurePa: readings.internalPressurePa, temperatureC: readings.temperatureC, now: .now))
- }
- if uuid == HousingUUID.internalPressure { DevLog.shared.sensors(readings, vacuum) }
- if vacuum.step != before { note("Séquence : \(vacuum.step)") }
- if uuid == HousingUUID.internalPressure, pumpRequested,
- let p = readings.internalPressurePa, p < Self.vacuumTargetPa {
- stopPump(reason: "vide atteint, \(Int(p)) Pa")
- }
- if [HousingUUID.internalPressure, HousingUUID.externalPressure, HousingUUID.temperature].contains(uuid) {
- lastSensorUpdate = .now
- }
- }
+ MainActor.assumeIsolated { ingest(uuid, data) }
}
}
diff --git a/OpenMerou/Housing/VacuumSequence.swift b/OpenMerou/Housing/VacuumSequence.swift
@@ -48,6 +48,8 @@ struct VacuumSequence: Equatable, Sendable {
static let openedAbsolutePa = 95_000.0
private(set) var step: Step = .prepare
+ /// Durée du test d'étanchéité ; raccourcie seulement pour le boîtier simulé.
+ var testDuration = VacuumSequence.testSeconds
private(set) var pressurePa: Double?
private(set) var temperatureC: Double?
@@ -63,7 +65,7 @@ struct VacuumSequence: Equatable, Sendable {
func testRemaining(now: Date) -> TimeInterval? {
guard case .testing(let baseline) = step else { return nil }
- return max(0, Self.testSeconds - now.timeIntervalSince(baseline.date))
+ return max(0, testDuration - now.timeIntervalSince(baseline.date))
}
/// Vrai quand les boutons vont à la caméra (sauf l'appui long à droite, gardé pour l'ouverture).
@@ -141,7 +143,7 @@ struct VacuumSequence: Equatable, Sendable {
let rise = correctedRise(since: baseline) ?? 0
if rise > Self.testMaxRisePa {
step = .failed(.leak(risePa: rise))
- } else if now.timeIntervalSince(baseline.date) >= Self.testSeconds {
+ } else if now.timeIntervalSince(baseline.date) >= testDuration {
step = .sealed(baseline)
}
case .sealed(let baseline):
diff --git a/OpenMerou/UI/CameraScreen.swift b/OpenMerou/UI/CameraScreen.swift
@@ -56,6 +56,10 @@ struct CameraScreen: View {
if housing.vacuum.step == .prepare {
Button("Essai à sec (sans mise sous vide)") { housing.bypassVacuum() }
.font(.footnote).padding(.top, 4)
+ if !housing.simulated {
+ Button("Simuler un boîtier (démonstration)") { housing.startSimulation() }
+ .font(.footnote)
+ }
}
Text(housing.status.label).font(.footnote).foregroundStyle(.secondary)
}
@@ -63,6 +67,8 @@ struct CameraScreen: View {
MenuView(model: model)
}
+ if housing.simulated { SimulatedButtons(housing: housing) }
+
if model.sleeping {
Color.black.ignoresSafeArea().onTapGesture { model.wake() }
}
@@ -221,3 +227,41 @@ struct MenuView: View {
}
}
}
+
+/// Boutons du boîtier simulé : même disposition que le vrai (croix à l'arrière, déclencheur en haut).
+struct SimulatedButtons: View {
+ let housing: HousingClient
+
+ var body: some View {
+ VStack {
+ Spacer()
+ HStack(alignment: .bottom) {
+ Button("Quitter la simulation") { housing.stopSimulation() }
+ .font(.caption).padding(8).background(.black.opacity(0.6), in: Capsule())
+ Spacer()
+ VStack(spacing: 6) {
+ key("camera.fill", .shutter)
+ key("chevron.up", .up)
+ HStack(spacing: 6) {
+ key("chevron.left", .left)
+ key("chevron.down", .down)
+ key("chevron.right", .right)
+ }
+ Text("Simulation · appui long possible").font(.caption2)
+ }
+ }
+ }
+ .padding(.horizontal).padding(.bottom, 44)
+ }
+
+ private func key(_ symbol: String, _ button: HousingButton) -> some View {
+ Image(systemName: symbol)
+ .font(.title3.weight(.bold))
+ .frame(width: 52, height: 44)
+ .background(.black.opacity(0.6), in: RoundedRectangle(cornerRadius: 10))
+ .overlay(RoundedRectangle(cornerRadius: 10).stroke(.white.opacity(0.6)))
+ .onTapGesture { housing.simulatedPress(button) }
+ .onLongPressGesture(minimumDuration: 1) { housing.simulatedPress(button, long: true) }
+ .accessibilityLabel(button.label)
+ }
+}
diff --git a/fastlane/Fastfile b/fastlane/Fastfile
@@ -122,9 +122,9 @@ platform :ios do
end
texts = {
"fr-CA" => ["App libre et gratuite pour boîtier de plongée compatible : boutons, pompe à vide, capteurs, caméra.",
- "0.6 : mode développement (Menu → Réglages → Développement) : valeurs brutes à l'écran et journal CSV des mesures et des événements, à récupérer par le bouton ⓘ ou dans l'app Fichiers. À faire dans l'eau : activer le mode, plonger le boîtier, noter la profondeur réelle."],
+ "0.7 : boîtier simulé (bouton « Simuler un boîtier » au premier écran, boutons à l'écran) pour les démonstrations ; mode développement (Menu → Réglages → Développement) : valeurs brutes à l'écran et journal CSV des mesures et des événements, à récupérer par le bouton ⓘ ou dans l'app Fichiers. À faire dans l'eau : activer le mode, plonger le boîtier, noter la profondeur réelle."],
"en-CA" => ["Free, open-source app for compatible dive housings: buttons, vacuum pump, sensors, camera.",
- "0.6: developer mode (Menu → Settings → Development): raw values on screen and a CSV log of measurements and events, shared from the ⓘ button or the Files app. In water: turn it on, submerge the housing, note the real depth."],
+ "0.7: simulated housing (Simulate a housing on the first screen, on-screen buttons) for demos; developer mode (Menu → Settings → Development): raw values on screen and a CSV log of measurements and events, shared from the ⓘ button or the Files app. In water: turn it on, submerge the housing, note the real depth."],
}
_, locs = asc(:get, "/v1/apps/#{app.id}/betaAppLocalizations")
texts.each do |locale, (description, _)|
diff --git a/project.yml b/project.yml
@@ -9,7 +9,7 @@ settings:
base:
DEVELOPMENT_TEAM: CM5RQKJH56
CODE_SIGN_STYLE: Automatic
- MARKETING_VERSION: "0.6"
+ MARKETING_VERSION: "0.7"
CURRENT_PROJECT_VERSION: "1"
SWIFT_VERSION: "6.0"
targets: