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.cpp@22:4e305ff8a050, 2019-04-18 (annotated)
- Committer:
- JamesCummins
- Date:
- Thu Apr 18 11:50:53 2019 +0000
- Revision:
- 22:4e305ff8a050
- Child:
- 23:61fa82f76808
Options Menu appears to be working. Change Brightness working (other than that it skips 0.7???) Need to complete adjust ball speed and high scores list. (Still need to save to SD card somehow)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JamesCummins | 22:4e305ff8a050 | 1 | #include "OptionsEngine.h" |
JamesCummins | 22:4e305ff8a050 | 2 | |
JamesCummins | 22:4e305ff8a050 | 3 | OptionsEngine::OptionsEngine(){ |
JamesCummins | 22:4e305ff8a050 | 4 | } |
JamesCummins | 22:4e305ff8a050 | 5 | |
JamesCummins | 22:4e305ff8a050 | 6 | OptionsEngine::~OptionsEngine(){ |
JamesCummins | 22:4e305ff8a050 | 7 | } |
JamesCummins | 22:4e305ff8a050 | 8 | |
JamesCummins | 22:4e305ff8a050 | 9 | void OptionsEngine::init(){ |
JamesCummins | 22:4e305ff8a050 | 10 | _state = BRIGHTNESS; |
JamesCummins | 22:4e305ff8a050 | 11 | _brightness = 0.5; |
JamesCummins | 22:4e305ff8a050 | 12 | |
JamesCummins | 22:4e305ff8a050 | 13 | } |
JamesCummins | 22:4e305ff8a050 | 14 | |
JamesCummins | 22:4e305ff8a050 | 15 | void OptionsEngine::options_menu(Gamepad &gamepad, N5110 &lcd){ |
JamesCummins | 22:4e305ff8a050 | 16 | Option choice = BRIGHTNESS; |
JamesCummins | 22:4e305ff8a050 | 17 | while(!(gamepad.check_event(gamepad.A_PRESSED))){ |
JamesCummins | 22:4e305ff8a050 | 18 | lcd.clear(); |
JamesCummins | 22:4e305ff8a050 | 19 | display_options(lcd); |
JamesCummins | 22:4e305ff8a050 | 20 | choice = option_selection(gamepad, lcd); |
JamesCummins | 22:4e305ff8a050 | 21 | lcd.refresh(); |
JamesCummins | 22:4e305ff8a050 | 22 | wait(0.2); |
JamesCummins | 22:4e305ff8a050 | 23 | } |
JamesCummins | 22:4e305ff8a050 | 24 | if(choice == BRIGHTNESS){ change_brightness(gamepad, lcd); } |
JamesCummins | 22:4e305ff8a050 | 25 | if(choice == BALL_SPEED){ /*change_ball_speed(gamepad, lcd);*/ } |
JamesCummins | 22:4e305ff8a050 | 26 | if(choice == HIGH_SCORES){ /*view_high_scores(gamepad, lcd);*/ } |
JamesCummins | 22:4e305ff8a050 | 27 | } |
JamesCummins | 22:4e305ff8a050 | 28 | |
JamesCummins | 22:4e305ff8a050 | 29 | void OptionsEngine::display_options(N5110 &lcd){ |
JamesCummins | 22:4e305ff8a050 | 30 | lcd.printString("Options menu", 6, 0); |
JamesCummins | 22:4e305ff8a050 | 31 | lcd.printString("Brightness", 12, 2); |
JamesCummins | 22:4e305ff8a050 | 32 | lcd.printString("Ball speed", 12, 3); |
JamesCummins | 22:4e305ff8a050 | 33 | lcd.printString("High scores", 9, 4); |
JamesCummins | 22:4e305ff8a050 | 34 | } |
JamesCummins | 22:4e305ff8a050 | 35 | |
JamesCummins | 22:4e305ff8a050 | 36 | Option OptionsEngine::option_selection(Gamepad &gamepad, N5110 &lcd){ |
JamesCummins | 22:4e305ff8a050 | 37 | OptionSelection fsm[3] = { |
JamesCummins | 22:4e305ff8a050 | 38 | {2,{HIGH_SCORES, BALL_SPEED, BRIGHTNESS}}, |
JamesCummins | 22:4e305ff8a050 | 39 | {3,{BRIGHTNESS, HIGH_SCORES, BALL_SPEED}}, |
JamesCummins | 22:4e305ff8a050 | 40 | {4,{BALL_SPEED, BRIGHTNESS, HIGH_SCORES}} |
JamesCummins | 22:4e305ff8a050 | 41 | }; |
JamesCummins | 22:4e305ff8a050 | 42 | if(gamepad.get_direction() == N){ _next_state = 0; } |
JamesCummins | 22:4e305ff8a050 | 43 | else if(gamepad.get_direction() == S){ _next_state = 1; } |
JamesCummins | 22:4e305ff8a050 | 44 | else{ _next_state = 2; } |
JamesCummins | 22:4e305ff8a050 | 45 | _state = fsm[_state].next_state[_next_state]; |
JamesCummins | 22:4e305ff8a050 | 46 | lcd.printChar('>', 0, fsm[_state].output); |
JamesCummins | 22:4e305ff8a050 | 47 | lcd.printChar('<', 78, fsm[_state].output); |
JamesCummins | 22:4e305ff8a050 | 48 | return _state; |
JamesCummins | 22:4e305ff8a050 | 49 | } |
JamesCummins | 22:4e305ff8a050 | 50 | |
JamesCummins | 22:4e305ff8a050 | 51 | void OptionsEngine::change_brightness(Gamepad &gamepad, N5110 &lcd){ |
JamesCummins | 22:4e305ff8a050 | 52 | while(!(gamepad.check_event(gamepad.A_PRESSED))){ |
JamesCummins | 22:4e305ff8a050 | 53 | lcd.clear(); |
JamesCummins | 22:4e305ff8a050 | 54 | lcd.printString("Brightness", 12, 0); |
JamesCummins | 22:4e305ff8a050 | 55 | lcd.printString("Use L and R to", 0, 3); |
JamesCummins | 22:4e305ff8a050 | 56 | lcd.printString("change", 24, 4); |
JamesCummins | 22:4e305ff8a050 | 57 | lcd.printString("A = confirm", 9, 5); |
JamesCummins | 22:4e305ff8a050 | 58 | lcd.drawRect(10, 16, 63, 8, FILL_TRANSPARENT); |
JamesCummins | 22:4e305ff8a050 | 59 | read_brightness_input(gamepad); |
JamesCummins | 22:4e305ff8a050 | 60 | for(int i = 0; i < _brightness*10; i ++){ |
JamesCummins | 22:4e305ff8a050 | 61 | lcd.drawRect(12+6*i, 18, 5, 4, FILL_BLACK); |
JamesCummins | 22:4e305ff8a050 | 62 | } |
JamesCummins | 22:4e305ff8a050 | 63 | lcd.setBrightness(_brightness); |
JamesCummins | 22:4e305ff8a050 | 64 | lcd.refresh(); |
JamesCummins | 22:4e305ff8a050 | 65 | wait(0.2); |
JamesCummins | 22:4e305ff8a050 | 66 | } |
JamesCummins | 22:4e305ff8a050 | 67 | } |
JamesCummins | 22:4e305ff8a050 | 68 | |
JamesCummins | 22:4e305ff8a050 | 69 | void OptionsEngine::read_brightness_input(Gamepad &gamepad){ |
JamesCummins | 22:4e305ff8a050 | 70 | if(gamepad.check_event(gamepad.L_PRESSED)){ _brightness -= 0.1f; } //Use of f to explicitly convert to a float (to fit declaration type in header file. |
JamesCummins | 22:4e305ff8a050 | 71 | if(gamepad.check_event(gamepad.R_PRESSED)){ _brightness += 0.1f; } //Otherwise 0.1 is implicitly converted to a double (giving warning messages). |
JamesCummins | 22:4e305ff8a050 | 72 | if(_brightness < 0){ _brightness = 0; } |
JamesCummins | 22:4e305ff8a050 | 73 | if(_brightness > 1){ _brightness = 1; } |
JamesCummins | 22:4e305ff8a050 | 74 | } |
JamesCummins | 22:4e305ff8a050 | 75 |