AdcInterpolator

Struct AdcInterpolator 

Source
pub struct AdcInterpolator<Pin, Word, const LENGTH: usize> { /* private fields */ }

Implementations§

Source§

impl<Pin, Word, const LENGTH: usize> AdcInterpolator<Pin, Word, LENGTH>

Source

pub fn new<ADC>(pin: Pin, config: Config<LENGTH>) -> Self
where Word: Copy + PartialOrd + TryFrom<u32>, <Word as TryFrom<u32>>::Error: Debug, Pin: Channel<ADC>,

Returns an interpolator using the provided config.

The values in config’s voltage_to_values field must be in ascending order by voltage or this function will panic when running in debug mode.

§Examples
use adc_interpolator::{AdcInterpolator, Config};

let config = Config {
    max_voltage: 1000,
    precision: 12,
    voltage_to_values: [
        (100, 40),
        (200, 30),
        (300, 10),
    ],
};

let interpolator = AdcInterpolator::new(pin, config);
Source

pub fn free(self) -> Pin

Destroys the interpolator and returns the Pin.

Source

pub fn read<Adc, ADC>( &mut self, adc: &mut Adc, ) -> Result<Option<u32>, Error<<Adc as OneShot<ADC, Word, Pin>>::Error>>
where Word: Copy + Into<u32> + PartialEq + PartialOrd, Pin: Channel<ADC>, Adc: OneShot<ADC, Word, Pin>,

Returns a value based on the table, using linear interpolation between values in the table if necessary. If adc_value falls outside the range of the table, returns Ok(None).

§Examples
use adc_interpolator::{AdcInterpolator, Config};

let config = Config {
    max_voltage: 1000,
    precision: 12,
    voltage_to_values: [
        (100, 40),
        (200, 30),
        (300, 10),
    ],
};

let mut interpolator = AdcInterpolator::new(pin, config);

// With voltage at 150 mV, the value is 35
assert_eq!(interpolator.read(&mut adc), Ok(Some(35)));
Source

pub fn min_value(&self) -> u32

Returns the smallest value that can be returned by read.

Source

pub fn max_value(&self) -> u32

Returns the largest value that can be returned by read.

Trait Implementations§

Source§

impl<Pin: Debug, Word: Debug, const LENGTH: usize> Debug for AdcInterpolator<Pin, Word, LENGTH>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Pin, Word, const LENGTH: usize> Freeze for AdcInterpolator<Pin, Word, LENGTH>
where Pin: Freeze, Word: Freeze,

§

impl<Pin, Word, const LENGTH: usize> RefUnwindSafe for AdcInterpolator<Pin, Word, LENGTH>
where Pin: RefUnwindSafe, Word: RefUnwindSafe,

§

impl<Pin, Word, const LENGTH: usize> Send for AdcInterpolator<Pin, Word, LENGTH>
where Pin: Send, Word: Send,

§

impl<Pin, Word, const LENGTH: usize> Sync for AdcInterpolator<Pin, Word, LENGTH>
where Pin: Sync, Word: Sync,

§

impl<Pin, Word, const LENGTH: usize> Unpin for AdcInterpolator<Pin, Word, LENGTH>
where Pin: Unpin, Word: Unpin,

§

impl<Pin, Word, const LENGTH: usize> UnwindSafe for AdcInterpolator<Pin, Word, LENGTH>
where Pin: UnwindSafe, Word: UnwindSafe,

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.