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.
Diff: Options_Engine/OptionsEngine.cpp
- Revision:
- 22:4e305ff8a050
- Child:
- 23:61fa82f76808
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options_Engine/OptionsEngine.cpp Thu Apr 18 11:50:53 2019 +0000 @@ -0,0 +1,75 @@ +#include "OptionsEngine.h" + +OptionsEngine::OptionsEngine(){ +} + +OptionsEngine::~OptionsEngine(){ +} + +void OptionsEngine::init(){ + _state = BRIGHTNESS; + _brightness = 0.5; + +} + +void OptionsEngine::options_menu(Gamepad &gamepad, N5110 &lcd){ + Option choice = BRIGHTNESS; + while(!(gamepad.check_event(gamepad.A_PRESSED))){ + lcd.clear(); + display_options(lcd); + choice = option_selection(gamepad, lcd); + lcd.refresh(); + wait(0.2); + } + if(choice == BRIGHTNESS){ change_brightness(gamepad, lcd); } + if(choice == BALL_SPEED){ /*change_ball_speed(gamepad, lcd);*/ } + if(choice == HIGH_SCORES){ /*view_high_scores(gamepad, lcd);*/ } +} + +void OptionsEngine::display_options(N5110 &lcd){ + lcd.printString("Options menu", 6, 0); + lcd.printString("Brightness", 12, 2); + lcd.printString("Ball speed", 12, 3); + lcd.printString("High scores", 9, 4); +} + +Option OptionsEngine::option_selection(Gamepad &gamepad, N5110 &lcd){ + OptionSelection fsm[3] = { + {2,{HIGH_SCORES, BALL_SPEED, BRIGHTNESS}}, + {3,{BRIGHTNESS, HIGH_SCORES, BALL_SPEED}}, + {4,{BALL_SPEED, BRIGHTNESS, HIGH_SCORES}} + }; + if(gamepad.get_direction() == N){ _next_state = 0; } + else if(gamepad.get_direction() == S){ _next_state = 1; } + else{ _next_state = 2; } + _state = fsm[_state].next_state[_next_state]; + lcd.printChar('>', 0, fsm[_state].output); + lcd.printChar('<', 78, fsm[_state].output); + return _state; +} + +void OptionsEngine::change_brightness(Gamepad &gamepad, N5110 &lcd){ + while(!(gamepad.check_event(gamepad.A_PRESSED))){ + lcd.clear(); + lcd.printString("Brightness", 12, 0); + lcd.printString("Use L and R to", 0, 3); + lcd.printString("change", 24, 4); + lcd.printString("A = confirm", 9, 5); + lcd.drawRect(10, 16, 63, 8, FILL_TRANSPARENT); + read_brightness_input(gamepad); + for(int i = 0; i < _brightness*10; i ++){ + lcd.drawRect(12+6*i, 18, 5, 4, FILL_BLACK); + } + lcd.setBrightness(_brightness); + lcd.refresh(); + wait(0.2); + } +} + +void OptionsEngine::read_brightness_input(Gamepad &gamepad){ + 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. + if(gamepad.check_event(gamepad.R_PRESSED)){ _brightness += 0.1f; } //Otherwise 0.1 is implicitly converted to a double (giving warning messages). + if(_brightness < 0){ _brightness = 0; } + if(_brightness > 1){ _brightness = 1; } +} + \ No newline at end of file