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