Update channel_state VREF on every measurement

Helps keep the VREF value in reports updated.
This commit is contained in:
atse 2023-08-21 13:01:07 +08:00
parent 7043974bb5
commit bdffcd4423
1 changed files with 6 additions and 2 deletions

View File

@ -265,7 +265,9 @@ impl Channels {
let samples = 50; let samples = 50;
let mut target_voltage = ElectricPotential::new::<volt>(0.0); let mut target_voltage = ElectricPotential::new::<volt>(0.0);
for _ in 0..samples { for _ in 0..samples {
target_voltage = target_voltage + self.read_vref(channel); let vref = self.read_vref(channel);
self.channel_state(channel).vref = vref;
target_voltage = target_voltage + vref;
} }
target_voltage = target_voltage / samples as f64; target_voltage = target_voltage / samples as f64;
let mut start_value = 1; let mut start_value = 1;
@ -372,7 +374,9 @@ impl Channels {
// Get current passing through TEC // Get current passing through TEC
pub fn get_tec_i(&mut self, channel: usize) -> ElectricCurrent { pub fn get_tec_i(&mut self, channel: usize) -> ElectricCurrent {
(self.read_itec(channel) - self.read_vref(channel)) / ElectricalResistance::new::<ohm>(0.4) let vref = self.read_vref(channel);
self.channel_state(channel).vref = vref;
(self.read_itec(channel) - vref) / ElectricalResistance::new::<ohm>(0.4)
} }
// Get voltage across TEC // Get voltage across TEC