Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Menu/Menu.cpp
- Revision:
- 14:9861fe85c803
- Parent:
- 13:bcf6bb69c597
- Child:
- 18:304700b5d8f8
--- a/Menu/Menu.cpp Wed Apr 03 13:42:58 2019 +0000 +++ b/Menu/Menu.cpp Thu Apr 04 18:19:26 2019 +0000 @@ -1,16 +1,23 @@ #include "Menu.h" +// Define the finite state machine for three different states: running game, display +// menu and display controls, {ouput,{a,b,c,d}} where a,b,c,d are inputs. +// The ouputs have been assigned to 0,1,2. +// There are four different relevent input combinations that have been assigned to +// 0,1,2,3. State _fsm[3] = { {0,{0,1,0,0}}, {1,{1,1,0,2}}, {2,{2,1,2,0}} }; +// Constructor and distructor Menu::Menu() {} Menu::~Menu() {} void Menu::init() { + // Initialise at the highest level, starting state is the menu. _state = 1; _controller.init(); } @@ -19,12 +26,15 @@ set_input(gamepad.check_event(Gamepad::START_PRESSED), gamepad.check_event(Gamepad::BACK_PRESSED), gamepad.check_event(Gamepad::X_PRESSED)); + // Select the current output, execute that output via the output function + // and update to the next state depending on the input. _output = _fsm[_state].output; output(lcd, gamepad); _state = _fsm[_state].next_state[_menu_input]; } void Menu::output(N5110 &lcd, Gamepad &gamepad) { + // 0, 1 and 2 have been assigned to the output of each state respectivley. if (_output == 0) { run_game(lcd, gamepad); } else if (_output == 1) { @@ -35,6 +45,11 @@ } void Menu::set_input(bool start, bool back, bool x) { + // 0, 1, 2, 3 have been assigned to each relevent input combination: + // if nothing is pressed, input = 0. + // if only back is pressed, input = 1. + // if only start is pressed, input = 2. + // if only X is pressed, input = 3. if (!start && !back && !x) { _menu_input = 0; } else if (!start && back) { @@ -60,6 +75,8 @@ } void Menu::display_menu(N5110 &lcd, Gamepad &gamepad) { + // Displays the menu and resets the controller to ensure a new game is + // ready to start when the state is switched to run game. _controller.init(); lcd.printString("Menu",30,0); lcd.printString("START- Play!",0,1);