From 1797beaf017a2ce052ba61a181c6e727eabcb4ea Mon Sep 17 00:00:00 2001 From: Jonathan Haylett Date: Mon, 11 Mar 2024 12:23:41 +0000 Subject: [PATCH] feat: add MenuButtonHints display mode --- HAL/pico/include/display/DisplayMode.hpp | 1 + HAL/pico/src/display/ConfigMenu.cpp | 15 +++++++++++++++ config/glyph/config.cpp | 22 ++++++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/HAL/pico/include/display/DisplayMode.hpp b/HAL/pico/include/display/DisplayMode.hpp index 003b8537..23ace4e2 100644 --- a/HAL/pico/include/display/DisplayMode.hpp +++ b/HAL/pico/include/display/DisplayMode.hpp @@ -12,6 +12,7 @@ typedef enum _DisplayModeId { DISPLAY_MODE_VIEWER, DISPLAY_MODE_CONFIG, DISPLAY_MODE_RGB_BRIGHTNESS, + DISPLAY_MODE_BUTTON_HINTS } DisplayModeId; class DisplayMode { diff --git a/HAL/pico/src/display/ConfigMenu.cpp b/HAL/pico/src/display/ConfigMenu.cpp index 22a566ca..32548596 100644 --- a/HAL/pico/src/display/ConfigMenu.cpp +++ b/HAL/pico/src/display/ConfigMenu.cpp @@ -123,6 +123,10 @@ ConfigMenu::ConfigMenu(Config &config, CommunicationBackend **backends, size_t b Config &config, uint8_t key ) { + // Restore gamemode. + if (menu->_backends[0] != nullptr) { + menu->_backends[0]->SetGameMode(display_backend->CurrentGameMode()); + } display_backend->SetDisplayMode(DISPLAY_MODE_VIEWER); }, }, @@ -219,6 +223,10 @@ void ConfigMenu::HandleControls( } else if (button == controls.back) { // If at top-level page, go back to input viewer. if (_current_menu_page->parent == nullptr) { + // Restore gamemode. + if (_backends[0] != nullptr) { + _backends[0]->SetGameMode(instance->CurrentGameMode()); + } instance->SetDisplayMode(DISPLAY_MODE_VIEWER); return; } @@ -229,6 +237,12 @@ void ConfigMenu::HandleControls( } void ConfigMenu::UpdateDisplay(IntegratedDisplay *instance, Adafruit_GFX &display) { + // Unset gamemode to prevent menu button presses being sent to console. + if (_backends[0] != nullptr && _backends[0]->CurrentGameMode() != nullptr) { + instance->SetGameMode(_backends[0]->CurrentGameMode()); + _backends[0]->SetGameMode(nullptr); + } + uint8_t font_width = instance->font_width; uint8_t font_height = instance->font_height; @@ -268,6 +282,7 @@ void ConfigMenu::SetDefaultMode( for (size_t i = 0; i < menu->_backends_count; i++) { set_mode(menu->_backends[i], config.game_mode_configs[mode_config_index], config); } + set_mode(display_backend, config.game_mode_configs[mode_config_index], config); } void ConfigMenu::SetDefaultUsbBackend( diff --git a/config/glyph/config.cpp b/config/glyph/config.cpp index 31417772..7370eec6 100644 --- a/config/glyph/config.cpp +++ b/config/glyph/config.cpp @@ -8,6 +8,7 @@ #include "display/ConfigMenu.hpp" #include "display/DisplayMode.hpp" #include "display/InputDisplay.hpp" +#include "display/MenuButtonHints.hpp" #include "display/RgbBrightnessMenu.hpp" #include "glyph_overrides.hpp" #include "input/DebouncedSwitchMatrixInput.hpp" @@ -154,6 +155,7 @@ void setup1() { // These have to be initialized after backends. CommunicationBackendId primary_backend_id = backends[0]->BackendId(); + static MenuButtonHints menu_button_hints(primary_backend_id); static InputDisplay input_display( input_viewer_buttons, input_viewer_buttons_count, @@ -161,7 +163,12 @@ void setup1() { ); static ConfigMenu config_menu(config, backends, backend_count); - static DisplayMode *display_modes[] = { &input_display, &config_menu, &rgb_brightness_menu }; + static DisplayMode *display_modes[] = { + &menu_button_hints, + &input_display, + &config_menu, + &rgb_brightness_menu, + }; size_t display_modes_count = count_of(display_modes); Wire1.setSDA(2); @@ -180,14 +187,17 @@ void setup1() { display_modes_count ); // clang-format on + display_backend->SetDisplayMode(DISPLAY_MODE_BUTTON_HINTS); } } void loop1() { - if (display_backend != nullptr) { - if (display_backend->CurrentGameMode() != backends[0]->CurrentGameMode()) { - display_backend->SetGameMode(backends[0]->CurrentGameMode()); - } - display_backend->SendReport(); + if (display_backend == nullptr) { + return; } + if (backends[0] != nullptr && backends[0]->CurrentGameMode() != nullptr && + display_backend->CurrentGameMode() != backends[0]->CurrentGameMode()) { + display_backend->SetGameMode(backends[0]->CurrentGameMode()); + } + display_backend->SendReport(); }