Peripherals: fix double registration of short and long press in Button class
All checks were successful
continuous-integration/drone/push Build is passing
gitea/skullc-peripherals/pipeline/head This commit looks good

This commit is contained in:
erki 2022-12-10 16:21:52 +02:00
parent a0639ec3f1
commit 8fbb0efd5d
2 changed files with 11 additions and 2 deletions

View File

@ -50,7 +50,7 @@ public:
}
else if (!is_pressed && was_pressed_)
{
if (time_held > TIMEOUT_SHORT_PRESS)
if (time_held > TIMEOUT_SHORT_PRESS && time_held <= TIMEOUT_LONG_PRESS)
new_state = ButtonPress::SHORT_PRESS;
time_pressed_down_ = 0;

View File

@ -109,7 +109,6 @@ TEST_CASE("Button reads presses properly.", "[peripherals],[button]")
SECTION("Long press is identified properly.")
{
HAL::millis = Button::TIMEOUT_LONG_PRESS + 2;
Gpio::set = false;
button.update();
@ -121,6 +120,16 @@ TEST_CASE("Button reads presses properly.", "[peripherals],[button]")
button.update();
REQUIRE(button.getState() == Peripherals::ButtonPress::NOT_PRESSED);
SECTION("Releasing keeps NOT_PRESSED state.")
{
HAL::millis += 1;
Gpio::set = false;
button.update();
REQUIRE(button.getState() == Peripherals::ButtonPress::NOT_PRESSED);
}
}
}
}