From 18891dbeaf5d587ed7def44ae2c0900510f5aea2 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Thu, 3 Feb 2022 13:55:39 +0100 Subject: [PATCH] Add ClearButtons into unit tests --- tests/unit/logic/helpers/helpers.ipp | 9 +++++++++ tests/unit/logic/load_filament/test_load_filament.cpp | 8 ++++++++ tests/unit/logic/tool_change/test_tool_change.cpp | 9 +++++++++ 3 files changed, 26 insertions(+) diff --git a/tests/unit/logic/helpers/helpers.ipp b/tests/unit/logic/helpers/helpers.ipp index 95ceb52..7e48377 100644 --- a/tests/unit/logic/helpers/helpers.ipp +++ b/tests/unit/logic/helpers/helpers.ipp @@ -152,3 +152,12 @@ void PressButtonAndDebounce(SM &sm, uint8_t btnIndex){ sm.Step(); // Inner } } + +template +void ClearButtons(SM &sm){ + hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCMaxValue); + while (mb::buttons.AnyButtonPressed()) { + main_loop(); + sm.Step(); // Inner + } +} diff --git a/tests/unit/logic/load_filament/test_load_filament.cpp b/tests/unit/logic/load_filament/test_load_filament.cpp index a21a3c5..1f63008 100644 --- a/tests/unit/logic/load_filament/test_load_filament.cpp +++ b/tests/unit/logic/load_filament/test_load_filament.cpp @@ -107,6 +107,8 @@ void FailedLoadToFindaResolveHelp(uint8_t slot, logic::LoadFilament &lf) { REQUIRE(WhileTopState(lf, ProgressCode::ERREngagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRHelpingFilament)); + + ClearButtons(lf); } void FailedLoadToFindaResolveHelpFindaTriggered(uint8_t slot, logic::LoadFilament &lf) { @@ -143,6 +145,8 @@ void FailedLoadToFindaResolveManual(uint8_t slot, logic::LoadFilament &lf) { // pulling filament back REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, slot, slot, true, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::RetractingFromFinda)); + ClearButtons(lf); + // Stage 3 - retracting from finda // we'll assume the finda is working correctly here REQUIRE(WhileCondition( @@ -182,6 +186,8 @@ void FailedLoadToFindaResolveManualNoFINDA(uint8_t slot, logic::LoadFilament &lf SimulateIdlerHoming(); + ClearButtons(lf); + // pulling filament back REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, false, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser)); } @@ -191,6 +197,8 @@ void FailedLoadToFindaResolveTryAgain(uint8_t slot, logic::LoadFilament &lf) { // the state machine should have restarted REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToFinda)); + ClearButtons(lf); + LoadFilamentSuccessful(slot, lf); } diff --git a/tests/unit/logic/tool_change/test_tool_change.cpp b/tests/unit/logic/tool_change/test_tool_change.cpp index ae861a2..29f818f 100644 --- a/tests/unit/logic/tool_change/test_tool_change.cpp +++ b/tests/unit/logic/tool_change/test_tool_change.cpp @@ -191,6 +191,7 @@ void ToolChangeFailLoadToFindaLeftBtn(logic::ToolChange &tc, uint8_t toSlot) { PressButtonAndDebounce(tc, mb::Left); REQUIRE(WhileTopState(tc, ProgressCode::ERREngagingIdler, 5000UL)); + ClearButtons(tc); REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, toSlot, toSlot, false, true, ml::off, ml::blink0, ErrorCode::RUNNING, ProgressCode::ERRHelpingFilament)); @@ -225,6 +226,8 @@ void ToolChangeFailLoadToFindaMiddleBtn(logic::ToolChange &tc, uint8_t toSlot) { 200000UL)); REQUIRE(VerifyState(tc, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), toSlot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToFinda)); + ClearButtons(tc); + // retry the whole operation // beware - the FeedToFinda state machine will leverage the already engaged Idler, // so the necessary number of steps to reach the FINDA is quite low (~200 was lowest once tested) @@ -243,6 +246,8 @@ void ToolChangeFailLoadToFindaRightBtnFINDA_FSensor(logic::ToolChange &tc, uint8 PressButtonAndDebounce(tc, mb::Right); CheckFinishedCorrectly(tc, toSlot); + + ClearButtons(tc); } void ToolChangeFailLoadToFindaRightBtnFINDA(logic::ToolChange &tc, uint8_t toSlot) { @@ -251,6 +256,8 @@ void ToolChangeFailLoadToFindaRightBtnFINDA(logic::ToolChange &tc, uint8_t toSlo PressButtonAndDebounce(tc, mb::Right); REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), toSlot, true, false, ml::off, ml::blink0, ErrorCode::FSENSOR_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser)); + + ClearButtons(tc); } void ToolChangeFailLoadToFindaRightBtn(logic::ToolChange &tc, uint8_t toSlot) { @@ -258,6 +265,8 @@ void ToolChangeFailLoadToFindaRightBtn(logic::ToolChange &tc, uint8_t toSlot) { PressButtonAndDebounce(tc, mb::Right); REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), toSlot, false, false, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser)); + + ClearButtons(tc); } TEST_CASE("tool_change::load_fail_FINDA_resolve_btnL", "[tool_change]") {