Add ClearButtons into unit tests

pull/154/head
D.R.racer 2022-02-03 13:55:39 +01:00 committed by DRracer
parent 7e759fdb51
commit 18891dbeaf
3 changed files with 26 additions and 0 deletions

View File

@ -152,3 +152,12 @@ void PressButtonAndDebounce(SM &sm, uint8_t btnIndex){
sm.Step(); // Inner
}
}
template <typename SM>
void ClearButtons(SM &sm){
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCMaxValue);
while (mb::buttons.AnyButtonPressed()) {
main_loop();
sm.Step(); // Inner
}
}

View File

@ -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);
}

View File

@ -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]") {