From c0079007f20b808a1e9fb453d38bc7a66dda7e4b Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 13 May 2020 22:11:25 +0200 Subject: [PATCH] do not overwrite dac value when pid is disengaged --- src/channel_state.rs | 4 ++-- src/channels.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/channel_state.rs b/src/channel_state.rs index 26e3f61..cd4e5d4 100644 --- a/src/channel_state.rs +++ b/src/channel_state.rs @@ -26,7 +26,7 @@ impl Default for ChannelState { impl ChannelState { /// Update PID state on ADC input, calculate new DAC output - pub fn update_pid(&mut self, now: Instant, adc_data: u32) { + pub fn update_pid(&mut self, now: Instant, adc_data: u32) -> u32 { self.adc_data = Some(adc_data); self.adc_time = now; @@ -34,6 +34,6 @@ impl ChannelState { let input = (adc_data as f64) / (ad7172::MAX_VALUE as f64); let temperature = self.sh.get_temperature(input); let output = self.pid.update(temperature); - self.dac_value = (output * (ad5680::MAX_VALUE as f64)) as u32; + (output * (ad5680::MAX_VALUE as f64)) as u32 } } diff --git a/src/channels.rs b/src/channels.rs index 0483463..6416161 100644 --- a/src/channels.rs +++ b/src/channels.rs @@ -48,10 +48,10 @@ impl Channels { let dac_value = { let state = self.channel_state(channel); - state.update_pid(instant, data); + let pid_output = state.update_pid(instant, data); if state.pid_engaged { - Some(state.dac_value) + Some(pid_output) } else { None }