AirsoftTimer software based on mbed

Dependencies:   mbed TextLCD keypad

Committer:
sillevl
Date:
Sat May 23 20:57:45 2015 +0000
Revision:
18:abcebc4d0da0
Parent:
17:19dbb1dbb640
Child:
19:2eba101d9c2c
work in progress;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sillevl 10:afc22465169e 1 #include "GameSelector.h"
sillevl 10:afc22465169e 2
sillevl 10:afc22465169e 3 GameSelector::GameSelector(Board* board){
sillevl 10:afc22465169e 4 this->board = board;
sillevl 18:abcebc4d0da0 5 //this->board->attach(this, &GameSelector::buttonEvent);
sillevl 10:afc22465169e 6 titles[0] = "Hold it";
sillevl 10:afc22465169e 7 titles[1] = "Capture the bomb";
sillevl 10:afc22465169e 8 titles[2] = "Hurry up";
sillevl 10:afc22465169e 9 titles[3] = "Search & destroy";
sillevl 10:afc22465169e 10 titles[4] = "Simple timer";
sillevl 10:afc22465169e 11 titles[5] = "DummyGame 6";
sillevl 10:afc22465169e 12 titles[6] = "DummyGame 7";
sillevl 10:afc22465169e 13 total_selections = 7;
sillevl 10:afc22465169e 14 current_selection = 0;
sillevl 10:afc22465169e 15 start_position = 0;
sillevl 17:19dbb1dbb640 16 selected_game = -1;
sillevl 17:19dbb1dbb640 17 }
sillevl 17:19dbb1dbb640 18
sillevl 17:19dbb1dbb640 19 int GameSelector::select(){
sillevl 17:19dbb1dbb640 20 print_list();
sillevl 17:19dbb1dbb640 21 printf("printed list\r\n");
sillevl 17:19dbb1dbb640 22 while(selected_game == -1){
sillevl 18:abcebc4d0da0 23 //board->leds->on(Leds::RIGHT);
sillevl 17:19dbb1dbb640 24 } // wait until selection is done
sillevl 17:19dbb1dbb640 25 //printf("game selected: %d \r\n", selected_game);
sillevl 17:19dbb1dbb640 26 return selected_game;
sillevl 10:afc22465169e 27 }
sillevl 10:afc22465169e 28
sillevl 18:abcebc4d0da0 29 /*uint32_t GameSelector::buttonEvent(uint32_t c){
sillevl 18:abcebc4d0da0 30 printf("Gameselector buttonEvent start, char: %c\r\n", c);
sillevl 17:19dbb1dbb640 31 switch(c){
sillevl 17:19dbb1dbb640 32 case '2':
sillevl 17:19dbb1dbb640 33 go_up();
sillevl 17:19dbb1dbb640 34 break;
sillevl 17:19dbb1dbb640 35 case '5':
sillevl 17:19dbb1dbb640 36 selected_game = current_selection;
sillevl 17:19dbb1dbb640 37 break;
sillevl 17:19dbb1dbb640 38 case '8':
sillevl 17:19dbb1dbb640 39 go_down();
sillevl 17:19dbb1dbb640 40 break;
sillevl 17:19dbb1dbb640 41 default:
sillevl 17:19dbb1dbb640 42 break;
sillevl 17:19dbb1dbb640 43 }
sillevl 17:19dbb1dbb640 44 //printf("end\r\n");
sillevl 18:abcebc4d0da0 45 return 0;
sillevl 18:abcebc4d0da0 46 }*/
sillevl 10:afc22465169e 47
sillevl 10:afc22465169e 48 void GameSelector::print_list(){
sillevl 10:afc22465169e 49 board->lcd->cls();
sillevl 10:afc22465169e 50 for(int i = 0; i < 4; i++){
sillevl 10:afc22465169e 51 board->lcd->locate(2,i);
sillevl 10:afc22465169e 52 board->lcd->printf(titles[i+start_position]);
sillevl 10:afc22465169e 53 }
sillevl 10:afc22465169e 54 print_selection_arrow();
sillevl 10:afc22465169e 55 print_up_down_arrows();
sillevl 10:afc22465169e 56 }
sillevl 10:afc22465169e 57
sillevl 10:afc22465169e 58 void GameSelector::print_up_down_arrows(){
sillevl 10:afc22465169e 59 if(start_position != 0){
sillevl 10:afc22465169e 60 board->lcd->locate(19,0);
sillevl 10:afc22465169e 61 board->lcd->putc('\x02');
sillevl 10:afc22465169e 62 }
sillevl 10:afc22465169e 63 if(start_position < total_selections - 4){
sillevl 10:afc22465169e 64 board->lcd->locate(19,3);
sillevl 10:afc22465169e 65 board->lcd->putc('\x03');
sillevl 10:afc22465169e 66 }
sillevl 10:afc22465169e 67 }
sillevl 10:afc22465169e 68
sillevl 10:afc22465169e 69 void GameSelector::print_selection_arrow(){
sillevl 10:afc22465169e 70 int line = current_selection - start_position;
sillevl 10:afc22465169e 71 board->lcd->locate(0,line);
sillevl 10:afc22465169e 72 board->lcd->putc('\x00');
sillevl 10:afc22465169e 73 }
sillevl 10:afc22465169e 74
sillevl 10:afc22465169e 75 void GameSelector::go_down(){
sillevl 10:afc22465169e 76 if(current_selection < (total_selections - 1)){
sillevl 10:afc22465169e 77 current_selection++;
sillevl 10:afc22465169e 78 }
sillevl 10:afc22465169e 79 if(current_selection - start_position >= 4){
sillevl 10:afc22465169e 80 start_position = current_selection - 3;
sillevl 10:afc22465169e 81 }
sillevl 10:afc22465169e 82 print_list();
sillevl 10:afc22465169e 83 }
sillevl 10:afc22465169e 84
sillevl 10:afc22465169e 85 void GameSelector::go_up(){
sillevl 10:afc22465169e 86 if(current_selection > 0){
sillevl 10:afc22465169e 87 current_selection--;
sillevl 10:afc22465169e 88 }
sillevl 10:afc22465169e 89 if(current_selection - start_position < 0){
sillevl 10:afc22465169e 90 start_position = current_selection;
sillevl 10:afc22465169e 91 }
sillevl 10:afc22465169e 92 print_list();
sillevl 10:afc22465169e 93 }