Skip to content

Commit

Permalink
feat: add MenuButtonHints display mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyHaystack committed Mar 11, 2024
1 parent bbd5f59 commit 1797bea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions HAL/pico/include/display/DisplayMode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef enum _DisplayModeId {
DISPLAY_MODE_VIEWER,
DISPLAY_MODE_CONFIG,
DISPLAY_MODE_RGB_BRIGHTNESS,
DISPLAY_MODE_BUTTON_HINTS
} DisplayModeId;

class DisplayMode {
Expand Down
15 changes: 15 additions & 0 deletions HAL/pico/src/display/ConfigMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
},
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
22 changes: 16 additions & 6 deletions config/glyph/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -154,14 +155,20 @@ 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,
primary_backend_id
);
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);
Expand All @@ -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();
}

0 comments on commit 1797bea

Please sign in to comment.