From 622361316754773b931ef9a6f12c6aeadf5302bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 17 Dec 2022 15:18:42 +0000 Subject: [PATCH] If finda is ever pressed, don't move selector. I moved the check higher. This triggered a FINDA FLICKER failure in Load_filament.cpp Now the test covers it :) (Didn't before) --- src/logic/load_filament.cpp | 1 + src/modules/selector.cpp | 12 ++++----- .../load_filament/test_load_filament.cpp | 27 ++++++++++++++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/logic/load_filament.cpp b/src/logic/load_filament.cpp index ec2b447..9a020f7 100644 --- a/src/logic/load_filament.cpp +++ b/src/logic/load_filament.cpp @@ -126,6 +126,7 @@ bool LoadFilament::StepInner() { 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 + InvalidateHoming(); if (!mf::finda.Pressed()) { Reset2(false); } else { diff --git a/src/modules/selector.cpp b/src/modules/selector.cpp index e2c015c..4a1560c 100644 --- a/src/modules/selector.cpp +++ b/src/modules/selector.cpp @@ -62,6 +62,12 @@ Selector::OperationResult Selector::MoveToSlot(uint8_t slot) { } plannedSlot = slot; + if (mf::finda.Pressed()) { + // @@TODO not sure why (if) this happens, but anyway - we must not move the selector if FINDA is pressed + // That includes the CutFilament operation as well + return OperationResult::Refused; + } + // if we are homing right now, just record the desired planned slot and return Accepted if (state == HomeBack) { return OperationResult::Accepted; @@ -73,12 +79,6 @@ Selector::OperationResult Selector::MoveToSlot(uint8_t slot) { return OperationResult::Accepted; } - if (mf::finda.Pressed()) { - // @@TODO not sure why (if) this happens, but anyway - we must not move the selector if FINDA is pressed - // That includes the CutFilament operation as well - return OperationResult::Refused; - } - // coordinates invalid, first home, then engage if (!homingValid && mg::globals.FilamentLoaded() < mg::FilamentLoadState::InSelector) { PlanHome(); diff --git a/tests/unit/logic/load_filament/test_load_filament.cpp b/tests/unit/logic/load_filament/test_load_filament.cpp index 951fd33..3927a22 100644 --- a/tests/unit/logic/load_filament/test_load_filament.cpp +++ b/tests/unit/logic/load_filament/test_load_filament.cpp @@ -385,10 +385,31 @@ TEST_CASE("load_filament::unlimited_load_manual_stop", "[load_filament]") { void LoadFilamentAlreadyPresentFilament(uint8_t slot, logic::LoadFilament &lf) { //one of the first steps of the state machine should pick up the fact that FINDA is on and transfer into the retracting phase + // Note that this will also trigger a FINDA FLICKERS error REQUIRE(WhileTopState(lf, ProgressCode::FeedingToFinda, 5000)); - REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, true, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::RetractingFromFinda)); - REQUIRE(WhileCondition(lf, std::bind(SimulateRetractFromFINDA, _1, 100), 5000)); - REQUIRE(WhileTopState(lf, ProgressCode::RetractingFromFinda, 5000)); + + REQUIRE(mf::finda.Pressed()); + REQUIRE((int)mg::globals.FilamentLoaded() == (int)mg::FilamentLoadState::AtPulley); + REQUIRE(mm::PulleyEnabled() == false); + REQUIRE(ml::leds.Mode(slot, ml::green) == ml::off); + REQUIRE(ml::leds.Mode(slot, ml::red) == ml::blink0); + REQUIRE(lf.Error() == ErrorCode::RUNNING); + REQUIRE(lf.TopLevelState() == ProgressCode::ERRDisengagingIdler); + + SimulateErrDisengagingIdler(lf, ErrorCode::FINDA_FLICKERS); + REQUIRE(VerifyState(lf, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), slot, true, false, ml::off, ml::blink0, ErrorCode::FINDA_FLICKERS, ProgressCode::ERRWaitingForUser)); + + // Let's resolve the error + SetFINDAStateAndDebounce(false); + + // Press middle button to resolve error + PressButtonAndDebounce(lf, mb::Middle, true); + + // Re-home idler and selector + REQUIRE_FALSE(mi::idler.HomingValid()); + REQUIRE_FALSE(ms::selector.HomingValid()); + SimulateIdlerAndSelectorHoming(lf); // failed load to FINDA = nothing blocking the selector - it can rehome + REQUIRE(VerifyState(lf, mg::FilamentLoadState::AtPulley, slot, slot, false, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToFinda)); // make FINDA switch on again REQUIRE(WhileCondition(lf, std::bind(SimulateFeedToFINDA, _1, 100), 5000));