From 2b371dc473007c2357381460c5ccd74ac7f98956 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 15 Jan 2024 20:34:08 -0500 Subject: [PATCH] Code improvement --- .../src/Overlay/ScreenCenter/screen_center.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/examples/PoolBox/application/src/Overlay/ScreenCenter/screen_center.cpp b/examples/PoolBox/application/src/Overlay/ScreenCenter/screen_center.cpp index efcb92fa..9525631b 100644 --- a/examples/PoolBox/application/src/Overlay/ScreenCenter/screen_center.cpp +++ b/examples/PoolBox/application/src/Overlay/ScreenCenter/screen_center.cpp @@ -13,7 +13,7 @@ namespace ScreenCenter { struct ButtonWatcher { enum struct State { WentDown, - DownFor25000ms, + DownFor2500ms, Unkown }; @@ -26,19 +26,16 @@ namespace ScreenCenter { State check(GenericButton button) { const auto controller = Periphery::get_primary_controller_as(); - if(controller.button.went_down(button)) { + if(!controller.button.was_down(button)) { this->timer.reset(); - return State::WentDown; - } - if(controller.button.was_down(button)) { - if(this->timer.is_expired_for(2500_ms)) { - return State::DownFor25000ms; + if(controller.button.went_down(button)) { + return State::WentDown; } } - else { - this->timer.reset(); + if(this->timer.is_expired_for(2500_ms)) { + return State::DownFor2500ms; } return State::Unkown; } @@ -96,7 +93,7 @@ namespace ScreenCenter { static const auto handle_button = [](ButtonWatcher& button_state, GenericButton button, int16_t &dst, const int16_t mlp) { switch(button_state.check(button)) { case ButtonWatcher::State::WentDown: - case ButtonWatcher::State::DownFor25000ms: + case ButtonWatcher::State::DownFor2500ms: dst += (1*mlp); break; }