Extract common Dis/Engaging of idler in Error states into base class
parent
c2325b687a
commit
afab309d27
|
|
@ -1,5 +1,6 @@
|
|||
/// @file command_base.cpp
|
||||
#include "command_base.h"
|
||||
#include "../modules/globals.h"
|
||||
#include "../modules/idler.h"
|
||||
#include "../modules/selector.h"
|
||||
#include "../modules/motion.h"
|
||||
|
|
@ -105,4 +106,17 @@ void CommandBase::ErrDisengagingIdler() {
|
|||
}
|
||||
}
|
||||
|
||||
void CommandBase::GoToErrDisengagingIdler(ErrorCode ec) {
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
error = ec;
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0);
|
||||
mi::idler.Disengage();
|
||||
}
|
||||
|
||||
void CommandBase::GoToErrEngagingIdler() {
|
||||
state = ProgressCode::ERREngagingIdler;
|
||||
mi::idler.Engage(mg::globals.ActiveSlot());
|
||||
}
|
||||
|
||||
} // namespace logic
|
||||
|
|
|
|||
|
|
@ -75,9 +75,15 @@ protected:
|
|||
/// If not, it returns false and sets the error to ErrorCode::INVALID_TOOL
|
||||
bool CheckToolIndex(uint8_t index);
|
||||
|
||||
/// Common error processing - disengaging idler
|
||||
/// Perform disengaging idler in ErrDisengagingIdler state
|
||||
void ErrDisengagingIdler();
|
||||
|
||||
/// Transit the state machine into ErrDisengagingIdler
|
||||
void GoToErrDisengagingIdler(ErrorCode ec);
|
||||
|
||||
/// Transit the state machine into ErrEngagingIdler
|
||||
void GoToErrEngagingIdler();
|
||||
|
||||
ProgressCode state; ///< current progress state of the state machine
|
||||
ErrorCode error; ///< current error code
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,11 +45,7 @@ bool LoadFilament::StepInner() {
|
|||
if (feed.Step()) {
|
||||
if (feed.State() == FeedToFinda::Failed) {
|
||||
// @@TODO - try to repeat 6x - push/pull sequence - probably something to put into feed_to_finda as an option
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
error = ErrorCode::FINDA_DIDNT_SWITCH_ON;
|
||||
mi::idler.Disengage();
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
||||
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_ON); // signal loading error
|
||||
} else {
|
||||
state = ProgressCode::RetractingFromFinda;
|
||||
retract.Reset();
|
||||
|
|
@ -59,14 +55,11 @@ bool LoadFilament::StepInner() {
|
|||
case ProgressCode::RetractingFromFinda:
|
||||
if (retract.Step()) {
|
||||
if (retract.State() == RetractFromFinda::Failed) {
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
error = ErrorCode::FINDA_DIDNT_SWITCH_OFF;
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
||||
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_OFF); // signal loading error
|
||||
} else {
|
||||
state = ProgressCode::DisengagingIdler;
|
||||
mi::idler.Disengage();
|
||||
}
|
||||
mi::idler.Disengage(); // disengage in both cases
|
||||
}
|
||||
break;
|
||||
case ProgressCode::DisengagingIdler:
|
||||
|
|
@ -88,8 +81,7 @@ bool LoadFilament::StepInner() {
|
|||
mui::Event ev = mui::userInput.ConsumeEvent();
|
||||
switch (ev) {
|
||||
case mui::Event::Left: // try to manually load just a tiny bit - help the filament with the pulley
|
||||
state = ProgressCode::ERREngagingIdler;
|
||||
mi::idler.Engage(mg::globals.ActiveSlot());
|
||||
GoToErrEngagingIdler();
|
||||
break;
|
||||
case mui::Event::Middle: // try again the whole sequence
|
||||
// however it depends on the state of FINDA - if it is on, we must perform unload first
|
||||
|
|
@ -127,7 +119,7 @@ bool LoadFilament::StepInner() {
|
|||
GoToRetractingFromFinda();
|
||||
} else if (mm::motion.QueueEmpty()) {
|
||||
// helped a bit, but FINDA didn't trigger, return to the main error state
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_ON);
|
||||
}
|
||||
return false;
|
||||
default: // we got into an unhandled state, better report it
|
||||
|
|
|
|||
|
|
@ -60,11 +60,7 @@ bool ToolChange::StepInner() {
|
|||
case ProgressCode::FeedingToFinda:
|
||||
if (feed.Step()) {
|
||||
if (feed.State() == FeedToFinda::Failed) {
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
error = ErrorCode::FINDA_DIDNT_SWITCH_ON;
|
||||
mi::idler.Disengage();
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
||||
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_ON); // signal loading error
|
||||
} else {
|
||||
state = ProgressCode::FeedingToBondtech;
|
||||
james.Reset(3);
|
||||
|
|
@ -74,11 +70,7 @@ bool ToolChange::StepInner() {
|
|||
case ProgressCode::FeedingToBondtech:
|
||||
if (james.Step()) {
|
||||
if (james.State() == FeedToBondtech::Failed) {
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
error = ErrorCode::FSENSOR_DIDNT_SWITCH_ON;
|
||||
mi::idler.Disengage();
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
||||
GoToErrDisengagingIdler(ErrorCode::FSENSOR_DIDNT_SWITCH_ON); // signal loading error
|
||||
} else {
|
||||
state = ProgressCode::OK;
|
||||
error = ErrorCode::OK;
|
||||
|
|
@ -97,8 +89,7 @@ bool ToolChange::StepInner() {
|
|||
mui::Event ev = mui::userInput.ConsumeEvent();
|
||||
switch (ev) {
|
||||
case mui::Event::Left: // try to manually load just a tiny bit - help the filament with the pulley
|
||||
state = ProgressCode::ERREngagingIdler;
|
||||
mi::idler.Engage(mg::globals.ActiveSlot());
|
||||
GoToErrEngagingIdler();
|
||||
break;
|
||||
case mui::Event::Middle: // try again the whole sequence
|
||||
Reset(mg::globals.ActiveSlot());
|
||||
|
|
@ -146,7 +137,7 @@ bool ToolChange::StepInner() {
|
|||
error = ErrorCode::RUNNING;
|
||||
} else if (mm::motion.QueueEmpty()) {
|
||||
// helped a bit, but FINDA/Fsensor didn't trigger, return to the main error state
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
GoToErrDisengagingIdler(ErrorCode::FSENSOR_DIDNT_SWITCH_ON);
|
||||
}
|
||||
return false;
|
||||
default: // we got into an unhandled state, better report it
|
||||
|
|
|
|||
|
|
@ -38,16 +38,11 @@ bool UnloadFilament::StepInner() {
|
|||
if (unl.Step()) {
|
||||
if (unl.State() == UnloadToFinda::Failed) {
|
||||
// couldn't unload to FINDA, report error and wait for user to resolve it
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
error = ErrorCode::FINDA_DIDNT_SWITCH_OFF;
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0);
|
||||
mi::idler.Disengage();
|
||||
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_OFF);
|
||||
} else if (mfs::fsensor.Pressed()) {
|
||||
// fsensor still pressed - that smells bad - a piece of filament may still be present in the heatsink
|
||||
// and that would cause serious problems while loading another filament
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
error = ErrorCode::FSENSOR_DIDNT_SWITCH_OFF;
|
||||
GoToErrDisengagingIdler(ErrorCode::FSENSOR_DIDNT_SWITCH_OFF);
|
||||
} else {
|
||||
state = ProgressCode::RetractingFromFinda;
|
||||
retract.Reset();
|
||||
|
|
@ -57,15 +52,12 @@ bool UnloadFilament::StepInner() {
|
|||
case ProgressCode::RetractingFromFinda:
|
||||
if (retract.Step()) {
|
||||
if (retract.State() == RetractFromFinda::Failed) {
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
error = ErrorCode::FINDA_DIDNT_SWITCH_OFF;
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
||||
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_OFF); // signal unloading error
|
||||
} else {
|
||||
state = ProgressCode::DisengagingIdler;
|
||||
}
|
||||
mi::idler.Disengage();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
case ProgressCode::DisengagingIdler:
|
||||
if (!mi::idler.Engaged()) {
|
||||
|
|
@ -85,8 +77,7 @@ bool UnloadFilament::StepInner() {
|
|||
mui::Event ev = mui::userInput.ConsumeEvent();
|
||||
switch (ev) {
|
||||
case mui::Event::Left: // try to manually unload just a tiny bit - help the filament with the pulley
|
||||
state = ProgressCode::ERREngagingIdler;
|
||||
mi::idler.Engage(mg::globals.ActiveSlot());
|
||||
GoToErrEngagingIdler();
|
||||
break;
|
||||
case mui::Event::Middle: // try again the whole sequence
|
||||
Reset(0);
|
||||
|
|
@ -127,7 +118,7 @@ bool UnloadFilament::StepInner() {
|
|||
error = ErrorCode::RUNNING;
|
||||
} else if (mm::motion.QueueEmpty()) {
|
||||
// helped a bit, but FINDA didn't trigger, return to the main error state
|
||||
state = ProgressCode::ERRDisengagingIdler;
|
||||
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_OFF);
|
||||
}
|
||||
return false;
|
||||
case ProgressCode::OK:
|
||||
|
|
|
|||
Loading…
Reference in New Issue