Skip to content

Commit

Permalink
idler: reduce duplicate code
Browse files Browse the repository at this point in the history
Change in memory:
Flash: 54 bytes
SRAM: 0 bytes
  • Loading branch information
gudnimg authored and DRracer committed Jan 2, 2025
1 parent 0eeef4c commit dc68b70
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/modules/idler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,7 @@ bool Idler::StallGuardAllowed(bool forward) const {
}

Idler::OperationResult Idler::Disengage() {
if (state == Moving || IsOnHold()) {
dbg_logic_P(PSTR("Moving --> Disengage refused"));
return OperationResult::Refused;
}
plannedSlot = IdleSlotIndex();
plannedMove = Operation::disengage;

// coordinates invalid, first home, then disengage
if (!homingValid) {
PlanHome();
return OperationResult::Accepted;
}

// already disengaged
if (Disengaged()) {
dbg_logic_P(PSTR("Idler Disengaged"));
return OperationResult::Accepted;
}

// disengaging
return InitMovementNoReinitAxis();
return PlanMoveInner(IdleSlotIndex(), Operation::disengage);
}

Idler::OperationResult Idler::PartiallyDisengage(uint8_t slot) {
Expand All @@ -114,7 +94,7 @@ Idler::OperationResult Idler::PlanMoveInner(uint8_t slot, Operation plannedOp) {
return OperationResult::Accepted;
}

// coordinates invalid, first home, then engage
// coordinates invalid, first home, then engage or disengage
// The MMU FW only decides to engage the Idler when it is supposed to do something and not while it is idle
// so rebooting the MMU while the printer is printing (and thus holding the filament by the moving Idler)
// should not be an issue
Expand All @@ -123,7 +103,7 @@ Idler::OperationResult Idler::PlanMoveInner(uint8_t slot, Operation plannedOp) {
return OperationResult::Accepted;
}

// already engaged
// already engaged or disengaged
if (currentlyEngaged == plannedMove) {
return OperationResult::Accepted;
}
Expand Down

0 comments on commit dc68b70

Please sign in to comment.