-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFiniteStateMachine.h
53 lines (41 loc) · 1.1 KB
/
FiniteStateMachine.h
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
#ifndef FINITESTATEMACHINE_H
#define FINITESTATEMACHINE_H
#include "Arduino.h"
//define the functionality of the states
class SuperState {
public:
SuperState(String name): name(name) {
}
virtual ~SuperState() {}
virtual void enter() {}
virtual void exit() {}
const String name;
};
class State {
public:
State(String name): name(name), superState(NULL) {
}
State(String name, SuperState *const superState): name(name), superState(superState) {
}
virtual ~State() {}
virtual void enter() {}
virtual void exit() {}
const String name;
SuperState * const superState;
};
//define the finite state machine functionality
class FiniteStateMachine {
public:
FiniteStateMachine(State& current, String name);
FiniteStateMachine& changeState(State& state);
State& getCurrentState();
virtual boolean isInState(State& state) const;
virtual boolean isInState(SuperState& superState) const;
unsigned long timeInCurrentState();
protected:
unsigned long stateChangeTime;
private:
State* currentState;
const String name;
};
#endif