-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotor.h
46 lines (41 loc) · 1.07 KB
/
Motor.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
#ifndef MOTOR_H
#define MOTOR_H
#include "StateMachine.h"
// structure to hold event data passed into state machine
struct MotorData : public EventData
{
int speed;
};
// the Motor state machine class
class Motor : public StateMachine
{
public:
Motor() : StateMachine(ST_MAX_STATES) {}
// external events taken by this state machine
void Halt();
void SetSpeed(MotorData*);
private:
// state machine state functions
void ST_Idle();
void ST_Stop();
void ST_Start(MotorData*);
void ST_ChangeSpeed(MotorData*);
void endFunc(){}
// state map to define state function order
BEGIN_STATE_MAP
STATE_MAP_ENTRY(Motor::ST_Idle)
STATE_MAP_ENTRY(Motor::ST_Stop)
STATE_MAP_ENTRY(Motor::ST_Start)
STATE_MAP_ENTRY(Motor::ST_ChangeSpeed)
END_STATE_MAP(Motor::endFunc)
// state enumeration order must match the order of state
// method entries in the state map
enum E_States {
ST_IDLE = 0,
ST_STOP,
ST_START,
ST_CHANGE_SPEED,
ST_MAX_STATES
};
};
#endif //MOTOR_H