|
Simple Arduino FSM
|
Contains the FSM for the Door. More...
#include <DoorCtrl.h>

Public Types | |
| enum | Event { Event::Open, Event::Close, Event::Opened, Event::Closed, Event::Error, Event::Resume, Event::NoEvent } |
| Enum holds all possible events. More... | |
| enum | State { State::opened, State::closing, State::closed, State::opening, State::errorState } |
| Enum holds all possible states for the Door. More... | |
Public Member Functions | |
| DoorCtrl () | |
| Construct a new Door Ctrl object and initailize the currentState with low state. More... | |
| void | loop () |
| Calls the do-function of the active state and hence generates Events. More... | |
| void | loop (Event currentEvent) |
| Procceses the current Event and calls the do-function of the active state. More... | |
| const State | getcurrentState () |
| Get the current State. More... | |
| String | decodeState (State state) |
| Decodes the State-Enum and returns a description. More... | |
Private Member Functions | |
| void | process (Event e) |
| Changes the state of the FSM based on the event Here is where the magic happens :) More... | |
| void | entryAction_opened () |
| executes the entry action of the opened state. More... | |
| DoorCtrl::Event | doAction_opened () |
| executes the main action of the opened state. More... | |
| void | exitAction_opened () |
| executes the exit action of the opened state. More... | |
| void | entryAction_closing () |
| executes the entry action of the closing state. More... | |
| DoorCtrl::Event | doAction_closing () |
| executes the main action of the closing state. More... | |
| void | exitAction_closing () |
| executes the exit action of the closing state. More... | |
| void | entryAction_closed () |
| executes the entry action of the closed state. More... | |
| DoorCtrl::Event | doAction_closed () |
| executes the main action of the closed state. More... | |
| void | exitAction_closed () |
| executes the exit action of the closed state. More... | |
| void | entryAction_opening () |
| executes the entry action of the opening state. More... | |
| DoorCtrl::Event | doAction_opening () |
| executes the main action of the opening state. More... | |
| void | exitAction_opening () |
| executes the exit action of the opening state. More... | |
| void | entryAction_errorState () |
| entry action of the errorState state. More... | |
| DoorCtrl::Event | doAction_errorState () |
| main action of the errorState state. More... | |
| void | exitAction_errorState () |
| exit action of the errorState state. More... | |
| String | decodeEvent (Event event) |
| Decodes the Event-Enum and returns a description. More... | |
Private Attributes | |
| State | lastStateBevorError |
| holds the last state of the FSM so it's possible to resume after error More... | |
| State | currentState |
| holds the current state of the FSM More... | |
| Event | currentEvent |
| holds the current event of the FSM More... | |
| Event(DoorCtrl::* | doActionFPtr )(void) = nullptr |
| Functionpointer to call the current states do-function. More... | |
| Door | pDoor = Door(0, 10) |
| Door Object with ClosedPostion 0 and OpenPosition 10. More... | |
|
strong |
Enum holds all possible events.
Definition at line 34 of file DoorCtrl.h.
|
strong |
Enum holds all possible states for the Door.
| Enumerator | |
|---|---|
| opened | 1 opended State |
| closing | 2 closing State |
| closed | 3 closed State |
| opening | 4 opening State |
| errorState | error State |
Definition at line 47 of file DoorCtrl.h.
| DoorCtrl::DoorCtrl | ( | ) |
Construct a new Door Ctrl object and initailize the currentState with low state.
Definition at line 17 of file DoorCtrl.cpp.
| void DoorCtrl::loop | ( | ) |
Calls the do-function of the active state and hence generates Events.
Definition at line 21 of file DoorCtrl.cpp.
| void DoorCtrl::loop | ( | Event | currentEvent | ) |
Procceses the current Event and calls the do-function of the active state.
| currentEvent | - Event |
Definition at line 26 of file DoorCtrl.cpp.
| const DoorCtrl::State DoorCtrl::getcurrentState | ( | ) |
| String DoorCtrl::decodeState | ( | State | state | ) |
Decodes the State-Enum and returns a description.
Move this Func to private if you don't need it in main
| state | - enum State |
Definition at line 211 of file DoorCtrl.cpp.
|
private |
Changes the state of the FSM based on the event Here is where the magic happens :)
| e | - Event |
Definition at line 36 of file DoorCtrl.cpp.
|
private |
executes the entry action of the opened state.
Definition at line 112 of file DoorCtrl.cpp.
|
private |
executes the main action of the opened state.
This is an idle-State so it returns always NoEvent when called
Definition at line 119 of file DoorCtrl.cpp.
|
private |
executes the exit action of the opened state.
Definition at line 125 of file DoorCtrl.cpp.
|
private |
executes the entry action of the closing state.
Definition at line 130 of file DoorCtrl.cpp.
|
private |
executes the main action of the closing state.
Calls close() and returns Event::Closed when the Door is closed. else returns NoEvent
Definition at line 137 of file DoorCtrl.cpp.
|
private |
executes the exit action of the closing state.
Definition at line 146 of file DoorCtrl.cpp.
|
private |
executes the entry action of the closed state.
Definition at line 151 of file DoorCtrl.cpp.
|
private |
executes the main action of the closed state.
This is an idle-State so it returns always NoEvent when called
Definition at line 158 of file DoorCtrl.cpp.
|
private |
executes the exit action of the closed state.
Definition at line 164 of file DoorCtrl.cpp.
|
private |
executes the entry action of the opening state.
Definition at line 169 of file DoorCtrl.cpp.
|
private |
executes the main action of the opening state.
Calls open() and returns Event::Closed when the Door is opend. else returns NoEvent.
Definition at line 176 of file DoorCtrl.cpp.
|
private |
executes the exit action of the opening state.
Definition at line 185 of file DoorCtrl.cpp.
|
private |
entry action of the errorState state.
Definition at line 190 of file DoorCtrl.cpp.
|
private |
main action of the errorState state.
Definition at line 198 of file DoorCtrl.cpp.
|
private |
exit action of the errorState state.
Definition at line 205 of file DoorCtrl.cpp.
|
private |
Decodes the Event-Enum and returns a description.
| event | - enum Event |
Definition at line 233 of file DoorCtrl.cpp.
|
private |
holds the last state of the FSM so it's possible to resume after error
Definition at line 94 of file DoorCtrl.h.
|
private |
holds the current state of the FSM
Definition at line 95 of file DoorCtrl.h.
|
private |
holds the current event of the FSM
Definition at line 96 of file DoorCtrl.h.
|
private |
Functionpointer to call the current states do-function.
https://stackoverflow.com/questions/1485983/calling-c-class-methods-via-a-function-pointer
Definition at line 103 of file DoorCtrl.h.
Door Object with ClosedPostion 0 and OpenPosition 10.
Definition at line 105 of file DoorCtrl.h.