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