From 8b0ad143113780d7c60659778406d96a9ac72761 Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 28 Aug 2023 14:52:09 +0800 Subject: [PATCH] steinhart_hart: Beta Parameter uom dimensions The Beta Parameter is not dimensionless, and has unit kelvin. Incorporate that into the type system. --- src/command_handler.rs | 4 +++- src/steinhart_hart.rs | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/command_handler.rs b/src/command_handler.rs index 3f30083..11e1595 100644 --- a/src/command_handler.rs +++ b/src/command_handler.rs @@ -34,11 +34,13 @@ use uom::{ ElectricPotential, ElectricalResistance, ThermodynamicTemperature, + TemperatureInterval, }, electric_current::ampere, electric_potential::volt, electrical_resistance::ohm, thermodynamic_temperature::degree_celsius, + temperature_interval::kelvin, }, }; @@ -243,7 +245,7 @@ impl Handler { use super::command_parser::ShParameter::*; match parameter { T0 => sh.t0 = ThermodynamicTemperature::new::(value), - B => sh.b = value, + B => sh.b = TemperatureInterval::new::(value), R0 => sh.r0 = ElectricalResistance::new::(value), } send_line(socket, b"{}"); diff --git a/src/steinhart_hart.rs b/src/steinhart_hart.rs index 87149df..af8985e 100644 --- a/src/steinhart_hart.rs +++ b/src/steinhart_hart.rs @@ -3,10 +3,12 @@ use uom::si::{ f64::{ ElectricalResistance, ThermodynamicTemperature, + TemperatureInterval, }, electrical_resistance::ohm, ratio::ratio, thermodynamic_temperature::{degree_celsius, kelvin}, + temperature_interval::kelvin as kelvin_interval, }; use serde::{Deserialize, Serialize}; @@ -15,17 +17,21 @@ use serde::{Deserialize, Serialize}; pub struct Parameters { /// Base temperature pub t0: ThermodynamicTemperature, - /// Base resistance + /// Resistance at base temperature pub r0: ElectricalResistance, /// Beta - pub b: f64, + pub b: TemperatureInterval, } impl Parameters { - /// Perform the voltage to temperature conversion. + /// Perform the resistance to temperature conversion. pub fn get_temperature(&self, r: ElectricalResistance) -> ThermodynamicTemperature { - let inv_temp = 1.0 / self.t0.get::() + (r / self.r0).get::().ln() / self.b; - ThermodynamicTemperature::new::(1.0 / inv_temp) + let t0 = TemperatureInterval::new::(self.t0.get::()); + + let inv_temp = 1.0 / t0 + (r / self.r0).get::().ln() / self.b; + let temp = 1.0 / inv_temp; + + ThermodynamicTemperature::new::(temp.get::()) } } @@ -34,7 +40,7 @@ impl Default for Parameters { Parameters { t0: ThermodynamicTemperature::new::(25.0), r0: ElectricalResistance::new::(10_000.0), - b: 3800.0, + b: TemperatureInterval::new::(3800.0), } } }