Year Two Project ELEC 2645: Embedded Systems Project Portable Weather Station
Dependencies: BMP180 ConfigFile N5110 PowerControl beep mbed
MainMenuScreen.h@0:da2b8c7a1ec1, 2015-05-11 (annotated)
- Committer:
- OHstin
- Date:
- Mon May 11 15:25:52 2015 +0000
- Revision:
- 0:da2b8c7a1ec1
Completed Weather Station
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OHstin | 0:da2b8c7a1ec1 | 1 | /** |
OHstin | 0:da2b8c7a1ec1 | 2 | @file MainMenuScreen.h |
OHstin | 0:da2b8c7a1ec1 | 3 | |
OHstin | 0:da2b8c7a1ec1 | 4 | */ |
OHstin | 0:da2b8c7a1ec1 | 5 | #ifndef MAINMENUSCREEN_H |
OHstin | 0:da2b8c7a1ec1 | 6 | #define MAINMENUSCREEN_H |
OHstin | 0:da2b8c7a1ec1 | 7 | |
OHstin | 0:da2b8c7a1ec1 | 8 | #include "ListController.h" |
OHstin | 0:da2b8c7a1ec1 | 9 | #include "Inputs.h" |
OHstin | 0:da2b8c7a1ec1 | 10 | |
OHstin | 0:da2b8c7a1ec1 | 11 | /** |
OHstin | 0:da2b8c7a1ec1 | 12 | @brief Displays the main menu on the LCD screen\n |
OHstin | 0:da2b8c7a1ec1 | 13 | @brief It is a list with four selectable options :\n |
OHstin | 0:da2b8c7a1ec1 | 14 | @brief temperature, pressue , log and settings |
OHstin | 0:da2b8c7a1ec1 | 15 | @author Augustine Kizito K |
OHstin | 0:da2b8c7a1ec1 | 16 | @date April 2015 |
OHstin | 0:da2b8c7a1ec1 | 17 | */ |
OHstin | 0:da2b8c7a1ec1 | 18 | |
OHstin | 0:da2b8c7a1ec1 | 19 | |
OHstin | 0:da2b8c7a1ec1 | 20 | |
OHstin | 0:da2b8c7a1ec1 | 21 | class MainMenuScreen : public ListController |
OHstin | 0:da2b8c7a1ec1 | 22 | { |
OHstin | 0:da2b8c7a1ec1 | 23 | private: |
OHstin | 0:da2b8c7a1ec1 | 24 | bool changeScreen; // tracks if the user pressed a button that changes the screen |
OHstin | 0:da2b8c7a1ec1 | 25 | int nextScreen; // tracks whether the user wants to go to |
OHstin | 0:da2b8c7a1ec1 | 26 | //the previous screen or next screen |
OHstin | 0:da2b8c7a1ec1 | 27 | |
OHstin | 0:da2b8c7a1ec1 | 28 | void onScrollUp(); // user pressed the scroll up button |
OHstin | 0:da2b8c7a1ec1 | 29 | void onScrollDown(); // user pressed the scroll down button |
OHstin | 0:da2b8c7a1ec1 | 30 | void onEnter(); // user pressed the enter button |
OHstin | 0:da2b8c7a1ec1 | 31 | |
OHstin | 0:da2b8c7a1ec1 | 32 | public: |
OHstin | 0:da2b8c7a1ec1 | 33 | /** |
OHstin | 0:da2b8c7a1ec1 | 34 | Creates an instance of the main menu screen |
OHstin | 0:da2b8c7a1ec1 | 35 | |
OHstin | 0:da2b8c7a1ec1 | 36 | */ |
OHstin | 0:da2b8c7a1ec1 | 37 | MainMenuScreen() |
OHstin | 0:da2b8c7a1ec1 | 38 | :ListController( "MainMenu", // Title |
OHstin | 0:da2b8c7a1ec1 | 39 | "Temperature", // Option 1 |
OHstin | 0:da2b8c7a1ec1 | 40 | "Pressure", // Option 2 |
OHstin | 0:da2b8c7a1ec1 | 41 | "Log", // Option 3 |
OHstin | 0:da2b8c7a1ec1 | 42 | "Settings", // Option 4 |
OHstin | 0:da2b8c7a1ec1 | 43 | 4) // Number of Options |
OHstin | 0:da2b8c7a1ec1 | 44 | {}; |
OHstin | 0:da2b8c7a1ec1 | 45 | /* |
OHstin | 0:da2b8c7a1ec1 | 46 | Manages the execution of the main menu screen |
OHstin | 0:da2b8c7a1ec1 | 47 | |
OHstin | 0:da2b8c7a1ec1 | 48 | @returns |
OHstin | 0:da2b8c7a1ec1 | 49 | 0 - User selected option 1\n |
OHstin | 0:da2b8c7a1ec1 | 50 | 1 - User selected option 2\n |
OHstin | 0:da2b8c7a1ec1 | 51 | 2 - User selected option 3\n |
OHstin | 0:da2b8c7a1ec1 | 52 | 3 - User selected option 4\n |
OHstin | 0:da2b8c7a1ec1 | 53 | |
OHstin | 0:da2b8c7a1ec1 | 54 | */ |
OHstin | 0:da2b8c7a1ec1 | 55 | int start(); |
OHstin | 0:da2b8c7a1ec1 | 56 | |
OHstin | 0:da2b8c7a1ec1 | 57 | |
OHstin | 0:da2b8c7a1ec1 | 58 | }; |
OHstin | 0:da2b8c7a1ec1 | 59 | int MainMenuScreen::start() |
OHstin | 0:da2b8c7a1ec1 | 60 | { |
OHstin | 0:da2b8c7a1ec1 | 61 | |
OHstin | 0:da2b8c7a1ec1 | 62 | |
OHstin | 0:da2b8c7a1ec1 | 63 | enterButton.mode(PullDown); // activate pull down resistor |
OHstin | 0:da2b8c7a1ec1 | 64 | upButton.mode(PullDown); // activate pull down resistor |
OHstin | 0:da2b8c7a1ec1 | 65 | downButton.mode(PullDown); // acivate pull down resistor |
OHstin | 0:da2b8c7a1ec1 | 66 | |
OHstin | 0:da2b8c7a1ec1 | 67 | upButton.rise(this,&MainMenuScreen::onScrollUp); // call onScrollUp when the up button is pressed |
OHstin | 0:da2b8c7a1ec1 | 68 | downButton.rise(this,&MainMenuScreen::onScrollDown); // call onScrollDown when the down button is pressed |
OHstin | 0:da2b8c7a1ec1 | 69 | enterButton.rise(this,&MainMenuScreen::onEnter); // call onEnter when the enter button is pressed |
OHstin | 0:da2b8c7a1ec1 | 70 | |
OHstin | 0:da2b8c7a1ec1 | 71 | // Launch the List Controller |
OHstin | 0:da2b8c7a1ec1 | 72 | ListController::showInfo(); |
OHstin | 0:da2b8c7a1ec1 | 73 | changeScreen = false; |
OHstin | 0:da2b8c7a1ec1 | 74 | |
OHstin | 0:da2b8c7a1ec1 | 75 | debounce.start(); // start the debouncing timer |
OHstin | 0:da2b8c7a1ec1 | 76 | |
OHstin | 0:da2b8c7a1ec1 | 77 | while(!changeScreen) { |
OHstin | 0:da2b8c7a1ec1 | 78 | |
OHstin | 0:da2b8c7a1ec1 | 79 | // mbed goes to sleep to save power |
OHstin | 0:da2b8c7a1ec1 | 80 | Sleep(); |
OHstin | 0:da2b8c7a1ec1 | 81 | } |
OHstin | 0:da2b8c7a1ec1 | 82 | |
OHstin | 0:da2b8c7a1ec1 | 83 | // detach all interrupts |
OHstin | 0:da2b8c7a1ec1 | 84 | upButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 85 | downButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 86 | enterButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 87 | backButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 88 | |
OHstin | 0:da2b8c7a1ec1 | 89 | return nextScreen; |
OHstin | 0:da2b8c7a1ec1 | 90 | } |
OHstin | 0:da2b8c7a1ec1 | 91 | |
OHstin | 0:da2b8c7a1ec1 | 92 | void MainMenuScreen::onScrollUp() |
OHstin | 0:da2b8c7a1ec1 | 93 | { |
OHstin | 0:da2b8c7a1ec1 | 94 | if (debounceSuccess()) { // debouncing successful |
OHstin | 0:da2b8c7a1ec1 | 95 | |
OHstin | 0:da2b8c7a1ec1 | 96 | ListController::scrollUp(); // scroll up |
OHstin | 0:da2b8c7a1ec1 | 97 | debounce.reset(); // reset the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 98 | } |
OHstin | 0:da2b8c7a1ec1 | 99 | } |
OHstin | 0:da2b8c7a1ec1 | 100 | |
OHstin | 0:da2b8c7a1ec1 | 101 | void MainMenuScreen::onScrollDown() |
OHstin | 0:da2b8c7a1ec1 | 102 | { |
OHstin | 0:da2b8c7a1ec1 | 103 | if (debounceSuccess()) { // debouncing successful |
OHstin | 0:da2b8c7a1ec1 | 104 | |
OHstin | 0:da2b8c7a1ec1 | 105 | ListController::scrollDown(); // scroll down |
OHstin | 0:da2b8c7a1ec1 | 106 | debounce.reset(); // reset the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 107 | } |
OHstin | 0:da2b8c7a1ec1 | 108 | } |
OHstin | 0:da2b8c7a1ec1 | 109 | |
OHstin | 0:da2b8c7a1ec1 | 110 | void MainMenuScreen::onEnter() |
OHstin | 0:da2b8c7a1ec1 | 111 | { |
OHstin | 0:da2b8c7a1ec1 | 112 | if (debounceSuccess()){ // debouncing successful |
OHstin | 0:da2b8c7a1ec1 | 113 | // sound the buzzer |
OHstin | 0:da2b8c7a1ec1 | 114 | playSound(); |
OHstin | 0:da2b8c7a1ec1 | 115 | nextScreen = ListController::getCurrentOption(); // get the option that user selected |
OHstin | 0:da2b8c7a1ec1 | 116 | changeScreen = true; // user wants to go to a different screen |
OHstin | 0:da2b8c7a1ec1 | 117 | // reset the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 118 | debounce.reset(); |
OHstin | 0:da2b8c7a1ec1 | 119 | } |
OHstin | 0:da2b8c7a1ec1 | 120 | } |
OHstin | 0:da2b8c7a1ec1 | 121 | |
OHstin | 0:da2b8c7a1ec1 | 122 | #endif |