rsiot/components/cmp_plc/plc/library/state_machine/
logic.rs

1use std::time::Duration;
2
3use crate::components::cmp_plc::plc::FbSystemData;
4
5use super::{I, Q, S};
6
7pub fn logic<TState>(
8    input: &I<TState>,
9    stat: &mut S<TState>,
10    system_data: &FbSystemData,
11) -> Q<TState>
12where
13    TState: Copy + PartialEq,
14{
15    let is_first_cycle;
16    if stat.current_state == input.new_state {
17        stat.state_time += system_data.period;
18        is_first_cycle = false;
19    } else {
20        stat.state_time = Duration::default();
21        stat.current_state = input.new_state;
22        is_first_cycle = true;
23    };
24
25    Q {
26        current_state: stat.current_state,
27        state_time: stat.state_time,
28        is_first_cycle,
29    }
30}