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@10:28575a6eaa13, 2019-05-07 (annotated)
- Committer:
 - Kern_EL17KJTF
 - Date:
 - Tue May 07 22:49:13 2019 +0000
 - Revision:
 - 10:28575a6eaa13
 - Child:
 - 11:b288d01533cc
 
Classes setup without error.
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 | 10:28575a6eaa13 | 9 | Options::Options() | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 10 | { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 11 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 12 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 13 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 14 | Options::~Options() | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 15 | { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 16 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 17 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 18 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 19 | void Options::options_init() { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 20 | float opt_brightness = 0.5; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 21 | float opt_contrast = 0.396; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 22 | int opt_volume = 1; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 23 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 24 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 25 | void Options::options_run(Gamepad &pad, N5110 &lcd) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 26 | wait_ms(250); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 27 | while (pad.check_event(Gamepad::BACK_PRESSED) == false) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 28 | //printf("Options State"); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 29 | lcd.clear(); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 30 | lcd.printString("Options",21,0); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 31 | options_brightness(pad, lcd); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 32 | options_contrast(pad, lcd); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 33 | options_volume(pad, lcd); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 34 | lcd.refresh(); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 35 | wait_ms(1.0f/24); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 36 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 37 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 38 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 39 | void Options::options_brightness(Gamepad &pad, N5110 &lcd) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 40 | if (pad.check_event(Gamepad::B_PRESSED) == true) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 41 | opt_brightness = 0; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 42 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 43 | if (pad.check_event(Gamepad::A_PRESSED) == true) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 44 | opt_brightness = 0.5; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 45 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 46 | lcd.setBrightness(opt_brightness); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 47 | lcd.printString("A/B = BackLite",0,2); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 48 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 49 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 50 | void Options::options_contrast(Gamepad &pad, N5110 &lcd) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 51 | opt_contrast = pad.read_pot(); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 52 | lcd.setContrast(opt_contrast); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 53 | lcd.printString("Pot = Contrast",0,3); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 54 | printf("Contrast = %f", opt_contrast); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 55 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 56 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 57 | void Options::options_volume(Gamepad &pad, N5110 &lcd) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 58 | if (pad.check_event(Gamepad::Y_PRESSED) == true) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 59 | opt_volume = 0; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 60 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 61 | if (pad.check_event(Gamepad::X_PRESSED) == true) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 62 | opt_volume = 1; | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 63 | pad.tone(2400, 0.2); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 64 | wait_ms(200); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 65 | pad.tone(2400, 0.2); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 66 | wait_ms(200); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 67 | pad.tone(2400, 0.2); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 68 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 69 | lcd.printString("X/Y = Volume",0,4); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 70 | if (opt_volume == 0) { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 71 | lcd.printString("Off",36,5); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 72 | } else { | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 73 | lcd.printString("On",36,5); | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 74 | } | 
| Kern_EL17KJTF | 10:28575a6eaa13 | 75 | |
| Kern_EL17KJTF | 10:28575a6eaa13 | 76 | } |