forked from M-Labs/kirdy
thermostat: split poll_adc & update_pid into 2 fns
This commit is contained in:
parent
c09ccc29cd
commit
d1cc677668
|
@ -92,7 +92,8 @@ fn main() -> ! {
|
|||
|
||||
laser.poll_and_update_output_current();
|
||||
|
||||
if thermostat.poll_adc_and_update_pid() {
|
||||
if thermostat.poll_adc() {
|
||||
thermostat.update_pid();
|
||||
if thermostat.get_temp_mon_status().over_temp_alarm {
|
||||
laser.power_down();
|
||||
thermostat.set_pid_engaged(false);
|
||||
|
|
|
@ -151,31 +151,36 @@ impl Thermostat{
|
|||
adc_calibration0
|
||||
}
|
||||
|
||||
pub fn poll_adc_and_update_pid(&mut self) -> bool {
|
||||
pub fn poll_adc(&mut self) -> bool {
|
||||
let mut data_rdy = false;
|
||||
self.ad7172.data_ready().unwrap().map(|_ch| {
|
||||
let data = self.ad7172.read_data().unwrap();
|
||||
let state: &mut PidState = &mut self.pid_ctrl_ch0;
|
||||
state.update(data);
|
||||
debug!("state.get_pid_engaged(): {:?}", state.get_pid_engaged());
|
||||
let pid_engaged = state.get_pid_engaged();
|
||||
if pid_engaged {
|
||||
match state.update_pid() {
|
||||
Some(pid_output) => {
|
||||
self.set_i(ElectricCurrent::new::<ampere>(pid_output));
|
||||
debug!("Temperature Set Point: {:?} degree", self.pid_ctrl_ch0.get_pid_setpoint().get::<degree_celsius>());
|
||||
}
|
||||
None => { }
|
||||
}
|
||||
}
|
||||
let temp = self.get_temperature();
|
||||
self.temp_mon.update_status(pid_engaged, temp);
|
||||
debug!("state.get_pid_engaged(): {:?}", pid_engaged);
|
||||
debug!("Temperature: {:?} degree", temp.get::<degree_celsius>());
|
||||
data_rdy = true;
|
||||
});
|
||||
data_rdy
|
||||
}
|
||||
|
||||
pub fn update_pid(&mut self) {
|
||||
let state: &mut PidState = &mut self.pid_ctrl_ch0;
|
||||
let pid_engaged = state.get_pid_engaged();
|
||||
if pid_engaged {
|
||||
match state.update_pid() {
|
||||
Some(pid_output) => {
|
||||
self.set_i(ElectricCurrent::new::<ampere>(pid_output));
|
||||
debug!("Temperature Set Point: {:?} degree", self.pid_ctrl_ch0.get_pid_setpoint().get::<degree_celsius>());
|
||||
}
|
||||
None => { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_temp_mon_status(&mut self) -> TempStatus {
|
||||
self.temp_mon.get_status()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue