forked from M-Labs/thermostat
Limit i_set within range of MAX1968 chip
This commit is contained in:
parent
76547be90a
commit
509b53d67d
|
@ -54,7 +54,8 @@ 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>;
|
||||||
|
@ -184,8 +185,14 @@ 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 => {
|
||||||
channels.channel_state(channel).pid_engaged = false;
|
|
||||||
let current = ElectricCurrent::new::<ampere>(value);
|
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.set_i(channel, current);
|
channels.set_i(channel, current);
|
||||||
channels.power_up(channel);
|
channels.power_up(channel);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue