pub struct Calibration { /* private fields */ }Expand description
A linear map from raw sensor counts to calibrated units.
Most cheap analog sensors report arbitrary counts - ADC steps, a raw voltage -
that mean nothing until they are converted to real units. A Calibration
applies the line value = scale * raw + offset. Build it from two readings
whose true values are known, then apply it to every sample.
§Examples
use pamoja_kit::Calibration;
// A humidity probe reads 0.5 V at 0 % and 2.5 V at 100 %.
let humidity = Calibration::two_point(0.5, 0.0, 2.5, 100.0);
assert_eq!(humidity.apply(1.5), 50.0);Implementations§
Source§impl Calibration
impl Calibration
Sourcepub fn two_point(
raw_low: f32,
value_low: f32,
raw_high: f32,
value_high: f32,
) -> Self
pub fn two_point( raw_low: f32, value_low: f32, raw_high: f32, value_high: f32, ) -> Self
Builds a calibration from two known (raw, value) points.
§Arguments
raw_low- a raw reading.value_low- the true value atraw_low.raw_high- another raw reading.value_high- the true value atraw_high.
§Returns
The line through both points. If the two raw readings are equal the slope is
undefined, so the calibration falls back to the constant value_low.
Trait Implementations§
Source§impl Clone for Calibration
impl Clone for Calibration
Source§fn clone(&self) -> Calibration
fn clone(&self) -> Calibration
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for Calibration
Source§impl Debug for Calibration
impl Debug for Calibration
Source§impl PartialEq for Calibration
impl PartialEq for Calibration
Source§fn eq(&self, other: &Calibration) -> bool
fn eq(&self, other: &Calibration) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for Calibration
Auto Trait Implementations§
impl Freeze for Calibration
impl RefUnwindSafe for Calibration
impl Send for Calibration
impl Sync for Calibration
impl Unpin for Calibration
impl UnsafeUnpin for Calibration
impl UnwindSafe for Calibration
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more