Skip to main content

Calibration

Struct Calibration 

Source
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

Source

pub fn linear(scale: f32, offset: f32) -> Self

Builds a calibration from a scale and offset directly.

§Arguments
  • scale - the multiplier applied to a raw reading.
  • offset - the constant added after scaling.
§Returns

The calibration value = scale * raw + offset.

Source

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 at raw_low.
  • raw_high - another raw reading.
  • value_high - the true value at raw_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.

Source

pub fn apply(&self, raw: f32) -> f32

Converts a raw reading into calibrated units.

§Arguments
  • raw - the uncalibrated sensor reading.
§Returns

The calibrated value.

Trait Implementations§

Source§

impl Clone for Calibration

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Copy for Calibration

Source§

impl Debug for Calibration

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Calibration

Source§

fn eq(&self, other: &Calibration) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Calibration

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.