A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.
Dependencies: ConfigFile N5110 PowerControl beep mbed
Diff: main.cpp
- Revision:
- 54:8180eec1656d
- Parent:
- 53:a3077af736bb
- Child:
- 55:bb4f6cc196c8
--- a/main.cpp Thu Apr 30 19:59:54 2015 +0000 +++ b/main.cpp Fri May 01 22:07:05 2015 +0000 @@ -12,6 +12,31 @@ #include <ctime> #include <cstdlib> +//read/write memory function +void memory() +{ + //write + if (!cfg.setValue("Open", player1initials)) {//key/value + error("Failure to set a value.\n"); + } + //Write to a file. + if (!cfg.write("/local/towerMemory.cfg")) { + error("Failure to write a configuration file.\n"); + } + +//read + char *key = "Open";//check key matches + + //check file-if read unsuccessful print error message + if (!cfg.read("/local/towerMemory.cfg")) { + error("Failure to read a configuration file.\n"); + } + //check size, if read sucessful + if (cfg.getValue(key, &player1initials[0], sizeof(player1initials))) { + serial.printf("%s\n",player1initials); + } +} + //struct for choosing initials struct State { char output1; @@ -58,9 +83,6 @@ //timer to read the joystick Ticker pollJoystick; -//serial out for debug -Serial serial(USBTX,USBRX); - //create enumerated type (0,1,2,3 etc. for direction) //could be extended for diagonals etc. enum DirectionName { @@ -562,8 +584,7 @@ //draws option cursor if(exitOption == 0) { lcd.printString("YES",33,3); - } - else if(exitOption == 1) { + } else if(exitOption == 1) { lcd.printString(" NO",33,3); } } @@ -930,7 +951,7 @@ drawHazards();//initiates hazards hazardFall();//increments hazards towards floor wait(0.1);//slow down objects - + if (printFlag) { //if flag set, clear flag and print joystick values to serial port printFlag = 0; @@ -1185,21 +1206,22 @@ pollJoystick.attach(&updateJoystick,1.0/10.0);//read joystick 10 times per second lcd.init();//initialise screen - + drawWelcome();//welcome screen - + lcd.clear();//clear pixels - + buttonA.mode(PullDown);//pull down buttonA buttonB.mode(PullDown);//pull down buttonB + memory(); int exitFlag = 0;//exit flag int mainOption = 0;//counter for main menu int exitOption = 1;//counter for exit menu - + timerA.attach(&timerExpiredA, 0.1);//checks state of buttonA timerB.attach(&timerExpiredB, 0.1);//checks state of buttonB - + while(1) { drawMainMenu();//draws main menu mainMenu(mainOption);//presents main menu options