Skip to main content

dspk_core/recording/
unit.rs

1use serde::{Deserialize, Serialize};
2
3/// Physical unit of a channel's scaled values (`stored * gain + offset`).
4/// Microvolts in one volt (formats storing volts per bit report µV).
5pub const MICROVOLTS_PER_VOLT: f64 = 1e6;
6
7#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum SignalUnit {
10    Volt,
11    Millivolt,
12    Microvolt,
13    Ampere,
14    Milliampere,
15    Microampere,
16    /// Normalized values or raw counts.
17    #[default]
18    Dimensionless,
19    /// Any unit not listed, by its symbol (e.g. `"Pa"`, `"g"`).
20    Other(String),
21}
22
23impl SignalUnit {
24    /// Display symbol (`"µV"`, `"mA"`, …); empty for [`SignalUnit::Dimensionless`].
25    pub fn symbol(&self) -> &str {
26        match self {
27            SignalUnit::Volt => "V",
28            SignalUnit::Millivolt => "mV",
29            SignalUnit::Microvolt => "µV",
30            SignalUnit::Ampere => "A",
31            SignalUnit::Milliampere => "mA",
32            SignalUnit::Microampere => "µA",
33            SignalUnit::Dimensionless => "",
34            SignalUnit::Other(symbol) => symbol,
35        }
36    }
37}