feat: main loop now listens to state
This commit is contained in:
+14
-14
@@ -14,7 +14,7 @@ StateMachine& StateMachine::getInstance() noexcept
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool StateMachine::setState(const State newState) noexcept
|
||||
bool StateMachine::setState(const STATE newState) noexcept
|
||||
{
|
||||
if (canSwitchToState(newState)) {
|
||||
state = newState;
|
||||
@@ -24,15 +24,15 @@ bool StateMachine::setState(const State newState) noexcept
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StateMachine::canSwitchToState(const State newState) const noexcept
|
||||
bool StateMachine::canSwitchToState(const STATE newState) const noexcept
|
||||
{
|
||||
// Error state is final
|
||||
if (state == State::ERROR) {
|
||||
if (state == STATE::ERROR) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Error state only settable via raiseError()
|
||||
if (newState == State::ERROR) {
|
||||
if (newState == STATE::ERROR) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -42,39 +42,39 @@ bool StateMachine::canSwitchToState(const State newState) const noexcept
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case StateMachine::State::INITIALIZING:
|
||||
case StateMachine::STATE::INITIALIZING:
|
||||
switch (newState) {
|
||||
// Can go to idle
|
||||
case State::IDLING:
|
||||
case STATE::IDLING:
|
||||
return true;
|
||||
// Can't go straight to moving
|
||||
case State::MOVING:
|
||||
case STATE::MOVING:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case StateMachine::State::IDLING:
|
||||
case StateMachine::STATE::IDLING:
|
||||
switch (newState) {
|
||||
// Can't initialize again
|
||||
case State::INITIALIZING:
|
||||
case STATE::INITIALIZING:
|
||||
return false;
|
||||
// Can enter move state
|
||||
case State::MOVING:
|
||||
case STATE::MOVING:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case StateMachine::State::MOVING:
|
||||
case StateMachine::STATE::MOVING:
|
||||
switch (newState) {
|
||||
// Can't initialize again
|
||||
case State::INITIALIZING:
|
||||
case STATE::INITIALIZING:
|
||||
return false;
|
||||
// Can go into idling
|
||||
case State::IDLING:
|
||||
case STATE::IDLING:
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -87,7 +87,7 @@ bool StateMachine::canSwitchToState(const State newState) const noexcept
|
||||
|
||||
bool StateMachine::raiseError(const String &reason) noexcept
|
||||
{
|
||||
state = State::ERROR;
|
||||
state = STATE::ERROR;
|
||||
lastError = reason;
|
||||
digitalWrite(ERROR_INDICATOR_LED_PIN, HIGH);
|
||||
if (Serial) {
|
||||
|
||||
Reference in New Issue
Block a user