2020-03-20 02:51:59 +08:00
|
|
|
use num_traits::float::Float;
|
2020-03-19 04:51:30 +08:00
|
|
|
|
|
|
|
/// Steinhart-Hart equation parameters
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Parameters {
|
2020-03-19 07:23:41 +08:00
|
|
|
pub t0: f64,
|
2020-03-20 05:56:14 +08:00
|
|
|
pub b: f64,
|
2020-03-19 07:23:41 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2020-03-19 07:23:41 +08:00
|
|
|
|
|
|
|
impl Default for Parameters {
|
|
|
|
fn default() -> Self {
|
2020-03-20 05:56:14 +08:00
|
|
|
Parameters {
|
2020-03-19 07:23:41 +08:00
|
|
|
t0: 0.001_4,
|
2020-03-20 05:56:14 +08:00
|
|
|
b: 0.000_000_099,
|
2020-03-19 07:23:41 +08:00
|
|
|
r0: 5_110.0,
|
2020-03-20 05:56:14 +08:00
|
|
|
}
|
2020-03-19 07:23:41 +08:00
|
|
|
}
|
|
|
|
}
|