From dc68b70cff55fc7b5eda7f290a42f0038dd06d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Wed, 25 Dec 2024 00:43:55 +0000 Subject: [PATCH] idler: reduce duplicate code Change in memory: Flash: 54 bytes SRAM: 0 bytes --- src/modules/idler.cpp | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/modules/idler.cpp b/src/modules/idler.cpp index 1539a3d0..fee16402 100644 --- a/src/modules/idler.cpp +++ b/src/modules/idler.cpp @@ -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) { @@ -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 @@ -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; }