AirsoftTimer software based on mbed
Dependencies: mbed TextLCD keypad
Revision 16:e8e96bf22df1, committed 2015-05-23
- Comitter:
- sillevl
- Date:
- Sat May 23 18:36:54 2015 +0000
- Parent:
- 15:78116b7254d5
- Child:
- 17:19dbb1dbb640
- Commit message:
- added observer for button events;
Changed in this revision
--- a/board/Board.cpp Sat May 23 17:55:38 2015 +0000 +++ b/board/Board.cpp Sat May 23 18:36:54 2015 +0000 @@ -7,4 +7,14 @@ key = new Key(pinouts.key); keyboard = new Keyboard(pinouts.keyboard); buzzer = new Buzzer(pinouts.buzzer); +} + +void Board::attach(ButtonListener *bl) +{ + listeners.push_back(bl); +} +void Board::buttonEvent(char c) +{ + for (int i = 0; i < listeners.size(); i++) + listeners[i]->buttonEvent(c); } \ No newline at end of file
--- a/board/Board.h Sat May 23 17:55:38 2015 +0000 +++ b/board/Board.h Sat May 23 18:36:54 2015 +0000 @@ -8,6 +8,8 @@ #include "Button.h" #include "Keyboard.h" +#include <vector> + // class for debug leds // class for eeprom memory // class for wireless (nordic chip or xbee) @@ -21,6 +23,14 @@ LcdPins lcd; }; +class ButtonListener +{ + public: + virtual void buttonEvent(char c){ + + }; +}; + class Board{ public: Board(Pinouts pinouts); @@ -32,6 +42,14 @@ Keyboard* keyboard; Buzzer* buzzer; + vector < ButtonListener * > listeners; + + void attach(ButtonListener *bl); + + protected: + void buttonEvent(char c); + + }; #endif \ No newline at end of file
--- a/games/DummyGame.cpp Sat May 23 17:55:38 2015 +0000 +++ b/games/DummyGame.cpp Sat May 23 18:36:54 2015 +0000 @@ -15,3 +15,7 @@ void DummyGame::setup(){ } + +void buttonEvent(char c){ + +}
--- a/games/DummyGame.h Sat May 23 17:55:38 2015 +0000 +++ b/games/DummyGame.h Sat May 23 18:36:54 2015 +0000 @@ -8,6 +8,7 @@ DummyGame(Board* board); virtual void run(); virtual void setup(); + };
--- a/games/Game.cpp Sat May 23 17:55:38 2015 +0000 +++ b/games/Game.cpp Sat May 23 18:36:54 2015 +0000 @@ -18,12 +18,6 @@ return board; } -uint32_t Game::keyEvent(uint32_t key){ - // play key pressed sound ? - // do nothing by default - return 0; -} - void Game::init(){ board->lcd->cls(); board->lcd->printf("Starting game");
--- a/games/Game.h Sat May 23 17:55:38 2015 +0000 +++ b/games/Game.h Sat May 23 18:36:54 2015 +0000 @@ -3,7 +3,7 @@ #include "../board/Board.h" -class Game{ +class Game : public ButtonListener{ public: Game(Board* board); static const char* NAME; @@ -23,8 +23,6 @@ Keyboard* keyboard; Buzzer* buzzer; - uint32_t keyEvent(uint32_t key); - void init(); void end();
--- a/objectives/Objective.cpp Sat May 23 17:55:38 2015 +0000 +++ b/objectives/Objective.cpp Sat May 23 18:36:54 2015 +0000 @@ -10,9 +10,7 @@ button = board->button; keyboard = board->keyboard; buzzer = board->buzzer; - - keyboard->attach(this,&Objective::keyEvent); - + status = WAITING; } @@ -30,10 +28,3 @@ status = COMPLETED; } -uint32_t Objective::keyEvent(uint32_t key){ - // play key pressed sound ? - // do nothing by default - return 0; -} - -
--- a/objectives/Objective.h Sat May 23 17:55:38 2015 +0000 +++ b/objectives/Objective.h Sat May 23 18:36:54 2015 +0000 @@ -3,7 +3,7 @@ #include "../games/Game.h" -class Objective{ +class Objective : public ButtonListener{ enum Status { WAITING, ACTIVE, COMPLETED }; @@ -24,9 +24,7 @@ Button* button; Keyboard* keyboard; Buzzer* buzzer; - - uint32_t keyEvent(uint32_t key); - + private: Status status;
--- a/objectives/WaitForKeyObjective.cpp Sat May 23 17:55:38 2015 +0000 +++ b/objectives/WaitForKeyObjective.cpp Sat May 23 18:36:54 2015 +0000 @@ -9,7 +9,7 @@ lcd->printf("press any key to continue"); } -uint32_t WaitForKeyObjective::keyEvent(uint32_t key){ +void WaitForKeyObjective::buttonEvent(char c){ + // complete objective if a button is pressed complete(); - return 0; } \ No newline at end of file
--- a/objectives/WaitForKeyObjective.h Sat May 23 17:55:38 2015 +0000 +++ b/objectives/WaitForKeyObjective.h Sat May 23 18:36:54 2015 +0000 @@ -8,10 +8,7 @@ public: WaitForKeyObjective(Game* game); virtual void run(); - - protected: - uint32_t keyEvent(uint32_t key); - + virtual void buttonEvent(char c); };