pub use summary::Summary;
use crate::sensors;
mod summary;
pub fn perform_sampling<SENSOR: sensors::Sensor>(
n: u8,
toggle_sensor: &mut impl FnMut(),
warmup_delay: &mut impl FnMut(),
adc_read: &mut impl FnMut() -> u16,
sensor: SENSOR,
) -> Summary<SENSOR> {
let mut sum = 0u32;
let mut min = u16::MAX;
let mut max = u16::MIN;
toggle_sensor();
warmup_delay();
adc_read();
adc_read();
adc_read();
for _ in 0..n {
let sample = adc_read();
max = max.max(sample);
min = min.min(sample);
sum += sample as u32;
}
toggle_sensor();
let avg = sum.div_ceil(n as u32) as u16;
Summary::<SENSOR> { n, avg, min, max, sensor }
}