Distance Sensor Embedded Systems Project SID: 200864479 James Erringham-Bruce
Dependencies: N5110 SRF02-JEB mbed
Diff: UserSettings/UserSettings.h
- Revision:
- 2:01f697b856de
- Parent:
- 1:f82359c58eda
--- a/UserSettings/UserSettings.h Wed May 04 21:20:21 2016 +0000 +++ b/UserSettings/UserSettings.h Thu May 05 14:18:51 2016 +0000 @@ -1,5 +1,5 @@ -/* -@file Settings.h +/** +@file UserSettings.h @brief Header file containing member functions and variables @author James Erringham-Bruce */ @@ -18,69 +18,92 @@ public: /** - @fn printScreen - @brief prints the settings screen - @brief controls the scroller icon at the far right of the screen + function is used to print the settings on the screen in order for the user to interact with and chose the option + within the function, it controls the scrolling for the screen */ void printScreen(); /** - @fn scrollUp_down - @brief control the scrolling of the screen - @brief both directions ( up, down ) + function allows the user to scroll up and down on the screen to view all the options + @param bank */ void scrollUp_Down(int bank); /** - @fn printText - @brief controls the printing of the text + function to return the value of the bank to invert + @returns bank - to invert colour */ + int setBank(); - /** - @fn cursorControl - @brief controlls the cursors movement and its selection - */ - int setBank(); - - void SendBufferToLCD(); // defining the private functions private: - /** - @var bankValue - @brief the bank that the cursor currently lies - */ - int bankValue; + }; + +//*****************************************************************************************************// + +// END OF CLASS // + +//*****************************************************************************************************// + #endif +/** +@struct settingsStrings +struct that holds the array of chars to state whether the LED & Buzzer are ON or OFF +*/ struct settingsStrings { - char LED_State[5]; // 3 chars to hold either "on" or "off" - char buzzer_State[5]; // 3 chars to hold either "on" or "off" + char LED_State[5]; /*!< 3 chars to hold either "on" or "off", 5 used to give space for printing text */ + char buzzer_State[5]; /*!< 3 chars to hold either "on" or "off" 5 used to give space for printing text */ }; settingsStrings setAndSaveSettings(); -char buffer2[14]; +char buffer2[14]; /*!<character length #2 as two strings are printed at once*/ + +char OFF[] = "OFF"; /*!< copy this string when off... */ +char ON[] = "ON"; /*!< copy this string when on... */ + +volatile bool LED_Toggle = 0; /*!< determines whether LED is logic high(1) or logic low (0)*/ +volatile bool buzzer_Toggle = 0; /*!< determines whether buzzer is logic high (1) or logic low (0)*/ +volatile bool brightness_Toggle = 0; /*!< determines whether the brightness is being changed */ -char OFF[] = "OFF"; // copy this string when off... -char ON[] = "ON"; // copy this string when on... +/** +function to allow the text that is off the screen to be printed when the user scrolls down the screen +*/ +void printText(settingsStrings state); + +/** +function that allows the main menu to be returned if the interrupt button has been pressed +*/ +void goBackToMenu(); -volatile bool LED_Toggle = 0; -volatile bool buzzer_Toggle = 0; -volatile bool brightness_Toggle = 0; +/** +function to allow the brightness of the LCD screen to be changed using PWM +@param br +*/ +void changeBrightness(float br); +/** +@namespace settingsStrings +@brief allows passage of the struct to be used in other functions +*/ +settingsStrings setString; -void printText(settingsStrings state); -void goBackToMenu(); -void changeBrightness(float br); +int brightness = 50; /*!< intialises the brightness at start up */ + +//*****************************************************************************************************// -volatile int savedBrightness = 10; // intially set to 50% +// END OF GLOBAL VARIABLES // -settingsStrings setString; +//*****************************************************************************************************// // SAVE THE STRINGS TO THE SETTINGS SCREEN AND REWRITE THE CHANGED DATA TO THE SYSTEM... settingsStrings setAndSaveSettings() { + /// checks position of the potentiometer + /// if the settings flag has been activated + /// flip the toggle of the if (selectorPot < 0.15f) { // for the LED toggle states - if (settings_flag) { + if (selector_flag) { LED_Toggle = !LED_Toggle; if (LED_Toggle) { strcpy(setString.LED_State,ON); @@ -89,58 +112,68 @@ strcpy(setString.LED_State,OFF); LED = 0; } - settings_flag = 0; // put the flag back to zero ready for another use + selector_flag = 0; // put the flag back to zero ready for another use } } if (selectorPot >= 0.3f && selectorPot < 0.45f) { // for the Buzzer toggle states - if (settings_flag) { + if (selector_flag) { buzzer_Toggle = !buzzer_Toggle; if (buzzer_Toggle) { strcpy(setString.buzzer_State,ON); } else { strcpy(setString.buzzer_State,OFF); } - settings_flag = 0; // put the flag back to zero ready for another use + selector_flag = 0; // put the flag back to zero ready for another use } } if (selectorPot >= 0.7f ) { // hold while brightness is changed - if (settings_flag) { + if (selector_flag) { do { - int brightness = selectorPot*100; - changeBrightness(selectorPot); + brightness = selectorPot*100; // setting brightness as a percentage + changeBrightness(selectorPot*2); int length = sprintf(buffer,"%d %% ",brightness); // defining max length of chars 84 ÷ 6 = 14 if ( length <= 14 ) { // if string will fit on display lcd.printString(buffer, 35, 5); } - if (backButton) { - settings_flag = 0; - } + if (back_flag) { + selector_flag = 0; + isInMenu = 0; + isInSettings = 1; + } // if back, return to settings not the main menu!! lcd.printString("Adjust Your",9,2); lcd.printString("Brightness",13,3); - } while (settings_flag); + } while (selector_flag); } + sprintf(buffer,"%d %% ",brightness); //ensure brightness is still printed after loop + lcd.printString(buffer, 35, 5); } return setString; } - +// FUNCTION TO PRINT THE SETTINGS SCREEN ACCORDING TO THE CHANGED PARAMETERS void UserSettings::printScreen() { + /// initially set the buzzer & LED to off + isInSettings = 1; unsigned int y_scroller = 0; - interruptSelector.fall(&settings_isr); settingsStrings newStrings; // call the struct - settings_flag = 0; + selector_flag = 0; + // COPY THE CHARS OFF TO THE EMPTY STATES strcpy(setString.LED_State,OFF); // set initial state as off strcpy(setString.buzzer_State,OFF); // set initial state as off - while (1) { - //settings_flag = 0; // put the flag back to zero ready for another use + + while (isInSettings) { + + goBackToMenu(); + if (settings_timer_flag) { settings_timer_flag = 0; lcd.clear(); unsigned int bank = setBank(); // normalising the scroller icons pixel values + /// set the scrolling ican and move down when the screen scrolls if ( selectorPot > 0.45f ) { y_scroller = ((selectorPot*25)*2) - 10; // 40 is the amount of free pixels the scrolling icon can move } @@ -149,16 +182,18 @@ if (y_scroller > 48) {// ensuring the scroller does not exceed out of bounds y_scroller = 48; } + // print new strings obtained printText(newStrings); lcd.drawLine(82,y_scroller,82,y_scroller+8,1);// scrolling icon lcd.drawLine(83,y_scroller,83,y_scroller+8,1);// scrolling icon lcd.refresh(); } - sleep(); + sleep(); // sleep after ticker has run } } +// FUNCTION TO RETURN THE BANK VALUE OF THE CURSOR int UserSettings::setBank() { int currentBank = 3; @@ -190,11 +225,12 @@ // FUNCTION TO OVERRIDE, WHEN THE BANK IS > 5 PUSH TEXT BACK TO A BANK ON SCREEN void printText(settingsStrings state) { - + /// pass in the new values of the buzzer and LED state from the struct state = setAndSaveSettings(); // assign new values // Print text as an array so that it can be manipulated to act as if the // text is scrolliing bank by bank + /// print the screen as an array that only displays parts of that array const char screenText[8][14] = { {" SETTINGS"}, { }, // empty slots @@ -207,7 +243,7 @@ }; int length, length2; unsigned int textRow = 0; - + /// print the states as a string even when scrolling is implemented if ( selectorPot < 0.45f ) { textRow = 5; length = sprintf(buffer,"%s",state.LED_State); // defining max length of chars 84 ÷ 6 = 14 @@ -249,28 +285,27 @@ lcd.printString(screenText[textRow],2,5); } -void settings_isr() -{ - settings_flag = 1; -} - -void goBackToMenu() -{ - if (backButton) { - - } -} - +// FUNCTION TO CHANGE THE BRIGHTNESS OF THE LCD BACKLIGHT void changeBrightness(float br) { - //br *= 0.12f; - + /// ensure the brightness value never goes out of range 0-1 if(br>=1) { br = 1; } else if(br <= 0) { br = 0; } + /// write the value to the PWM pin defined as 'backLight' + backLight.write(br); +} - backLight.write(br); -} \ No newline at end of file +//*****************************************************************************************************// + +// END OF FUNCTION IMPLEMENTATIONS // + +//*****************************************************************************************************// + + + + +