rsiot/components/cmp_plc/plc/library/edge_detect/
rising_edge.rsuse serde::{Deserialize, Serialize};
use crate::components::cmp_plc::plc::FbSystemData;
use super::super::super::function_block_base::{FunctionBlockBase, IFunctionBlock};
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct I {
pub i: bool,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct Q {
pub q: bool,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct S {
prev_i: bool,
}
impl IFunctionBlock<I, Q, S> for FunctionBlockBase<I, Q, S> {
fn logic(input: &mut I, stat: &mut S, _system_data: &FbSystemData) -> Q {
let rising_edge = input.i && !stat.prev_i;
stat.prev_i = input.i;
Q { q: rising_edge }
}
}
pub type FB = FunctionBlockBase<I, Q, S>;