Files

32 lines
831 B
C++
Raw Permalink Normal View History

#pragma once
#include <Arduino.h>
// Singleton-instance
class StateMachine
{
2025-12-15 20:13:05 +01:00
public:
enum class STATE {
INITIALIZING,
IDLING,
MOVING,
2025-12-15 22:39:25 +01:00
FAULT
};
2025-12-15 20:13:05 +01:00
2025-12-14 12:43:31 +01:00
StateMachine(const StateMachine&) = delete;
StateMachine(StateMachine&&) = delete;
static StateMachine& getInstance() noexcept;
2025-12-15 20:13:05 +01:00
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
2025-12-15 20:13:05 +01:00
bool setState(const STATE newState) noexcept;
bool raiseError(const String& reason) noexcept;
2025-12-15 20:13:05 +01:00
bool canSwitchToState(const STATE newState) const noexcept;
private:
2025-12-14 18:57:28 +01:00
StateMachine() noexcept;
2025-12-15 20:13:05 +01:00
STATE state = STATE::INITIALIZING;
String lastError = "";
};