forked from pa-pa/AskSinPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchStateMachine.cpp
33 lines (27 loc) · 852 Bytes
/
SwitchStateMachine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "SwitchStateMachine.h"
namespace as {
void SwitchStateMachine::switchState(uint8_t oldstate,uint8_t newstate) {}
void SwitchStateMachine::setState (uint8_t next,uint32_t delay,const SwitchPeerList& lst,uint8_t deep) {
// check deep to prevent infinite recursion
if( next != AS_CM_JT_NONE && deep < 4) {
// first cancel possible running alarm
aclock.cancel(alarm);
// if state is different
if (state != next) {
switchState(state, next);
state = next;
}
if (delay == DELAY_NO) {
// go immediately to the next state
next = getNextState();
delay = getDelayForState(next,lst);
setState(next, delay, lst, ++deep);
}
else if (delay != DELAY_INFINITE) {
alarm.list(lst);
alarm.set(delay);
aclock.add(alarm);
}
}
}
}