From eb9aeb160a11228cb0dcf5ab0e4942908c6bbe1b Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 13 May 2020 00:15:29 +0200 Subject: [PATCH] add Channels::read_ref_adc() --- src/channels.rs | 14 ++++++++++++++ src/main.rs | 15 ++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/channels.rs b/src/channels.rs index 6937d34..ff4d0db 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -75,4 +75,18 @@ impl Channels { channel }) } + + pub fn read_ref_adc(&mut self, channel: usize) -> u16 { + match channel { + 0 => self.channel0.ref_adc.convert( + &self.channel0.ref_pin, + stm32f4xx_hal::adc::config::SampleTime::Cycles_480 + ), + 1 => self.channel1.ref_adc.convert( + &self.channel1.ref_pin, + stm32f4xx_hal::adc::config::SampleTime::Cycles_480 + ), + _ => unreachable!(), + } + } } diff --git a/src/main.rs b/src/main.rs index 3cd1036..d0b3ad4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,19 +141,16 @@ fn main() -> ! { } Command::Show(ShowCommand::Input) => { for channel in 0..CHANNELS { - let state = channels.channel_state(channel); - if let Some(adc_data) = state.adc_data { + if let Some(adc_data) = channels.channel_state(channel).adc_data { + let ref_adc_data = channels.read_ref_adc(channel); + let state = channels.channel_state(channel); let _ = writeln!( - socket, "t={} raw{}=0x{:06X}", - state.adc_time, channel, adc_data + socket, "t={} raw{}=0x{:06X} ref_adc={}", + state.adc_time, channel, adc_data, + ref_adc_data ); } } - - let ref0 = channels.channel0.ref_adc.convert( - &channels.channel0.ref_pin, stm32f4xx_hal::adc::config::SampleTime::Cycles_480 - ); - let _ = writeln!(socket, "ref0={}", ref0); } Command::Show(ShowCommand::Pid) => { for channel in 0..CHANNELS {