Trait staticfraction::StaticFractionDescription
[−]
[src]
pub trait StaticFractionDescription<C> { const NUM_OFFSET: C; const NUM_FACTOR: C; const DENOM: C; }
Description of transformation parameters
A datum x is transformed to a value y by the formula y = (NUM_OFFSET + x * NUM_FACTOR) / DENOM.
It is required that those values are reduced, ie. that there is no prime factor common to the three constants.
You can create descriptions like in this example:
#[derive(Default)] struct VoltageFromADCDescription; impl staticfraction::StaticFractionDescription<u32> for VoltageFromADCDescription { const NUM_OFFSET: u32 = 0; const NUM_FACTOR: u32 = 1; const DENOM: u32 = 204; } type VoltageFromADC = staticfraction::StaticFraction<u8, u32, VoltageFromADCDescription>;
TODO: Provide a macro that expresses the same with
StaticFractionType!(VoltageFromADC, 0u8, 255u8, 0, 1, 125, 100)
.