forked from pa-pa/AskSinPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchStateMachine.cpp
37 lines (31 loc) · 1.18 KB
/
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
34
35
36
37
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http:https://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------
#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);
}
}
}
}