From 5f0e8a92127cb8901ca6c22ef3ea6d6f5f456e08 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 15 Jan 2024 20:46:00 -0500 Subject: [PATCH] Use pulses instead of frame based movement --- .../Overlay/ScreenCenter/screen_center.cpp | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/examples/PoolBox/application/src/Overlay/ScreenCenter/screen_center.cpp b/examples/PoolBox/application/src/Overlay/ScreenCenter/screen_center.cpp index 9525631b..058d1ae8 100644 --- a/examples/PoolBox/application/src/Overlay/ScreenCenter/screen_center.cpp +++ b/examples/PoolBox/application/src/Overlay/ScreenCenter/screen_center.cpp @@ -10,32 +10,43 @@ namespace ScreenCenter { using namespace JabyEngine; using GenericButton = Periphery::GenericController::Button; - struct ButtonWatcher { + struct ButtonPulser { + static constexpr auto StartTime = 2500_ms; + static constexpr auto PulseTime = 100_ms; + enum struct State { WentDown, - DownFor2500ms, + Pulse, Unkown }; - SimpleTimer timer; + SimpleTimer timer; + uint8_t pulse_time; void setup() { this->timer.reset(); + this->pulse_time = StartTime; + } + + void reset() { + ButtonPulser::setup(); } State check(GenericButton button) { const auto controller = Periphery::get_primary_controller_as(); if(!controller.button.was_down(button)) { - this->timer.reset(); - + ButtonPulser::reset(); if(controller.button.went_down(button)) { return State::WentDown; } } - if(this->timer.is_expired_for(2500_ms)) { - return State::DownFor2500ms; + if(this->timer.is_expired_for(this->pulse_time)) { + this->pulse_time = PulseTime; + this->timer.reset(); + + return State::Pulse; } return State::Unkown; } @@ -49,8 +60,9 @@ namespace ScreenCenter { static constexpr uint16_t ScanlinesV = 240; #endif //JABYENGINE_PAL - static const auto frame = Frame::create(); - static ButtonWatcher button_watcher[4]; + static const auto frame = Frame::create(); + + static ButtonPulser button_pulse[4]; static void (*update)() = nullptr; static int16_t offset_x = 0; static int16_t offset_y = 0; @@ -90,10 +102,10 @@ namespace ScreenCenter { } static void update_interactive() { - 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::DownFor2500ms: + static const auto handle_button = [](ButtonPulser& button_pulse, GenericButton button, int16_t &dst, const int16_t mlp) { + switch(button_pulse.check(button)) { + case ButtonPulser::State::WentDown: + case ButtonPulser::State::Pulse: dst += (1*mlp); break; } @@ -108,10 +120,10 @@ namespace ScreenCenter { const auto controller = Periphery::get_primary_controller_as(); - handle_button(button_watcher[0], GenericButton::Left, offset_x, -1); - handle_button(button_watcher[1], GenericButton::Right, offset_x, 1); - handle_button(button_watcher[2], GenericButton::Up, offset_y, -1); - handle_button(button_watcher[3], GenericButton::Down, offset_y, 1); + handle_button(button_pulse[0], GenericButton::Left, offset_x, -1); + handle_button(button_pulse[1], GenericButton::Right, offset_x, 1); + handle_button(button_pulse[2], GenericButton::Up, offset_y, -1); + handle_button(button_pulse[3], GenericButton::Down, offset_y, 1); auto cursor = FontWriter::update(CenterPoint); FontWriter::bios_font_writer.write(cursor, ModeStr, TVModeStr); @@ -124,8 +136,8 @@ namespace ScreenCenter { static void setup() { Shared::back_menu.reset(); - for(auto& button : button_watcher) { - button.setup(); + for(auto& pulse : button_pulse) { + pulse.setup(); } update = update_enter_state;