-
Notifications
You must be signed in to change notification settings - Fork 3
/
state.cpp
executable file
·32 lines (25 loc) · 997 Bytes
/
state.cpp
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
#include "state.h"
#include <Arduino.h>
state* currentState = NULL;
/**************************************************************************/
/*!
@brief Transition from the current state to a new state. It is not safe to call this method during a states end method. Doing so will result in undefined behaviour
*/
/**************************************************************************/
void setState(state *newState) {
if(newState == currentState) return;
if(currentState!=NULL && currentState->end!=NULL)
currentState->end();
currentState = newState;
if(currentState!=NULL && currentState->init!=NULL)
currentState->init();
}
/**************************************************************************/
/*!
@brief Call the current states spin method (if it has one)
*/
/**************************************************************************/
void spinCurrentState() {
if(currentState!=NULL && currentState->spin!=NULL)
currentState->spin();
}