AirsoftTimer software based on mbed

Dependencies:   mbed TextLCD keypad

Files at this revision

API Documentation at this revision

Comitter:
sillevl
Date:
Sat Dec 13 12:24:37 2014 +0000
Parent:
4:2c91c9eccf3a
Child:
6:8035ee13db25
Commit message:
Refactored game board (all hardware) and added abstract game class

Changed in this revision

Airsofttimer.cpp Show annotated file Show diff for this revision Revisions of this file
Airsofttimer.h Show annotated file Show diff for this revision Revisions of this file
board/Board.cpp Show annotated file Show diff for this revision Revisions of this file
board/Board.h Show annotated file Show diff for this revision Revisions of this file
board/Buzzer.cpp Show annotated file Show diff for this revision Revisions of this file
board/Buzzer.h Show annotated file Show diff for this revision Revisions of this file
board/LCD.cpp Show annotated file Show diff for this revision Revisions of this file
board/LCD.h Show annotated file Show diff for this revision Revisions of this file
board/Leds.h Show annotated file Show diff for this revision Revisions of this file
games/DummyGame.cpp Show annotated file Show diff for this revision Revisions of this file
games/DummyGame.h Show annotated file Show diff for this revision Revisions of this file
games/Game.cpp Show annotated file Show diff for this revision Revisions of this file
games/Game.h Show annotated file Show diff for this revision Revisions of this file
--- a/Airsofttimer.cpp	Sat Dec 13 10:11:24 2014 +0000
+++ b/Airsofttimer.cpp	Sat Dec 13 12:24:37 2014 +0000
@@ -11,14 +11,14 @@
 //    lcdPins      = {P1_31, P1_30, P0_23, P0_24, P0_23, P0_26};   // E=P1.31, RS=P1.30, D4=P0.23 -> D7=P0.26
 
 Airsofttimer::Airsofttimer(Pinouts pinouts){
-    //create lcd
-    lcd = new LCD(pinouts.lcd.rs, pinouts.lcd.e, pinouts.lcd.p4, pinouts.lcd.p5, pinouts.lcd.p6, pinouts.lcd.p7, LCD::LCD20x4);
-    //create leds
-    //create button
-    //create key
-    //create keyboard
+    board = new Board(pinouts);   
     init();
-    //run();
+    
+    while(true){
+        Game* game = Game::create_game(board, 0);
+        game->run();
+        delete game;
+    }
 }
 
 const char* Airsofttimer::LOGO[16] = {
@@ -28,16 +28,10 @@
     "    \xFF    \xFF  \xFF\xFF\xFF"
 };
 
-
 void Airsofttimer::init(){
-    // initial beep on startup
-    // clear screen
-    // show PIC logo
-    for(int line = 0; line < 4; line++){
-        //lcd->setCursor(0,line);
-        //lcd->print(LOGO[line]);    
-    }
-    // wait 5 sec
-    // clear LCD    
-    
+    board->buzzer->startupBeep();
+    board->lcd->cls();
+    board->lcd->showLogo(LOGO);
+    wait(5.0);
+    board->lcd->cls(); 
 }
--- a/Airsofttimer.h	Sat Dec 13 10:11:24 2014 +0000
+++ b/Airsofttimer.h	Sat Dec 13 12:24:37 2014 +0000
@@ -4,33 +4,20 @@
 #define AIRSOFTTIMER_H
 
 #include "mbed.h"
