Represent valve states as array of bools
This commit is contained in:
parent
767bbb1c56
commit
9cae0cbaa3
2 changed files with 23 additions and 11 deletions
|
|
@ -26,8 +26,8 @@ pub enum TesterStatus {
|
||||||
|
|
||||||
pub struct TesterIo {
|
pub struct TesterIo {
|
||||||
peripheral: dp::PeripheralHandle,
|
peripheral: dp::PeripheralHandle,
|
||||||
valve_states: u8,
|
|
||||||
tester_status: TesterStatus,
|
tester_status: TesterStatus,
|
||||||
|
valve_states: [bool; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TesterIo {
|
impl TesterIo {
|
||||||
|
|
@ -76,20 +76,23 @@ impl TesterIo {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
peripheral: handle,
|
peripheral: handle,
|
||||||
valve_states: 0,
|
valve_states: [false; 8],
|
||||||
tester_status: TesterStatus::Ready,
|
tester_status: TesterStatus::Ready,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn valve_states(&self) -> u8 {
|
pub fn valve_states(&self) -> &[bool] {
|
||||||
self.valve_states
|
&self.valve_states
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, dp_master: &mut dp::DpMaster, events: &dp::DpEvents) {
|
pub fn update(&mut self, dp_master: &mut dp::DpMaster, events: &dp::DpEvents) {
|
||||||
let peripheral = dp_master.get_mut(self.peripheral);
|
let peripheral = dp_master.get_mut(self.peripheral);
|
||||||
if peripheral.is_running() && events.cycle_completed {
|
if peripheral.is_running() && events.cycle_completed {
|
||||||
// Die 8 Eingänge der ET200B werden auf die 8 Bits für die Ventile gemapped.
|
// Die 8 Eingänge der ET200B werden auf die 8 Bits für die Ventile gemapped.
|
||||||
self.valve_states = peripheral.pi_i()[0];
|
let pi_i = peripheral.pi_i();
|
||||||
|
for (i, valve) in self.valve_states.iter_mut().enumerate() {
|
||||||
|
*valve = pi_i[i / 8] & (1 << (i % 8)) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Ausgänge:
|
// Ausgänge:
|
||||||
// - Bit 0: Leuchtmelder "Test-Station bereit"
|
// - Bit 0: Leuchtmelder "Test-Station bereit"
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ const VALVE_TERMINAL_IDENT_NUMBER: u16 = 0x0a35;
|
||||||
pub struct ValveTerminal {
|
pub struct ValveTerminal {
|
||||||
peripheral: dp::PeripheralHandle,
|
peripheral: dp::PeripheralHandle,
|
||||||
address: profirust::Address,
|
address: profirust::Address,
|
||||||
valve_states: u8,
|
valve_states: [bool; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ValveTerminal {
|
impl ValveTerminal {
|
||||||
|
|
@ -68,7 +68,7 @@ impl ValveTerminal {
|
||||||
Self {
|
Self {
|
||||||
peripheral: handle,
|
peripheral: handle,
|
||||||
address: default_address,
|
address: default_address,
|
||||||
valve_states: 0,
|
valve_states: [false; 8],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,18 +89,27 @@ impl ValveTerminal {
|
||||||
let peripheral = dp_master.get_mut(self.peripheral);
|
let peripheral = dp_master.get_mut(self.peripheral);
|
||||||
peripheral.reset_address(address);
|
peripheral.reset_address(address);
|
||||||
peripheral.pi_q_mut().fill(0u8);
|
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) {
|
pub fn update_valve_states(&mut self, valve_states: &[bool]) {
|
||||||
self.valve_states = valve_states;
|
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) {
|
pub fn update(&mut self, dp_master: &mut dp::DpMaster, events: &dp::DpEvents) {
|
||||||
let peripheral = dp_master.get_mut(self.peripheral);
|
let peripheral = dp_master.get_mut(self.peripheral);
|
||||||
if peripheral.is_running() && events.cycle_completed {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue