diff --git a/Peripherals/Inc/peripherals_button.hpp b/Peripherals/Inc/peripherals_button.hpp index 37d4e03..0116dda 100644 --- a/Peripherals/Inc/peripherals_button.hpp +++ b/Peripherals/Inc/peripherals_button.hpp @@ -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; diff --git a/Tests/button.cpp b/Tests/button.cpp index b8c6b00..096f0fc 100644 --- a/Tests/button.cpp +++ b/Tests/button.cpp @@ -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); + } } } }