AirsoftTimer software based on mbed

Dependencies:   mbed TextLCD keypad

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GameSelector.cpp Source File

GameSelector.cpp

00001 #include "GameSelector.h"
00002 
00003 GameSelector::GameSelector(Board* board){
00004     this->board = board;
00005     this->board->attach(this, &GameSelector::buttonEvent);
00006     titles[0] = "Hold it";
00007     titles[1] = "Capture the bomb";
00008     titles[2] = "Hurry up";
00009     titles[3] = "Search & destroy";
00010     titles[4] = "Simple timer";
00011     titles[5] = "DummyGame 6";
00012     titles[6] = "DummyGame 7";
00013     total_selections = 7;  
00014     current_selection = 0;
00015     start_position = 0;
00016     selected_game = -1;
00017     
00018     update_screen = false;
00019 }
00020 
00021 int GameSelector::select(){
00022     print_list();
00023     while(selected_game == -1){
00024         if(update_screen){
00025             print_list();    
00026         }
00027     } // wait until selection is done
00028     return selected_game;
00029 }
00030 
00031 uint32_t GameSelector::buttonEvent(uint32_t c){
00032     switch(c){
00033         case '2':
00034             go_up();
00035             update_screen = true;
00036             break;
00037         case '5':
00038             selected_game = current_selection;
00039             break;
00040         case '8':
00041             go_down();
00042             update_screen = true;
00043             break;
00044         default:
00045             break;  
00046     }
00047     return 0;
00048 }
00049 
00050 void GameSelector::print_list(){
00051     board->lcd->cls();
00052     for(int i = 0; i < 4; i++){
00053         board->lcd->locate(2,i);
00054         board->lcd->printf(titles[i+start_position]);
00055     }
00056     print_selection_arrow();
00057     print_up_down_arrows();
00058     
00059     update_screen = false;
00060 }
00061 
00062 void GameSelector::print_up_down_arrows(){
00063     if(start_position != 0){
00064         board->lcd->locate(19,0);
00065         board->lcd->putc('\x02');
00066     }
00067     if(start_position < total_selections - 4){
00068         board->lcd->locate(19,3);
00069         board->lcd->putc('\x03');
00070     }
00071 }
00072 
00073 void GameSelector::print_selection_arrow(){
00074     int line = current_selection - start_position;
00075     board->lcd->locate(0,line);
00076     board->lcd->putc('\x00');
00077 }
00078 
00079 void GameSelector::go_down(){
00080     if(current_selection < (total_selections - 1)){
00081         current_selection++;
00082     }
00083     if(current_selection - start_position >= 4){
00084         start_position = current_selection - 3;
00085     }
00086     //print_list();
00087 }
00088 
00089 void GameSelector::go_up(){
00090     if(current_selection > 0){
00091         current_selection--;
00092     }
00093     if(current_selection - start_position < 0){
00094         start_position = current_selection;
00095     }
00096     //print_list();
00097 }