Add globa Panic() function
The intent is to halt the firmware while retaining the reporting capabilities and blinking LEDspull/112/head
parent
dc3d8941f7
commit
b4d4807971
|
|
@ -2,6 +2,7 @@
|
|||
#include "../modules/idler.h"
|
||||
#include "../modules/selector.h"
|
||||
#include "../modules/motion.h"
|
||||
#include "../modules/leds.h"
|
||||
|
||||
namespace logic {
|
||||
|
||||
|
|
@ -76,6 +77,15 @@ bool CommandBase::Step() {
|
|||
return StepInner();
|
||||
}
|
||||
|
||||
void CommandBase::Panic(ErrorCode ec) {
|
||||
state = ProgressCode::ERRInternal;
|
||||
error = ec;
|
||||
for (uint8_t i = 0; i < config::toolCount; ++i) {
|
||||
ml::leds.SetMode(i, ml::green, ml::blink0);
|
||||
ml::leds.SetMode(i, ml::red, ml::blink0);
|
||||
}
|
||||
}
|
||||
|
||||
bool CommandBase::CheckToolIndex(uint8_t index) {
|
||||
if (index >= config::toolCount) {
|
||||
error = ErrorCode::INVALID_TOOL;
|
||||
|
|
|
|||
|
|
@ -61,6 +61,14 @@ public:
|
|||
/// Please see ErrorCode for more details
|
||||
virtual ErrorCode Error() const { return error; }
|
||||
|
||||
/// Switches the state machine into an error state of code ec.
|
||||
/// It shall be used to halt the firmware while retaining the capability of reporting the error state to the printer
|
||||
/// - a kind of similar to runtime assertions.
|
||||
/// Called from main.cpp's global funtion Panic() .
|
||||
/// The derived state machines have no (implemented) way of getting out of this state (intentionally).
|
||||
/// The only way out is to reset the board.
|
||||
void Panic(ErrorCode ec);
|
||||
|
||||
protected:
|
||||
/// @returns true if the slot/tool index is within specified range (0 - config::toolCount)
|
||||
/// If not, it returns false and sets the error to ErrorCode::INVALID_TOOL
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
#include "version.h"
|
||||
|
||||
#include "panic.h"
|
||||
|
||||
/// Global instance of the protocol codec
|
||||
static mp::Protocol protocol;
|
||||
|
||||
|
|
@ -331,6 +333,10 @@ bool CheckMsgs() {
|
|||
return false;
|
||||
}
|
||||
|
||||
void Panic(ErrorCode ec) {
|
||||
currentCommand->Panic(ec);
|
||||
}
|
||||
|
||||
/// Main loop of the firmware
|
||||
/// Proposed architecture
|
||||
/// checkMsgs();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "logic/error_codes.h"
|
||||
|
||||
/// Switches the currently active logic state machine into an error state of code ec.
|
||||
/// It shall be used to halt the firmware while retaining the capability of reporting the error state to the printer
|
||||
/// - a kind of similar to runtime assertions.
|
||||
/// Implementation is in main.cpp, where we know the currently active logic state machine.
|
||||
/// The only way out is to reset the board.
|
||||
extern void Panic(ErrorCode ec);
|
||||
Loading…
Reference in New Issue