|
|
|
|
@ -13,7 +13,7 @@ const VALVE_TERMINAL_IDENT_NUMBER: u16 = 0x0a35;
|
|
|
|
|
pub struct ValveTerminal {
|
|
|
|
|
peripheral: dp::PeripheralHandle,
|
|
|
|
|
address: profirust::Address,
|
|
|
|
|
valve_states: u8,
|
|
|
|
|
valve_states: [bool; 8],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ValveTerminal {
|
|
|
|
|
@ -68,7 +68,7 @@ impl ValveTerminal {
|
|
|
|
|
Self {
|
|
|
|
|
peripheral: handle,
|
|
|
|
|
address: default_address,
|
|
|
|
|
valve_states: 0,
|
|
|
|
|
valve_states: [false; 8],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -89,18 +89,27 @@ impl ValveTerminal {
|
|
|
|
|
let peripheral = dp_master.get_mut(self.peripheral);
|
|
|
|
|
peripheral.reset_address(address);
|
|
|
|
|
peripheral.pi_q_mut().fill(0u8);
|
|
|
|
|
self.valve_states = 0;
|
|
|
|
|
self.valve_states = [false; 8];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update_valve_states(&mut self, valve_states: u8) {
|
|
|
|
|
self.valve_states = valve_states;
|
|
|
|
|
pub fn update_valve_states(&mut self, valve_states: &[bool]) {
|
|
|
|
|
if self.valve_states != valve_states {
|
|
|
|
|
self.valve_states.copy_from_slice(valve_states);
|
|
|
|
|
log::info!("Ventile: {:?}", valve_states);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update(&mut self, dp_master: &mut dp::DpMaster, events: &dp::DpEvents) {
|
|
|
|
|
let peripheral = dp_master.get_mut(self.peripheral);
|
|
|
|
|
if peripheral.is_running() && events.cycle_completed {
|
|
|
|
|
peripheral.pi_q_mut()[0] = self.valve_states;
|
|
|
|
|
let pi_q = peripheral.pi_q_mut();
|
|
|
|
|
pi_q.fill(0);
|
|
|
|
|
for (i, valve) in self.valve_states.iter().enumerate() {
|
|
|
|
|
let bit_index = i * 2;
|
|
|
|
|
let bit_value = if *valve { 1 } else { 0 };
|
|
|
|
|
pi_q[bit_index / 8] |= bit_value << (bit_index % 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|