A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.

Dependencies:   ConfigFile N5110 PowerControl beep mbed

Revision:
74:d76be537bafd
Parent:
73:1b03202c987a
Child:
75:445c1ea33944
--- a/main.cpp	Sun May 10 06:58:58 2015 +0000
+++ b/main.cpp	Sun May 10 09:36:23 2015 +0000
@@ -26,14 +26,6 @@
     if (!cfg.setValue("Open3", player3initials)) {//key/value
         error("Failure to set a value.\n");
     }
-//    ///Sets a Key and Value.
-//    if (!cfg.setValue("Open4", diff)) {//key/value
-//        error("Failure to set a value.\n");
-//    }
-//    ///Sets a Key and Value.
-//    if (!cfg.setValue("Open5", fx)) {//key/value
-//        error("Failure to set a value.\n");
-//    }
     ///If a file does not already exist, create one.
     ///If one already exits, append the file.
     if (!cfg.write("/local/towerMemory.cfg")) {//Write key and value to CFG file
@@ -48,8 +40,6 @@
     char *key1 = "Open1";
     char *key2 = "Open2";
     char *key3 = "Open3";
-    char *key4 = "Open4";
-    char *key5 = "Open5";
 
     ///Checks Key and Value - if read is unsuccessful it an prints error message.
     if (!cfg.read("/local/towerMemory.cfg")) {
@@ -58,23 +48,24 @@
     ///check file size - if size acceptable, prints buffer to location.
     if (cfg.getValue(key1, &player1initials[0], sizeof(player1initials))) {
         serial.printf("%s\n",player1initials);
-    }
+        char a = (int)player1initials[10];
+        //highScore1 = a; 
+        serial.printf("%d\n",highScore1);
+        }
     //check file size - if size acceptable, prints buffer to location.
     if (cfg.getValue(key2, &player2initials[0], sizeof(player2initials))) {
         serial.printf("%s\n",player2initials);
-    }
+        char b = (int)player2initials[10];
+       // highScore2 = b;
+        serial.printf("%c\n",highScore2);
+     }
     //check file size - if size acceptable, prints buffer to location.
     if (cfg.getValue(key3, &player3initials[0], sizeof(player3initials))) {
         serial.printf("%s\n",player3initials);
+        char c = (int)player3initials[10];
+        //highScore3 = c;
+        serial.printf("%c\n",highScore3);
     }
-//    //check file size - if size acceptable, prints buffer to location.
-//    if (cfg.getValue(key4, &diff[0], sizeof(diff))) {
-//        serial.printf("%s\n",diff);
-//    }
-//    //check file size - if size acceptable, prints buffer to location.
-//    if (cfg.getValue(key5, &fx[0], sizeof(fx))) {
-//        serial.printf("%s\n",fx);
-//    }
 }
 
 ///Struct declaration for storing alphabet arrays.
@@ -1039,8 +1030,7 @@
                 z=fsm[state3].output3;
                 lcd.printChar(z,52,2);
             }
-            if(buttonFlagA) {
-                //rightness(1.0); 
+            if(buttonFlagA) { 
                 actionButtons();
                 buttonFlagA = 0;
                 buttonFlagB = 0;
@@ -1240,8 +1230,6 @@
     while(1) {
         actionButtons();
         optionsMenu(option);//presents options
-        
-        newButtonA = buttonFlagA;
 
 //================ Difficulty menu =======================
         if ((option == 0)&&(buttonFlagA)) {
@@ -1339,12 +1327,21 @@
     printFlag = 1;
 }
 
-///Turns screen backlighting off for standby.
+///Turns screen backlighting.
 void screenOff()
 {
     lcd.setBrightness(0.0);
 }
 
+///When idle, calls the funtion void screenOff();
+void idleMode()
+{
+    if((buttonFlagA)||(buttonFlagB)||(joystick.direction)) { //call standby mode if idle
+        int time = 60;
+        standby.attach(&screenOff,time);
+    }
+}
+
 int main()
 {
     PHY_PowerDown();//powers down the Ethernet
@@ -1364,12 +1361,11 @@
     int mainOption = 0;//counter for main menu
     int exitOption = 1;//counter for exit menu
     
+    read();//set high scores using flash memory
     timerA.attach(&timerExpiredA, 0.1);//checks state of buttonA
     timerB.attach(&timerExpiredB, 0.1);//checks state of buttonB
+    idleMode();//turns off screen if idle.
     
-    if((!buttonFlagA)||(!buttonFlagB)||(!joystick.direction)){//call standby mode if idle
-        standby.attach(&screenOff,60);}
-  
     while(1) {
         drawMainMenu();//draws main menu
         mainMenu(mainOption);//presents main menu options