blob: 7d2447cf1d9bd2e310e59e396423330822bae2c7 (
plain)
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
|
#ifndef MOTOR_HPP_INCLUDED
#define MOTOR_HPP_INCLUDED
#include <tinyfsm.hpp>
// ----------------------------------------------------------------------------
// Event declarations
//
struct MotorUp : tinyfsm::Event { };
struct MotorDown : tinyfsm::Event { };
struct MotorStop : tinyfsm::Event { };
// ----------------------------------------------------------------------------
// Motor (FSM base class) declaration
//
class Motor
: public tinyfsm::Fsm<Motor>
{
/* NOTE: react(), entry() and exit() functions need to be accessible
* from tinyfsm::Fsm class. You might as well declare friendship to
* tinyfsm::Fsm, and make these functions private:
*
* friend class Fsm;
*/
public:
/* default reaction for unhandled events */
void react(tinyfsm::Event const &) { };
/* non-virtual declaration: reactions are the same for all states */
void react(MotorUp const &);
void react(MotorDown const &);
void react(MotorStop const &);
virtual void entry(void) = 0; /* pure virtual: enforce implementation in all states */
void exit(void) { }; /* no exit actions at all */
protected:
static int direction;
public:
static int getDirection() { return direction; }
};
#endif
|