-#include "board/LCD.h" 
-#include "board/Leds.h"
-#include "board/Key.h"
-#include "board/Buzzer.h"
-#include "board/Button.h"
-#include "board/Keyboard.h"
-
-struct Pinouts{
-    PinName button;
-    PinName key;
-    LedPins leds;
-    PinName buzzer;
-    KeyboardPins keyboard;
-    LcdPins lcd;
-};
+#include "board/Board.h"
+#include "games/Game.h"
 
 class Airsofttimer
 {
     static const char* LOGO[];
+    
     public: 
     Airsofttimer(Pinouts pinouts);
     
+    private:
+    Board* board;
     
-    private:
-    void init();
-    LCD* lcd;
-    
+    void init();   
 
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/board/Board.cpp	Sat Dec 13 12:24:37 2014 +0000
@@ -0,0 +1,10 @@
+#include "Board.h"
+
+Board::Board(Pinouts pinouts){
+    lcd = new LCD(pinouts.lcd.rs, pinouts.lcd.e, pinouts.lcd.p4, pinouts.lcd.p5, pinouts.lcd.p6, pinouts.lcd.p7, LCD::LCD20x4);
+    leds = new Leds(pinouts.leds.left, pinouts.leds.right);
+    button = new Button(pinouts.button);
+    key = new Key(pinouts.key);
+    keyboard = new Keyboard(pinouts.keyboard);
+    buzzer = new Buzzer(pinouts.buzzer);    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/board/Board.h	Sat Dec 13 12:24:37 2014 +0000
@@ -0,0 +1,37 @@
+#ifndef BOARD_H
+#define BOARD_H
+
+#include "LCD.h" 
+#include "Leds.h"
+#include "Key.h"
+#include "Buzzer.h"
+#include "Button.h"
+#include "Keyboard.h"
+
+// class for debug leds
+// class for eeprom memory
+// class for wireless (nordic chip or xbee)
+
+struct Pinouts{
+    PinName button;
+    PinName key;
+    LedPins leds;
+    PinName buzzer;
+    KeyboardPins keyboard;
+    LcdPins lcd;
+};
+
+class Board{
+    public:
+    Board(Pinouts pinouts);
+    
+    LCD* lcd;
+    Leds* leds;
+    Key* key;
+    Button* button;
+    Keyboard* keyboard;
+    Buzzer* buzzer;
+    
+};
+
+#endif
\ No newline at end of file
--- a/board/Buzzer.cpp	Sat Dec 13 10:11:24 2014 +0000
+++ b/board/Buzzer.cpp	Sat Dec 13 12:24:37 2014 +0000
@@ -2,4 +2,8 @@
 
 Buzzer::Buzzer(PinName buzzerPin){
     
+}
+
+void Buzzer::startupBeep(){
+    
 }
\ No newline at end of file
--- a/board/Buzzer.h	Sat Dec 13 10:11:24 2014 +0000
+++ b/board/Buzzer.h	Sat Dec 13 12:24:37 2014 +0000
@@ -7,6 +7,7 @@
 
     public:
     Buzzer(PinName buzzerPin);    
+    void startupBeep();
 };
 
 #endif
\ No newline at end of file
--- a/board/LCD.cpp	Sat Dec 13 10:11:24 2014 +0000
+++ b/board/LCD.cpp	Sat Dec 13 12:24:37 2014 +0000
@@ -2,4 +2,11 @@
 
 LCD::LCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type) : TextLCD(rs, e, d4, d5, d6, d7, type) {
 
+}
+
+void LCD::showLogo(const char** logo){
+    for(int line = 0; line < 4; line++){
+        this->locate(0,line);
+        this->printf(logo[line]);    
+    }    
 }
\ No newline at end of file
--- a/board/LCD.h	Sat Dec 13 10:11:24 2014 +0000
+++ b/board/LCD.h	Sat Dec 13 12:24:37 2014 +0000
@@ -16,6 +16,7 @@
     
     public:
     LCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
+    void showLogo(const char** logo);
     
 };
 
--- a/board/Leds.h	Sat Dec 13 10:11:24 2014 +0000
+++ b/board/Leds.h	Sat Dec 13 12:24:37 2014 +0000
@@ -5,7 +5,7 @@
 
 struct LedPins{
     PinName left;
-    PinName richt;
+    PinName right;
 };
 
 class Leds{
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/games/DummyGame.cpp	Sat Dec 13 12:24:37 2014 +0000
@@ -0,0 +1,14 @@
+#include "DummyGame.h"
+
+const char* NAME = "DummyGame";
+
+DummyGame::DummyGame(Board* board) : Game(board){
+    
+}
+
+void DummyGame::run(){
+    board->lcd->printf("DummyGame");   
+    while(true){
+        // don't return from this function yet (only if the game ends);   
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/games/DummyGame.h	Sat Dec 13 12:24:37 2014 +0000
@@ -0,0 +1,13 @@
+#ifndef DUMMYGAME_H
+#define DUMMYGAME_H
+
+#include "Game.h"
+
+class DummyGame : public Game{
+    public:
+    DummyGame(Board* board);
+    virtual void run();
+};
+
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/games/Game.cpp	Sat Dec 13 12:24:37 2014 +0000
@@ -0,0 +1,12 @@
+#include "Game.h"
+#include "DummyGame.h"
+
+Game::Game(Board* board){
+    this->board = board;
+}
+
+Game* Game::create_game(Board* board, int choice){
+    Game* game = new DummyGame(board);
+    return  game;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/games/Game.h	Sat Dec 13 12:24:37 2014 +0000
@@ -0,0 +1,20 @@
+#ifndef GAME_H
+#define GAME_H
+
+#include "../board/Board.h"
+
+class Game{
+    public:
+    Game(Board* board);
+    static const char* NAME;
+    static Game* create_game(Board* board, int choice); //factory method
+    
+    virtual void run() = 0;
+    
+    protected:
+    Board* board;
+    
+};
+
+
+#endif
\ No newline at end of file