Switched custom quantities to using a macro for generation.

This commit is contained in:
Zachary Sunforge
2024-07-10 22:06:16 -07:00
parent da5fca74ef
commit a9f46c549e
9 changed files with 197 additions and 229 deletions

View File

@ -43,58 +43,7 @@ pub trait Quantity<V: Value>: Copy + PartialEq + PartialOrd + Add + Sub {
}
}
pub trait Value: Num + Copy + PartialOrd + FromPrimitive + NumCast + Display {
//----- Temperature ----------------------------------
#[inline(always)]
fn kelvins(self) -> Kelvins<Self> {
Kelvins(self)
}
#[inline(always)]
fn deci_kelvins(self) -> DeciKelvins<Self> {
DeciKelvins(self)
}
#[inline(always)]
fn degrees_celsius(self) -> DegreesCelsius<Self> {
DegreesCelsius(self)
}
#[inline(always)]
fn deci_degrees_celsius(self) -> DeciDegreesCelsius<Self> {
DeciDegreesCelsius(self)
}
//----- Voltage ----------------------------------
#[inline(always)]
fn volts(self) -> Volts<Self> {
Volts(self)
}
#[inline(always)]
fn millivolts(self) -> MilliVolts<Self> {
MilliVolts(self)
}
//----- Resistance ----------------------------------
#[inline(always)]
fn ohms(self) -> Ohms<Self> {
Ohms(self)
}
//----- Volume rate ----------------------------------
#[inline(always)]
fn liters_per_minute(self) -> LitersPerMinute<Self> {
LitersPerMinute(self)
}
//----- Irradiance ----------------------------------
#[inline(always)]
fn watts_per_square_meter(self) -> WattsPerSquareMeter<Self> {
WattsPerSquareMeter(self)
}
}
pub trait Value: Num + Copy + PartialOrd + FromPrimitive + NumCast + Display {}
impl<V> Value for V where V: Num + Copy + PartialOrd + FromPrimitive + NumCast + Display {}
#[derive(Copy, Clone)]
@ -161,6 +110,12 @@ mod defmt_impl {
}
}
impl<Q: Quantity<usize>> Format for Fmt<usize, Q> {
fn format(&self, fmt: Formatter) {
write!(fmt, "{} {}", self.quantity.value(), Q::symbol());
}
}
impl<Q: Quantity<i8>> Format for Fmt<i8, Q> {
fn format(&self, fmt: Formatter) {
write!(fmt, "{} {}", self.quantity.value(), Q::symbol());
@ -191,6 +146,12 @@ mod defmt_impl {
}
}
impl<Q: Quantity<isize>> Format for Fmt<isize, Q> {
fn format(&self, fmt: Formatter) {
write!(fmt, "{} {}", self.quantity.value(), Q::symbol());
}
}
impl<Q: Quantity<f32>> Format for Fmt<f32, Q> {
fn format(&self, fmt: Formatter) {
write!(fmt, "{} {}", self.quantity.value(), Q::symbol());