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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::time::Duration;

use super::{I, Q, S};

pub fn logic<TState>(input: &I<TState>, stat: &mut S<TState>) -> Q<TState>
where
    TState: Copy + PartialEq,
{
    let is_first_cycle;
    if stat.current_state == input.new_state {
        stat.state_time += input.cycle_time;
        is_first_cycle = false;
    } else {
        stat.state_time = Duration::default();
        stat.current_state = input.new_state;
        is_first_cycle = true;
    };

    Q {
        current_state: stat.current_state,
        state_time: stat.state_time,
        is_first_cycle,
    }
}