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

Dependencies:   ConfigFile N5110 PowerControl beep mbed

Revision:
8:457183719776
Parent:
7:217810c90306
Child:
9:bb550cff98b3
--- a/main.cpp	Wed Apr 15 15:30:45 2015 +0000
+++ b/main.cpp	Wed Apr 15 15:53:54 2015 +0000
@@ -506,6 +506,7 @@
     int mainOption = 0;//counter for main menu
     int exitOption = 0;//counter for exit menu
     int option = 0;//counter for options menu
+    int subOption = 0;//counter for sub options menu
 
     // loop 1 - Main menu
     while(1) {
@@ -819,6 +820,9 @@
 ////////////////////// difficulty settings ////////////////////////////////////
                     if ((option == 1)&&(buttonA == 1)) {
 
+                        actionButton();
+                        backButton();
+
                         lcd.clear();
                         backGround();
                         lcd.drawRect(0,47,84,0,1);//bottom border
@@ -834,18 +838,57 @@
                             actionButton();
                             backButton();
 
-                            if(buttonB == 1) {
-                                lcd.clear();
-                                break;
+                            // joystick selection
+                            if (printFlag) {  //if flag set, clear flag and print joystick values to serial port
+                                printFlag = 0;
+                                serial.printf("x = %f y = %f button = %d ",joystick.x,joystick.y,joystick.button);
+
+                                // option up
+                                if (joystick.direction == UP) {
+                                    serial.printf(" UP\n");
+                                    subOption = subOption--;
+                                    if (subOption < 0)subOption = 0;
+                                }
+                                // option down
+                                if (joystick.direction == DOWN) {
+                                    serial.printf(" DOWN\n");
+                                    subOption = subOption++;
+                                    if (subOption > 2)subOption = 2;
+                                }
+                                // Centre / Unknown orientation
+                                if (joystick.direction == CENTRE)
+                                    serial.printf(" CENTRE\n");
+                                if (joystick.direction == UNKNOWN)
+                                    serial.printf(" Unsupported direction\n");
+
+                                // 'Easy' option 1
+                                if (subOption == 0) {
+                                    lcd.drawCircle(72,19,2,1);
+                                    refreshCursor2();
+                                    refreshCursor3();
+                                }
+                                // 'Normal' option 2
+                                if (subOption == 1) {
+                                    lcd.drawCircle(72,27,2,1);
+
+                                }
+                                // 'Forget It' option 3
+                                if (subOption == 2){
+                                    lcd.drawCircle(72,35,2,1);
+                                }
+                                if(buttonB == 1) {
+                                    lcd.clear();
+                                    break;
+                                }
                             }
                         }
                     }
-                }
 
-                // back to menu
-                if(buttonB == 1) {
-                    lcd.clear();
-                    break;
+                    // back to menu
+                    if(buttonB == 1) {
+                        lcd.clear();
+                        break;
+                    }
                 }
             }
         }
@@ -853,40 +896,38 @@
 }
 
 // read default positions of the joystick to calibrate later readings
-void calibrateJoystick()
-{
-    button.mode(PullDown);
-    // must not move during calibration
-    joystick.x0 = xPot; //initial positions in the range 0.0 to 1.0 (0.5 if centred exactly)
-    joystick.y0 = yPot;
-}
-
-void updateJoystick()
-{
-    // read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred)
-    joystick.x = xPot - joystick.x0;
-    joystick.y = yPot - joystick.y0;
-    // read button state
-    joystick.button = button;
-
-    // calculate direction depending on x,y values
-    // tolerance allows a little lee-way in case joystick not exactly in the stated direction
-    if ( fabs(joystick.y) < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
-        joystick.direction = CENTRE;
-    } else if ( joystick.y > DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
-        joystick.direction = UP;
-    } else if ( joystick.y < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
-        joystick.direction = DOWN;
-    } else if ( joystick.x > DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
-        joystick.direction = RIGHT;
-    } else if ( joystick.x < DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
-        joystick.direction = LEFT;
-    } else {
-        joystick.direction = UNKNOWN;
+    void calibrateJoystick() {
+        button.mode(PullDown);
+        // must not move during calibration
+        joystick.x0 = xPot; //initial positions in the range 0.0 to 1.0 (0.5 if centred exactly)
+        joystick.y0 = yPot;
     }
 
-    // set flag for printing
-    printFlag = 1;
-}
+    void updateJoystick() {
+        // read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred)
+        joystick.x = xPot - joystick.x0;
+        joystick.y = yPot - joystick.y0;
+        // read button state
+        joystick.button = button;
+
+        // calculate direction depending on x,y values
+        // tolerance allows a little lee-way in case joystick not exactly in the stated direction
+        if ( fabs(joystick.y) < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
+            joystick.direction = CENTRE;
+        } else if ( joystick.y > DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
+            joystick.direction = UP;
+        } else if ( joystick.y < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
+            joystick.direction = DOWN;
+        } else if ( joystick.x > DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
+            joystick.direction = RIGHT;
+        } else if ( joystick.x < DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
+            joystick.direction = LEFT;
+        } else {
+            joystick.direction = UNKNOWN;
+        }
+
+        // set flag for printing
+        printFlag = 1;
+    }