void PiWars::processButton(const InputEvent &event) { // Remember when we recieved this input _lastInput = std::chrono::system_clock::now(); // We only respond to key release if((int32_t)InputEventButtonValue::RELEASE == event.getButtonValue()) { // Is there on menu open? if(!_currentMenu) { // Is it the 'OK' button if(KEY_ENTER == event.getCode()) { // Display the main menu _currentMenu = _mainMenu; _displayingInfo = false; } } else { if(KEY_RIGHT == event.getCode()) { _currentMenu->next(); } else if(KEY_LEFT == event.getCode()) { _currentMenu->previous(); } else if(KEY_ENTER) { bool isMainMenu = (_currentMenu == _mainMenu); std::string currentEntry = _currentMenu->current(); // Assume the menu will no longer be active after this _currentMenu = nullptr; // Assume the 'info' window is no longer being displayed _displayingInfo = false; // Are we on the main menu? if(isMainMenu) { if(0 == currentEntry.compare(menuItemInfo)) { _displayingInfo = true; } else if(0 == currentEntry.compare(menuItemBrains)) { // Get the Brains menu and set it as the current menu _currentMenu = _brains->menu(); } else if(0 == currentEntry.compare(menuItemCamera)) { // Toggle the camera if(_cameraPipe) { fwrite("\n", 1, 1, _cameraPipe); fflush(_cameraPipe); _cameraRecording = !_cameraRecording; } } else if(0 == currentEntry.compare(menuItemShutdown)) { _running = false; } } else { // Currently we assume it must be the 'Brains' menu. So pass on // the select for processing _brains->selectMenuEntry(currentEntry); } } } // Update the display to reflect any changes above updateDisplay(); } }