Migrated from uom to custom quantity implementation.
This commit is contained in:
@ -1,33 +1,25 @@
|
||||
use libm::{log, logf};
|
||||
use uom::si::electrical_resistance::ohm;
|
||||
use uom::si::quantities::{ThermodynamicTemperature, ElectricalResistance};
|
||||
use uom::si::thermodynamic_temperature::kelvin;
|
||||
use crate::quantity::{Kelvins, Ohms};
|
||||
|
||||
/// Convert thermistor resistance to a temperature using beta parameter equation
|
||||
pub fn convert_beta(
|
||||
resistance: ElectricalResistance<f32>,
|
||||
resistance: Ohms<f32>,
|
||||
beta: f32,
|
||||
reference_temp: ThermodynamicTemperature<f32>,
|
||||
reference_resist: ElectricalResistance<f32>,
|
||||
) -> ThermodynamicTemperature<f32> {
|
||||
let ohms = resistance.get::<ohm>();
|
||||
let reference_kelvin = reference_temp.get::<kelvin>();
|
||||
let reference_ohms = reference_resist.get::<ohm>();
|
||||
|
||||
let result_kelvin = 1.0 / ((1.0 / reference_kelvin) + (1.0 / beta) * logf(ohms / reference_ohms));
|
||||
ThermodynamicTemperature::new::<kelvin>(result_kelvin)
|
||||
reference_temp: Kelvins<f32>,
|
||||
reference_resist: Ohms<f32>,
|
||||
) -> Kelvins<f32> {
|
||||
let kelvins = 1.0 / ((1.0 / reference_temp.0) + (1.0 / beta) * logf(resistance.0 / reference_resist.0));
|
||||
Kelvins(kelvins)
|
||||
}
|
||||
|
||||
/// Convert thermistor resistance to a temperature using Steinhart-Hart equation
|
||||
pub fn convert_steinhart(
|
||||
resistance: ElectricalResistance<f32>,
|
||||
resistance: Ohms<f64>,
|
||||
a: f64,
|
||||
b: f64,
|
||||
c: f64,
|
||||
) -> ThermodynamicTemperature<f32> {
|
||||
let ohms = resistance.get::<ohm>() as f64;
|
||||
|
||||
let log_omhs = log(ohms);
|
||||
) -> Kelvins<f32> {
|
||||
let log_omhs = log(resistance.0);
|
||||
let kelvins = 1.0 / (a + b * log_omhs + c * log_omhs * log_omhs * log_omhs);
|
||||
ThermodynamicTemperature::new::<kelvin>(kelvins as f32)
|
||||
Kelvins(kelvins as f32)
|
||||
}
|
||||
|
Reference in New Issue
Block a user