Unittests: set buttons more consistently
parent
872b2206ed
commit
c2325b687a
|
|
@ -8,11 +8,11 @@ namespace user_input {
|
||||||
UserInput userInput;
|
UserInput userInput;
|
||||||
|
|
||||||
void UserInput::Step() {
|
void UserInput::Step() {
|
||||||
if (buttons::buttons.ButtonPressed(0))
|
if (buttons::buttons.ButtonPressed(mb::Left))
|
||||||
eventQueue.push(Event::Left);
|
eventQueue.push(Event::Left);
|
||||||
if (buttons::buttons.ButtonPressed(1))
|
if (buttons::buttons.ButtonPressed(mb::Middle))
|
||||||
eventQueue.push(Event::Middle);
|
eventQueue.push(Event::Middle);
|
||||||
if (buttons::buttons.ButtonPressed(2))
|
if (buttons::buttons.ButtonPressed(mb::Right))
|
||||||
eventQueue.push(Event::Right);
|
eventQueue.push(Event::Right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,3 +143,12 @@ void InvalidSlot(SM &logicSM, uint8_t activeSlot, uint8_t invSlot){
|
||||||
logicSM.Reset(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));
|
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?
|
// - 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
|
// In this case we check the first option
|
||||||
|
PressButtonAndDebounce(lf, mb::Left);
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, false, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERREngagingIdler));
|
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
|
// simulate the user fixed the issue himself
|
||||||
|
|
||||||
// Perform press on button 2 + debounce + switch on FINDA
|
// 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);
|
hal::gpio::WritePin(FINDA_PIN, hal::gpio::Level::high);
|
||||||
while (!mb::buttons.ButtonPressed(2)) {
|
PressButtonAndDebounce(lf, mb::Right);
|
||||||
main_loop();
|
|
||||||
lf.Step();
|
|
||||||
}
|
|
||||||
// pulling filament back
|
// pulling filament back
|
||||||
REQUIRE(VerifyState(lf, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), slot, true, true, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::RetractingFromFinda));
|
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) {
|
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)
|
// 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);
|
PressButtonAndDebounce(lf, mb::Right);
|
||||||
while (!mb::buttons.ButtonPressed(2)) {
|
|
||||||
main_loop();
|
|
||||||
lf.Step();
|
|
||||||
}
|
|
||||||
// pulling filament back
|
// 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));
|
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) {
|
void FailedLoadToFindaResolveTryAgain(uint8_t slot, logic::LoadFilament &lf) {
|
||||||
// Perform press on button 1 + debounce
|
PressButtonAndDebounce(lf, mb::Middle);
|
||||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCLimits[1][0] + 1);
|
|
||||||
while (!mb::buttons.ButtonPressed(1)) {
|
|
||||||
main_loop();
|
|
||||||
lf.Step();
|
|
||||||
}
|
|
||||||
|
|
||||||
// the state machine should have restarted
|
// 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));
|
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
|
// In this case we check the first option
|
||||||
|
|
||||||
// Perform press on button 1 + debounce
|
// Perform press on button 0 + debounce
|
||||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCLimits[0][0] + 1);
|
PressButtonAndDebounce(uf, mb::Left);
|
||||||
while (!mb::buttons.ButtonPressed(0)) {
|
|
||||||
main_loop();
|
|
||||||
uf.StepInner();
|
|
||||||
}
|
|
||||||
|
|
||||||
// we still think we have filament loaded at this stage
|
// we still think we have filament loaded at this stage
|
||||||
// idler should have been disengaged
|
// 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?
|
// - 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
|
// In this case we check the second option
|
||||||
|
PressButtonAndDebounce(uf, mb::Middle);
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
// we still think we have filament loaded at this stage
|
// we still think we have filament loaded at this stage
|
||||||
// idler should have been disengaged
|
// 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
|
b.Step(); // should detect the press but remain in detected state - wait for debounce
|
||||||
mt::IncMillis();
|
mt::IncMillis();
|
||||||
}
|
}
|
||||||
CHECK(!b.ButtonPressed(0));
|
CHECK(!b.ButtonPressed(mb::Left));
|
||||||
CHECK(!b.ButtonPressed(1));
|
CHECK(!b.ButtonPressed(mb::Middle));
|
||||||
CHECK(!b.ButtonPressed(2));
|
CHECK(!b.ButtonPressed(mb::Right));
|
||||||
|
|
||||||
// 1023
|
// 1023
|
||||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||||
b.Step(); // reset to waiting
|
b.Step(); // reset to waiting
|
||||||
mt::IncMillis();
|
mt::IncMillis();
|
||||||
}
|
}
|
||||||
CHECK(!b.ButtonPressed(0));
|
CHECK(!b.ButtonPressed(mb::Left));
|
||||||
CHECK(!b.ButtonPressed(1));
|
CHECK(!b.ButtonPressed(mb::Middle));
|
||||||
CHECK(!b.ButtonPressed(2));
|
CHECK(!b.ButtonPressed(mb::Right));
|
||||||
|
|
||||||
// 5
|
// 5
|
||||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||||
b.Step(); // pressed again, still in debouncing state
|
b.Step(); // pressed again, still in debouncing state
|
||||||
mt::IncMillis();
|
mt::IncMillis();
|
||||||
}
|
}
|
||||||
CHECK(!b.ButtonPressed(0));
|
CHECK(!b.ButtonPressed(mb::Left));
|
||||||
CHECK(!b.ButtonPressed(1));
|
CHECK(!b.ButtonPressed(mb::Middle));
|
||||||
CHECK(!b.ButtonPressed(2));
|
CHECK(!b.ButtonPressed(mb::Right));
|
||||||
|
|
||||||
// 9
|
// 9
|
||||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||||
b.Step(); // no change
|
b.Step(); // no change
|
||||||
mt::IncMillis();
|
mt::IncMillis();
|
||||||
}
|
}
|
||||||
CHECK(!b.ButtonPressed(0));
|
CHECK(!b.ButtonPressed(mb::Left));
|
||||||
CHECK(!b.ButtonPressed(1));
|
CHECK(!b.ButtonPressed(mb::Middle));
|
||||||
CHECK(!b.ButtonPressed(2));
|
CHECK(!b.ButtonPressed(mb::Right));
|
||||||
|
|
||||||
// 6
|
// 6
|
||||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||||
b.Step(); // no change
|
b.Step(); // no change
|
||||||
mt::IncMillis();
|
mt::IncMillis();
|
||||||
}
|
}
|
||||||
CHECK(!b.ButtonPressed(0));
|
CHECK(!b.ButtonPressed(mb::Left));
|
||||||
CHECK(!b.ButtonPressed(1));
|
CHECK(!b.ButtonPressed(mb::Middle));
|
||||||
CHECK(!b.ButtonPressed(2));
|
CHECK(!b.ButtonPressed(mb::Right));
|
||||||
|
|
||||||
// 7
|
// 7
|
||||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||||
b.Step(); // one step from "pressed"
|
b.Step(); // one step from "pressed"
|
||||||
mt::IncMillis();
|
mt::IncMillis();
|
||||||
}
|
}
|
||||||
CHECK(!b.ButtonPressed(0));
|
CHECK(!b.ButtonPressed(mb::Left));
|
||||||
CHECK(!b.ButtonPressed(1));
|
CHECK(!b.ButtonPressed(mb::Middle));
|
||||||
CHECK(!b.ButtonPressed(2));
|
CHECK(!b.ButtonPressed(mb::Right));
|
||||||
|
|
||||||
// 8
|
// 8
|
||||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||||
b.Step(); // fifth set of samples - should report "pressed" finally
|
b.Step(); // fifth set of samples - should report "pressed" finally
|
||||||
mt::IncMillis();
|
mt::IncMillis();
|
||||||
}
|
}
|
||||||
CHECK(b.ButtonPressed(0));
|
CHECK(b.ButtonPressed(mb::Left));
|
||||||
CHECK(!b.ButtonPressed(1));
|
CHECK(!b.ButtonPressed(mb::Middle));
|
||||||
CHECK(!b.ButtonPressed(2));
|
CHECK(!b.ButtonPressed(mb::Right));
|
||||||
|
|
||||||
// 1023
|
// 1023
|
||||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||||
b.Step(); // sixth set of samples - button released (no debouncing on release)
|
b.Step(); // sixth set of samples - button released (no debouncing on release)
|
||||||
mt::IncMillis();
|
mt::IncMillis();
|
||||||
}
|
}
|
||||||
CHECK(!b.ButtonPressed(0));
|
CHECK(!b.ButtonPressed(mb::Left));
|
||||||
CHECK(!b.ButtonPressed(1));
|
CHECK(!b.ButtonPressed(mb::Middle));
|
||||||
CHECK(!b.ButtonPressed(2));
|
CHECK(!b.ButtonPressed(mb::Right));
|
||||||
|
|
||||||
// 1023
|
// 1023
|
||||||
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
for (uint8_t i = 0; i < oversampleFactor; ++i) {
|
||||||
b.Step(); // seventh set of samples - still released
|
b.Step(); // seventh set of samples - still released
|
||||||
mt::IncMillis();
|
mt::IncMillis();
|
||||||
}
|
}
|
||||||
CHECK(!b.ButtonPressed(0));
|
CHECK(!b.ButtonPressed(mb::Left));
|
||||||
CHECK(!b.ButtonPressed(1));
|
CHECK(!b.ButtonPressed(mb::Middle));
|
||||||
CHECK(!b.ButtonPressed(2));
|
CHECK(!b.ButtonPressed(mb::Right));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue