Year Two Project ELEC 2645: Embedded Systems Project Portable Weather Station
Dependencies: BMP180 ConfigFile N5110 PowerControl beep mbed
LogOptionScreen.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 LogOptionScreen.h |
OHstin | 0:da2b8c7a1ec1 | 3 | */ |
OHstin | 0:da2b8c7a1ec1 | 4 | #ifndef LOGOPTIONSCREEN_H |
OHstin | 0:da2b8c7a1ec1 | 5 | #define LOGOPTIONSCREEN_H |
OHstin | 0:da2b8c7a1ec1 | 6 | |
OHstin | 0:da2b8c7a1ec1 | 7 | #include "ListController.h" |
OHstin | 0:da2b8c7a1ec1 | 8 | #include "Inputs.h" |
OHstin | 0:da2b8c7a1ec1 | 9 | |
OHstin | 0:da2b8c7a1ec1 | 10 | /** |
OHstin | 0:da2b8c7a1ec1 | 11 | @brief Allos the user to select which parameter they would\n |
OHstin | 0:da2b8c7a1ec1 | 12 | @brief like to log or view a previous log i.e either temperature or pressure\n |
OHstin | 0:da2b8c7a1ec1 | 13 | @brief it consists of a list controller with two options |
OHstin | 0:da2b8c7a1ec1 | 14 | @author Augustine K Kizito |
OHstin | 0:da2b8c7a1ec1 | 15 | @date April 2015 |
OHstin | 0:da2b8c7a1ec1 | 16 | */ |
OHstin | 0:da2b8c7a1ec1 | 17 | |
OHstin | 0:da2b8c7a1ec1 | 18 | |
OHstin | 0:da2b8c7a1ec1 | 19 | class LogOptionScreen : public ListController // inherit the list Controller properties |
OHstin | 0:da2b8c7a1ec1 | 20 | { |
OHstin | 0:da2b8c7a1ec1 | 21 | private: |
OHstin | 0:da2b8c7a1ec1 | 22 | bool changeScreen; // tracks if the user pressed a button that changes the screen |
OHstin | 0:da2b8c7a1ec1 | 23 | int nextScreen; // tracks whether the user wants to go to |
OHstin | 0:da2b8c7a1ec1 | 24 | //the previous screen or next screen |
OHstin | 0:da2b8c7a1ec1 | 25 | |
OHstin | 0:da2b8c7a1ec1 | 26 | void onScrollUp(); // user pressed the scroll up button |
OHstin | 0:da2b8c7a1ec1 | 27 | void onScrollDown(); // user pressed the scroll down button |
OHstin | 0:da2b8c7a1ec1 | 28 | void onEnter(); // user pressed the enter button |
OHstin | 0:da2b8c7a1ec1 | 29 | void onBack(); // user pressed the back button |
OHstin | 0:da2b8c7a1ec1 | 30 | |
OHstin | 0:da2b8c7a1ec1 | 31 | public: |
OHstin | 0:da2b8c7a1ec1 | 32 | /** |
OHstin | 0:da2b8c7a1ec1 | 33 | Creates an instance of the log options screen |
OHstin | 0:da2b8c7a1ec1 | 34 | |
OHstin | 0:da2b8c7a1ec1 | 35 | */ |
OHstin | 0:da2b8c7a1ec1 | 36 | LogOptionScreen() |
OHstin | 0:da2b8c7a1ec1 | 37 | :ListController( "Parameter", // Title |
OHstin | 0:da2b8c7a1ec1 | 38 | "Temperature", // Option 1 |
OHstin | 0:da2b8c7a1ec1 | 39 | "Pressure", // Option 2 |
OHstin | 0:da2b8c7a1ec1 | 40 | "", // Option 3 |
OHstin | 0:da2b8c7a1ec1 | 41 | "", // Option 4 |
OHstin | 0:da2b8c7a1ec1 | 42 | 2) // Number of Options |
OHstin | 0:da2b8c7a1ec1 | 43 | {}; |
OHstin | 0:da2b8c7a1ec1 | 44 | /** |
OHstin | 0:da2b8c7a1ec1 | 45 | Manages the execution of the Log Options Screen |
OHstin | 0:da2b8c7a1ec1 | 46 | |
OHstin | 0:da2b8c7a1ec1 | 47 | @returns |
OHstin | 0:da2b8c7a1ec1 | 48 | |
OHstin | 0:da2b8c7a1ec1 | 49 | -1 - Navigate to previous screen\n |
OHstin | 0:da2b8c7a1ec1 | 50 | 0 - User selected option 1\n |
OHstin | 0:da2b8c7a1ec1 | 51 | 1 - User selected option 2 |
OHstin | 0:da2b8c7a1ec1 | 52 | |
OHstin | 0:da2b8c7a1ec1 | 53 | */ |
OHstin | 0:da2b8c7a1ec1 | 54 | int start(); |
OHstin | 0:da2b8c7a1ec1 | 55 | |
OHstin | 0:da2b8c7a1ec1 | 56 | |
OHstin | 0:da2b8c7a1ec1 | 57 | }; |
OHstin | 0:da2b8c7a1ec1 | 58 | |
OHstin | 0:da2b8c7a1ec1 | 59 | |
OHstin | 0:da2b8c7a1ec1 | 60 | |
OHstin | 0:da2b8c7a1ec1 | 61 | |
OHstin | 0:da2b8c7a1ec1 | 62 | |
OHstin | 0:da2b8c7a1ec1 | 63 | |
OHstin | 0:da2b8c7a1ec1 | 64 | int LogOptionScreen::start() |
OHstin | 0:da2b8c7a1ec1 | 65 | { |
OHstin | 0:da2b8c7a1ec1 | 66 | |
OHstin | 0:da2b8c7a1ec1 | 67 | // Activate PullDown Resistors |
OHstin | 0:da2b8c7a1ec1 | 68 | enterButton.mode(PullDown); |
OHstin | 0:da2b8c7a1ec1 | 69 | upButton.mode(PullDown); |
OHstin | 0:da2b8c7a1ec1 | 70 | downButton.mode(PullDown); |
OHstin | 0:da2b8c7a1ec1 | 71 | backButton.mode(PullDown); |
OHstin | 0:da2b8c7a1ec1 | 72 | |
OHstin | 0:da2b8c7a1ec1 | 73 | upButton.rise(this,&LogOptionScreen::onScrollUp); // call onScrollUp when the up button is pressed |
OHstin | 0:da2b8c7a1ec1 | 74 | downButton.rise(this,&LogOptionScreen::onScrollDown); // call onScrollDown when the down button is pressed |
OHstin | 0:da2b8c7a1ec1 | 75 | enterButton.rise(this,&LogOptionScreen::onEnter); // call onEnter when the enter button is pressed |
OHstin | 0:da2b8c7a1ec1 | 76 | backButton.rise(this,&LogOptionScreen::onBack); // call onBack when the back button is pressed |
OHstin | 0:da2b8c7a1ec1 | 77 | |
OHstin | 0:da2b8c7a1ec1 | 78 | // Launch the List Controller |
OHstin | 0:da2b8c7a1ec1 | 79 | ListController::showInfo(); |
OHstin | 0:da2b8c7a1ec1 | 80 | changeScreen = false; |
OHstin | 0:da2b8c7a1ec1 | 81 | |
OHstin | 0:da2b8c7a1ec1 | 82 | debounce.start(); // start the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 83 | |
OHstin | 0:da2b8c7a1ec1 | 84 | while(!changeScreen) { |
OHstin | 0:da2b8c7a1ec1 | 85 | |
OHstin | 0:da2b8c7a1ec1 | 86 | // mbed goes to sleep to save power |
OHstin | 0:da2b8c7a1ec1 | 87 | Sleep(); |
OHstin | 0:da2b8c7a1ec1 | 88 | } |
OHstin | 0:da2b8c7a1ec1 | 89 | |
OHstin | 0:da2b8c7a1ec1 | 90 | // detach all interrupts |
OHstin | 0:da2b8c7a1ec1 | 91 | upButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 92 | downButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 93 | enterButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 94 | backButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 95 | |
OHstin | 0:da2b8c7a1ec1 | 96 | return nextScreen; |
OHstin | 0:da2b8c7a1ec1 | 97 | } |
OHstin | 0:da2b8c7a1ec1 | 98 | |
OHstin | 0:da2b8c7a1ec1 | 99 | void LogOptionScreen::onScrollUp() |
OHstin | 0:da2b8c7a1ec1 | 100 | { |
OHstin | 0:da2b8c7a1ec1 | 101 | if (debounceSuccess()) { // check if debouncing succeeded |
OHstin | 0:da2b8c7a1ec1 | 102 | |
OHstin | 0:da2b8c7a1ec1 | 103 | ListController::scrollUp(); // scroll up |
OHstin | 0:da2b8c7a1ec1 | 104 | debounce.reset(); // reset the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 105 | } |
OHstin | 0:da2b8c7a1ec1 | 106 | } |
OHstin | 0:da2b8c7a1ec1 | 107 | |
OHstin | 0:da2b8c7a1ec1 | 108 | void LogOptionScreen::onScrollDown() |
OHstin | 0:da2b8c7a1ec1 | 109 | { |
OHstin | 0:da2b8c7a1ec1 | 110 | if (debounceSuccess()) { // check if debouncing succeeded |
OHstin | 0:da2b8c7a1ec1 | 111 | |
OHstin | 0:da2b8c7a1ec1 | 112 | ListController::scrollDown(); // scroll down |
OHstin | 0:da2b8c7a1ec1 | 113 | debounce.reset(); // reset the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 114 | } |
OHstin | 0:da2b8c7a1ec1 | 115 | } |
OHstin | 0:da2b8c7a1ec1 | 116 | |
OHstin | 0:da2b8c7a1ec1 | 117 | void LogOptionScreen::onEnter() |
OHstin | 0:da2b8c7a1ec1 | 118 | { |
OHstin | 0:da2b8c7a1ec1 | 119 | if (debounceSuccess()) { // check if debouncing succeeded |
OHstin | 0:da2b8c7a1ec1 | 120 | // Sound the buzzer |
OHstin | 0:da2b8c7a1ec1 | 121 | playSound(); |
OHstin | 0:da2b8c7a1ec1 | 122 | nextScreen = ListController::getCurrentOption(); // get the option that user selected |
OHstin | 0:da2b8c7a1ec1 | 123 | changeScreen = true; // user wants to go to a different screen |
OHstin | 0:da2b8c7a1ec1 | 124 | debounce.reset(); // reset the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 125 | } |
OHstin | 0:da2b8c7a1ec1 | 126 | } |
OHstin | 0:da2b8c7a1ec1 | 127 | |
OHstin | 0:da2b8c7a1ec1 | 128 | void LogOptionScreen::onBack() |
OHstin | 0:da2b8c7a1ec1 | 129 | { |
OHstin | 0:da2b8c7a1ec1 | 130 | if(debounceSuccess()) { // debouncing succeeded |
OHstin | 0:da2b8c7a1ec1 | 131 | // sound the buzzer |
OHstin | 0:da2b8c7a1ec1 | 132 | playSound(); |
OHstin | 0:da2b8c7a1ec1 | 133 | nextScreen = -1; // go to previous screen |
OHstin | 0:da2b8c7a1ec1 | 134 | changeScreen = true; // user wants to go to a different screen |
OHstin | 0:da2b8c7a1ec1 | 135 | debounce.reset(); |
OHstin | 0:da2b8c7a1ec1 | 136 | } |
OHstin | 0:da2b8c7a1ec1 | 137 | |
OHstin | 0:da2b8c7a1ec1 | 138 | } |
OHstin | 0:da2b8c7a1ec1 | 139 | |
OHstin | 0:da2b8c7a1ec1 | 140 | #endif |