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.
Options_Engine/OptionsEngine.h@38:a85bc227b907, 2019-05-09 (annotated)
- Committer:
- JamesCummins
- Date:
- Thu May 09 01:09:18 2019 +0000
- Revision:
- 38:a85bc227b907
- Parent:
- 37:de1f584bce71
Doxygen documentation written out and in line commenting completed. Game working and finished. Tests.h still to write out
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| JamesCummins | 22:4e305ff8a050 | 1 | #ifndef OPTIONSENGINE_H | 
| JamesCummins | 22:4e305ff8a050 | 2 | #define OPTIONSENGINE_H | 
| JamesCummins | 22:4e305ff8a050 | 3 | |
| JamesCummins | 22:4e305ff8a050 | 4 | #include "mbed.h" | 
| JamesCummins | 22:4e305ff8a050 | 5 | #include "Gamepad.h" | 
| JamesCummins | 22:4e305ff8a050 | 6 | #include "N5110.h" | 
| JamesCummins | 22:4e305ff8a050 | 7 | #include "Ball.h" | 
| JamesCummins | 24:c6415cc74b17 | 8 | #include "Pause.h" | 
| JamesCummins | 24:c6415cc74b17 | 9 | #include "SDFileSystem.h" | 
| JamesCummins | 22:4e305ff8a050 | 10 | |
| JamesCummins | 37:de1f584bce71 | 11 | /** Enum for choice currently selected in Options Menu*/ | 
| JamesCummins | 22:4e305ff8a050 | 12 | enum Option{ | 
| JamesCummins | 37:de1f584bce71 | 13 | BRIGHTNESS, /**<Top menu option*/ | 
| JamesCummins | 37:de1f584bce71 | 14 | BALL_SPEED, /**<Middle menu option*/ | 
| JamesCummins | 37:de1f584bce71 | 15 | HIGH_SCORES /**<Bottom menu option*/ | 
| JamesCummins | 22:4e305ff8a050 | 16 | }; | 
| JamesCummins | 22:4e305ff8a050 | 17 | |
| JamesCummins | 37:de1f584bce71 | 18 | /** Option Selection struct*/ | 
| JamesCummins | 22:4e305ff8a050 | 19 | struct OptionSelection{ | 
| JamesCummins | 37:de1f584bce71 | 20 | int output; /**< Integer output for line to print arrows */ | 
| JamesCummins | 37:de1f584bce71 | 21 | Option next_state[3]; /**< Array of enums for possible next option */ | 
| JamesCummins | 22:4e305ff8a050 | 22 | }; | 
| JamesCummins | 24:c6415cc74b17 | 23 | |
| JamesCummins | 38:a85bc227b907 | 24 | /** Options Engine Class | 
| JamesCummins | 38:a85bc227b907 | 25 | @brief Library to power the options menu | 
| JamesCummins | 38:a85bc227b907 | 26 | @brief Features methods | 
| JamesCummins | 38:a85bc227b907 | 27 | |
| JamesCummins | 38:a85bc227b907 | 28 | @author James Cummins | 
| JamesCummins | 38:a85bc227b907 | 29 | |
| JamesCummins | 38:a85bc227b907 | 30 | @code | 
| JamesCummins | 38:a85bc227b907 | 31 | |
| JamesCummins | 38:a85bc227b907 | 32 | #include "mbed.h" | 
| JamesCummins | 38:a85bc227b907 | 33 | #include "OptionsEngine.h" | 
| JamesCummins | 38:a85bc227b907 | 34 | |
| JamesCummins | 38:a85bc227b907 | 35 | //Create an engine object for the Options Menu | 
| JamesCummins | 38:a85bc227b907 | 36 | OptionsEngine opt; | 
| JamesCummins | 38:a85bc227b907 | 37 | Gamepad gamepad; | 
| JamesCummins | 38:a85bc227b907 | 38 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); | 
| JamesCummins | 38:a85bc227b907 | 39 | Ball ball; | 
| JamesCummins | 38:a85bc227b907 | 40 | |
| JamesCummins | 38:a85bc227b907 | 41 | int main(){ | 
| JamesCummins | 38:a85bc227b907 | 42 | //Enum for the user's option choice initialised to first menu item (brightness) | 
| JamesCummins | 38:a85bc227b907 | 43 | Option choice = BRIGHTNESS; | 
| JamesCummins | 38:a85bc227b907 | 44 | while(!(gamepad.check_event(gamepad.A_PRESSED))){ | 
| JamesCummins | 38:a85bc227b907 | 45 | //display options renders the options menu | 
| JamesCummins | 38:a85bc227b907 | 46 | //option selection renders the arrows which point to the current selection | 
| JamesCummins | 38:a85bc227b907 | 47 | lcd.clear(); | 
| JamesCummins | 38:a85bc227b907 | 48 | opt.display_options(lcd); | 
| JamesCummins | 38:a85bc227b907 | 49 | choice = opt.option_selection(gamepad, lcd); | 
| JamesCummins | 38:a85bc227b907 | 50 | lcd.refresh(); | 
| JamesCummins | 38:a85bc227b907 | 51 | //longer wait time than normal game fps to compensate for button bounce | 
| JamesCummins | 38:a85bc227b907 | 52 | wait(0.2); | 
| JamesCummins | 38:a85bc227b907 | 53 | } | 
| JamesCummins | 38:a85bc227b907 | 54 | //each menu option called by its respective enum | 
| JamesCummins | 38:a85bc227b907 | 55 | if(choice == BRIGHTNESS){ opt.change_brightness(gamepad, lcd); } | 
| JamesCummins | 38:a85bc227b907 | 56 | if(choice == BALL_SPEED){ opt.change_ball_speed(gamepad, lcd, ball); } | 
| JamesCummins | 38:a85bc227b907 | 57 | if(choice == HIGH_SCORES){ opt.view_high_scores(gamepad, lcd); } | 
| JamesCummins | 38:a85bc227b907 | 58 | } | 
| JamesCummins | 38:a85bc227b907 | 59 | |
| JamesCummins | 38:a85bc227b907 | 60 | @endcode | 
| JamesCummins | 38:a85bc227b907 | 61 | |
| JamesCummins | 38:a85bc227b907 | 62 | */ | 
| JamesCummins | 38:a85bc227b907 | 63 | |
| JamesCummins | 22:4e305ff8a050 | 64 | class OptionsEngine { | 
| JamesCummins | 22:4e305ff8a050 | 65 | |
| JamesCummins | 22:4e305ff8a050 | 66 | public: | 
| JamesCummins | 37:de1f584bce71 | 67 | /** | 
| JamesCummins | 37:de1f584bce71 | 68 | * @brief Create an engine object for the Options menu | 
| JamesCummins | 37:de1f584bce71 | 69 | */ | 
| JamesCummins | 37:de1f584bce71 | 70 | OptionsEngine(); | 
| JamesCummins | 37:de1f584bce71 | 71 | /** | 
| JamesCummins | 37:de1f584bce71 | 72 | * @brief Delete an Options Engine object to free up memory | 
| JamesCummins | 37:de1f584bce71 | 73 | */ | 
| JamesCummins | 37:de1f584bce71 | 74 | ~OptionsEngine(); | 
| JamesCummins | 37:de1f584bce71 | 75 | /** | 
| JamesCummins | 37:de1f584bce71 | 76 | * @brief Initialise Options menu settings. Set brightness to 50%, set initial | 
| JamesCummins | 37:de1f584bce71 | 77 | * option to the top one in the list, and set ball speed sensitivity to 5/10 | 
| JamesCummins | 37:de1f584bce71 | 78 | */ | 
| JamesCummins | 37:de1f584bce71 | 79 | void init(); | 
| JamesCummins | 37:de1f584bce71 | 80 | /** | 
| JamesCummins | 37:de1f584bce71 | 81 | * @brief Render the options menu on the LCD screen | 
| JamesCummins | 37:de1f584bce71 | 82 | * @param lcd - N5110 object to interact with LCD screen | 
| JamesCummins | 37:de1f584bce71 | 83 | */ | 
| JamesCummins | 25:b52aa23df120 | 84 | void display_options(N5110 &lcd); | 
| JamesCummins | 37:de1f584bce71 | 85 | /** | 
| JamesCummins | 37:de1f584bce71 | 86 | * @brief Read the user input, highlight and store the current option on the screen | 
| JamesCummins | 37:de1f584bce71 | 87 | * @param gamepad - Gamepad object to read the user input | 
| JamesCummins | 37:de1f584bce71 | 88 | * @param lcd - N5110 object to display arrows on LCD screen | 
| JamesCummins | 37:de1f584bce71 | 89 | * @returns an Enum of the option selected - BRIGHTNESS, BALL_SPEED or HIGH_SCORES | 
| JamesCummins | 37:de1f584bce71 | 90 | */ | 
| JamesCummins | 25:b52aa23df120 | 91 | Option option_selection(Gamepad &gamepad, N5110 &lcd); | 
| JamesCummins | 37:de1f584bce71 | 92 | /** | 
| JamesCummins | 37:de1f584bce71 | 93 | * @brief Set the brightness of the LCD screen | 
| JamesCummins | 37:de1f584bce71 | 94 | * @param gamepad - Gamepad object to detect button press | 
| JamesCummins | 37:de1f584bce71 | 95 | * @param lcd - N5110 object to alter brightness and display graphic interface | 
| JamesCummins | 37:de1f584bce71 | 96 | */ | 
| JamesCummins | 22:4e305ff8a050 | 97 | void change_brightness(Gamepad &gamepad, N5110 &lcd); | 
| JamesCummins | 37:de1f584bce71 | 98 | /** | 
| JamesCummins | 37:de1f584bce71 | 99 | * @brief Set the ball speed multiplier | 
| JamesCummins | 37:de1f584bce71 | 100 | * @param gamepad - Gamepad object to detect button press | 
| JamesCummins | 37:de1f584bce71 | 101 | * @param lcd - N5110 object to display graphic interface | 
| JamesCummins | 37:de1f584bce71 | 102 | * @details ball speed is a continual multiplier to the values sensed by the | 
| JamesCummins | 37:de1f584bce71 | 103 | * accelerometer, altering the sensitivity of the sensed input | 
| JamesCummins | 37:de1f584bce71 | 104 | * (i.e the same change in tilt causes a greater change in the | 
| JamesCummins | 37:de1f584bce71 | 105 | * ball's position | 
| JamesCummins | 37:de1f584bce71 | 106 | */ | 
| JamesCummins | 23:61fa82f76808 | 107 | void change_ball_speed(Gamepad &gamepad, N5110 &lcd, Ball &ball); | 
| JamesCummins | 37:de1f584bce71 | 108 | /** | 
| JamesCummins | 37:de1f584bce71 | 109 | * @brief Display the high scores for the selected game mode on the LCD screen | 
| JamesCummins | 37:de1f584bce71 | 110 | * @param gamepad - Gamepad object to sense user's selection | 
| JamesCummins | 37:de1f584bce71 | 111 | * @param lcd - N5110 object to display chosen leaderboard on LCD Screen | 
| JamesCummins | 37:de1f584bce71 | 112 | */ | 
| JamesCummins | 26:0dc10374546f | 113 | void view_high_scores(Gamepad &gamepad, N5110 &lcd); | 
| JamesCummins | 22:4e305ff8a050 | 114 | |
| JamesCummins | 22:4e305ff8a050 | 115 | private: | 
| JamesCummins | 22:4e305ff8a050 | 116 | void read_brightness_input(Gamepad &gamepad); | 
| JamesCummins | 23:61fa82f76808 | 117 | void read_ball_speed_input(Gamepad &gamepad); | 
| JamesCummins | 26:0dc10374546f | 118 | void print_high_scores(N5110 &lcd); | 
| JamesCummins | 35:138ad0faa42b | 119 | void read_classic_high_scores(); | 
| JamesCummins | 26:0dc10374546f | 120 | void read_bb_high_scores(); | 
| JamesCummins | 22:4e305ff8a050 | 121 | Option _state; | 
| JamesCummins | 22:4e305ff8a050 | 122 | int _next_state; | 
| JamesCummins | 22:4e305ff8a050 | 123 | float _brightness; | 
| JamesCummins | 22:4e305ff8a050 | 124 | int _ball_speed; | 
| JamesCummins | 24:c6415cc74b17 | 125 | Mode _leaderboard; | 
| JamesCummins | 35:138ad0faa42b | 126 | int _classic_index[6]; | 
| JamesCummins | 35:138ad0faa42b | 127 | float _classic_values[6]; | 
| JamesCummins | 35:138ad0faa42b | 128 | int _bb_index[6]; | 
| JamesCummins | 35:138ad0faa42b | 129 | float _bb_values[6]; | 
| JamesCummins | 22:4e305ff8a050 | 130 | |
| JamesCummins | 22:4e305ff8a050 | 131 | }; | 
| JamesCummins | 22:4e305ff8a050 | 132 | #endif |