Limit i_set within range of MAX1968 chip

atse 2024-04-03 11:31:34 +08:00
parent 76547be90a
commit cb4d5b737e
1 changed files with 10 additions and 1 deletions

View File

@ -129,7 +129,16 @@ impl<'a> Channels<'a> {
voltage
}
pub fn set_i(&mut self, channel: usize, i_set: ElectricCurrent) -> ElectricCurrent {
pub fn set_i(&mut self, channel: usize, mut i_set: ElectricCurrent) -> ElectricCurrent {
// Silently clamp i_set to available range of MAX1968 chip
let min = ElectricCurrent::new::<ampere>(-3.0);
let max = ElectricCurrent::new::<ampere>(3.0);
if i_set < min {
i_set = min;
}
if i_set > max {
i_set = max;
}
let vref_meas = match channel.into() {
0 => self.channel0.vref_meas,
1 => self.channel1.vref_meas,