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.
lib/Options/Options.cpp@23:ecb74e52163d, 2019-05-09 (annotated)
- Committer:
- Kern_EL17KJTF
- Date:
- Thu May 09 00:25:50 2019 +0000
- Revision:
- 23:ecb74e52163d
- Parent:
- 11:b288d01533cc
Documentation - Options Class Complete.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Kern_EL17KJTF | 10:28575a6eaa13 | 1 | /* |
| Kern_EL17KJTF | 10:28575a6eaa13 | 2 | ELEC2645 Project |
| Kern_EL17KJTF | 10:28575a6eaa13 | 3 | Options.cpp |
| Kern_EL17KJTF | 10:28575a6eaa13 | 4 | Class file for Options in Donkey Kong game. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 5 | */ |
| Kern_EL17KJTF | 10:28575a6eaa13 | 6 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 7 | #include "Options.h" |
| Kern_EL17KJTF | 10:28575a6eaa13 | 8 | |
| Kern_EL17KJTF | 23:ecb74e52163d | 9 | // Constructor - Doesn't require any setup. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 10 | Options::Options() |
| Kern_EL17KJTF | 10:28575a6eaa13 | 11 | { |
| Kern_EL17KJTF | 10:28575a6eaa13 | 12 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 13 | } |
| Kern_EL17KJTF | 10:28575a6eaa13 | 14 | |
| Kern_EL17KJTF | 23:ecb74e52163d | 15 | // Deconstructor - Doesn't require any setup. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 16 | Options::~Options() |
| Kern_EL17KJTF | 10:28575a6eaa13 | 17 | { |
| Kern_EL17KJTF | 10:28575a6eaa13 | 18 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 19 | } |
| Kern_EL17KJTF | 10:28575a6eaa13 | 20 | |
| Kern_EL17KJTF | 23:ecb74e52163d | 21 | // External variables to be used inside and out of the class. |
| Kern_EL17KJTF | 23:ecb74e52163d | 22 | float opt_brightness = 0.5; |
| Kern_EL17KJTF | 23:ecb74e52163d | 23 | float opt_contrast = 0.396; |
| Kern_EL17KJTF | 23:ecb74e52163d | 24 | int opt_volume = 1; |
| Kern_EL17KJTF | 11:b288d01533cc | 25 | |
| Kern_EL17KJTF | 23:ecb74e52163d | 26 | // Runs and controls all the options functions. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 27 | void Options::options_run(Gamepad &pad, N5110 &lcd) { |
| Kern_EL17KJTF | 10:28575a6eaa13 | 28 | wait_ms(250); |
| Kern_EL17KJTF | 23:ecb74e52163d | 29 | while (pad.check_event(Gamepad::BACK_PRESSED) == false) { // Continues to show this screen until BACK button pressed. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 30 | //printf("Options State"); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 31 | lcd.clear(); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 32 | lcd.printString("Options",21,0); |
| Kern_EL17KJTF | 23:ecb74e52163d | 33 | options_brightness(pad, lcd); // Calls brightness function within class. |
| Kern_EL17KJTF | 23:ecb74e52163d | 34 | options_contrast(pad, lcd); // Calls contrast function within class. |
| Kern_EL17KJTF | 23:ecb74e52163d | 35 | options_volume(pad, lcd); // Calls volume function within class. |
| Kern_EL17KJTF | 23:ecb74e52163d | 36 | lcd.refresh(); // Reloads screen on every cycle, controlled by fps. Default set to 24. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 37 | wait_ms(1.0f/24); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 38 | } |
| Kern_EL17KJTF | 10:28575a6eaa13 | 39 | } |
| Kern_EL17KJTF | 10:28575a6eaa13 | 40 | |
| Kern_EL17KJTF | 23:ecb74e52163d | 41 | // Toggles the backlight on LCD screen, ON/OFF based on button inputs. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 42 | void Options::options_brightness(Gamepad &pad, N5110 &lcd) { |
| Kern_EL17KJTF | 23:ecb74e52163d | 43 | if (pad.check_event(Gamepad::B_PRESSED) == true) { // If B is pressed, will turn off backlight. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 44 | opt_brightness = 0; |
| Kern_EL17KJTF | 10:28575a6eaa13 | 45 | } |
| Kern_EL17KJTF | 23:ecb74e52163d | 46 | if (pad.check_event(Gamepad::A_PRESSED) == true) { // If A is pressed, will turn on backlight. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 47 | opt_brightness = 0.5; |
| Kern_EL17KJTF | 10:28575a6eaa13 | 48 | } |
| Kern_EL17KJTF | 10:28575a6eaa13 | 49 | lcd.setBrightness(opt_brightness); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 50 | lcd.printString("A/B = BackLite",0,2); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 51 | } |
| Kern_EL17KJTF | 10:28575a6eaa13 | 52 | |
| Kern_EL17KJTF | 23:ecb74e52163d | 53 | // Controls the LCD screen contrast based on gamepad potentiometer value. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 54 | void Options::options_contrast(Gamepad &pad, N5110 &lcd) { |
| Kern_EL17KJTF | 23:ecb74e52163d | 55 | opt_contrast = pad.read_pot(); // Gets potentiometer value from gamepad and assigns it to a value. |
| Kern_EL17KJTF | 23:ecb74e52163d | 56 | lcd.setContrast(opt_contrast); // Uses set value to change actual LCD contrast. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 57 | lcd.printString("Pot = Contrast",0,3); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 58 | printf("Contrast = %f", opt_contrast); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 59 | } |
| Kern_EL17KJTF | 10:28575a6eaa13 | 60 | |
| Kern_EL17KJTF | 23:ecb74e52163d | 61 | // Toggles the volume for the game, ON/OFF based on button inputs. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 62 | void Options::options_volume(Gamepad &pad, N5110 &lcd) { |
| Kern_EL17KJTF | 23:ecb74e52163d | 63 | if (pad.check_event(Gamepad::Y_PRESSED) == true) { // If Y is pressed, will disable volume. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 64 | opt_volume = 0; |
| Kern_EL17KJTF | 10:28575a6eaa13 | 65 | } |
| Kern_EL17KJTF | 23:ecb74e52163d | 66 | if (pad.check_event(Gamepad::X_PRESSED) == true) { // If X is press, will enable volume. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 67 | opt_volume = 1; |
| Kern_EL17KJTF | 23:ecb74e52163d | 68 | pad.tone(2400, 0.2); // Plays a set of beeps to confirm the volume is on. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 69 | wait_ms(200); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 70 | pad.tone(2400, 0.2); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 71 | wait_ms(200); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 72 | pad.tone(2400, 0.2); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 73 | } |
| Kern_EL17KJTF | 10:28575a6eaa13 | 74 | lcd.printString("X/Y = Volume",0,4); |
| Kern_EL17KJTF | 23:ecb74e52163d | 75 | if (opt_volume == 0) { // Shows on screen the current volume state. |
| Kern_EL17KJTF | 10:28575a6eaa13 | 76 | lcd.printString("Off",36,5); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 77 | } else { |
| Kern_EL17KJTF | 10:28575a6eaa13 | 78 | lcd.printString("On",36,5); |
| Kern_EL17KJTF | 10:28575a6eaa13 | 79 | } |
| Kern_EL17KJTF | 10:28575a6eaa13 | 80 | } |