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