Change DegreesCelsius to Celsius
Version bump
This commit is contained in:
@ -11,7 +11,7 @@ members = [
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.3.7"
|
||||
version = "0.3.8"
|
||||
edition = "2021"
|
||||
repository = "https://git.bfpower.io/BFPOWER/physical"
|
||||
readme = "README.md"
|
||||
@ -154,4 +154,4 @@ overflow-checks = true
|
||||
lto = true
|
||||
panic = "abort"
|
||||
incremental = false
|
||||
codegen-units = 1
|
||||
codegen-units = 1
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Before upgrading check that everything is available on all tier1 targets here:
|
||||
# https://rust-lang.github.io/rustup-components-history
|
||||
[toolchain]
|
||||
channel = "1.75"
|
||||
channel = "1.81"
|
||||
components = [ "rust-src", "rustfmt", "llvm-tools" ]
|
||||
targets = [
|
||||
"thumbv7em-none-eabi",
|
||||
|
@ -9,12 +9,12 @@ quantity_type! {Kelvins, "K"}
|
||||
|
||||
impl <V: Value> Kelvins<V> {
|
||||
#[inline]
|
||||
pub fn to_degrees_celsius(self) -> DegreesCelsius<V> {
|
||||
pub fn to_celsius(self) -> Celsius<V> {
|
||||
//TODO: Make const
|
||||
let offset = V::from_f64(KELVIN_CELSIUS_OFFSET).unwrap();
|
||||
DegreesCelsius(self.0 - offset)
|
||||
Celsius(self.0 - offset)
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn to_deci_kelvins(self) -> DeciKelvins<V> {
|
||||
let multiplier = V::from_u8(DECI).unwrap();
|
||||
@ -34,31 +34,31 @@ impl<V: Value> DeciKelvins<V> {
|
||||
}
|
||||
|
||||
//----- Degrees Celsius ----------------------------------
|
||||
quantity_type! {DegreesCelsius, "℃"}
|
||||
quantity_type! {Celsius, "℃"}
|
||||
|
||||
impl <V: Value> DegreesCelsius<V> {
|
||||
impl <V: Value> Celsius<V> {
|
||||
#[inline]
|
||||
pub fn to_kelvins(self) -> Kelvins<V> {
|
||||
//TODO: Make const
|
||||
let offset = V::from_f64(KELVIN_CELSIUS_OFFSET).unwrap();
|
||||
Kelvins(self.0 + offset)
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn to_deci_degrees_celsius(self) -> DeciDegreesCelsius<V> {
|
||||
pub fn to_deci_celsius(self) -> DeciCelsius<V> {
|
||||
let multiplier = V::from_u8(DECI).unwrap();
|
||||
DeciDegreesCelsius(self.0 * multiplier)
|
||||
DeciCelsius(self.0 * multiplier)
|
||||
}
|
||||
}
|
||||
|
||||
//----- Deci Degrees Celsius ----------------------------------
|
||||
quantity_type! {DeciDegreesCelsius, "d℃"}
|
||||
quantity_type! {DeciCelsius, "d℃"}
|
||||
|
||||
impl<V: Value> DeciDegreesCelsius<V> {
|
||||
impl<V: Value> DeciCelsius<V> {
|
||||
#[inline]
|
||||
pub fn to_degrees_celsius(self) -> DegreesCelsius<V> {
|
||||
pub fn to_celsius(self) -> Celsius<V> {
|
||||
let divisor = V::from_u8(DECI).unwrap();
|
||||
DegreesCelsius(self.0 / divisor)
|
||||
Celsius(self.0 / divisor)
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,24 +74,24 @@ mod tests {
|
||||
fn convert_f32() {
|
||||
let kelvins: Kelvins<f32> = 298.15.kelvins();
|
||||
let deci_kelvins: DeciKelvins<f32> = 2_981.5.deci_kelvins();
|
||||
let celsius: DegreesCelsius<f32> = 25.0.degrees_celsius();
|
||||
let deci_celsius: DeciDegreesCelsius<f32> = 250.0.deci_degrees_celsius();
|
||||
|
||||
assert_approx_eq!(f32, kelvins.to_degrees_celsius().0, celsius.0);
|
||||
let celsius: Celsius<f32> = 25.0.celsius();
|
||||
let deci_celsius: DeciCelsius<f32> = 250.0.deci_celsius();
|
||||
|
||||
assert_approx_eq!(f32, kelvins.to_celsius().0, celsius.0);
|
||||
assert_approx_eq!(f32, celsius.to_kelvins().0, kelvins.0);
|
||||
|
||||
assert_approx_eq!(f32, deci_kelvins.to_kelvins().0, kelvins.0);
|
||||
assert_approx_eq!(f32, kelvins.to_deci_kelvins().0, deci_kelvins.0);
|
||||
|
||||
assert_approx_eq!(f32, deci_celsius.to_degrees_celsius().0, celsius.0);
|
||||
assert_approx_eq!(f32, celsius.to_deci_degrees_celsius().0, deci_celsius.0);
|
||||
|
||||
assert_approx_eq!(f32, deci_celsius.to_celsius().0, celsius.0);
|
||||
assert_approx_eq!(f32, celsius.to_deci_celsius().0, deci_celsius.0);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn convert_u16() {
|
||||
let kelvins: Kelvins<u16> = 298.kelvins();
|
||||
let degrees_celsius: DegreesCelsius<u16> = 25.degrees_celsius();
|
||||
|
||||
assert_eq!(degrees_celsius.0, kelvins.to_degrees_celsius().0);
|
||||
let celsius: Celsius<u16> = 25.celsius();
|
||||
|
||||
assert_eq!(celsius.0, kelvins.to_celsius().0);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
use crate::error::InvalidValue;
|
||||
use crate::quantity::{DeciDegreesCelsius, MilliVolts, Quantity};
|
||||
use crate::quantity::{DeciCelsius, MilliVolts, Quantity};
|
||||
|
||||
#[inline]
|
||||
pub fn convert(
|
||||
voltage: MilliVolts<i16>,
|
||||
) -> Result<DeciDegreesCelsius<i16>, InvalidValue> {
|
||||
) -> Result<DeciCelsius<i16>, InvalidValue> {
|
||||
const MIN_VOLTAGE: MilliVolts<i16> = MilliVolts(-550);
|
||||
const MAX_VOLTAGE: MilliVolts<i16> = MilliVolts(1_500);
|
||||
|
||||
if voltage >= MIN_VOLTAGE && voltage <= MAX_VOLTAGE {
|
||||
Ok(DeciDegreesCelsius(voltage.value()))
|
||||
Ok(DeciCelsius(voltage.value()))
|
||||
} else {
|
||||
Err(InvalidValue)
|
||||
}
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
use libm::pow;
|
||||
use crate::error::InvalidValue;
|
||||
use crate::quantity::{DegreesCelsius, MilliVolts, Quantity};
|
||||
use crate::quantity::{Celsius, MilliVolts, Quantity};
|
||||
|
||||
fn _convert(
|
||||
voltage: MilliVolts<f64>,
|
||||
) -> Result<DegreesCelsius<f32>, InvalidValue> {
|
||||
) -> Result<Celsius<f32>, InvalidValue> {
|
||||
let mv = voltage.value();
|
||||
let mv_pow2 = mv * mv;
|
||||
let mv_pow3 = mv_pow2 * mv;
|
||||
@ -27,7 +27,7 @@ fn _convert(
|
||||
+ -1.0450598E-2 * mv_pow7
|
||||
+ -5.1920577E-4 * mv_pow8;
|
||||
|
||||
Ok(DegreesCelsius(celsius as f32))
|
||||
Ok(Celsius(celsius as f32))
|
||||
} else if mv > 0.0 && mv < 20.644 {
|
||||
let mv_pow7 = mv_pow6 * mv;
|
||||
let mv_pow8 = mv_pow7 * mv;
|
||||
@ -43,7 +43,7 @@ fn _convert(
|
||||
+ 1.057734E-6 * mv_pow8
|
||||
+ -1.052755E-8 * mv_pow9;
|
||||
|
||||
Ok(DegreesCelsius(celsius as f32))
|
||||
Ok(Celsius(celsius as f32))
|
||||
} else if mv >= 20.644 && mv <= 54.886 {
|
||||
let celsius = 1.318058e2
|
||||
+ 4.830222E+1 * mv
|
||||
@ -53,7 +53,7 @@ fn _convert(
|
||||
+ 8.802193E-6 * mv_pow5
|
||||
+ -3.110810E-8 * mv_pow6;
|
||||
|
||||
Ok(DegreesCelsius(celsius as f32))
|
||||
Ok(Celsius(celsius as f32))
|
||||
} else {
|
||||
Err(InvalidValue)
|
||||
}
|
||||
@ -69,8 +69,8 @@ fn _convert(
|
||||
#[inline]
|
||||
pub fn convert_direct(
|
||||
voltage: MilliVolts<f64>,
|
||||
r_junction: DegreesCelsius<f32>,
|
||||
) -> Result<DegreesCelsius<f32>, InvalidValue> {
|
||||
r_junction: Celsius<f32>,
|
||||
) -> Result<Celsius<f32>, InvalidValue> {
|
||||
let base_temp = _convert(voltage)?;
|
||||
|
||||
Ok(base_temp + r_junction)
|
||||
@ -85,8 +85,8 @@ pub fn convert_direct(
|
||||
#[inline]
|
||||
pub fn convert_seebeck(
|
||||
voltage: MilliVolts<f64>,
|
||||
r_junction: DegreesCelsius<f32>,
|
||||
) -> Result<DegreesCelsius<f32>, InvalidValue> {
|
||||
r_junction: Celsius<f32>,
|
||||
) -> Result<Celsius<f32>, InvalidValue> {
|
||||
let voltage_correction = temp_to_voltage_seebeck(r_junction)?;
|
||||
_convert(MilliVolts(voltage.0 + voltage_correction.0 as f64))
|
||||
}
|
||||
@ -100,14 +100,14 @@ pub fn convert_seebeck(
|
||||
#[inline]
|
||||
pub fn convert_polynomial(
|
||||
voltage: MilliVolts<f64>,
|
||||
r_junction: DegreesCelsius<f64>,
|
||||
) -> Result<DegreesCelsius<f32>, InvalidValue> {
|
||||
r_junction: Celsius<f64>,
|
||||
) -> Result<Celsius<f32>, InvalidValue> {
|
||||
let voltage_correction = temp_to_voltage_poly(r_junction)?;
|
||||
_convert(MilliVolts(voltage.0 + voltage_correction.0 as f64))
|
||||
}
|
||||
|
||||
pub fn temp_to_voltage_poly(
|
||||
temperature: DegreesCelsius<f64>,
|
||||
temperature: Celsius<f64>,
|
||||
) -> Result<MilliVolts<f32>, InvalidValue> {
|
||||
let celsius = temperature.value();
|
||||
let cel_pow2 = celsius * celsius;
|
||||
@ -159,7 +159,7 @@ pub fn temp_to_voltage_poly(
|
||||
|
||||
#[inline]
|
||||
pub fn temp_to_voltage_seebeck(
|
||||
temperature: DegreesCelsius<f32>,
|
||||
temperature: Celsius<f32>,
|
||||
) -> Result<MilliVolts<f32>, InvalidValue> {
|
||||
if temperature.value() >= -2.0 && temperature.value() <= 800.0 {
|
||||
Ok(MilliVolts(0.041 * temperature.value()))
|
||||
|
Reference in New Issue
Block a user