Files
MinumelArmMCU/StateMachine.hpp
T

32 lines
831 B
C++
Executable File

#pragma once
#include <Arduino.h>
// Singleton-instance
class StateMachine
{
public:
enum class STATE {
INITIALIZING,
IDLING,
MOVING,
ERROR
};
StateMachine(const StateMachine&) = delete;
StateMachine(StateMachine&&) = delete;
static StateMachine& getInstance() noexcept;
STATE getState() const noexcept { return state; };
String getLastError() const noexcept { return lastError; };
// May fail if a state transition from state a to b is not valid
bool setState(const STATE newState) noexcept;
bool raiseError(const String& reason) noexcept;
bool canSwitchToState(const STATE newState) const noexcept;
private:
StateMachine() noexcept;
STATE state = STATE::INITIALIZING;
String lastError = "";
};