rsiot/components/cmp_plc/plc/library/edge_detect/
rising_edge.rs1use serde::{Deserialize, Serialize};
4
5use crate::components::cmp_plc::plc::FbSystemData;
6
7use super::super::super::function_block_base::{FunctionBlockBase, IFunctionBlock};
8
9#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
11pub struct I {
12 pub i: bool,
14}
15
16#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
18pub struct Q {
19 pub q: bool,
21}
22
23#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
25pub struct S {
26 prev_i: bool,
27}
28
29impl IFunctionBlock<I, Q, S> for FunctionBlockBase<I, Q, S> {
30 fn logic(input: &mut I, stat: &mut S, _system_data: &FbSystemData) -> Q {
31 let rising_edge = input.i && !stat.prev_i;
32 stat.prev_i = input.i;
33
34 Q { q: rising_edge }
35 }
36}
37
38pub type FB = FunctionBlockBase<I, Q, S>;