Unittests: set buttons more consistently
parent
872b2206ed
commit
c2325b687a
|
|
@ -8,11 +8,11 @@ namespace user_input {
|
|||
UserInput userInput;
|
||||
|
||||
void UserInput::Step() {
|
||||
if (buttons::buttons.ButtonPressed(0))
|
||||
if (buttons::buttons.ButtonPressed(mb::Left))
|
||||
eventQueue.push(Event::Left);
|
||||
if (buttons::buttons.ButtonPressed(1))
|
||||
if (buttons::buttons.ButtonPressed(mb::Middle))
|
||||
eventQueue.push(Event::Middle);
|
||||
if (buttons::buttons.ButtonPressed(2))
|
||||
if (buttons::buttons.ButtonPressed(mb::Right))
|
||||
eventQueue.push(Event::Right);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,3 +143,12 @@ void InvalidSlot(SM &logicSM, uint8_t activeSlot, uint8_t invSlot){
|
|||
logicSM.Reset(invSlot);
|
||||
REQUIRE(VerifyState(logicSM, mg::FilamentLoadState::AtPulley, mi::Idler::IdleSlotIndex(), activeSlot, false, false, ml::off, ml::off, ErrorCode::INVALID_TOOL, ProgressCode::OK));
|
||||
}
|
||||
|
||||
template <typename SM>
|
||||
void PressButtonAndDebounce(SM &sm, uint8_t btnIndex){
|
||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCLimits[btnIndex][0] + 1);
|
||||
while (!mb::buttons.ButtonPressed(btnIndex)) {
|
||||
main_loop();
|
||||
sm.StepInner();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,13 +99,7 @@ void FailedLoadToFindaResolveHelp(uint8_t slot, logic::LoadFilament &lf) {
|
|||
// - resolve the problem by hand - after pressing the button we shall check, that FINDA is off and we should do what?
|
||||
|
||||
// In this case we check the first option
|
||||
|
||||
// Perform press on button 0 + debounce
|
||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCLimits[0][0] + 1);
|
||||
while (!mb::buttons.ButtonPressed(0)) {
|
||||
main_loop();
|
||||
lf.Step();
|
||||
}
|
||||
PressButtonAndDebounce(lf, mb::Left);
|
||||
|
||||
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERREngagingIdler));
|
||||
|
||||
|
|
@ -140,12 +134,9 @@ void FailedLoadToFindaResolveManual(uint8_t slot, logic::LoadFilament &lf) {
|
|||
// simulate the user fixed the issue himself
|
||||
|
||||
// Perform press on button 2 + debounce + switch on FINDA
|
||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCLimits[2][0] + 1);
|
||||
hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::high);
|
||||
while (!mb::buttons.ButtonPressed(2)) {
|
||||
main_loop();
|
||||
lf.Step();
|
||||
}
|
||||
PressButtonAndDebounce(lf, mb::Right);
|
||||
|
||||
// pulling filament back
|
||||
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, true, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::RetractingFromFinda));
|
||||
|
||||
|
|
@ -168,22 +159,14 @@ void FailedLoadToFindaResolveManual(uint8_t slot, logic::LoadFilament &lf) {
|
|||
|
||||
void FailedLoadToFindaResolveManualNoFINDA(uint8_t slot, logic::LoadFilament &lf) {
|
||||
// Perform press on button 2 + debounce + keep FINDA OFF (i.e. the user didn't solve anything)
|
||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCLimits[2][0] + 1);
|
||||
while (!mb::buttons.ButtonPressed(2)) {
|
||||
main_loop();
|
||||
lf.Step();
|
||||
}
|
||||
PressButtonAndDebounce(lf, mb::Right);
|
||||
|
||||
// pulling filament back
|
||||
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser));
|
||||
}
|
||||
|
||||
void FailedLoadToFindaResolveTryAgain(uint8_t slot, logic::LoadFilament &lf) {
|
||||
// Perform press on button 1 + debounce
|
||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCLimits[1][0] + 1);
|
||||
while (!mb::buttons.ButtonPressed(1)) {
|
||||
main_loop();
|
||||
lf.Step();
|
||||
}
|
||||
PressButtonAndDebounce(lf, mb::Middle);
|
||||
|
||||
// the state machine should have restarted
|
||||
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::FeedingToFinda));
|
||||
|
|
|
|||
|
|
@ -156,12 +156,8 @@ void FindaDidntTriggerResolveHelp(uint8_t slot, logic::UnloadFilament &uf) {
|
|||
|
||||
// In this case we check the first option
|
||||
|
||||
// Perform press on button 1 + debounce
|
||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCLimits[0][0] + 1);
|
||||
while (!mb::buttons.ButtonPressed(0)) {
|
||||
main_loop();
|
||||
uf.StepInner();
|
||||
}
|
||||
// Perform press on button 0 + debounce
|
||||
PressButtonAndDebounce(uf, mb::Left);
|
||||
|
||||
// we still think we have filament loaded at this stage
|
||||
// idler should have been disengaged
|
||||
|
|
@ -239,13 +235,7 @@ void FindaDidntTriggerResolveTryAgain(uint8_t slot, logic::UnloadFilament &uf) {
|
|||
// - resolve the problem by hand - after pressing the button we shall check, that FINDA is off and we should do what?
|
||||
|
||||
// In this case we check the second option
|
||||
|
||||
// Perform press on button 2 + debounce
|
||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCLimits[1][0] + 1);
|
||||
while (!mb::buttons.ButtonPressed(1)) {
|
||||
main_loop();
|
||||
uf.StepInner();
|
||||
}
|
||||
PressButtonAndDebounce(uf, mb::Middle);
|
||||
|
||||
// we still think we have filament loaded at this stage
|
||||
// idler should have been disengaged
|
||||
|
|
|
|||
|
|
@ -115,79 +115,79 @@ TEST_CASE("buttons::Step-debounce-one-button", "[buttons]") {
|
|||
b.Step(); // should detect the press but remain in detected state - wait for debounce
|
||||
mt::IncMillis();
|
||||
}
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
CHECK(!b.ButtonPressed(mb::Left));
|
||||
CHECK(!b.ButtonPressed(mb::Middle));
|
||||
CHECK(!b.ButtonPressed(mb::Right));
|
||||
|
||||
// 1023
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||
b.Step(); // reset to waiting
|
||||
mt::IncMillis();
|
||||
}
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
CHECK(!b.ButtonPressed(mb::Left));
|
||||
CHECK(!b.ButtonPressed(mb::Middle));
|
||||
CHECK(!b.ButtonPressed(mb::Right));
|
||||
|
||||
// 5
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||
b.Step(); // pressed again, still in debouncing state
|
||||
mt::IncMillis();
|
||||
}
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
CHECK(!b.ButtonPressed(mb::Left));
|
||||
CHECK(!b.ButtonPressed(mb::Middle));
|
||||
CHECK(!b.ButtonPressed(mb::Right));
|
||||
|
||||
// 9
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||
b.Step(); // no change
|
||||
mt::IncMillis();
|
||||
}
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
CHECK(!b.ButtonPressed(mb::Left));
|
||||
CHECK(!b.ButtonPressed(mb::Middle));
|
||||
CHECK(!b.ButtonPressed(mb::Right));
|
||||
|
||||
// 6
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||
b.Step(); // no change
|
||||
mt::IncMillis();
|
||||
}
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
CHECK(!b.ButtonPressed(mb::Left));
|
||||
CHECK(!b.ButtonPressed(mb::Middle));
|
||||
CHECK(!b.ButtonPressed(mb::Right));
|
||||
|
||||
// 7
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||
b.Step(); // one step from "pressed"
|
||||
mt::IncMillis();
|
||||
}
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
CHECK(!b.ButtonPressed(mb::Left));
|
||||
CHECK(!b.ButtonPressed(mb::Middle));
|
||||
CHECK(!b.ButtonPressed(mb::Right));
|
||||
|
||||
// 8
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||
b.Step(); // fifth set of samples - should report "pressed" finally
|
||||
mt::IncMillis();
|
||||
}
|
||||
CHECK(b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
CHECK(b.ButtonPressed(mb::Left));
|
||||
CHECK(!b.ButtonPressed(mb::Middle));
|
||||
CHECK(!b.ButtonPressed(mb::Right));
|
||||
|
||||
// 1023
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||
b.Step(); // sixth set of samples - button released (no debouncing on release)
|
||||
mt::IncMillis();
|
||||
}
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
CHECK(!b.ButtonPressed(mb::Left));
|
||||
CHECK(!b.ButtonPressed(mb::Middle));
|
||||
CHECK(!b.ButtonPressed(mb::Right));
|
||||
|
||||
// 1023
|
||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||
b.Step(); // seventh set of samples - still released
|
||||
mt::IncMillis();
|
||||
}
|
||||
CHECK(!b.ButtonPressed(0));
|
||||
CHECK(!b.ButtonPressed(1));
|
||||
CHECK(!b.ButtonPressed(2));
|
||||
CHECK(!b.ButtonPressed(mb::Left));
|
||||
CHECK(!b.ButtonPressed(mb::Middle));
|
||||
CHECK(!b.ButtonPressed(mb::Right));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue