v0.5.3: add alarm sounds
This commit is contained in:
parent
4eb67a76ec
commit
fcd8c1146f
10 changed files with 1121 additions and 12 deletions
623
patient-monitor-simulation-v0.5.2-to-v0.5.3.patch
Normal file
623
patient-monitor-simulation-v0.5.2-to-v0.5.3.patch
Normal file
|
|
@ -0,0 +1,623 @@
|
||||||
|
diff -ruN a/Cargo.toml b/Cargo.toml
|
||||||
|
--- a/Cargo.toml 2026-11-12 13:10:05.130839688 +0000
|
||||||
|
+++ b/Cargo.toml 2026-11-12 13:27:14.340210857 +0000
|
||||||
|
@@ -1,6 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "patient-monitor-simulation"
|
||||||
|
-version = "0.5.2"
|
||||||
|
+version = "0.5.3"
|
||||||
|
edition = "2021"
|
||||||
|
license = "MIT"
|
||||||
|
description = "Synthetic patient-monitor simulation for teaching (not for clinical use)"
|
||||||
|
diff -ruN a/README.de.md b/README.de.md
|
||||||
|
--- a/README.de.md 2026-11-12 13:10:05.131166243 +0000
|
||||||
|
+++ b/README.de.md 2026-11-12 13:28:21.812109359 +0000
|
||||||
|
@@ -1,4 +1,4 @@
|
||||||
|
-# Patient Monitor Simulation (PaMSim) — v0.5.2
|
||||||
|
+# Patient Monitor Simulation (PaMSim) — v0.5.3
|
||||||
|
|
||||||
|
Ein mit Rust und GTK4 entwickelter Patient*innenmonitor-Simulator mit zwei Fenstern für die Lehre unter Fedora Linux.
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@
|
||||||
|
## Installation, Kompilierung und Start unter Fedora
|
||||||
|
|
||||||
|
```bash
|
||||||
|
-sudo dnf install rust cargo gcc pkgconf-pkg-config gtk4-devel
|
||||||
|
+sudo dnf install rust cargo gcc pkgconf-pkg-config gtk4-devel pipewire-utils
|
||||||
|
cargo test
|
||||||
|
cargo run --release
|
||||||
|
```
|
||||||
|
@@ -47,6 +47,39 @@
|
||||||
|
Unter Wayland sollte das Fenster vor dem Wechsel in den Vollbildmodus auf den gewünschten Präsentationsbildschirm verschoben werden.
|
||||||
|
Der Vollbildmodus sperrt den Computer nicht gegen andere Eingaben.
|
||||||
|
|
||||||
|
+## Akustische Alarme (v0.5.3)
|
||||||
|
+
|
||||||
|
+Die akustische Alarmierung ist **standardmäßig eingeschaltet**. Im
|
||||||
|
+Admin-Fenster lässt sie sich mit **Audible alarms** aktivieren bzw. stummschalten.
|
||||||
|
+Mit **Test tone** kann die Tonausgabe unabhängig von der Stummschaltung geprüft
|
||||||
|
+werden. Die optischen Alarme blinken bei stummgeschalteter Tonausgabe weiterhin.
|
||||||
|
+
|
||||||
|
+- **Kritische Rhythmusalarme:** VT, PVT, Kammerflimmern und Asystolie lösen
|
||||||
|
+ einen Doppelton aus (zweimal kurz 880 Hz), der ungefähr alle 1,5 Sekunden
|
||||||
|
+ wiederholt wird.
|
||||||
|
+- **Numerische und technische Alarme:** Grenzwertüberschreitungen sowie
|
||||||
|
+ **NO SENSOR** und **NO READING** lösen einen kurzen Ton mit 700 Hz aus,
|
||||||
|
+ der ungefähr alle 2,5 Sekunden wiederholt wird.
|
||||||
|
+- Kritische Alarme haben Vorrang. Auch bei mehreren gleichzeitig aktiven
|
||||||
|
+ Alarmen wird nur eine Tonfolge ausgegeben. Bei behobenem Alarm oder
|
||||||
|
+ Stummschaltung verstummt die Ausgabe. Ausgeblendete Monitorbereiche
|
||||||
|
+ lösen keine akustischen Alarme aus.
|
||||||
|
+- Nicht verfügbare Messwerte, etwa NIBP vor der ersten abgeschlossenen Messung,
|
||||||
|
+ lösen keinen numerischen Grenzwertalarm aus. Eine laufende NIBP-Messung
|
||||||
|
+ selbst ist kein Alarm. Die Audioausgabe wird unabhängig von der Darstellung
|
||||||
|
+ der Kurven verarbeitet.
|
||||||
|
+
|
||||||
|
+Unter Fedora wird **`pw-play`** aus dem Paket `pipewire-utils` verwendet,
|
||||||
|
+alternativ **`paplay`**. Es sind weder zusätzliche Rust-Bibliotheken noch
|
||||||
|
+mitzuliefernde Audiodateien notwendig: Das Programm erzeugt seine WAV-Töne
|
||||||
|
+zur Laufzeit. Falls kein Wiedergabeprogramm verfügbar ist, erscheint im
|
||||||
|
+Admin-Fenster ein entsprechender Hinweis; der Monitor bleibt funktionstüchtig.
|
||||||
|
+Wiedergabegerät und Lautstärke werden über die Systemeinstellungen verwaltet.
|
||||||
|
+
|
||||||
|
+**Wichtig:** Diese didaktischen Tonsignale entsprechen nicht den Anforderungen
|
||||||
|
+an Medizinproduktealarme (insbesondere IEC 60601-1-8) und dürfen nicht zur
|
||||||
|
+klinischen Überwachung verwendet werden.
|
||||||
|
+
|
||||||
|
## Numerische Alarmgrenzen (seit v0.4.0; Anordnung und Voreinstellungen seit v0.4.1)
|
||||||
|
|
||||||
|
Für jeden angezeigten numerischen Messwert können im zugehörigen Admin-Bereich **unabhängige optionale untere (↓) und obere (↑) Alarmgrenzen** festgelegt werden.
|
||||||
|
@@ -379,3 +412,13 @@
|
||||||
|
die anderen Wertefelder vertikal zusammenzudrängen. Beim Ausblenden einzelner
|
||||||
|
Monitorbereiche werden beide Spalten gemeinsam neu aufgeteilt.
|
||||||
|
Das Messverhalten und die Alarmfunktionen bleiben unverändert.
|
||||||
|
+
|
||||||
|
+## v0.5.3 — Akustische Alarmierung
|
||||||
|
+
|
||||||
|
+- Alarmausgabe mit `pw-play` (PipeWire) bzw. `paplay` (Fallback), ohne neue
|
||||||
|
+ Rust-Bibliotheken.
|
||||||
|
+- Admin-Bedienelemente zum Stummschalten und für einen Testton.
|
||||||
|
+- Unterschiedliche Töne für kritische Rhythmusalarme und Standard- bzw.
|
||||||
|
+ technische Alarme; kritische Alarme haben Vorrang.
|
||||||
|
+- Die Audioausgabe ist von der Kurvendarstellung entkoppelt.
|
||||||
|
+- Bisherige optische Alarme und Simulationsfunktionen bleiben unverändert.
|
||||||
|
diff -ruN a/README.md b/README.md
|
||||||
|
--- a/README.md 2026-11-12 13:10:05.130976637 +0000
|
||||||
|
+++ b/README.md 2026-11-12 13:28:21.810121988 +0000
|
||||||
|
@@ -1,4 +1,4 @@
|
||||||
|
-# Patient Monitor Simulation (PaMSim) — v0.5.2
|
||||||
|
+# Patient Monitor Simulation (PaMSim) — v0.5.3
|
||||||
|
|
||||||
|
A two-window, Rust/GTK4 patient-monitor simulator for teaching on Fedora Linux.
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@
|
||||||
|
## Build and run on Fedora
|
||||||
|
|
||||||
|
```bash
|
||||||
|
-sudo dnf install rust cargo gcc pkgconf-pkg-config gtk4-devel
|
||||||
|
+sudo dnf install rust cargo gcc pkgconf-pkg-config gtk4-devel pipewire-utils
|
||||||
|
cargo test
|
||||||
|
cargo run --release
|
||||||
|
```
|
||||||
|
@@ -48,6 +48,35 @@
|
||||||
|
fullscreen. On Wayland, move the monitor to the presentation screen before
|
||||||
|
activating fullscreen. Fullscreen does not lock down the computer.
|
||||||
|
|
||||||
|
+## Audible alarms (v0.5.3)
|
||||||
|
+
|
||||||
|
+Sound is **enabled by default**. The Admin window has an **Audible alarms**
|
||||||
|
+checkbox for muting and a **Test tone** button (works even while muted).
|
||||||
|
+Visual alarms keep blinking normally when sound is off.
|
||||||
|
+
|
||||||
|
+- **Critical rhythm alarm:** VT, PVT, VF and asystole produce a double beep
|
||||||
|
+ (two short 880 Hz tones), repeated approximately every 1.5 seconds.
|
||||||
|
+- **Numerical and SpO₂ technical alarms:** out-of-range values, **NO SENSOR**
|
||||||
|
+ and **NO READING** produce a single 700 Hz beep, repeated approximately
|
||||||
|
+ every 2.5 seconds.
|
||||||
|
+- Critical alarms have priority: only one tone pattern is played even if
|
||||||
|
+ multiple alarms are active. The sound stops when all alarms clear or when
|
||||||
|
+ the checkbox is unchecked. Alarms on hidden monitor channels are excluded.
|
||||||
|
+- Values not yet available (e.g. NIBP before a completed measurement) do not
|
||||||
|
+ trigger numerical limit alarms. The cuff measurement cycle by itself is not
|
||||||
|
+ an alarm. Audio playback is separate from waveform rendering and simulation.
|
||||||
|
+
|
||||||
|
+On Fedora, sound is played through **`pw-play`** from `pipewire-utils`, with
|
||||||
|
+**`paplay`** as a fallback. No additional Rust crates or sound files are needed:
|
||||||
|
+the application creates its own short WAV tones at runtime. If neither player
|
||||||
|
+is installed, Admin reports that audio is unavailable; the monitor continues
|
||||||
|
+to work normally. `Test tone` helps verify the desktop audio output. The
|
||||||
|
+application uses the system output device and mixer volume.
|
||||||
|
+
|
||||||
|
+**Important:** These simple teaching tones do not comply with medical-device
|
||||||
|
+alarm standards (including IEC 60601-1-8) and must never be relied on for
|
||||||
|
+clinical monitoring.
|
||||||
|
+
|
||||||
|
## Numerical alarm limits (v0.4.0; layout and presets updated in v0.4.1)
|
||||||
|
|
||||||
|
Each displayed numeric measurement has an **independent optional lower (↓) and
|
||||||
|
@@ -411,3 +440,12 @@
|
||||||
|
NIBP reserves an empty cell in the left waveform column instead of shortening
|
||||||
|
the other numeric rows. Hiding any channel reflows both columns together.
|
||||||
|
No NIBP measurement logic or alarm behavior was changed.
|
||||||
|
+
|
||||||
|
+## v0.5.3 — Audible alarm output
|
||||||
|
+
|
||||||
|
+- Alarm-tone playback through Fedora PipeWire (`pw-play`) or PulseAudio
|
||||||
|
+ compatibility (`paplay`), without any new Rust library dependencies.
|
||||||
|
+- Admin controls to mute/unmute alarms or play a test tone.
|
||||||
|
+- Distinct critical-rhythm and standard/technical patterns; critical priority.
|
||||||
|
+- Audio keeps running independently of the monitor's drawing callback.
|
||||||
|
+- Visual alarms and existing physiological simulation remain unchanged.
|
||||||
|
diff -ruN a/src/alarm.rs b/src/alarm.rs
|
||||||
|
--- a/src/alarm.rs 1970-01-01 00:00:00.000000000 +0000
|
||||||
|
+++ b/src/alarm.rs 2026-11-12 13:27:13.323621333 +0000
|
||||||
|
@@ -0,0 +1,364 @@
|
||||||
|
+//! Audible teaching alarms. This is not a clinical alarm system.
|
||||||
|
+//!
|
||||||
|
+//! The decision uses the same available readings, visibility settings and limits
|
||||||
|
+//! as the monitor. Sound is played using Fedora's PipeWire command-line player
|
||||||
|
+//! (or paplay) without adding a native audio-library dependency to Cargo.
|
||||||
|
+
|
||||||
|
+use std::env;
|
||||||
|
+use std::fs::{self, OpenOptions};
|
||||||
|
+use std::io::{self, Write};
|
||||||
|
+use std::path::{Path, PathBuf};
|
||||||
|
+use std::process::{Child, Command, Stdio};
|
||||||
|
+use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||||
|
+
|
||||||
|
+use crate::model::{AlarmLimits, AlarmState, Parameters, PulseConduction, Spo2Status};
|
||||||
|
+use crate::simulation::Simulator;
|
||||||
|
+
|
||||||
|
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
+pub enum AlarmLevel {
|
||||||
|
+ #[default]
|
||||||
|
+ None,
|
||||||
|
+ Standard,
|
||||||
|
+ Critical,
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+fn outside(limits: AlarmLimits, value: Option<i32>) -> bool {
|
||||||
|
+ limits.evaluate(value) != AlarmState::Normal
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+/// Only parameters actually shown on the monitor contribute audible alarms.
|
||||||
|
+/// Missing numeric values do not trigger threshold alarms, but missing SpO2
|
||||||
|
+/// readings and disconnected sensors are explicit technical alarms.
|
||||||
|
+pub fn level(p: &Parameters, sim: &Simulator) -> AlarmLevel {
|
||||||
|
+ let mut result = AlarmLevel::None;
|
||||||
|
+ let hr = (p.ecg_rhythm.has_qrs() && p.heart_rate > 0).then_some(p.heart_rate);
|
||||||
|
+ let captured = p.ecg_rhythm.can_generate_pulse()
|
||||||
|
+ && p.heart_rate > 0
|
||||||
|
+ && p.pulse_conduction != PulseConduction::None;
|
||||||
|
+ let pr = if captured { sim.pulse_rate() } else { None };
|
||||||
|
+
|
||||||
|
+ if p.show_ecg {
|
||||||
|
+ if p.ecg_rhythm.rhythm_alarm().is_some() {
|
||||||
|
+ return AlarmLevel::Critical;
|
||||||
|
+ }
|
||||||
|
+ if outside(p.alarms.hr, hr) {
|
||||||
|
+ result = AlarmLevel::Standard;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if p.show_spo2 {
|
||||||
|
+ let status = p.spo2_status_at_quality(pr, sim.poor_signal_lost(), sim.spo2_quality(p));
|
||||||
|
+ if status != Spo2Status::Available
|
||||||
|
+ || outside(p.alarms.spo2, Some(p.spo2))
|
||||||
|
+ || outside(p.alarms.pr, pr)
|
||||||
|
+ {
|
||||||
|
+ result = AlarmLevel::Standard;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if p.show_art {
|
||||||
|
+ let (sys, dia, map) = sim.displayed_art_pressures(p, captured);
|
||||||
|
+ if outside(p.alarms.art_sys, sys)
|
||||||
|
+ || outside(p.alarms.art_dia, dia)
|
||||||
|
+ || outside(p.alarms.art_map, map)
|
||||||
|
+ || outside(p.alarms.ppv, Some(p.pulse_pressure_variation))
|
||||||
|
+ {
|
||||||
|
+ result = AlarmLevel::Standard;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if p.show_capno && (outside(p.alarms.etco2, Some(p.etco2))
|
||||||
|
+ || outside(p.alarms.rr, Some(p.respiratory_rate)))
|
||||||
|
+ {
|
||||||
|
+ result = AlarmLevel::Standard;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if p.show_nibp {
|
||||||
|
+ let reading = sim.nibp().reading();
|
||||||
|
+ if outside(p.alarms.nibp_sys, reading.map(|r| r.systolic))
|
||||||
|
+ || outside(p.alarms.nibp_dia, reading.map(|r| r.diastolic))
|
||||||
|
+ || outside(p.alarms.nibp_map, reading.map(|r| r.mean()))
|
||||||
|
+ {
|
||||||
|
+ result = AlarmLevel::Standard;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ result
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+/// Very short, original synthesized sine beeps; mono PCM16 WAV.
|
||||||
|
+fn wav(critical: bool) -> Vec<u8> {
|
||||||
|
+ const SAMPLE_RATE: u32 = 44_100;
|
||||||
|
+ let segments: &[(f64, f64)] = if critical {
|
||||||
|
+ &[(880.0, 0.16), (0.0, 0.09), (880.0, 0.16)]
|
||||||
|
+ } else {
|
||||||
|
+ &[(700.0, 0.18)]
|
||||||
|
+ };
|
||||||
|
+ let samples: usize = segments.iter()
|
||||||
|
+ .map(|(_, seconds)| (seconds * f64::from(SAMPLE_RATE)).round() as usize)
|
||||||
|
+ .sum();
|
||||||
|
+ let size = (samples * 2) as u32;
|
||||||
|
+ let mut bytes = Vec::with_capacity(44 + size as usize);
|
||||||
|
+ bytes.extend_from_slice(b"RIFF");
|
||||||
|
+ bytes.extend_from_slice(&(size + 36).to_le_bytes());
|
||||||
|
+ bytes.extend_from_slice(b"WAVEfmt ");
|
||||||
|
+ bytes.extend_from_slice(&16_u32.to_le_bytes()); // PCM format chunk
|
||||||
|
+ bytes.extend_from_slice(&1_u16.to_le_bytes()); // PCM
|
||||||
|
+ bytes.extend_from_slice(&1_u16.to_le_bytes()); // mono
|
||||||
|
+ bytes.extend_from_slice(&SAMPLE_RATE.to_le_bytes());
|
||||||
|
+ bytes.extend_from_slice(&(SAMPLE_RATE * 2).to_le_bytes()); // byte rate
|
||||||
|
+ bytes.extend_from_slice(&2_u16.to_le_bytes()); // block align
|
||||||
|
+ bytes.extend_from_slice(&16_u16.to_le_bytes()); // bits per sample
|
||||||
|
+ bytes.extend_from_slice(b"data");
|
||||||
|
+ bytes.extend_from_slice(&size.to_le_bytes());
|
||||||
|
+
|
||||||
|
+ for &(frequency, seconds) in segments {
|
||||||
|
+ let count = (seconds * f64::from(SAMPLE_RATE)).round() as usize;
|
||||||
|
+ for i in 0..count {
|
||||||
|
+ let t = i as f64 / f64::from(SAMPLE_RATE);
|
||||||
|
+ let remaining = (count - i) as f64 / f64::from(SAMPLE_RATE);
|
||||||
|
+ let envelope = (t / 0.012).min(1.0).min(remaining / 0.012).max(0.0);
|
||||||
|
+ let value = if frequency > 0.0 {
|
||||||
|
+ (2.0 * std::f64::consts::PI * frequency * t).sin() * envelope * 0.17
|
||||||
|
+ } else { 0.0 };
|
||||||
|
+ let sample = (value * f64::from(i16::MAX)).round() as i16;
|
||||||
|
+ bytes.extend_from_slice(&sample.to_le_bytes());
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ bytes
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+struct SoundFiles {
|
||||||
|
+ standard: PathBuf,
|
||||||
|
+ critical: PathBuf,
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+impl Drop for SoundFiles {
|
||||||
|
+ fn drop(&mut self) {
|
||||||
|
+ let _ = fs::remove_file(&self.standard);
|
||||||
|
+ let _ = fs::remove_file(&self.critical);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+fn write_new(path: &Path, content: &[u8]) -> io::Result<()> {
|
||||||
|
+ let mut out = OpenOptions::new().write(true).create_new(true).open(path)?;
|
||||||
|
+ out.write_all(content)
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+impl SoundFiles {
|
||||||
|
+ fn create_in(directory: &Path) -> io::Result<Self> {
|
||||||
|
+ let nonce = SystemTime::now().duration_since(UNIX_EPOCH)
|
||||||
|
+ .unwrap_or_default().as_nanos();
|
||||||
|
+ let prefix = format!("pamsim-{}-{nonce}", std::process::id());
|
||||||
|
+ let standard = directory.join(format!("{prefix}-alarm.wav"));
|
||||||
|
+ let critical = directory.join(format!("{prefix}-critical.wav"));
|
||||||
|
+ write_new(&standard, &wav(false))?;
|
||||||
|
+ if let Err(err) = write_new(&critical, &wav(true)) {
|
||||||
|
+ let _ = fs::remove_file(&standard);
|
||||||
|
+ return Err(err);
|
||||||
|
+ }
|
||||||
|
+ Ok(Self { standard, critical })
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ fn create() -> io::Result<Self> {
|
||||||
|
+ if let Some(runtime) = env::var_os("XDG_RUNTIME_DIR") {
|
||||||
|
+ if let Ok(files) = Self::create_in(Path::new(&runtime)) {
|
||||||
|
+ return Ok(files);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ Self::create_in(&env::temp_dir())
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+fn command_on_path(name: &str) -> bool {
|
||||||
|
+ env::var_os("PATH").is_some_and(|paths| {
|
||||||
|
+ env::split_paths(&paths).any(|dir| {
|
||||||
|
+ let candidate = dir.join(name);
|
||||||
|
+ if !candidate.is_file() { return false; }
|
||||||
|
+ #[cfg(unix)]
|
||||||
|
+ {
|
||||||
|
+ use std::os::unix::fs::PermissionsExt;
|
||||||
|
+ fs::metadata(&candidate).is_ok_and(|meta| meta.permissions().mode() & 0o111 != 0)
|
||||||
|
+ }
|
||||||
|
+ #[cfg(not(unix))]
|
||||||
|
+ { true }
|
||||||
|
+ })
|
||||||
|
+ })
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+/// Sound playback runs outside the GTK drawing callback. At most one short
|
||||||
|
+/// player process exists at a time; stopping or muting kills an active tone.
|
||||||
|
+pub struct AlarmAudio {
|
||||||
|
+ player: Option<&'static str>,
|
||||||
|
+ files: Option<SoundFiles>,
|
||||||
|
+ child: Option<Child>,
|
||||||
|
+ previous: AlarmLevel,
|
||||||
|
+ next_at: Instant,
|
||||||
|
+ error_reported: bool,
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+impl AlarmAudio {
|
||||||
|
+ pub fn new() -> Self {
|
||||||
|
+ let player = ["pw-play", "paplay"].into_iter().find(|name| command_on_path(name));
|
||||||
|
+ let files = if player.is_some() {
|
||||||
|
+ match SoundFiles::create() {
|
||||||
|
+ Ok(files) => Some(files),
|
||||||
|
+ Err(error) => {
|
||||||
|
+ eprintln!("PaMSim: cannot prepare alarm tones: {error}");
|
||||||
|
+ None
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ } else { None };
|
||||||
|
+ if player.is_none() {
|
||||||
|
+ eprintln!("PaMSim: alarm audio unavailable; install pipewire-utils (pw-play) on Fedora.");
|
||||||
|
+ }
|
||||||
|
+ Self {
|
||||||
|
+ player, files, child: None, previous: AlarmLevel::None,
|
||||||
|
+ next_at: Instant::now(), error_reported: false,
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ pub fn available(&self) -> bool {
|
||||||
|
+ self.player.is_some() && self.files.is_some()
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ fn stop_child(&mut self) {
|
||||||
|
+ if let Some(mut child) = self.child.take() {
|
||||||
|
+ let _ = child.kill();
|
||||||
|
+ let _ = child.wait();
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ fn reap(&mut self) {
|
||||||
|
+ if let Some(child) = self.child.as_mut() {
|
||||||
|
+ match child.try_wait() {
|
||||||
|
+ Ok(Some(status)) => {
|
||||||
|
+ self.child = None;
|
||||||
|
+ if !status.success() && !self.error_reported {
|
||||||
|
+ eprintln!("PaMSim: alarm sound player exited with {status}; check PipeWire and the output device.");
|
||||||
|
+ self.error_reported = true;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ Err(error) => {
|
||||||
|
+ self.child = None;
|
||||||
|
+ if !self.error_reported {
|
||||||
|
+ eprintln!("PaMSim: could not check alarm playback: {error}");
|
||||||
|
+ self.error_reported = true;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ Ok(None) => {}
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ fn play(&mut self, level: AlarmLevel) {
|
||||||
|
+ self.reap();
|
||||||
|
+ if self.child.is_some() { return; }
|
||||||
|
+ let (Some(player), Some(files)) = (self.player, self.files.as_ref()) else { return; };
|
||||||
|
+ let filename = if level == AlarmLevel::Critical { &files.critical } else { &files.standard };
|
||||||
|
+ match Command::new(player).arg(filename)
|
||||||
|
+ .stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null()).spawn()
|
||||||
|
+ {
|
||||||
|
+ Ok(child) => self.child = Some(child),
|
||||||
|
+ Err(error) if !self.error_reported => {
|
||||||
|
+ eprintln!("PaMSim: alarm sound playback failed: {error}");
|
||||||
|
+ self.error_reported = true;
|
||||||
|
+ }
|
||||||
|
+ Err(_) => {}
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /// Called from a 100-ms GLib timer, not the 250-Hz waveform simulator.
|
||||||
|
+ /// Critical rhythms: double tone every 1.5 s; other alarms: single tone
|
||||||
|
+ /// every 2.5 s. Stop promptly when muted or all alarm states clear.
|
||||||
|
+ pub fn update(&mut self, level: AlarmLevel, enabled: bool) {
|
||||||
|
+ self.reap();
|
||||||
|
+ if !enabled || level == AlarmLevel::None {
|
||||||
|
+ self.stop_child();
|
||||||
|
+ self.previous = AlarmLevel::None;
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ let now = Instant::now();
|
||||||
|
+ if level != self.previous {
|
||||||
|
+ self.stop_child();
|
||||||
|
+ self.previous = level;
|
||||||
|
+ self.next_at = now;
|
||||||
|
+ }
|
||||||
|
+ if now >= self.next_at {
|
||||||
|
+ self.play(level);
|
||||||
|
+ self.next_at = now + if level == AlarmLevel::Critical {
|
||||||
|
+ Duration::from_millis(1500)
|
||||||
|
+ } else { Duration::from_millis(2500) };
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /// Manual test is independent of the audible-alarm enable checkbox.
|
||||||
|
+ pub fn test(&mut self) {
|
||||||
|
+ self.stop_child();
|
||||||
|
+ self.play(AlarmLevel::Standard);
|
||||||
|
+ self.next_at = Instant::now() + Duration::from_millis(2500);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+impl Drop for AlarmAudio {
|
||||||
|
+ fn drop(&mut self) {
|
||||||
|
+ self.stop_child();
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[cfg(test)]
|
||||||
|
+mod tests {
|
||||||
|
+ use super::*;
|
||||||
|
+ use crate::model::{AlarmSettings, EcgRhythm};
|
||||||
|
+
|
||||||
|
+ #[test]
|
||||||
|
+ fn valid_wav_files_and_distinct_tone_patterns() {
|
||||||
|
+ for critical in [false, true] {
|
||||||
|
+ let bytes = wav(critical);
|
||||||
|
+ assert_eq!(&bytes[..4], b"RIFF");
|
||||||
|
+ assert_eq!(&bytes[8..12], b"WAVE");
|
||||||
|
+ assert_eq!(&bytes[36..40], b"data");
|
||||||
|
+ assert_eq!(u32::from_le_bytes(bytes[4..8].try_into().unwrap()) as usize + 8, bytes.len());
|
||||||
|
+ assert_eq!(u32::from_le_bytes(bytes[40..44].try_into().unwrap()) as usize + 44, bytes.len());
|
||||||
|
+ }
|
||||||
|
+ assert!(wav(true).len() > wav(false).len());
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ #[test]
|
||||||
|
+ fn normal_signals_are_silent_and_numeric_limit_alarms_beep() {
|
||||||
|
+ let mut p = Parameters::default();
|
||||||
|
+ let sim = Simulator::new(&p);
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
+ p.alarms = AlarmSettings::adult();
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
+ p.heart_rate = 110;
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::Standard);
|
||||||
|
+ p.show_ecg = false;
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ #[test]
|
||||||
|
+ fn rhythms_are_critical_and_sensor_issues_are_standard() {
|
||||||
|
+ let mut p = Parameters::default();
|
||||||
|
+ p.spo2_sensor_attached = false;
|
||||||
|
+ let sim = Simulator::new(&p);
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::Standard);
|
||||||
|
+ p.spo2_sensor_attached = true;
|
||||||
|
+ p.ecg_rhythm = EcgRhythm::VentricularFibrillation;
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::Critical);
|
||||||
|
+ p.ecg_rhythm = EcgRhythm::Asystole;
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::Critical);
|
||||||
|
+ p.show_ecg = false;
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::Standard); // no SpO2 reading
|
||||||
|
+ p.show_spo2 = false;
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ #[test]
|
||||||
|
+ fn no_nibp_measurement_does_not_trigger_numeric_alarm() {
|
||||||
|
+ let mut p = Parameters::default();
|
||||||
|
+ p.alarms.nibp_sys.lower = Some(120);
|
||||||
|
+ let sim = Simulator::new(&p);
|
||||||
|
+ assert!(sim.nibp().reading().is_none());
|
||||||
|
+ assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff -ruN a/src/main.rs b/src/main.rs
|
||||||
|
--- a/src/main.rs 2026-11-12 12:48:16.000000000 +0000
|
||||||
|
+++ b/src/main.rs 2026-11-12 13:27:14.335943186 +0000
|
||||||
|
@@ -1,3 +1,4 @@
|
||||||
|
+mod alarm;
|
||||||
|
mod model;
|
||||||
|
mod nibp;
|
||||||
|
mod render;
|
||||||
|
diff -ruN a/src/model.rs b/src/model.rs
|
||||||
|
--- a/src/model.rs 2026-11-12 12:58:26.000000000 +0000
|
||||||
|
+++ b/src/model.rs 2026-11-12 13:27:14.337421392 +0000
|
||||||
|
@@ -201,6 +201,7 @@
|
||||||
|
pub struct Parameters {
|
||||||
|
pub patient_name: String, // displayed in the monitor header, blank = generic title
|
||||||
|
pub alarms: AlarmSettings,
|
||||||
|
+ pub audible_alarms: bool, // mute only the sound, never the visual alarms
|
||||||
|
pub ecg_rhythm: EcgRhythm,
|
||||||
|
pub heart_rate: i32, // bpm, organized electrical rate; not mechanical pulse rate
|
||||||
|
pub pulse_conduction: PulseConduction,
|
||||||
|
@@ -275,6 +276,7 @@
|
||||||
|
Self {
|
||||||
|
patient_name: String::new(),
|
||||||
|
alarms: AlarmSettings::default(),
|
||||||
|
+ audible_alarms: true,
|
||||||
|
ecg_rhythm: EcgRhythm::Sinus,
|
||||||
|
heart_rate: 75,
|
||||||
|
pulse_conduction: PulseConduction::OneToOne,
|
||||||
|
diff -ruN a/src/ui.rs b/src/ui.rs
|
||||||
|
--- a/src/ui.rs 2026-11-12 12:59:46.000000000 +0000
|
||||||
|
+++ b/src/ui.rs 2026-11-12 13:27:14.339539904 +0000
|
||||||
|
@@ -1,13 +1,14 @@
|
||||||
|
//! GTK4 Admin and Monitor windows; all callbacks run on the GTK main thread.
|
||||||
|
use std::cell::{Cell, RefCell};
|
||||||
|
use std::rc::Rc;
|
||||||
|
-use std::time::Instant;
|
||||||
|
+use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
use gtk::gdk;
|
||||||
|
use gtk::glib;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
use gtk::{Application, ApplicationWindow, Orientation};
|
||||||
|
|
||||||
|
+use crate::alarm::{self, AlarmAudio};
|
||||||
|
use crate::model::{AlarmLimits, AlarmSettings, ArterialShape, CapnoShape, EcgRhythm, Parameters, PulseConduction, Spo2Quality};
|
||||||
|
use crate::render;
|
||||||
|
use crate::simulation::Simulator;
|
||||||
|
@@ -25,8 +26,18 @@
|
||||||
|
pub fn create_windows(app: &Application) {
|
||||||
|
let parameters = Rc::new(RefCell::new(Parameters::default()));
|
||||||
|
let simulator = Rc::new(RefCell::new(Simulator::new(¶meters.borrow())));
|
||||||
|
+ let audio = Rc::new(RefCell::new(AlarmAudio::new()));
|
||||||
|
let monitor = create_monitor(app, parameters.clone(), simulator.clone());
|
||||||
|
- let admin = create_admin(app, parameters, simulator, &monitor);
|
||||||
|
+ let admin = create_admin(app, parameters.clone(), simulator.clone(), &monitor, audio.clone());
|
||||||
|
+
|
||||||
|
+ // Alarm evaluation has its own 100-ms timer; waveform drawing never blocks
|
||||||
|
+ // on sound playback. Audio also continues if the monitor is not mapped.
|
||||||
|
+ glib::timeout_add_local(Duration::from_millis(100), move || {
|
||||||
|
+ let config = parameters.borrow();
|
||||||
|
+ let current = alarm::level(&config, &simulator.borrow());
|
||||||
|
+ audio.borrow_mut().update(current, config.audible_alarms);
|
||||||
|
+ glib::ControlFlow::Continue
|
||||||
|
+ });
|
||||||
|
|
||||||
|
// Present monitor first, then leave controls in the foreground.
|
||||||
|
monitor.present();
|
||||||
|
@@ -90,7 +101,8 @@
|
||||||
|
|
||||||
|
fn create_admin(app: &Application, params: SharedParams,
|
||||||
|
simulator: Rc<RefCell<Simulator>>,
|
||||||
|
- monitor: &ApplicationWindow) -> ApplicationWindow {
|
||||||
|
+ monitor: &ApplicationWindow,
|
||||||
|
+ audio: Rc<RefCell<AlarmAudio>>) -> ApplicationWindow {
|
||||||
|
let window = ApplicationWindow::builder()
|
||||||
|
.application(app)
|
||||||
|
.title(concat!("Patient Monitor — Admin v", env!("CARGO_PKG_VERSION")))
|
||||||
|
@@ -131,6 +143,28 @@
|
||||||
|
preset_row.append(&preset_caption);
|
||||||
|
preset_row.append(&preset_dropdown);
|
||||||
|
controls.append(&preset_row);
|
||||||
|
+
|
||||||
|
+ // Sound control is independent of visual alarm limits and of the rhythm.
|
||||||
|
+ let sound_row = gtk::Box::new(Orientation::Horizontal, 12);
|
||||||
|
+ let audible = gtk::CheckButton::with_label("Audible alarms");
|
||||||
|
+ audible.set_active(params.borrow().audible_alarms);
|
||||||
|
+ audible.connect_toggled({
|
||||||
|
+ let params = params.clone();
|
||||||
|
+ move |button| params.borrow_mut().audible_alarms = button.is_active()
|
||||||
|
+ });
|
||||||
|
+ sound_row.append(&audible);
|
||||||
|
+ let test_sound = gtk::Button::with_label("Test tone");
|
||||||
|
+ test_sound.connect_clicked({
|
||||||
|
+ let audio = audio.clone();
|
||||||
|
+ move |_| audio.borrow_mut().test()
|
||||||
|
+ });
|
||||||
|
+ sound_row.append(&test_sound);
|
||||||
|
+ if !audio.borrow().available() {
|
||||||
|
+ let missing = gtk::Label::new(Some("Audio unavailable — install pipewire-utils"));
|
||||||
|
+ missing.set_xalign(0.0);
|
||||||
|
+ sound_row.append(&missing);
|
||||||
|
+ }
|
||||||
|
+ controls.append(&sound_row);
|
||||||
|
let updating_preset = Rc::new(Cell::new(false));
|
||||||
|
let mut alarm_editors: Vec<(AlarmEditor, fn(&AlarmSettings) -> AlarmLimits)> = Vec::new();
|
||||||
|
|
||||||
2
patient-monitor-simulation/Cargo.lock
generated
2
patient-monitor-simulation/Cargo.lock
generated
|
|
@ -438,7 +438,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "patient-monitor-simulation"
|
name = "patient-monitor-simulation"
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gtk4",
|
"gtk4",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "patient-monitor-simulation"
|
name = "patient-monitor-simulation"
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
description = "Synthetic patient-monitor simulation for teaching (not for clinical use)"
|
description = "Synthetic patient-monitor simulation for teaching (not for clinical use)"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ Ein mit Rust und GTK4 entwickelter Patient*innenmonitor-Simulator mit zwei Fenst
|
||||||
## Installation, Kompilierung und Start unter Fedora
|
## Installation, Kompilierung und Start unter Fedora
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo dnf install rust cargo gcc pkgconf-pkg-config gtk4-devel
|
sudo dnf install rust cargo gcc pkgconf-pkg-config gtk4-devel pipewire-utils
|
||||||
cargo test
|
cargo test
|
||||||
cargo run --release
|
cargo run --release
|
||||||
```
|
```
|
||||||
|
|
@ -43,6 +43,39 @@ Mit **F11** wird der Vollbildmodus aktiviert bzw. umgeschaltet, mit **Esc** wird
|
||||||
Unter Wayland sollte das Fenster vor dem Wechsel in den Vollbildmodus auf den gewünschten Präsentationsbildschirm verschoben werden.
|
Unter Wayland sollte das Fenster vor dem Wechsel in den Vollbildmodus auf den gewünschten Präsentationsbildschirm verschoben werden.
|
||||||
Der Vollbildmodus sperrt den Computer nicht gegen andere Eingaben.
|
Der Vollbildmodus sperrt den Computer nicht gegen andere Eingaben.
|
||||||
|
|
||||||
|
## Akustische Alarme (v0.5.3)
|
||||||
|
|
||||||
|
Die akustische Alarmierung ist **standardmäßig eingeschaltet**. Im
|
||||||
|
Admin-Fenster lässt sie sich mit **Audible alarms** aktivieren bzw. stummschalten.
|
||||||
|
Mit **Test tone** kann die Tonausgabe unabhängig von der Stummschaltung geprüft
|
||||||
|
werden. Die optischen Alarme blinken bei stummgeschalteter Tonausgabe weiterhin.
|
||||||
|
|
||||||
|
- **Kritische Rhythmusalarme:** VT, PVT, Kammerflimmern und Asystolie lösen
|
||||||
|
einen Doppelton aus (zweimal kurz 880 Hz), der ungefähr alle 1,5 Sekunden
|
||||||
|
wiederholt wird.
|
||||||
|
- **Numerische und technische Alarme:** Grenzwertüberschreitungen sowie
|
||||||
|
**NO SENSOR** und **NO READING** lösen einen kurzen Ton mit 700 Hz aus,
|
||||||
|
der ungefähr alle 2,5 Sekunden wiederholt wird.
|
||||||
|
- Kritische Alarme haben Vorrang. Auch bei mehreren gleichzeitig aktiven
|
||||||
|
Alarmen wird nur eine Tonfolge ausgegeben. Bei behobenem Alarm oder
|
||||||
|
Stummschaltung verstummt die Ausgabe. Ausgeblendete Monitorbereiche
|
||||||
|
lösen keine akustischen Alarme aus.
|
||||||
|
- Nicht verfügbare Messwerte, etwa NIBP vor der ersten abgeschlossenen Messung,
|
||||||
|
lösen keinen numerischen Grenzwertalarm aus. Eine laufende NIBP-Messung
|
||||||
|
selbst ist kein Alarm. Die Audioausgabe wird unabhängig von der Darstellung
|
||||||
|
der Kurven verarbeitet.
|
||||||
|
|
||||||
|
Unter Fedora wird **`pw-play`** aus dem Paket `pipewire-utils` verwendet,
|
||||||
|
alternativ **`paplay`**. Es sind weder zusätzliche Rust-Bibliotheken noch
|
||||||
|
mitzuliefernde Audiodateien notwendig: Das Programm erzeugt seine WAV-Töne
|
||||||
|
zur Laufzeit. Falls kein Wiedergabeprogramm verfügbar ist, erscheint im
|
||||||
|
Admin-Fenster ein entsprechender Hinweis; der Monitor bleibt funktionstüchtig.
|
||||||
|
Wiedergabegerät und Lautstärke werden über die Systemeinstellungen verwaltet.
|
||||||
|
|
||||||
|
**Wichtig:** Diese didaktischen Tonsignale entsprechen nicht den Anforderungen
|
||||||
|
an Medizinproduktealarme (insbesondere IEC 60601-1-8) und dürfen nicht zur
|
||||||
|
klinischen Überwachung verwendet werden.
|
||||||
|
|
||||||
## Numerische Alarmgrenzen (seit v0.4.0; Anordnung und Voreinstellungen seit v0.4.1)
|
## Numerische Alarmgrenzen (seit v0.4.0; Anordnung und Voreinstellungen seit v0.4.1)
|
||||||
|
|
||||||
Für jeden angezeigten numerischen Messwert können im zugehörigen Admin-Bereich **unabhängige optionale untere (↓) und obere (↑) Alarmgrenzen** festgelegt werden.
|
Für jeden angezeigten numerischen Messwert können im zugehörigen Admin-Bereich **unabhängige optionale untere (↓) und obere (↑) Alarmgrenzen** festgelegt werden.
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,22 @@
|
||||||
--- README.de.md 2026-11-12 13:05:10.000000000 +0000
|
--- README.de.md 2026-11-12 13:10:05.131166243 +0000
|
||||||
+++ README.de.md 2026-11-12 13:10:05.131166243 +0000
|
+++ README.de.md 2026-11-12 13:28:21.812109359 +0000
|
||||||
@@ -1,4 +1,4 @@
|
@@ -1,4 +1,4 @@
|
||||||
-# Patient Monitor Simulation (PaMSim) — v0.5.1
|
-# Patient Monitor Simulation (PaMSim) — v0.5.2
|
||||||
+# Patient Monitor Simulation (PaMSim) — v0.5.2
|
+# Patient Monitor Simulation (PaMSim) — v0.5.3
|
||||||
|
|
||||||
Ein mit Rust und GTK4 entwickelter Patient*innenmonitor-Simulator mit zwei Fenstern für die Lehre unter Fedora Linux.
|
Ein mit Rust und GTK4 entwickelter Patient*innenmonitor-Simulator mit zwei Fenstern für die Lehre unter Fedora Linux.
|
||||||
|
|
||||||
|
@@ -412,3 +445,13 @@
|
||||||
|
die anderen Wertefelder vertikal zusammenzudrängen. Beim Ausblenden einzelner
|
||||||
|
Monitorbereiche werden beide Spalten gemeinsam neu aufgeteilt.
|
||||||
|
Das Messverhalten und die Alarmfunktionen bleiben unverändert.
|
||||||
|
+
|
||||||
|
+## v0.5.3 — Akustische Alarmierung
|
||||||
|
+
|
||||||
|
+- Alarmausgabe mit `pw-play` (PipeWire) bzw. `paplay` (Fallback), ohne neue
|
||||||
|
+ Rust-Bibliotheken.
|
||||||
|
+- Admin-Bedienelemente zum Stummschalten und für einen Testton.
|
||||||
|
+- Unterschiedliche Töne für kritische Rhythmusalarme und Standard- bzw.
|
||||||
|
+ technische Alarme; kritische Alarme haben Vorrang.
|
||||||
|
+- Die Audioausgabe ist von der Kurvendarstellung entkoppelt.
|
||||||
|
+- Bisherige optische Alarme und Simulationsfunktionen bleiben unverändert.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# Patient Monitor Simulation (PaMSim) — v0.5.2
|
# Patient Monitor Simulation (PaMSim) — v0.5.3
|
||||||
|
|
||||||
A two-window, Rust/GTK4 patient-monitor simulator for teaching on Fedora Linux.
|
A two-window, Rust/GTK4 patient-monitor simulator for teaching on Fedora Linux.
|
||||||
|
|
||||||
|
|
@ -9,7 +9,7 @@ A two-window, Rust/GTK4 patient-monitor simulator for teaching on Fedora Linux.
|
||||||
## Build and run on Fedora
|
## Build and run on Fedora
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo dnf install rust cargo gcc pkgconf-pkg-config gtk4-devel
|
sudo dnf install rust cargo gcc pkgconf-pkg-config gtk4-devel pipewire-utils
|
||||||
cargo test
|
cargo test
|
||||||
cargo run --release
|
cargo run --release
|
||||||
```
|
```
|
||||||
|
|
@ -48,6 +48,35 @@ The monitor can be resized and toggled fullscreen with **F11**; **Esc** exits
|
||||||
fullscreen. On Wayland, move the monitor to the presentation screen before
|
fullscreen. On Wayland, move the monitor to the presentation screen before
|
||||||
activating fullscreen. Fullscreen does not lock down the computer.
|
activating fullscreen. Fullscreen does not lock down the computer.
|
||||||
|
|
||||||
|
## Audible alarms (v0.5.3)
|
||||||
|
|
||||||
|
Sound is **enabled by default**. The Admin window has an **Audible alarms**
|
||||||
|
checkbox for muting and a **Test tone** button (works even while muted).
|
||||||
|
Visual alarms keep blinking normally when sound is off.
|
||||||
|
|
||||||
|
- **Critical rhythm alarm:** VT, PVT, VF and asystole produce a double beep
|
||||||
|
(two short 880 Hz tones), repeated approximately every 1.5 seconds.
|
||||||
|
- **Numerical and SpO₂ technical alarms:** out-of-range values, **NO SENSOR**
|
||||||
|
and **NO READING** produce a single 700 Hz beep, repeated approximately
|
||||||
|
every 2.5 seconds.
|
||||||
|
- Critical alarms have priority: only one tone pattern is played even if
|
||||||
|
multiple alarms are active. The sound stops when all alarms clear or when
|
||||||
|
the checkbox is unchecked. Alarms on hidden monitor channels are excluded.
|
||||||
|
- Values not yet available (e.g. NIBP before a completed measurement) do not
|
||||||
|
trigger numerical limit alarms. The cuff measurement cycle by itself is not
|
||||||
|
an alarm. Audio playback is separate from waveform rendering and simulation.
|
||||||
|
|
||||||
|
On Fedora, sound is played through **`pw-play`** from `pipewire-utils`, with
|
||||||
|
**`paplay`** as a fallback. No additional Rust crates or sound files are needed:
|
||||||
|
the application creates its own short WAV tones at runtime. If neither player
|
||||||
|
is installed, Admin reports that audio is unavailable; the monitor continues
|
||||||
|
to work normally. `Test tone` helps verify the desktop audio output. The
|
||||||
|
application uses the system output device and mixer volume.
|
||||||
|
|
||||||
|
**Important:** These simple teaching tones do not comply with medical-device
|
||||||
|
alarm standards (including IEC 60601-1-8) and must never be relied on for
|
||||||
|
clinical monitoring.
|
||||||
|
|
||||||
## Numerical alarm limits (v0.4.0; layout and presets updated in v0.4.1)
|
## Numerical alarm limits (v0.4.0; layout and presets updated in v0.4.1)
|
||||||
|
|
||||||
Each displayed numeric measurement has an **independent optional lower (↓) and
|
Each displayed numeric measurement has an **independent optional lower (↓) and
|
||||||
|
|
@ -411,3 +440,12 @@ The left waveform column and right numeric column now share the same row grid.
|
||||||
NIBP reserves an empty cell in the left waveform column instead of shortening
|
NIBP reserves an empty cell in the left waveform column instead of shortening
|
||||||
the other numeric rows. Hiding any channel reflows both columns together.
|
the other numeric rows. Hiding any channel reflows both columns together.
|
||||||
No NIBP measurement logic or alarm behavior was changed.
|
No NIBP measurement logic or alarm behavior was changed.
|
||||||
|
|
||||||
|
## v0.5.3 — Audible alarm output
|
||||||
|
|
||||||
|
- Alarm-tone playback through Fedora PipeWire (`pw-play`) or PulseAudio
|
||||||
|
compatibility (`paplay`), without any new Rust library dependencies.
|
||||||
|
- Admin controls to mute/unmute alarms or play a test tone.
|
||||||
|
- Distinct critical-rhythm and standard/technical patterns; critical priority.
|
||||||
|
- Audio keeps running independently of the monitor's drawing callback.
|
||||||
|
- Visual alarms and existing physiological simulation remain unchanged.
|
||||||
|
|
|
||||||
364
patient-monitor-simulation/src/alarm.rs
Normal file
364
patient-monitor-simulation/src/alarm.rs
Normal file
|
|
@ -0,0 +1,364 @@
|
||||||
|
//! Audible teaching alarms. This is not a clinical alarm system.
|
||||||
|
//!
|
||||||
|
//! The decision uses the same available readings, visibility settings and limits
|
||||||
|
//! as the monitor. Sound is played using Fedora's PipeWire command-line player
|
||||||
|
//! (or paplay) without adding a native audio-library dependency to Cargo.
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
use std::fs::{self, OpenOptions};
|
||||||
|
use std::io::{self, Write};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process::{Child, Command, Stdio};
|
||||||
|
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
use crate::model::{AlarmLimits, AlarmState, Parameters, PulseConduction, Spo2Status};
|
||||||
|
use crate::simulation::Simulator;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum AlarmLevel {
|
||||||
|
#[default]
|
||||||
|
None,
|
||||||
|
Standard,
|
||||||
|
Critical,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn outside(limits: AlarmLimits, value: Option<i32>) -> bool {
|
||||||
|
limits.evaluate(value) != AlarmState::Normal
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Only parameters actually shown on the monitor contribute audible alarms.
|
||||||
|
/// Missing numeric values do not trigger threshold alarms, but missing SpO2
|
||||||
|
/// readings and disconnected sensors are explicit technical alarms.
|
||||||
|
pub fn level(p: &Parameters, sim: &Simulator) -> AlarmLevel {
|
||||||
|
let mut result = AlarmLevel::None;
|
||||||
|
let hr = (p.ecg_rhythm.has_qrs() && p.heart_rate > 0).then_some(p.heart_rate);
|
||||||
|
let captured = p.ecg_rhythm.can_generate_pulse()
|
||||||
|
&& p.heart_rate > 0
|
||||||
|
&& p.pulse_conduction != PulseConduction::None;
|
||||||
|
let pr = if captured { sim.pulse_rate() } else { None };
|
||||||
|
|
||||||
|
if p.show_ecg {
|
||||||
|
if p.ecg_rhythm.rhythm_alarm().is_some() {
|
||||||
|
return AlarmLevel::Critical;
|
||||||
|
}
|
||||||
|
if outside(p.alarms.hr, hr) {
|
||||||
|
result = AlarmLevel::Standard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.show_spo2 {
|
||||||
|
let status = p.spo2_status_at_quality(pr, sim.poor_signal_lost(), sim.spo2_quality(p));
|
||||||
|
if status != Spo2Status::Available
|
||||||
|
|| outside(p.alarms.spo2, Some(p.spo2))
|
||||||
|
|| outside(p.alarms.pr, pr)
|
||||||
|
{
|
||||||
|
result = AlarmLevel::Standard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.show_art {
|
||||||
|
let (sys, dia, map) = sim.displayed_art_pressures(p, captured);
|
||||||
|
if outside(p.alarms.art_sys, sys)
|
||||||
|
|| outside(p.alarms.art_dia, dia)
|
||||||
|
|| outside(p.alarms.art_map, map)
|
||||||
|
|| outside(p.alarms.ppv, Some(p.pulse_pressure_variation))
|
||||||
|
{
|
||||||
|
result = AlarmLevel::Standard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.show_capno && (outside(p.alarms.etco2, Some(p.etco2))
|
||||||
|
|| outside(p.alarms.rr, Some(p.respiratory_rate)))
|
||||||
|
{
|
||||||
|
result = AlarmLevel::Standard;
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.show_nibp {
|
||||||
|
let reading = sim.nibp().reading();
|
||||||
|
if outside(p.alarms.nibp_sys, reading.map(|r| r.systolic))
|
||||||
|
|| outside(p.alarms.nibp_dia, reading.map(|r| r.diastolic))
|
||||||
|
|| outside(p.alarms.nibp_map, reading.map(|r| r.mean()))
|
||||||
|
{
|
||||||
|
result = AlarmLevel::Standard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Very short, original synthesized sine beeps; mono PCM16 WAV.
|
||||||
|
fn wav(critical: bool) -> Vec<u8> {
|
||||||
|
const SAMPLE_RATE: u32 = 44_100;
|
||||||
|
let segments: &[(f64, f64)] = if critical {
|
||||||
|
&[(880.0, 0.16), (0.0, 0.09), (880.0, 0.16)]
|
||||||
|
} else {
|
||||||
|
&[(700.0, 0.18)]
|
||||||
|
};
|
||||||
|
let samples: usize = segments.iter()
|
||||||
|
.map(|(_, seconds)| (seconds * f64::from(SAMPLE_RATE)).round() as usize)
|
||||||
|
.sum();
|
||||||
|
let size = (samples * 2) as u32;
|
||||||
|
let mut bytes = Vec::with_capacity(44 + size as usize);
|
||||||
|
bytes.extend_from_slice(b"RIFF");
|
||||||
|
bytes.extend_from_slice(&(size + 36).to_le_bytes());
|
||||||
|
bytes.extend_from_slice(b"WAVEfmt ");
|
||||||
|
bytes.extend_from_slice(&16_u32.to_le_bytes()); // PCM format chunk
|
||||||
|
bytes.extend_from_slice(&1_u16.to_le_bytes()); // PCM
|
||||||
|
bytes.extend_from_slice(&1_u16.to_le_bytes()); // mono
|
||||||
|
bytes.extend_from_slice(&SAMPLE_RATE.to_le_bytes());
|
||||||
|
bytes.extend_from_slice(&(SAMPLE_RATE * 2).to_le_bytes()); // byte rate
|
||||||
|
bytes.extend_from_slice(&2_u16.to_le_bytes()); // block align
|
||||||
|
bytes.extend_from_slice(&16_u16.to_le_bytes()); // bits per sample
|
||||||
|
bytes.extend_from_slice(b"data");
|
||||||
|
bytes.extend_from_slice(&size.to_le_bytes());
|
||||||
|
|
||||||
|
for &(frequency, seconds) in segments {
|
||||||
|
let count = (seconds * f64::from(SAMPLE_RATE)).round() as usize;
|
||||||
|
for i in 0..count {
|
||||||
|
let t = i as f64 / f64::from(SAMPLE_RATE);
|
||||||
|
let remaining = (count - i) as f64 / f64::from(SAMPLE_RATE);
|
||||||
|
let envelope = (t / 0.012).min(1.0).min(remaining / 0.012).max(0.0);
|
||||||
|
let value = if frequency > 0.0 {
|
||||||
|
(2.0 * std::f64::consts::PI * frequency * t).sin() * envelope * 0.17
|
||||||
|
} else { 0.0 };
|
||||||
|
let sample = (value * f64::from(i16::MAX)).round() as i16;
|
||||||
|
bytes.extend_from_slice(&sample.to_le_bytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SoundFiles {
|
||||||
|
standard: PathBuf,
|
||||||
|
critical: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for SoundFiles {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let _ = fs::remove_file(&self.standard);
|
||||||
|
let _ = fs::remove_file(&self.critical);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_new(path: &Path, content: &[u8]) -> io::Result<()> {
|
||||||
|
let mut out = OpenOptions::new().write(true).create_new(true).open(path)?;
|
||||||
|
out.write_all(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SoundFiles {
|
||||||
|
fn create_in(directory: &Path) -> io::Result<Self> {
|
||||||
|
let nonce = SystemTime::now().duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap_or_default().as_nanos();
|
||||||
|
let prefix = format!("pamsim-{}-{nonce}", std::process::id());
|
||||||
|
let standard = directory.join(format!("{prefix}-alarm.wav"));
|
||||||
|
let critical = directory.join(format!("{prefix}-critical.wav"));
|
||||||
|
write_new(&standard, &wav(false))?;
|
||||||
|
if let Err(err) = write_new(&critical, &wav(true)) {
|
||||||
|
let _ = fs::remove_file(&standard);
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
Ok(Self { standard, critical })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create() -> io::Result<Self> {
|
||||||
|
if let Some(runtime) = env::var_os("XDG_RUNTIME_DIR") {
|
||||||
|
if let Ok(files) = Self::create_in(Path::new(&runtime)) {
|
||||||
|
return Ok(files);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Self::create_in(&env::temp_dir())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn command_on_path(name: &str) -> bool {
|
||||||
|
env::var_os("PATH").is_some_and(|paths| {
|
||||||
|
env::split_paths(&paths).any(|dir| {
|
||||||
|
let candidate = dir.join(name);
|
||||||
|
if !candidate.is_file() { return false; }
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
fs::metadata(&candidate).is_ok_and(|meta| meta.permissions().mode() & 0o111 != 0)
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
{ true }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sound playback runs outside the GTK drawing callback. At most one short
|
||||||
|
/// player process exists at a time; stopping or muting kills an active tone.
|
||||||
|
pub struct AlarmAudio {
|
||||||
|
player: Option<&'static str>,
|
||||||
|
files: Option<SoundFiles>,
|
||||||
|
child: Option<Child>,
|
||||||
|
previous: AlarmLevel,
|
||||||
|
next_at: Instant,
|
||||||
|
error_reported: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AlarmAudio {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let player = ["pw-play", "paplay"].into_iter().find(|name| command_on_path(name));
|
||||||
|
let files = if player.is_some() {
|
||||||
|
match SoundFiles::create() {
|
||||||
|
Ok(files) => Some(files),
|
||||||
|
Err(error) => {
|
||||||
|
eprintln!("PaMSim: cannot prepare alarm tones: {error}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { None };
|
||||||
|
if player.is_none() {
|
||||||
|
eprintln!("PaMSim: alarm audio unavailable; install pipewire-utils (pw-play) on Fedora.");
|
||||||
|
}
|
||||||
|
Self {
|
||||||
|
player, files, child: None, previous: AlarmLevel::None,
|
||||||
|
next_at: Instant::now(), error_reported: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn available(&self) -> bool {
|
||||||
|
self.player.is_some() && self.files.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stop_child(&mut self) {
|
||||||
|
if let Some(mut child) = self.child.take() {
|
||||||
|
let _ = child.kill();
|
||||||
|
let _ = child.wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reap(&mut self) {
|
||||||
|
if let Some(child) = self.child.as_mut() {
|
||||||
|
match child.try_wait() {
|
||||||
|
Ok(Some(status)) => {
|
||||||
|
self.child = None;
|
||||||
|
if !status.success() && !self.error_reported {
|
||||||
|
eprintln!("PaMSim: alarm sound player exited with {status}; check PipeWire and the output device.");
|
||||||
|
self.error_reported = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
self.child = None;
|
||||||
|
if !self.error_reported {
|
||||||
|
eprintln!("PaMSim: could not check alarm playback: {error}");
|
||||||
|
self.error_reported = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(None) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn play(&mut self, level: AlarmLevel) {
|
||||||
|
self.reap();
|
||||||
|
if self.child.is_some() { return; }
|
||||||
|
let (Some(player), Some(files)) = (self.player, self.files.as_ref()) else { return; };
|
||||||
|
let filename = if level == AlarmLevel::Critical { &files.critical } else { &files.standard };
|
||||||
|
match Command::new(player).arg(filename)
|
||||||
|
.stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null()).spawn()
|
||||||
|
{
|
||||||
|
Ok(child) => self.child = Some(child),
|
||||||
|
Err(error) if !self.error_reported => {
|
||||||
|
eprintln!("PaMSim: alarm sound playback failed: {error}");
|
||||||
|
self.error_reported = true;
|
||||||
|
}
|
||||||
|
Err(_) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called from a 100-ms GLib timer, not the 250-Hz waveform simulator.
|
||||||
|
/// Critical rhythms: double tone every 1.5 s; other alarms: single tone
|
||||||
|
/// every 2.5 s. Stop promptly when muted or all alarm states clear.
|
||||||
|
pub fn update(&mut self, level: AlarmLevel, enabled: bool) {
|
||||||
|
self.reap();
|
||||||
|
if !enabled || level == AlarmLevel::None {
|
||||||
|
self.stop_child();
|
||||||
|
self.previous = AlarmLevel::None;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let now = Instant::now();
|
||||||
|
if level != self.previous {
|
||||||
|
self.stop_child();
|
||||||
|
self.previous = level;
|
||||||
|
self.next_at = now;
|
||||||
|
}
|
||||||
|
if now >= self.next_at {
|
||||||
|
self.play(level);
|
||||||
|
self.next_at = now + if level == AlarmLevel::Critical {
|
||||||
|
Duration::from_millis(1500)
|
||||||
|
} else { Duration::from_millis(2500) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Manual test is independent of the audible-alarm enable checkbox.
|
||||||
|
pub fn test(&mut self) {
|
||||||
|
self.stop_child();
|
||||||
|
self.play(AlarmLevel::Standard);
|
||||||
|
self.next_at = Instant::now() + Duration::from_millis(2500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for AlarmAudio {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.stop_child();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::model::{AlarmSettings, EcgRhythm};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn valid_wav_files_and_distinct_tone_patterns() {
|
||||||
|
for critical in [false, true] {
|
||||||
|
let bytes = wav(critical);
|
||||||
|
assert_eq!(&bytes[..4], b"RIFF");
|
||||||
|
assert_eq!(&bytes[8..12], b"WAVE");
|
||||||
|
assert_eq!(&bytes[36..40], b"data");
|
||||||
|
assert_eq!(u32::from_le_bytes(bytes[4..8].try_into().unwrap()) as usize + 8, bytes.len());
|
||||||
|
assert_eq!(u32::from_le_bytes(bytes[40..44].try_into().unwrap()) as usize + 44, bytes.len());
|
||||||
|
}
|
||||||
|
assert!(wav(true).len() > wav(false).len());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn normal_signals_are_silent_and_numeric_limit_alarms_beep() {
|
||||||
|
let mut p = Parameters::default();
|
||||||
|
let sim = Simulator::new(&p);
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
p.alarms = AlarmSettings::adult();
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
p.heart_rate = 110;
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::Standard);
|
||||||
|
p.show_ecg = false;
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rhythms_are_critical_and_sensor_issues_are_standard() {
|
||||||
|
let mut p = Parameters::default();
|
||||||
|
p.spo2_sensor_attached = false;
|
||||||
|
let sim = Simulator::new(&p);
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::Standard);
|
||||||
|
p.spo2_sensor_attached = true;
|
||||||
|
p.ecg_rhythm = EcgRhythm::VentricularFibrillation;
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::Critical);
|
||||||
|
p.ecg_rhythm = EcgRhythm::Asystole;
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::Critical);
|
||||||
|
p.show_ecg = false;
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::Standard); // no SpO2 reading
|
||||||
|
p.show_spo2 = false;
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_nibp_measurement_does_not_trigger_numeric_alarm() {
|
||||||
|
let mut p = Parameters::default();
|
||||||
|
p.alarms.nibp_sys.lower = Some(120);
|
||||||
|
let sim = Simulator::new(&p);
|
||||||
|
assert!(sim.nibp().reading().is_none());
|
||||||
|
assert_eq!(level(&p, &sim), AlarmLevel::None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
mod alarm;
|
||||||
mod model;
|
mod model;
|
||||||
mod nibp;
|
mod nibp;
|
||||||
mod render;
|
mod render;
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,7 @@ impl AlarmSettings {
|
||||||
pub struct Parameters {
|
pub struct Parameters {
|
||||||
pub patient_name: String, // displayed in the monitor header, blank = generic title
|
pub patient_name: String, // displayed in the monitor header, blank = generic title
|
||||||
pub alarms: AlarmSettings,
|
pub alarms: AlarmSettings,
|
||||||
|
pub audible_alarms: bool, // mute only the sound, never the visual alarms
|
||||||
pub ecg_rhythm: EcgRhythm,
|
pub ecg_rhythm: EcgRhythm,
|
||||||
pub heart_rate: i32, // bpm, organized electrical rate; not mechanical pulse rate
|
pub heart_rate: i32, // bpm, organized electrical rate; not mechanical pulse rate
|
||||||
pub pulse_conduction: PulseConduction,
|
pub pulse_conduction: PulseConduction,
|
||||||
|
|
@ -275,6 +276,7 @@ impl Default for Parameters {
|
||||||
Self {
|
Self {
|
||||||
patient_name: String::new(),
|
patient_name: String::new(),
|
||||||
alarms: AlarmSettings::default(),
|
alarms: AlarmSettings::default(),
|
||||||
|
audible_alarms: true,
|
||||||
ecg_rhythm: EcgRhythm::Sinus,
|
ecg_rhythm: EcgRhythm::Sinus,
|
||||||
heart_rate: 75,
|
heart_rate: 75,
|
||||||
pulse_conduction: PulseConduction::OneToOne,
|
pulse_conduction: PulseConduction::OneToOne,
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
//! GTK4 Admin and Monitor windows; all callbacks run on the GTK main thread.
|
//! GTK4 Admin and Monitor windows; all callbacks run on the GTK main thread.
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::time::Instant;
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use gtk::gdk;
|
use gtk::gdk;
|
||||||
use gtk::glib;
|
use gtk::glib;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Application, ApplicationWindow, Orientation};
|
use gtk::{Application, ApplicationWindow, Orientation};
|
||||||
|
|
||||||
|
use crate::alarm::{self, AlarmAudio};
|
||||||
use crate::model::{AlarmLimits, AlarmSettings, ArterialShape, CapnoShape, EcgRhythm, Parameters, PulseConduction, Spo2Quality};
|
use crate::model::{AlarmLimits, AlarmSettings, ArterialShape, CapnoShape, EcgRhythm, Parameters, PulseConduction, Spo2Quality};
|
||||||
use crate::render;
|
use crate::render;
|
||||||
use crate::simulation::Simulator;
|
use crate::simulation::Simulator;
|
||||||
|
|
@ -25,8 +26,18 @@ const MONITOR_GREY: AccentColor = (0.80, 0.84, 0.87);
|
||||||
pub fn create_windows(app: &Application) {
|
pub fn create_windows(app: &Application) {
|
||||||
let parameters = Rc::new(RefCell::new(Parameters::default()));
|
let parameters = Rc::new(RefCell::new(Parameters::default()));
|
||||||
let simulator = Rc::new(RefCell::new(Simulator::new(¶meters.borrow())));
|
let simulator = Rc::new(RefCell::new(Simulator::new(¶meters.borrow())));
|
||||||
|
let audio = Rc::new(RefCell::new(AlarmAudio::new()));
|
||||||
let monitor = create_monitor(app, parameters.clone(), simulator.clone());
|
let monitor = create_monitor(app, parameters.clone(), simulator.clone());
|
||||||
let admin = create_admin(app, parameters, simulator, &monitor);
|
let admin = create_admin(app, parameters.clone(), simulator.clone(), &monitor, audio.clone());
|
||||||
|
|
||||||
|
// Alarm evaluation has its own 100-ms timer; waveform drawing never blocks
|
||||||
|
// on sound playback. Audio also continues if the monitor is not mapped.
|
||||||
|
glib::timeout_add_local(Duration::from_millis(100), move || {
|
||||||
|
let config = parameters.borrow();
|
||||||
|
let current = alarm::level(&config, &simulator.borrow());
|
||||||
|
audio.borrow_mut().update(current, config.audible_alarms);
|
||||||
|
glib::ControlFlow::Continue
|
||||||
|
});
|
||||||
|
|
||||||
// Present monitor first, then leave controls in the foreground.
|
// Present monitor first, then leave controls in the foreground.
|
||||||
monitor.present();
|
monitor.present();
|
||||||
|
|
@ -90,7 +101,8 @@ fn create_monitor(app: &Application, params: SharedParams,
|
||||||
|
|
||||||
fn create_admin(app: &Application, params: SharedParams,
|
fn create_admin(app: &Application, params: SharedParams,
|
||||||
simulator: Rc<RefCell<Simulator>>,
|
simulator: Rc<RefCell<Simulator>>,
|
||||||
monitor: &ApplicationWindow) -> ApplicationWindow {
|
monitor: &ApplicationWindow,
|
||||||
|
audio: Rc<RefCell<AlarmAudio>>) -> ApplicationWindow {
|
||||||
let window = ApplicationWindow::builder()
|
let window = ApplicationWindow::builder()
|
||||||
.application(app)
|
.application(app)
|
||||||
.title(concat!("Patient Monitor — Admin v", env!("CARGO_PKG_VERSION")))
|
.title(concat!("Patient Monitor — Admin v", env!("CARGO_PKG_VERSION")))
|
||||||
|
|
@ -131,6 +143,28 @@ fn create_admin(app: &Application, params: SharedParams,
|
||||||
preset_row.append(&preset_caption);
|
preset_row.append(&preset_caption);
|
||||||
preset_row.append(&preset_dropdown);
|
preset_row.append(&preset_dropdown);
|
||||||
controls.append(&preset_row);
|
controls.append(&preset_row);
|
||||||
|
|
||||||
|
// Sound control is independent of visual alarm limits and of the rhythm.
|
||||||
|
let sound_row = gtk::Box::new(Orientation::Horizontal, 12);
|
||||||
|
let audible = gtk::CheckButton::with_label("Audible alarms");
|
||||||
|
audible.set_active(params.borrow().audible_alarms);
|
||||||
|
audible.connect_toggled({
|
||||||
|
let params = params.clone();
|
||||||
|
move |button| params.borrow_mut().audible_alarms = button.is_active()
|
||||||
|
});
|
||||||
|
sound_row.append(&audible);
|
||||||
|
let test_sound = gtk::Button::with_label("Test tone");
|
||||||
|
test_sound.connect_clicked({
|
||||||
|
let audio = audio.clone();
|
||||||
|
move |_| audio.borrow_mut().test()
|
||||||
|
});
|
||||||
|
sound_row.append(&test_sound);
|
||||||
|
if !audio.borrow().available() {
|
||||||
|
let missing = gtk::Label::new(Some("Audio unavailable — install pipewire-utils"));
|
||||||
|
missing.set_xalign(0.0);
|
||||||
|
sound_row.append(&missing);
|
||||||
|
}
|
||||||
|
controls.append(&sound_row);
|
||||||
let updating_preset = Rc::new(Cell::new(false));
|
let updating_preset = Rc::new(Cell::new(false));
|
||||||
let mut alarm_editors: Vec<(AlarmEditor, fn(&AlarmSettings) -> AlarmLimits)> = Vec::new();
|
let mut alarm_editors: Vec<(AlarmEditor, fn(&AlarmSettings) -> AlarmLimits)> = Vec::new();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue