adc_interpolator/lib.rs
1#![cfg_attr(not(test), no_std)]
2
3//! An interpolator for analog-to-digital converters.
4//!
5//! Convert voltage readings from an ADC into meaningful values using
6//! linear interpolation.
7//!
8//! # Examples
9//!
10//! ```
11//! use adc_interpolator::{AdcInterpolator, Config};
12//! # use embedded_hal_mock::{
13//! # adc::{Mock, MockChan0, Transaction},
14//! # common::Generic,
15//! # MockError,
16//! # };
17//! # let pin = MockChan0 {};
18//! # let expectations: [Transaction<u16>; 1] = [Transaction::read(0, 614)];
19//! # let mut adc = Mock::new(&expectations);
20//! # let pin = MockChan0 {};
21//!
22//! let config = Config {
23//! max_voltage: 1000, // 1000 mV maximum voltage
24//! precision: 12, // 12-bit precision
25//! voltage_to_values: [
26//! (100, 40), // 100 mV -> 40
27//! (200, 30), // 200 mV -> 30
28//! (300, 10), // 300 mV -> 10
29//! ],
30//! };
31//!
32//! let mut interpolator = AdcInterpolator::new(pin, config);
33//!
34//! // With voltage at 150 mV, the value is 35
35//! assert_eq!(interpolator.read(&mut adc), Ok(Some(35)));
36//! ```
37
38mod adc_interpolator;
39mod interpolate;
40
41pub use self::adc_interpolator::{AdcInterpolator, Config};