pub struct AdcInterpolator<Pin, Word, const LENGTH: usize> { /* private fields */ }Implementations§
Source§impl<Pin, Word, const LENGTH: usize> AdcInterpolator<Pin, Word, LENGTH>
impl<Pin, Word, const LENGTH: usize> AdcInterpolator<Pin, Word, LENGTH>
Sourcepub fn new<ADC>(pin: Pin, config: Config<LENGTH>) -> Self
pub fn new<ADC>(pin: Pin, config: Config<LENGTH>) -> Self
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);Sourcepub fn read<Adc, ADC>(
&mut self,
adc: &mut Adc,
) -> Result<Option<u32>, Error<<Adc as OneShot<ADC, Word, Pin>>::Error>>
pub fn read<Adc, ADC>( &mut self, adc: &mut Adc, ) -> Result<Option<u32>, Error<<Adc as OneShot<ADC, Word, Pin>>::Error>>
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)));Trait Implementations§
Auto Trait Implementations§
impl<Pin, Word, const LENGTH: usize> Freeze for AdcInterpolator<Pin, Word, LENGTH>
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>
impl<Pin, Word, const LENGTH: usize> Sync for AdcInterpolator<Pin, Word, LENGTH>
impl<Pin, Word, const LENGTH: usize> Unpin for AdcInterpolator<Pin, Word, LENGTH>
impl<Pin, Word, const LENGTH: usize> UnwindSafe for AdcInterpolator<Pin, Word, LENGTH>where
Pin: UnwindSafe,
Word: UnwindSafe,
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