Hotkeys, Crash, Menu Fix + Tidying (#1324)

* Fix for hotkeys not allowing repeats.

Re-arrange on the main menu screen code.

Added virtual to GPEvent destructors to make sure we are calling all the way up the chain.

* Lock-up fixes, new/delete was happening while the update() function was being called by display

Some code clean-ups, moved all of the gpscreen destructors to virtual so we do not have to switch() the delete function.

Moved some init functions around so we always call init() first

* Add ability to exit menu with pin-based menu toggle. Fix rapid-press of menu toggle
This commit is contained in:
Luke A
2025-03-26 14:22:36 -04:00
committed by GitHub
parent 84cc1c131b
commit 1cd95437c8
24 changed files with 192 additions and 204 deletions

View File

@@ -4,7 +4,6 @@
#include "gpaddon.h"
#include <vector>
#include <pico/mutex.h>
enum ADDON_PROCESS {
CORE0_INPUT,

View File

@@ -215,19 +215,17 @@ private:
uint8_t displayIsPowerOn = 1;
uint32_t prevMillis;
std::string statusBar;
Gamepad* gamepad;
bool configMode;
GPGFX* gpDisplay;
GPScreen* gpScreen;
Mask_t prevValues;
DisplayMode currDisplayMode;
DisplayMode prevDisplayMode;
DisplayMode nextDisplayMode;
bool turnOffWhenSuspended;
uint32_t bootMode;
DisplaySaverMode displaySaverMode;
GPGFX_DisplayTypeOptions gpOptions;
GamepadButtonMapping *mapMenuToggle;
GamepadButtonMapping *mapMenuSelect;
};

View File

@@ -7,6 +7,8 @@
class GPScreen : public GPWidget {
public:
GPScreen(){}
virtual ~GPScreen() {}
void draw();
virtual int8_t update() = 0;
void clear();

View File

@@ -8,6 +8,7 @@ class GPWidget : public GPGFX_UI {
public:
GPWidget() {}
GPWidget(GPGFX* renderer) { setRenderer(renderer); }
virtual ~GPWidget(){}
virtual void draw() {}
virtual int8_t update() { return 0; }

View File

@@ -102,6 +102,7 @@ class ButtonLayoutScreen : public GPScreen {
public:
ButtonLayoutScreen() {}
ButtonLayoutScreen(GPGFX* renderer) { setRenderer(renderer); }
virtual ~ButtonLayoutScreen(){}
virtual int8_t update();
virtual void init();
virtual void shutdown();

View File

@@ -7,6 +7,7 @@ class ConfigScreen : public GPScreen {
public:
ConfigScreen() {}
ConfigScreen(GPGFX* renderer) { setRenderer(renderer); }
virtual ~ConfigScreen(){}
virtual int8_t update();
virtual void init();
virtual void shutdown();

View File

@@ -11,6 +11,7 @@ class DisplaySaverScreen : public GPScreen {
public:
DisplaySaverScreen() {}
DisplaySaverScreen(GPGFX* renderer) { setRenderer(renderer); }
virtual ~DisplaySaverScreen() {}
virtual int8_t update();
virtual void init();
virtual void shutdown();

View File

@@ -40,6 +40,7 @@ class MainMenuScreen : public GPScreen {
public:
MainMenuScreen() {}
MainMenuScreen(GPGFX* renderer) { setRenderer(renderer); }
virtual ~MainMenuScreen() {}
void setMenu(std::vector<MenuEntry>* menu);
virtual int8_t update();
virtual void init();
@@ -69,13 +70,13 @@ class MainMenuScreen : public GPScreen {
int32_t currentTurboMode();
void updateMenuNavigation(GpioAction action);
void updateEventMenuNavigation(GpioAction action);
void chooseAndReturn();
void setMenuHome();
protected:
virtual void drawScreen();
private:
uint8_t menuIndex = 0;
bool isPressed = false;
uint32_t checkDebounce;
std::vector<MenuEntry>* currentMenu;
@@ -83,9 +84,11 @@ class MainMenuScreen : public GPScreen {
uint16_t prevButtonState = 0;
uint8_t prevDpadState = 0;
Mask_t prevValues;
GPMenu* gpMenu;
GPMenu* gpMenu = nullptr;
const uint8_t menuLineSize = 4;
GpioAction eventAction;
bool screenIsPrompting = false;
bool promptChoice = false;
bool isMenuReady = false;

View File

@@ -8,6 +8,7 @@ class PinViewerScreen : public GPScreen {
public:
PinViewerScreen() {}
PinViewerScreen(GPGFX* renderer) { setRenderer(renderer); }
virtual ~PinViewerScreen(){}
virtual int8_t update();
virtual void init();
virtual void shutdown();

View File

@@ -6,7 +6,8 @@
class RestartScreen : public GPScreen {
public:
RestartScreen() {}
RestartScreen(GPGFX* renderer) { setRenderer(renderer); }
RestartScreen(GPGFX* renderer, uint32_t mode) { setRenderer(renderer); setBootMode(mode); }
virtual ~RestartScreen() {}
virtual int8_t update();
virtual void init();
virtual void shutdown();

View File

@@ -7,6 +7,7 @@ class SplashScreen : public GPScreen {
public:
SplashScreen() {}
SplashScreen(GPGFX* renderer) { setRenderer(renderer); }
virtual ~SplashScreen(){}
virtual int8_t update();
virtual void init();
virtual void shutdown();

View File

@@ -7,6 +7,7 @@ class StatsScreen : public GPScreen {
public:
StatsScreen() {}
StatsScreen(GPGFX* renderer) { setRenderer(renderer); }
virtual ~StatsScreen(){}
virtual int8_t update();
virtual void init();
virtual void shutdown();

View File

@@ -8,7 +8,7 @@ class GPEncoderChangeEvent : public GPEvent {
this->encoder = id;
this->direction = dir;
}
~GPEncoderChangeEvent() {}
virtual ~GPEncoderChangeEvent() {}
uint8_t encoder = 0;
int8_t direction = 0;

View File

@@ -6,7 +6,7 @@
class GPEvent {
public:
GPEvent() {}
~GPEvent() {}
virtual ~GPEvent() {}
virtual GPEventType eventType() { return this->_eventType; }
private:

View File

@@ -31,7 +31,7 @@ class GPGamepadEvent : public GPEvent {
this->state.lt = lt;
this->state.rt = rt;
}
~GPGamepadEvent() {}
virtual ~GPGamepadEvent() {}
GamepadState state;
private:

View File

@@ -9,7 +9,7 @@ class GPMenuNavigateEvent : public GPEvent {
GPMenuNavigateEvent(GpioAction action) {
this->menuAction = action;
}
~GPMenuNavigateEvent() {}
virtual ~GPMenuNavigateEvent() {}
GPEventType eventType() { return this->_eventType; }

View File

@@ -8,7 +8,7 @@ class GPProfileChangeEvent : public GPEvent {
this->previousValue = prev;
this->currentValue = curr;
}
~GPProfileChangeEvent() {}
virtual ~GPProfileChangeEvent() {}
GPEventType eventType() { return this->_eventType; }

View File

@@ -9,7 +9,7 @@ class GPRestartEvent : public GPEvent {
GPRestartEvent(System::BootMode mode) {
this->bootMode = mode;
}
~GPRestartEvent() {}
virtual ~GPRestartEvent() {}
GPEventType eventType() { return this->_eventType; }

View File

@@ -10,7 +10,7 @@ class GPStorageSaveEvent : public GPEvent {
this->forceSave = force;
this->restartAfterSave = restart;
}
~GPStorageSaveEvent() {}
virtual ~GPStorageSaveEvent() {}
GPEventType eventType() { return this->_eventType; }

View File

@@ -9,7 +9,7 @@ class GPSystemRebootEvent : public GPEvent {
GPSystemRebootEvent(System::BootMode mode) {
this->bootMode = mode;
}
~GPSystemRebootEvent() {}
virtual ~GPSystemRebootEvent() {}
GPEventType eventType() { return this->_eventType; }

View File

@@ -9,7 +9,7 @@ class GPUSBHostEvent : public GPEvent {
this->vendorID = vid;
this->productID = pid;
}
~GPUSBHostEvent() {}
virtual ~GPUSBHostEvent() {}
uint8_t deviceAddress = 0;
uint16_t vendorID = 0;
@@ -21,7 +21,7 @@ class GPUSBHostMountEvent : public GPUSBHostEvent {
public:
GPUSBHostMountEvent() {}
GPUSBHostMountEvent(uint8_t devAddr, uint16_t vid, uint16_t pid) : GPUSBHostEvent(devAddr, vid, pid) {}
~GPUSBHostMountEvent() {}
virtual ~GPUSBHostMountEvent() {}
GPEventType eventType() { return this->_eventType; }
private:
@@ -32,7 +32,7 @@ class GPUSBHostUnmountEvent : public GPUSBHostEvent {
public:
GPUSBHostUnmountEvent() {}
GPUSBHostUnmountEvent(uint8_t devAddr, uint16_t vid, uint16_t pid) : GPUSBHostEvent(devAddr, vid, pid) {}
~GPUSBHostUnmountEvent() {}
virtual ~GPUSBHostUnmountEvent() {}
GPEventType eventType() { return this->_eventType; }
private:

View File

@@ -46,8 +46,6 @@ void DisplayAddon::setup() {
// Setup GPGFX
gpDisplay->init(gpOptions);
gamepad = Storage::getInstance().GetGamepad();
displaySaverTimer = options.displaySaverTimeout;
displaySaverTimeout = displaySaverTimer;
configMode = Storage::getInstance().GetConfigMode();
@@ -65,6 +63,8 @@ void DisplayAddon::setup() {
}
}
prevValues = Storage::getInstance().GetGamepad()->debouncedGpio;
// set current display mode
if (!configMode) {
if (Storage::getInstance().getDisplayOptions().splashMode != static_cast<SplashMode>(SPLASH_MODE_NONE)) {
@@ -85,34 +85,7 @@ void DisplayAddon::setup() {
bool DisplayAddon::updateDisplayScreen() {
if ( gpScreen != nullptr ) {
gpScreen->shutdown();
switch(prevDisplayMode) {
case CONFIG_INSTRUCTION:
delete (ConfigScreen*)gpScreen;
break;
case SPLASH:
delete (SplashScreen*)gpScreen;
break;
case MAIN_MENU:
delete (MainMenuScreen*)gpScreen;
break;
case BUTTONS:
delete (ButtonLayoutScreen*)gpScreen;
break;
case PIN_VIEWER:
delete (PinViewerScreen*)gpScreen;
break;
case DISPLAY_SAVER:
delete (DisplaySaverScreen*)gpScreen;
break;
case STATS:
delete (StatsScreen*)gpScreen;
break;
case RESTART:
delete (RestartScreen*)gpScreen;
break;
default:
break;
}
delete gpScreen; // Virtual deconstructor
gpScreen = nullptr;
}
switch(currDisplayMode) {
@@ -124,7 +97,6 @@ bool DisplayAddon::updateDisplayScreen() {
break;
case MAIN_MENU:
gpScreen = new MainMenuScreen(gpDisplay);
((MainMenuScreen*)gpScreen)->setMenuHome();
break;
case BUTTONS:
gpScreen = new ButtonLayoutScreen(gpDisplay);
@@ -139,29 +111,33 @@ bool DisplayAddon::updateDisplayScreen() {
gpScreen = new StatsScreen(gpDisplay);
break;
case RESTART:
gpScreen = new RestartScreen(gpDisplay);
((RestartScreen*)gpScreen)->setBootMode(bootMode);
gpScreen = new RestartScreen(gpDisplay, bootMode);
break;
default:
gpScreen = nullptr;
break;
};
if (gpScreen != nullptr) {
gpScreen->init();
prevDisplayMode = currDisplayMode;
return true;
}
if (gpScreen == nullptr )
return false;
gpScreen->init();
prevDisplayMode = currDisplayMode;
nextDisplayMode = currDisplayMode;
return true;
}
bool DisplayAddon::isDisplayPowerOff()
{
Gamepad * gamepad = Storage::getInstance().GetGamepad();
if (turnOffWhenSuspended && get_usb_suspended()) {
if (displayIsPowerOn) setDisplayPower(0);
if (displayIsPowerOn)
setDisplayPower(0);
return true;
} else {
if (!displayIsPowerOn) setDisplayPower(1);
if (!displayIsPowerOn)
setDisplayPower(1);
}
if (!displaySaverTimeout) return false;
@@ -202,15 +178,24 @@ void DisplayAddon::process() {
return;
}
// Core0 requested a new display mode
if (nextDisplayMode != currDisplayMode ) {
currDisplayMode = nextDisplayMode;
updateDisplayScreen();
}
int8_t screenReturn = gpScreen->update();
gpScreen->draw();
if (!configMode && screenReturn < 0) {
Mask_t values = Storage::getInstance().GetGamepad()->debouncedGpio;
if ((values & mapMenuToggle->pinMask) || (values & mapMenuSelect->pinMask)) {
if (currDisplayMode != DisplayMode::MAIN_MENU) {
screenReturn = DisplayMode::MAIN_MENU;
if (prevValues != values) {
if ((values & mapMenuToggle->pinMask) || (values & mapMenuSelect->pinMask)) {
if (currDisplayMode != DisplayMode::MAIN_MENU) {
screenReturn = DisplayMode::MAIN_MENU;
}
}
prevValues = values;
}
}
@@ -231,23 +216,19 @@ const DisplayOptions& DisplayAddon::getDisplayOptions() {
void DisplayAddon::handleSystemRestart(GPEvent* e) {
currDisplayMode = DisplayMode::RESTART;
nextDisplayMode = DisplayMode::RESTART;
bootMode = (uint32_t)((GPRestartEvent*)e)->bootMode;
updateDisplayScreen();
}
void DisplayAddon::handleMenuNavigation(GPEvent* e) {
if (currDisplayMode != MAIN_MENU) {
if (((GPMenuNavigateEvent*)e)->menuAction == GpioAction::MENU_NAVIGATION_TOGGLE) {
currDisplayMode = MAIN_MENU;
updateDisplayScreen();
}
} else {
if (((GPMenuNavigateEvent*)e)->menuAction != GpioAction::MENU_NAVIGATION_TOGGLE) {
((MainMenuScreen*)gpScreen)->updateMenuNavigation(((GPMenuNavigateEvent*)e)->menuAction);
} else {
currDisplayMode = BUTTONS;
updateDisplayScreen();
// Swap between main menu and buttons if we press toggle
if (((GPMenuNavigateEvent*)e)->menuAction == GpioAction::MENU_NAVIGATION_TOGGLE) {
if (currDisplayMode == BUTTONS) {
nextDisplayMode = MAIN_MENU;
} else if (currDisplayMode == MAIN_MENU) {
nextDisplayMode = BUTTONS;
}
} else if (currDisplayMode == MAIN_MENU) {
((MainMenuScreen*)gpScreen)->updateEventMenuNavigation(((GPMenuNavigateEvent*)e)->menuAction);
}
}

View File

@@ -41,7 +41,7 @@ void MainMenuScreen::init() {
menuLabel = Storage::getInstance().getProfileOptions().gpioMappingsSets[profileCtr-1].profileLabel;
}
if (menuLabel.empty()) {
menuLabel = "Profile #" + std::to_string(profileCtr);
menuLabel = "Profile #" + std::to_string(profileCtr+1);
}
MenuEntry menuEntry = {menuLabel, NULL, nullptr, std::bind(&MainMenuScreen::currentProfile, this), std::bind(&MainMenuScreen::selectProfile, this), profileCtr+1};
profilesMenu.push_back(menuEntry);
@@ -80,6 +80,8 @@ void MainMenuScreen::init() {
prevTurbo = Storage::getInstance().getAddonOptions().turboOptions.enabled;
updateTurbo = Storage::getInstance().getAddonOptions().turboOptions.enabled;
setMenuHome();
}
void MainMenuScreen::shutdown() {
@@ -88,6 +90,7 @@ void MainMenuScreen::shutdown() {
}
void MainMenuScreen::drawScreen() {
if (gpMenu == nullptr) return;
gpMenu->setVisibility(!screenIsPrompting);
if (!screenIsPrompting) {
@@ -131,35 +134,42 @@ int8_t MainMenuScreen::update() {
uint16_t buttonState = getGamepad()->state.buttons;
uint8_t dpadState = getGamepad()->state.dpad;
if (!isPressed) {
if (prevValues != values) {
if (values & mapMenuUp->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_UP);
else if (values & mapMenuDown->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_DOWN);
else if (values & mapMenuLeft->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_LEFT);
else if (values & mapMenuRight->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_RIGHT);
else if (values & mapMenuSelect->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_SELECT);
else if (values & mapMenuBack->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_BACK);
if (prevValues != values) {
if (values & mapMenuUp->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_UP);
else if (values & mapMenuDown->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_DOWN);
else if (values & mapMenuLeft->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_LEFT);
else if (values & mapMenuRight->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_RIGHT);
else if (values & mapMenuSelect->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_SELECT);
else if (values & mapMenuBack->pinMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_BACK);
else if (values & mapMenuToggle->pinMask) {
// Menu toggle will always exit out of main menu
exitToScreen = DisplayMode::BUTTONS;
exitToScreenBeforePrompt = DisplayMode::BUTTONS;
}
if (gamepadOptions.miniMenuGamepadInput == true ) {
if (prevDpadState != dpadState ) {
if (dpadState == mapMenuUp->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_UP);
else if (dpadState == mapMenuDown->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_DOWN);
else if (dpadState == mapMenuLeft->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_LEFT);
else if (dpadState == mapMenuRight->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_RIGHT);
}
if ( prevButtonState != buttonState ) {
if (buttonState == mapMenuSelect->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_SELECT);
else if (buttonState == mapMenuBack->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_BACK);
}
}
if (gamepadOptions.miniMenuGamepadInput == true ) {
if (prevDpadState != dpadState ) {
if (dpadState == mapMenuUp->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_UP);
else if (dpadState == mapMenuDown->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_DOWN);
else if (dpadState == mapMenuLeft->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_LEFT);
else if (dpadState == mapMenuRight->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_RIGHT);
}
if ( prevButtonState != buttonState ) {
if (buttonState == mapMenuSelect->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_SELECT);
else if (buttonState == mapMenuBack->buttonMask) updateMenuNavigation(GpioAction::MENU_NAVIGATION_BACK);
}
} else {
isPressed = false; // Flip isPressed to false
}
prevButtonState = buttonState;
prevDpadState = dpadState;
prevValues = values;
// Core0 Event Navigations
if (eventAction != GpioAction::NONE) {
updateMenuNavigation(eventAction);
eventAction = GpioAction::NONE;
}
if ((exitToScreen != -1) && ((changeRequiresSave) || (changeRequiresReboot))) {
// trying to exit menu but a change requires a save/reboot
exitToScreenBeforePrompt = exitToScreen;
@@ -173,125 +183,109 @@ int8_t MainMenuScreen::update() {
}
}
void MainMenuScreen::updateEventMenuNavigation(GpioAction action) {
eventAction = action;
}
void MainMenuScreen::updateMenuNavigation(GpioAction action) {
bool changeIndex = false;
if (gpMenu == nullptr)
return;
uint16_t menuIndex = gpMenu->getIndex();
uint16_t menuSize = gpMenu->getDataSize();
if (isMenuReady) {
switch (action) {
case GpioAction::MENU_NAVIGATION_UP:
if (!screenIsPrompting) {
if (menuIndex > 0) {
menuIndex--;
} else {
menuIndex = menuSize-1;
}
changeIndex = true;
} else {
if (screenIsPrompting) {
switch(action) {
case GpioAction::MENU_NAVIGATION_UP:
case GpioAction::MENU_NAVIGATION_DOWN:
case GpioAction::MENU_NAVIGATION_LEFT:
case GpioAction::MENU_NAVIGATION_RIGHT:
promptChoice = !promptChoice;
}
isPressed = true;
break;
case GpioAction::MENU_NAVIGATION_DOWN:
if (!screenIsPrompting) {
if (menuIndex < menuSize-1) {
menuIndex++;
} else {
menuIndex = 0;
}
changeIndex = true;
} else {
promptChoice = !promptChoice;
}
isPressed = true;
break;
case GpioAction::MENU_NAVIGATION_LEFT:
if (!screenIsPrompting) {
if ((menuIndex-menuLineSize) > 0) {
menuIndex -= menuLineSize;
} else {
menuIndex = 0;
}
changeIndex = true;
} else {
promptChoice = !promptChoice;
}
isPressed = true;
break;
case GpioAction::MENU_NAVIGATION_RIGHT:
if (!screenIsPrompting) {
if ((menuIndex+menuLineSize) < (menuSize-1)) {
menuIndex += menuLineSize;
} else {
menuIndex = (menuSize-1);
}
changeIndex = true;
} else {
promptChoice = !promptChoice;
}
isPressed = true;
break;
case GpioAction::MENU_NAVIGATION_SELECT:
if (!screenIsPrompting) {
if (currentMenu->at(menuIndex).submenu != nullptr) {
previousMenu = currentMenu;
currentMenu = currentMenu->at(menuIndex).submenu;
gpMenu->setMenuData(currentMenu);
gpMenu->setMenuTitle(previousMenu->at(menuIndex).label);
menuIndex = 0;
changeIndex = true;
} else {
currentMenu->at(menuIndex).action();
}
} else {
break;
case GpioAction::MENU_NAVIGATION_SELECT:
if (promptChoice) {
saveOptions();
} else {
resetOptions();
exitToScreen = DisplayMode::BUTTONS;
exitToScreenBeforePrompt = DisplayMode::BUTTONS;
isPressed = false;
}
}
isPressed = true;
break;
case GpioAction::MENU_NAVIGATION_BACK:
if (!screenIsPrompting) {
break;
case GpioAction::MENU_NAVIGATION_BACK:
// back again goes back to the menu
screenIsPrompting = false;
break;
default:
break;
}
} else {
switch (action) {
case GpioAction::MENU_NAVIGATION_UP:
if ( menuIndex == 0 ) {
gpMenu->setIndex(menuSize-1);
} else {
gpMenu->setIndex(menuIndex-1);
}
break;
case GpioAction::MENU_NAVIGATION_DOWN:
if (menuIndex < menuSize-1) {
gpMenu->setIndex(menuIndex+1);
} else {
gpMenu->setIndex(0);
}
break;
case GpioAction::MENU_NAVIGATION_LEFT:
if ((menuIndex-menuLineSize) > 0) {
gpMenu->setIndex(menuIndex - menuLineSize);
} else {
gpMenu->setIndex(0);
}
break;
case GpioAction::MENU_NAVIGATION_RIGHT:
if ((menuIndex+menuLineSize) < (menuSize-1)) {
gpMenu->setIndex(menuIndex + menuLineSize);
} else {
gpMenu->setIndex(menuSize-1);
}
break;
case GpioAction::MENU_NAVIGATION_SELECT:
if (currentMenu->at(menuIndex).submenu != nullptr) {
previousMenu = currentMenu;
currentMenu = currentMenu->at(menuIndex).submenu;
gpMenu->setMenuData(currentMenu);
gpMenu->setMenuTitle(previousMenu->at(menuIndex).label);
gpMenu->setIndex(0);
} else {
currentMenu->at(menuIndex).action();
}
break;
case GpioAction::MENU_NAVIGATION_BACK:
if (previousMenu != nullptr) {
currentMenu = previousMenu;
previousMenu = nullptr;
menuIndex = 0;
changeIndex = true;
gpMenu->setMenuData(currentMenu);
gpMenu->setMenuTitle(MAIN_MENU_NAME);
gpMenu->setIndex(0);
} else {
exitToScreen = DisplayMode::BUTTONS;
exitToScreenBeforePrompt = DisplayMode::BUTTONS;
isPressed = false;
}
} else {
// back again goes back to the menu
screenIsPrompting = false;
isPressed = false;
}
isPressed = true;
break;
default:
break;
break;
default:
break;
}
}
}
if (changeIndex) gpMenu->setIndex(menuIndex);
}
void MainMenuScreen::chooseAndReturn() {
if (previousMenu != nullptr) {
currentMenu = previousMenu;
previousMenu = nullptr;
menuIndex = 0;
gpMenu->setMenuData(currentMenu);
gpMenu->setMenuTitle(MAIN_MENU_NAME);
gpMenu->setIndex(menuIndex);
gpMenu->setIndex(0);
} else {
exitToScreen = DisplayMode::BUTTONS;
exitToScreenBeforePrompt = DisplayMode::BUTTONS;
@@ -313,8 +307,8 @@ int32_t MainMenuScreen::modeValue() {
}
void MainMenuScreen::selectInputMode() {
if (currentMenu->at(menuIndex).optionValue != -1) {
InputMode valueToSave = (InputMode)currentMenu->at(menuIndex).optionValue;
if (currentMenu->at(gpMenu->getIndex()).optionValue != -1) {
InputMode valueToSave = (InputMode)currentMenu->at(gpMenu->getIndex()).optionValue;
prevInputMode = Storage::getInstance().GetGamepad()->getOptions().inputMode;
updateInputMode = valueToSave;
@@ -333,8 +327,8 @@ int32_t MainMenuScreen::currentInputMode() {
}
void MainMenuScreen::selectDPadMode() {
if (currentMenu->at(menuIndex).optionValue != -1) {
DpadMode valueToSave = (DpadMode)currentMenu->at(menuIndex).optionValue;
if (currentMenu->at(gpMenu->getIndex()).optionValue != -1) {
DpadMode valueToSave = (DpadMode)currentMenu->at(gpMenu->getIndex()).optionValue;
prevDpadMode = Storage::getInstance().GetGamepad()->getOptions().dpadMode;
updateDpadMode = valueToSave;
@@ -349,8 +343,8 @@ int32_t MainMenuScreen::currentDpadMode() {
}
void MainMenuScreen::selectSOCDMode() {
if (currentMenu->at(menuIndex).optionValue != -1) {
SOCDMode valueToSave = (SOCDMode)currentMenu->at(menuIndex).optionValue;
if (currentMenu->at(gpMenu->getIndex()).optionValue != -1) {
SOCDMode valueToSave = (SOCDMode)currentMenu->at(gpMenu->getIndex()).optionValue;
prevSocdMode = Storage::getInstance().GetGamepad()->getOptions().socdMode;
updateSocdMode = valueToSave;
@@ -426,8 +420,8 @@ void MainMenuScreen::saveOptions() {
}
void MainMenuScreen::selectProfile() {
if (currentMenu->at(menuIndex).optionValue != -1) {
uint8_t valueToSave = currentMenu->at(menuIndex).optionValue;
if (currentMenu->at(gpMenu->getIndex()).optionValue != -1) {
uint8_t valueToSave = currentMenu->at(gpMenu->getIndex()).optionValue;
prevProfile = Storage::getInstance().GetGamepad()->getOptions().profileNumber;
updateProfile = valueToSave;
@@ -442,8 +436,8 @@ int32_t MainMenuScreen::currentProfile() {
}
void MainMenuScreen::selectFocusMode() {
if (currentMenu->at(menuIndex).optionValue != -1) {
bool valueToSave = (bool)currentMenu->at(menuIndex).optionValue;
if (currentMenu->at(gpMenu->getIndex()).optionValue != -1) {
bool valueToSave = (bool)currentMenu->at(gpMenu->getIndex()).optionValue;
prevFocus = Storage::getInstance().getAddonOptions().focusModeOptions.enabled;
updateFocus = valueToSave;
@@ -458,8 +452,8 @@ int32_t MainMenuScreen::currentFocusMode() {
}
void MainMenuScreen::selectTurboMode() {
if (currentMenu->at(menuIndex).optionValue != -1) {
bool valueToSave = (bool)currentMenu->at(menuIndex).optionValue;
if (currentMenu->at(gpMenu->getIndex()).optionValue != -1) {
bool valueToSave = (bool)currentMenu->at(gpMenu->getIndex()).optionValue;
prevTurbo = Storage::getInstance().getAddonOptions().turboOptions.enabled;
updateTurbo = valueToSave;

View File

@@ -420,20 +420,21 @@ void Gamepad::read()
state.rt = 0;
}
void Gamepad::hotkey()
{
void Gamepad::hotkey() {
if (options.lockHotkeys)
return;
// Look for a hot-key
GamepadHotkey action;
bool hasHotkey = false;
for(int i = 0; i < 16; i++) {
if (pressedHotkey(hotkeys[i])) {
action = selectHotkey(hotkeys[i]);
processHotkeyAction(action);
lastAction = action;
processHotkeyAction(selectHotkey(hotkeys[i]));
hasHotkey = true;
}
}
if (hasHotkey == false ) {
lastAction = HOTKEY_NONE;
}
}
void Gamepad::clearState() {
@@ -699,11 +700,13 @@ void Gamepad::processHotkeyAction(GamepadHotkey action) {
}
break;
default: // Unknown action
return;
break;
}
// only save if requested
if (reqSave) {
EventManager::getInstance().triggerEvent(new GPStorageSaveEvent(true));
}
lastAction = action;
}