Prusa-Firmware-MMU/src/logic/feed_to_bondtech.cpp

68 lines
2.6 KiB
C++

#include "feed_to_bondtech.h"
#include "../modules/buttons.h"
#include "../modules/fsensor.h"
#include "../modules/globals.h"
#include "../modules/idler.h"
#include "../modules/leds.h"
#include "../modules/motion.h"
#include "../modules/permanent_storage.h"
#include "../debug.h"
namespace logic {
void FeedToBondtech::Reset(uint8_t maxRetries) {
dbg_logic_P(PSTR("\nFeed to Bondtech\n\n"));
state = EngagingIdler;
this->maxRetries = maxRetries;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::blink0);
mi::idler.Engage(mg::globals.ActiveSlot());
}
bool FeedToBondtech::Step() {
switch (state) {
case EngagingIdler:
if (mi::idler.Engaged()) {
dbg_logic_P(PSTR("Feed to Bondtech --> Idler engaged"));
dbg_logic_sprintf_P(PSTR("Pulley start steps %u"), mm::motion.CurPosition(mm::Pulley));
state = PushingFilament;
mm::motion.InitAxis(mm::Pulley);
mm::motion.PlanMove<mm::Pulley>(config::defaultBowdenLength, config::pulleyFeedrate); //@@TODO constants - there was some strange acceleration sequence in the original FW,
// we can probably hand over some array of constants for hand-tuned acceleration + leverage some smoothing in the stepper as well
}
return false;
case PushingFilament:
//dbg_logic_P(PSTR("Feed to Bondtech --> Pushing"));
if (mfs::fsensor.Pressed()) {
mm::motion.AbortPlannedMoves(); // stop pushing filament
mi::idler.Disengage();
mg::globals.SetFilamentLoaded(mg::FilamentLoadState::InNozzle);
state = DisengagingIdler;
} else if (mm::motion.StallGuard(mm::Pulley)) {
// stall guard occurred during movement - the filament got stuck
state = Failed; // @@TODO may be even report why it failed
} else if (mm::motion.QueueEmpty()) { // all moves have been finished and the fsensor didn't switch on
state = Failed;
}
return false;
case DisengagingIdler:
if (!mi::idler.Engaged()) {
dbg_logic_P(PSTR("Feed to Bondtech --> Idler disengaged"));
dbg_logic_sprintf_P(PSTR("Pulley end steps %u"), mm::motion.CurPosition(mm::Pulley));
state = OK;
mm::motion.Disable(mm::Pulley);
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on);
}
return false;
case OK:
dbg_logic_P(PSTR("Feed to Bondtech OK"));
return true;
case Failed:
dbg_logic_P(PSTR("Feed to Bondtech FAILED"));
return true;
default:
return true;
}
}
} // namespace logic