forked from hoffmannjoern/IoT-Shield-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parkinglot.cpp
50 lines (45 loc) · 1.01 KB
/
Parkinglot.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
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "Parkinglot.h"
#include "QmlModel.h"
Parkinglot::Parkinglot(QmlModel& model) : model(model) {}
void Parkinglot::process(Events event)
{
// input
if(event == pay && credit <9) {
credit++;
}
if(event == free) {
credit = 0;
}
if(event == tick && (state == S4 || state == S5) && credit >= 1) {
credit--;
}
// transition
if(event == tick && state == S4 && credit == 1) {
// special tick if only one credit left: enter alert state (S5)
state = S5;
} else {
state = transitions[state][event];
}
// output
switch(state)
{
case S0:
model.setState(false, false, false, -1);
break;
case S1:
model.setState(true, false, false, credit);
break;
case S2:
model.setState(true, false, false, credit);
break;
case S3:
model.setState(true, false, false, credit);
break;
case S4:
model.setState(false, false, true, credit);
break;
case S5:
model.setState(false, true, false, credit);
break;
}
}