Simple Arduino FSM
DoorCtrl.h
Go to the documentation of this file.
1 
15 #ifndef DoorCTRL_H__
16 #define DoorCTRL_H__
17 
18 #include "LogConfiguration.h"
19 
20 #include "Door.h"
21 
27 class DoorCtrl {
28  //=====PUBLIC====================================================================================
29  public:
34  enum class Event { Open,
35  Close,
36  Opened,
37  Closed,
38  Error,
39  Resume,
40  NoEvent
41  };
42 
47  enum class State { opened,
48  closing,
49  closed,
50  opening,
51  errorState
52  };
53 
60  DoorCtrl();
61 
66  void loop();
67 
73  void loop(Event currentEvent);
74 
80  const State getcurrentState();
81 
90  String decodeState(State state);
91 
92  //=====PRIVATE====================================================================================
93  private:
97 
103  Event (DoorCtrl::*doActionFPtr)(void) = nullptr; //initialize in CTor!!
104 
105  Door pDoor = Door(0, 10);
106 
107  //=====PrivateFunctions=========================================================================
114  void process(Event e);
115  //=====StateFunctions=====
116  //=====opened==========================================================
121  void entryAction_opened();
122 
131 
136  void exitAction_opened();
137 
138  //=====closing==========================================================
143  void entryAction_closing();
144 
154 
159  void exitAction_closing();
160 
161  //=====closed==========================================================
166  void entryAction_closed();
167 
176 
181  void exitAction_closed();
182 
183  //=====opening==========================================================
188  void entryAction_opening();
189 
199 
204  void exitAction_opening();
205 
206  //==errorState==========================================================
211  void entryAction_errorState();
212 
219 
224  void exitAction_errorState();
225 
226  //============================================================================
227  //==Aux-Function==============================================================
228 
235  String decodeEvent(Event event);
236 };
237 #endif
State lastStateBevorError
holds the last state of the FSM so it's possible to resume after error
Definition: DoorCtrl.h:94
Event currentEvent
holds the current event of the FSM
Definition: DoorCtrl.h:96
void entryAction_closing()
executes the entry action of the closing state.
Definition: DoorCtrl.cpp:130
void exitAction_opening()
executes the exit action of the opening state.
Definition: DoorCtrl.cpp:185
DoorCtrl::Event doAction_opened()
executes the main action of the opened state.
Definition: DoorCtrl.cpp:119
No event generated.
void entryAction_closed()
executes the entry action of the closed state.
Definition: DoorCtrl.cpp:151
void process(Event e)
Changes the state of the FSM based on the event Here is where the magic happens :)
Definition: DoorCtrl.cpp:36
DoorCtrl()
Construct a new Door Ctrl object and initailize the currentState with low state.
Definition: DoorCtrl.cpp:17
State currentState
holds the current state of the FSM
Definition: DoorCtrl.h:95
DoorCtrl::Event doAction_errorState()
main action of the errorState state.
Definition: DoorCtrl.cpp:198
Ext: Start Opening.
DoorCtrl::Event doAction_opening()
executes the main action of the opening state.
Definition: DoorCtrl.cpp:176
Provides the basic Functions to Controll the Door.
Definition: Door.h:22
const State getcurrentState()
Get the current State.
Definition: DoorCtrl.cpp:32
Contains the FSM for the Door.
Definition: DoorCtrl.h:27
void exitAction_closed()
executes the exit action of the closed state.
Definition: DoorCtrl.cpp:164
void entryAction_errorState()
entry action of the errorState state.
Definition: DoorCtrl.cpp:190
DoorCtrl::Event doAction_closing()
executes the main action of the closing state.
Definition: DoorCtrl.cpp:137
void exitAction_opened()
executes the exit action of the opened state.
Definition: DoorCtrl.cpp:125
DoorCtrl::Event doAction_closed()
executes the main action of the closed state.
Definition: DoorCtrl.cpp:158
void entryAction_opening()
executes the entry action of the opening state.
Definition: DoorCtrl.cpp:169
Contains Pre-Compiler directives for diffent Serialprints for Datalogin.
Door pDoor
Door Object with ClosedPostion 0 and OpenPosition 10.
Definition: DoorCtrl.h:105
State
Enum holds all possible states for the Door.
Definition: DoorCtrl.h:47
String decodeState(State state)
Decodes the State-Enum and returns a description.
Definition: DoorCtrl.cpp:211
void exitAction_errorState()
exit action of the errorState state.
Definition: DoorCtrl.cpp:205
void loop()
Calls the do-function of the active state and hence generates Events.
Definition: DoorCtrl.cpp:21
Ext: Start Closeing.
Signal: Close position reached.
Signal: Open position reached.
void exitAction_closing()
executes the exit action of the closing state.
Definition: DoorCtrl.cpp:146
Event
Enum holds all possible events.
Definition: DoorCtrl.h:34
Event(DoorCtrl::* doActionFPtr)(void)
Functionpointer to call the current states do-function.
Definition: DoorCtrl.h:103
String decodeEvent(Event event)
Decodes the Event-Enum and returns a description.
Definition: DoorCtrl.cpp:233
Ext: Resume after Error occured.
Implementation of the Door-Class.
void entryAction_opened()
executes the entry action of the opened state.
Definition: DoorCtrl.cpp:112