From a88eef87ef981594d8b49de246dd4ccff0c86bc3 Mon Sep 17 00:00:00 2001 From: Izzy Jones Date: Mon, 3 Jun 2024 10:08:39 -0400 Subject: [PATCH] Add a hotkey to cycle between profiles. (#1031) * Fixed selecting B3 in the hotkey settings * Added support for cycling profiles * Reverted values to expected numbers * Removed Next Profile localization to separate into another pull request * Adjust spacing for consistency --- headers/storagemanager.h | 1 + proto/enums.proto | 1 + src/gamepad.cpp | 8 +++++++- src/storagemanager.cpp | 5 +++++ www/src/Pages/SettingsPage.jsx | 1 + 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/headers/storagemanager.h b/headers/storagemanager.h index 57f370b30..7c5db4294 100644 --- a/headers/storagemanager.h +++ b/headers/storagemanager.h @@ -69,6 +69,7 @@ class Storage { uint8_t * GetFeatureData(); void setProfile(const uint32_t); // profile support for multiple mappings + void nextProfile(); void setFunctionalPinMappings(); void ResetSettings(); // EEPROM Reset Feature diff --git a/proto/enums.proto b/proto/enums.proto index 456084fe9..999857cdd 100644 --- a/proto/enums.proto +++ b/proto/enums.proto @@ -274,6 +274,7 @@ enum GamepadHotkey HOTKEY_S2_BUTTON = 32; HOTKEY_A1_BUTTON = 33; HOTKEY_A2_BUTTON = 34; + HOTKEY_NEXT_PROFILE = 35; } // This has to be kept in sync with LEDFormat in NeoPico.hpp diff --git a/src/gamepad.cpp b/src/gamepad.cpp index 2f68556de..07fa9eb5a 100644 --- a/src/gamepad.cpp +++ b/src/gamepad.cpp @@ -81,7 +81,6 @@ void Gamepad::setup() } } - lastAction = HOTKEY_NONE; } /** @@ -438,6 +437,13 @@ void Gamepad::processHotkeyAction(GamepadHotkey action) { reqSave = true; } break; + case HOTKEY_NEXT_PROFILE: + if (action != lastAction) { + Storage::getInstance().nextProfile(); + userRequestedReinit = true; + reqSave = true; + } + break; default: // Unknown action return; } diff --git a/src/storagemanager.cpp b/src/storagemanager.cpp index 9150e03de..b655c698c 100644 --- a/src/storagemanager.cpp +++ b/src/storagemanager.cpp @@ -119,6 +119,11 @@ void Storage::setProfile(const uint32_t profileNum) this->config.gamepadOptions.profileNumber = (profileNum < 1 || profileNum > 4) ? 1 : profileNum; } +void Storage::nextProfile() +{ + this->config.gamepadOptions.profileNumber = (this->config.gamepadOptions.profileNumber % 4) + 1; +} + void Storage::setFunctionalPinMappings() { GpioMappingInfo* alts = nullptr; diff --git a/www/src/Pages/SettingsPage.jsx b/www/src/Pages/SettingsPage.jsx index cb2c971b5..04fcb66d4 100644 --- a/www/src/Pages/SettingsPage.jsx +++ b/www/src/Pages/SettingsPage.jsx @@ -244,6 +244,7 @@ const HOTKEY_ACTIONS = [ { labelKey: 'hotkey-actions.load-profile-2', value: 16 }, { labelKey: 'hotkey-actions.load-profile-3', value: 17 }, { labelKey: 'hotkey-actions.load-profile-4', value: 18 }, + { labelKey: 'hotkey-actions.next-profile', value: 35 }, { labelKey: 'hotkey-actions.l3-button', value: 19 }, { labelKey: 'hotkey-actions.r3-button', value: 20 }, { labelKey: 'hotkey-actions.touchpad-button', value: 21 },