Compare commits
1 Commits
509b53d67d
...
cb4d5b737e
Author | SHA1 | Date |
---|---|---|
atse | cb4d5b737e |
|
@ -129,7 +129,16 @@ impl<'a> Channels<'a> {
|
||||||
voltage
|
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() {
|
let vref_meas = match channel.into() {
|
||||||
0 => self.channel0.vref_meas,
|
0 => self.channel0.vref_meas,
|
||||||
1 => self.channel1.vref_meas,
|
1 => self.channel1.vref_meas,
|
||||||
|
|
|
@ -54,8 +54,7 @@ pub enum Handler {
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
ReportError,
|
ReportError,
|
||||||
PostFilterRateError,
|
PostFilterRateError,
|
||||||
FlashError,
|
FlashError
|
||||||
InputOutOfRangeError,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type JsonBuffer = Vec<u8, U1024>;
|
pub type JsonBuffer = Vec<u8, U1024>;
|
||||||
|
@ -185,14 +184,8 @@ impl Handler {
|
||||||
fn set_pwm (socket: &mut TcpSocket, channels: &mut Channels, channel: usize, pin: PwmPin, value: f64) -> Result<Handler, Error> {
|
fn set_pwm (socket: &mut TcpSocket, channels: &mut Channels, channel: usize, pin: PwmPin, value: f64) -> Result<Handler, Error> {
|
||||||
match pin {
|
match pin {
|
||||||
PwmPin::ISet => {
|
PwmPin::ISet => {
|
||||||
let current = ElectricCurrent::new::<ampere>(value);
|
|
||||||
let min = ElectricCurrent::new::<ampere>(-3.0);
|
|
||||||
let max = ElectricCurrent::new::<ampere>(3.0);
|
|
||||||
if current < min || current > max {
|
|
||||||
send_line(socket, b"{\"error\": \"i_set has unit A and should be in range [-3, +3]\"}");
|
|
||||||
return Err(Error::InputOutOfRangeError);
|
|
||||||
}
|
|
||||||
channels.channel_state(channel).pid_engaged = false;
|
channels.channel_state(channel).pid_engaged = false;
|
||||||
|
let current = ElectricCurrent::new::<ampere>(value);
|
||||||
channels.set_i(channel, current);
|
channels.set_i(channel, current);
|
||||||
channels.power_up(channel);
|
channels.power_up(channel);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue