From 66ed1bf2374ca7e07222adcd31b9870c49e14f73 Mon Sep 17 00:00:00 2001 From: Jonathan Haylett Date: Sat, 21 Oct 2023 14:47:35 +0100 Subject: [PATCH] feat: track current game mode config index Track index of current game mode config to prevent switching from one GameModeConfig to the same GameModeConfig, which in turn prevents spamming of keypresses when entering a keyboard mode on RP2040. Closes #21 --- src/core/mode_selection.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/mode_selection.cpp b/src/core/mode_selection.cpp index 2da87c01..d0b897f2 100644 --- a/src/core/mode_selection.cpp +++ b/src/core/mode_selection.cpp @@ -13,6 +13,8 @@ uint64_t mode_activation_masks[sizeof(Config::game_mode_configs) / sizeof(GameModeConfig)]; +size_t current_mode_index = 0; + void set_mode(CommunicationBackend *backend, ControllerMode *mode) { // Delete keyboard mode in case one is set, so we don't end up getting both controller and // keyboard inputs. @@ -107,7 +109,8 @@ void select_mode( for (size_t i = 0; i < mode_configs_count; i++) { const GameModeConfig &mode_config = mode_configs[i]; - if (all_buttons_held(inputs.buttons, mode_activation_masks[i])) { + if (all_buttons_held(inputs.buttons, mode_activation_masks[i]) && i != current_mode_index) { + current_mode_index = i; set_mode(backend, mode_config, keyboard_modes, keyboard_modes_count); return; }