thermostat/src/steinhart_hart.rs

32 lines
636 B
Rust
Raw Normal View History

use num_traits::float::Float;
2020-03-19 04:51:30 +08:00
/// Steinhart-Hart equation parameters
#[derive(Clone, Debug)]
pub struct Parameters {
pub t0: f64,
2020-03-20 05:56:14 +08:00
pub b: f64,
pub r0: f64,
2020-03-19 04:51:30 +08:00
}
impl Parameters {
/// Perform the voltage to temperature conversion.
///
/// Result unit: Kelvin
///
/// TODO: verify
2020-03-20 05:56:14 +08:00
pub fn get_temperature(&self, r: f64) -> f64 {
let inv_temp = 1.0 / self.t0 + (r / self.r0).ln() / self.b;
2020-03-19 04:51:30 +08:00
1.0 / inv_temp
}
}
impl Default for Parameters {
fn default() -> Self {
2020-03-20 05:56:14 +08:00
Parameters {
t0: 0.001_4,
2020-03-20 05:56:14 +08:00
b: 0.000_000_099,
r0: 5_110.0,
2020-03-20 05:56:14 +08:00
}
}
}