From ce08d93ae2d157f9933471476dd996fc2523d2e4 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Fri, 16 Feb 2024 00:50:50 -0600 Subject: [PATCH] Fix Pacman pause button glitches (again) (#1906) --- firmware/application/external/pacman/ui_pacman.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/firmware/application/external/pacman/ui_pacman.cpp b/firmware/application/external/pacman/ui_pacman.cpp index a1dcc20f..8436ac21 100644 --- a/firmware/application/external/pacman/ui_pacman.cpp +++ b/firmware/application/external/pacman/ui_pacman.cpp @@ -33,23 +33,27 @@ void PacmanView::paint(Painter& painter) { } auto switches_raw = swizzled_switches() & ((1 << (int)Switch::Right) | (1 << (int)Switch::Left) | (1 << (int)Switch::Down) | (1 << (int)Switch::Up) | (1 << (int)Switch::Sel) | (1 << (int)Switch::Dfu)); + auto switches_debounced = get_switches_state().to_ulong(); // For the Select (Start/Pause) button, wait for release to avoid repeat uint8_t buttons_to_wait_for = (1 << (int)Switch::Sel); if (wait_for_button_release) { - if ((switches_raw & buttons_to_wait_for) == 0) + if ((switches_debounced & buttons_to_wait_for) == 0) wait_for_button_release = false; - switches_raw &= ~buttons_to_wait_for; + switches_debounced &= ~buttons_to_wait_for; } else { - if (switches_raw & buttons_to_wait_for) + if (switches_debounced & buttons_to_wait_for) wait_for_button_release = true; } + // For the directional buttons, use the raw inputs for fastest response time but_RIGHT = (switches_raw & (1 << (int)Switch::Right)) != 0; but_LEFT = (switches_raw & (1 << (int)Switch::Left)) != 0; but_DOWN = (switches_raw & (1 << (int)Switch::Down)) != 0; but_UP = (switches_raw & (1 << (int)Switch::Up)) != 0; - but_A = (switches_raw & (1 << (int)Switch::Sel)) != 0; + + // For the pause button, use the debounced input to avoid glitches, and OR in the value to make sure that we don't clear it before it's seen + but_A |= (switches_debounced & (1 << (int)Switch::Sel)) != 0; _game.Step(); }