-
Notifications
You must be signed in to change notification settings - Fork 1
/
Demo.be
53 lines (39 loc) · 1.43 KB
/
Demo.be
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# define the states
stIdle = "stIdle"
stProcessing = "stProcessing"
stFinished = "stFinished"
# define the transistions
trStartProcessing = "StartProcessing"
trProcessFinished= "ProcessFinished"
trWaitForNextJob = "WaitForNextJob"
# create the state manager
fsm = StateMan("fsm-demo")
# define state stIdle
fsm
.addState(stIdle)
# define the transistion to following state (multiple definitions are allowed)
.next(stProcessing,trStartProcessing)
# define a callback method, when the state is entered
.onEnter(def () print(f"entering {stIdle}") end)
# define a callback method when the state is leaved
.onLeave(def () print(f"leaving {stIdle}") end)
# define a callback method the will be cyclically called, when the state is active
.onTimer(def () print(f"just in state {stIdle}") end)
# define state stProcessing
fsm
.addState(stProcessing)
.next(stFinished,trProcessFinished)
.onEnter(def () print(f"entering {stProcessing}") end)
.onLeave(def () print(f"leaving {stProcessing}") end)
.onTimer(def () print(f"just in state {stProcessing}") end)
# define state stFinished
fsm
.addState(stFinished)
.next(stIdle,trWaitForNextJob)
.onEnter(def () print(f"entering {stFinished}") end)
.onLeave(def () print(f"leaving {stFinished}") end)
.onTimer(def () print(f"just in state {stFinished}") end)
# print out infos
fsm.infoEnable=true
# start the state-machine
fsm.start()