Dependencies:   MMA8452 N5110 PowerControl beep mbed

Revision:
9:522f9311ff4b
Parent:
8:aebb468546c5
--- a/GameFSM.h	Sat May 09 22:59:15 2015 +0000
+++ b/GameFSM.h	Sun May 10 17:21:39 2015 +0000
@@ -1,7 +1,13 @@
 /**
 @file GameFSM.h
-
-@brief Header file of Game's Finite stage Machine
+@brief Header file of Game's Finite Stage Machine.
+@brief This header file contains header file from Game.h, Clock.h, Menu.h, N5110.h and mbed.h.
+@brief It also has functions of setting flag for four buttons.
+@brief It shows stages of the whole programme and devided into 4 sectors and an initial stage with 
+@brief regarding Game Mode sector, High Score sector, Game Screen sector, Your Score sector and Main Menu stage.
+@brief Revision 1.0
+@author Huynh Minh Tuan Le
+@date April 2015
 */
 #ifndef GAMEFSM_H
 #define GAMEFSM_H
@@ -10,80 +16,91 @@
 #include "Clock.h"
 #include "N5110.h"
 #include "Menu.h"
-#include "PowerControl/PowerControl.h"
 #include "mbed.h"
 
-Game game;
-Clock countdown;
-Menu menu;
+
+Game game; ///<A game object declared from the Game class.
+Clock countdown; ///<A countdown object declared from the Clock class. 
+Menu menu; ///<A menu object declared from the Menu class.
+
 /**
 @namespace ButtonA
-@brief Button A of interrupting service
+@brief Button A of interrupting service.
 */
 InterruptIn ButtonA(p16);
 /**
 @namespace ButtonB
-@brief Button B of interrupting service
+@brief Button B of interrupting service.
 */
 InterruptIn ButtonB(p15);
 /**
 @namespace ButtonD
-@brief Button Down of interrupting service
+@brief Down button of interrupting service.
 */
 InterruptIn ButtonD(p24);
 /**
 @namespace ButtonU
-@brief Button Up of interrupting service
+@brief Up button of interrupting service.
 */
 InterruptIn ButtonU(p23);
 
-int BuAFlag = 0;
-int BuBFlag = 0;
-int BuDFlag = 0;
-int BuUFlag = 0;
+int BuAFlag = 0; ///<A button A flag variable.
+int BuBFlag = 0; ///<A button B flag variable.
+int BuDFlag = 0; ///<A Down button flag variable.
+int BuUFlag = 0; ///<A up button flag variable.
 
-int stage = 0;
-int substage = 0;
+int stage = 0; ///<Stage variable for Finite Stage Machine.
 
-Timer debounce;
+Timer debounce; ///<A timer object for debouncing the buttons.
 
 void BuAPress()
 {
-    if (debounce.read_ms()>300) {
-        BuAFlag = 1; //Set flag for button A
+    debounce.start(); //Start timer for debounce object.
+    if (debounce.read_ms()>200) {
+        BuAFlag = 1; ///Set flag for button A
+        debounce.stop(); //Stop timer
     }
 }
 
 void BuBPress()
 {
-    if (debounce.read_ms()>300) {
-        BuBFlag = 1; //Set flag for button B
+    debounce.start(); //Start timer for debounce object.
+    if (debounce.read_ms()>200) {
+        BuBFlag = 1; ///Set flag for button B
+        debounce.stop(); //Stop timer
     }
 }
 
 void BuDPress()
 {
-    if (debounce.read_ms()>300) {
-        BuDFlag = 1; //Set flag for button Down
+    debounce.start(); //Start timer for debounce object.
+    if (debounce.read_ms()>200) {
+        BuDFlag = 1; ///Set flag for button Down
+        debounce.stop(); //Stop timer
     }
 }
 
 void BuUPress()
 {
-    if (debounce.read_ms()>300) {
-        BuUFlag = 1; //Set flag for button Up
+    debounce.start(); //Start timer for debounce object.
+    if (debounce.read_ms()>200) {
+        BuUFlag = 1; ///Set flag for button Up
+        debounce.stop(); //Stop timer
     }
 }
 
+///Game FSM Class
 class FSM
 {
 public:
     /**
-    The function contains FSM of the whole programme
+    * The function contains FSM of the programme.
     */
     void proact();
+    /**
+    * The function that set all the buttons flag to 0. 
+    */
     void resetButton();
-    void sleepMode();
 };
 
 void FSM::resetButton()
@@ -127,7 +144,8 @@
             }
             
             break;
-
+            
+//////////HIGH SCORE SECTOR//////////
         case 2: //(Main stage 2)Sub stage 0: HIGH SCORE sector - Cursor is at Easy line
             
             menu.highscore();
@@ -248,7 +266,8 @@
             }
             
             break;
-
+            
+//////////RESET STAGE//////////
             //This case is a game condition setting case
             //Clock countdown was set to 60 seconds
             //Score was set to 0
@@ -257,7 +276,8 @@
             resetButton();
             stage = 4;
             break;
-//////////GAME MODE SECTOR/////////
+            
+//////////GAME MODE SECTOR//////////
         case 4: //(Main stage 4)Sub stage 0: GAME MODE sector - Cursor at Easy line
             
             menu.gameset();
@@ -318,10 +338,11 @@
             }
             
             break;
-
+            
+//////////GAME SCREEN SECTOR//////////
         case 7: //(Main stage 4)Sub stage 3: GAME SCREEN sector - Easy mode
             
-            timer.attach(&timerExpired,0.5);
+            timer.attach(&timerExpired,1.0);
             gatimer.attach(&gatimerExpired,0.1); //Update time for Easy mode is 0.1s
             while(CClock > 0) {
                 countdown.countDown();
@@ -339,7 +360,7 @@
 
         case 8: //(Main stage 4)Sub stage 4: GAME SCREEN sector - Normal mode
             
-            timer.attach(&timerExpired,0.5);
+            timer.attach(&timerExpired,1.0);
             gatimer.attach(&gatimerExpired,0.2); //Update time for Normal mode is 0.2s
             while(CClock > 0) {
                 countdown.countDown();
@@ -357,7 +378,7 @@
 
         case 9: //(Main stage 4)Sub stage 5: GAME SCREEN sector - Hard mode
             
-            timer.attach(&timerExpired,0.5);
+            timer.attach(&timerExpired,1.0);
             gatimer.attach(&gatimerExpired,0.4); //Update time for Hard mode is 0.4s
             while(CClock > 0) {
                 countdown.countDown();
@@ -372,7 +393,8 @@
             stage = 10; //Go to stage 10: Your score menu
 
             break;
-
+            
+//////////YOUR SCORE SECTOR//////////
         case 10: //Main stage 5: YOUR SCORE sector - Cursor at Main menu line
             
             menu.yourscore();