From 9a57d88c0466e94133b1079999ef5f4f65b22c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Wed, 25 Dec 2024 01:37:30 +0000 Subject: [PATCH] idler/selector: simplify init The homing is always invalidated in all cases. Let's simply invalidate the homing only in the init method. The state machine's Ready state then decides when it is OK to perform the homing move. We shouldn't need to guess the axis's position, and should assume its not correct. Currently the init methods are only called during the boot up sequence. Change in memory: Flash: -126 bytes SRAM: 0 bytes --- src/modules/idler.cpp | 11 +++-------- src/modules/selector.cpp | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/modules/idler.cpp b/src/modules/idler.cpp index 1539a3d0..a3dda51b 100644 --- a/src/modules/idler.cpp +++ b/src/modules/idler.cpp @@ -155,6 +155,7 @@ bool Idler::Step() { return false; case Ready: if (!homingValid && mg::globals.FilamentLoaded() < mg::InFSensor) { + // home the Idler only in case we don't have filament loaded in the printer (or at least we think we don't) PlanHome(); return false; } @@ -166,14 +167,8 @@ bool Idler::Step() { } void Idler::Init() { - if (mg::globals.FilamentLoaded() < mg::InFSensor) { - // home the Idler only in case we don't have filament loaded in the printer (or at least we think we don't) - PlanHome(); - } else { - // otherwise assume the Idler is at its idle position (that's where it usually is) - mm::motion.SetPosition(mm::Idler, SlotPosition(IdleSlotIndex()).v); - InvalidateHoming(); // and plan homing sequence ASAP - } + // Re-home axis at first opportunity. See 'Ready' state. + InvalidateHoming(); } } // namespace idler diff --git a/src/modules/selector.cpp b/src/modules/selector.cpp index 56514da4..5e63ced4 100644 --- a/src/modules/selector.cpp +++ b/src/modules/selector.cpp @@ -122,6 +122,7 @@ bool Selector::Step() { return false; case Ready: if (!homingValid && mg::globals.FilamentLoaded() < mg::InSelector && (!mf::finda.Pressed())) { + // home the Selector only in case we don't have filament loaded (or at least we think we don't) PlanHome(); return false; } @@ -133,14 +134,8 @@ bool Selector::Step() { } void Selector::Init() { - if (mg::globals.FilamentLoaded() < mg::FilamentLoadState::InSelector && (!mf::finda.Pressed())) { - // home the Selector only in case we don't have filament loaded (or at least we think we don't) - PlanHome(); - } else { - // otherwise set selector's position according to know slot positions (and pretend it is correct) - mm::motion.SetPosition(mm::Selector, SlotPosition(mg::globals.ActiveSlot()).v); - InvalidateHoming(); // and plan homing sequence ASAP - } + // Re-home axis at first opportunity. See 'Ready' state. + InvalidateHoming(); } } // namespace selector