AirsoftTimer software based on mbed
Dependencies: mbed TextLCD keypad
Revision 10:afc22465169e, committed 2014-12-14
- Comitter:
- sillevl
- Date:
- Sun Dec 14 11:50:19 2014 +0000
- Parent:
- 9:b587bae22691
- Child:
- 11:50572814f73e
- Commit message:
- Added game selector skeleton + demo
Changed in this revision
--- a/Airsofttimer.cpp Sat Dec 13 13:59:28 2014 +0000 +++ b/Airsofttimer.cpp Sun Dec 14 11:50:19 2014 +0000 @@ -1,5 +1,6 @@ #include "Airsofttimer.h" +#include "games/GameSelector.h" // buttonPin = P0_4; //P0.4 // keyPin = P0_5; //P0.5 @@ -43,19 +44,7 @@ // show a list of games, and select one int Airsofttimer::select_game(){ - board->lcd->cls(); - board->lcd->printf(" DummyGame 1 \x02"); - board->lcd->printf(" DummyGame 2 "); - board->lcd->printf(" DummyGame 3 "); - board->lcd->printf(" DummyGame 4 \x03"); - - // draw arrows (refactor this later) - board->lcd->locate(0,0); - board->lcd->putc('\x00'); - board->lcd->locate(0,19); - board->lcd->putc('\x02'); - board->lcd->locate(3,19); - board->lcd->putc('\x03'); - while(true){} // wait until selection is done + GameSelector* selector = new GameSelector(board); + selector->run(); return 0; } \ No newline at end of file
--- a/board/Buzzer.cpp Sat Dec 13 13:59:28 2014 +0000 +++ b/board/Buzzer.cpp Sun Dec 14 11:50:19 2014 +0000 @@ -1,7 +1,9 @@ #include "Buzzer.h" +#include "mbed.h" Buzzer::Buzzer(PinName buzzerPin){ - + DigitalOut buzzer(buzzerPin); + buzzer = 0; } void Buzzer::startupBeep(){
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/games/GameSelector.cpp Sun Dec 14 11:50:19 2014 +0000 @@ -0,0 +1,79 @@ +#include "GameSelector.h" + +GameSelector::GameSelector(Board* board){ + this->board = board; + titles[0] = "Hold it"; + titles[1] = "Capture the bomb"; + titles[2] = "Hurry up"; + titles[3] = "Search & destroy"; + titles[4] = "Simple timer"; + titles[5] = "DummyGame 6"; + titles[6] = "DummyGame 7"; + total_selections = 7; + current_selection = 0; + start_position = 0; +} + +void GameSelector::run(){ + print_list(); + //demo + wait(0.5); + while(true){ + for(int i = 0; i < 10; i++){ + go_down(); + wait(0.5); + } + for(int i = 0; i < 10; i++){ + go_up(); + wait(0.5); + } + + } // wait until selection is done +} + +void GameSelector::print_list(){ + board->lcd->cls(); + for(int i = 0; i < 4; i++){ + board->lcd->locate(2,i); + board->lcd->printf(titles[i+start_position]); + } + print_selection_arrow(); + print_up_down_arrows(); +} + +void GameSelector::print_up_down_arrows(){ + if(start_position != 0){ + board->lcd->locate(19,0); + board->lcd->putc('\x02'); + } + if(start_position < total_selections - 4){ + board->lcd->locate(19,3); + board->lcd->putc('\x03'); + } +} + +void GameSelector::print_selection_arrow(){ + int line = current_selection - start_position; + board->lcd->locate(0,line); + board->lcd->putc('\x00'); +} + +void GameSelector::go_down(){ + if(current_selection < (total_selections - 1)){ + current_selection++; + } + if(current_selection - start_position >= 4){ + start_position = current_selection - 3; + } + print_list(); +} + +void GameSelector::go_up(){ + if(current_selection > 0){ + current_selection--; + } + if(current_selection - start_position < 0){ + start_position = current_selection; + } + print_list(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/games/GameSelector.h Sun Dec 14 11:50:19 2014 +0000 @@ -0,0 +1,26 @@ +#ifndef GAMESELECTOR_H +#define GAMESELECTOR_H + +#include "../board/Board.h" + +class GameSelector{ + Board* board; + void print_up_down_arrows(); + void print_selection_arrow(); + void print_list(); + + void go_down(); + void go_up(); + + int start_position; + int current_selection; + int total_selections; + + char* titles[7]; + + public: + GameSelector(Board* board); + void run(); +}; + +#endif \ No newline at end of file