Distance Sensor Embedded Systems Project SID: 200864479 James Erringham-Bruce
Dependencies: N5110 SRF02-JEB mbed
Main/MainMenu.h
- Committer:
- ll13j7b
- Date:
- 2016-05-04
- Revision:
- 1:f82359c58eda
- Child:
- 2:01f697b856de
File content as of revision 1:f82359c58eda:
/* @file MainMenu.h @brief Header file containing member functions and variables @author James Erringham-Bruce */ #ifndef MAINMENU_H #define MAINMENU_H #include "mbed.h" // mbed library #include "Radar.h" #include "Graph.h" #include "UserSettings.h" // creating the class used in plotting the graph class Menu { // defining the public functions and variables public: void mainMenu(); void runSelection(int bank); void printText(); int getBank(); /** @fn numerical @brief shows the numerical readings on screen - speed, distance */ void numerical(); // defining the private functions and variables private: }; #endif Graph graph; Radar radar; UserSettings setting; volatile int menu_screen = 0; // function to return the value of the bank the potentiometer corresponds to for the menu int Menu::getBank() { int bankReturn; if (selectorPot < 0.25f) { bankReturn = 2; } if (selectorPot >= 0.25f && selectorPot < 0.5f) { bankReturn = 3; } if (selectorPot >= 0.5f && selectorPot < 0.75f) { bankReturn = 4; } if (selectorPot >= 0.75f) { bankReturn = 5; } return bankReturn; } // MAIN MENU FUNCTION WHERE THE USER CAN INTERFACE void Menu::mainMenu() { int bank = 0; // initialise the bank menu_screen = 1; // declaring the menu screen is active while (1) { lcd.clear(); bank = getBank(); // get the bank value printText(); // print the users options and title // looping through one bank of the screen ( bank 0 in this case) // similar algorithm to my scrolling method int tempBank = bank*8; for ( int columns = 0; columns < 84; columns++ ) { // multiply by eight to convert bank value to the rows in that bank for ( int currentBank = (bank*8) - 1; currentBank < tempBank+8; currentBank++) { if (lcd.getPixel(columns, currentBank)) { // if the pixel is set lcd.clearPixel(columns, currentBank); // clear it } else { // set the other pixels lcd.setPixel(columns, currentBank); // basically inverting the screen } } } runSelection(bank); // check if a selection has been made lcd.refresh(); wait(0.5); } } void Menu::runSelection(int bank) { if (bank == 2 && button == 1) { menu_screen = 0; setting.printScreen(); } if (bank == 3 && button == 1) { menu_screen = 0; graph.plotGraph(); } if (bank == 4 && button == 1) { menu_screen = 0; numerical(); } if (bank == 5 && button == 1) { menu_screen = 0; radar.radarMode(); } } // FUNCTION TO PRINT THE DISTANCE ON SCREEN IN NUMERICAL FORM void Menu::numerical() { while (1) { int avgCm = getAverageReadingCm(); int avgInch = getAverageReadingInch(); if (g_timer_flag) { // firing the first timer flag g_timer_flag = 0; lcd.clear(); // clear the screen ( preparing for the reading to be dispalyed lcd.printString("DISTANCE", 18, 0); printReading(avgCm ,avgInch); // printing the reading on the screen calling a previous function lcd.refresh(); // refresh the screen displaying the average reading } sleep(); // sleep before next interrupt } } void Menu::printText() { lcd.printString("MENU",30,0); // print the title lcd.drawLine(28,8,54,8,1); // underlining the title lcd.printString("SETTINGS",17,2); // options lcd.printString("GRAPH PLOT",12,3); lcd.printString("NUMERICAL",16,4); lcd.printString("RADAR MODE",12,5); }