2024-01-17 12:18:32 +08:00
|
|
|
use num_traits::float::Float;
|
2024-02-23 11:38:26 +08:00
|
|
|
use serde::{Deserialize, Serialize};
|
2024-01-17 12:18:32 +08:00
|
|
|
use uom::si::{
|
2024-02-27 16:26:05 +08:00
|
|
|
f32::{
|
2024-01-17 12:18:32 +08:00
|
|
|
ElectricalResistance,
|
|
|
|
ThermodynamicTemperature,
|
|
|
|
},
|
|
|
|
electrical_resistance::ohm,
|
|
|
|
ratio::ratio,
|
|
|
|
thermodynamic_temperature::{degree_celsius, kelvin},
|
|
|
|
};
|
2024-02-06 15:20:23 +08:00
|
|
|
use miniconf::Tree;
|
2024-01-17 12:18:32 +08:00
|
|
|
|
|
|
|
/// Steinhart-Hart equation parameters
|
2024-02-23 11:38:26 +08:00
|
|
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
2024-01-17 12:18:32 +08:00
|
|
|
pub struct Parameters {
|
|
|
|
/// Base temperature
|
|
|
|
pub t0: ThermodynamicTemperature,
|
|
|
|
/// Base resistance
|
|
|
|
pub r0: ElectricalResistance,
|
|
|
|
/// Beta
|
2024-02-27 16:26:05 +08:00
|
|
|
pub b: f32,
|
2024-01-17 12:18:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Parameters {
|
|
|
|
/// Perform the voltage to temperature conversion.
|
|
|
|
pub fn get_temperature(&self, r: ElectricalResistance) -> ThermodynamicTemperature {
|
|
|
|
let inv_temp = 1.0 / self.t0.get::<kelvin>() + (r / self.r0).get::<ratio>().ln() / self.b;
|
|
|
|
ThermodynamicTemperature::new::<kelvin>(1.0 / inv_temp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Parameters {
|
|
|
|
fn default() -> Self {
|
|
|
|
Parameters {
|
|
|
|
t0: ThermodynamicTemperature::new::<degree_celsius>(25.0),
|
|
|
|
r0: ElectricalResistance::new::<ohm>(10_000.0),
|
|
|
|
b: 3800.0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|