Year Two Project ELEC 2645: Embedded Systems Project Portable Weather Station
Dependencies: BMP180 ConfigFile N5110 PowerControl beep mbed
TemperatureScreen.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 TemperatureScreen.h |
OHstin | 0:da2b8c7a1ec1 | 3 | |
OHstin | 0:da2b8c7a1ec1 | 4 | */ |
OHstin | 0:da2b8c7a1ec1 | 5 | |
OHstin | 0:da2b8c7a1ec1 | 6 | #ifndef TEMPERATURESCREEN_H |
OHstin | 0:da2b8c7a1ec1 | 7 | #define TEMPERATURESCREEN_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 Displays the Temperature options\n |
OHstin | 0:da2b8c7a1ec1 | 14 | @brief It is a list with two selectable options :\n |
OHstin | 0:da2b8c7a1ec1 | 15 | @brief view temp and temp plot\n |
OHstin | 0:da2b8c7a1ec1 | 16 | @brief view temp shows the current temperature along with the sentiment\n |
OHstin | 0:da2b8c7a1ec1 | 17 | @brief temp plot plots the temperature against time on the LCD screen at various intervals\n |
OHstin | 0:da2b8c7a1ec1 | 18 | @author Augustine Kizito K |
OHstin | 0:da2b8c7a1ec1 | 19 | @date April 2015 |
OHstin | 0:da2b8c7a1ec1 | 20 | */ |
OHstin | 0:da2b8c7a1ec1 | 21 | |
OHstin | 0:da2b8c7a1ec1 | 22 | |
OHstin | 0:da2b8c7a1ec1 | 23 | |
OHstin | 0:da2b8c7a1ec1 | 24 | class TemperatureScreen : public ListController // inherit the list Controller properties |
OHstin | 0:da2b8c7a1ec1 | 25 | { |
OHstin | 0:da2b8c7a1ec1 | 26 | private: |
OHstin | 0:da2b8c7a1ec1 | 27 | bool changeScreen; // tracks if the user pressed a button that changes the screen |
OHstin | 0:da2b8c7a1ec1 | 28 | int nextScreen; // tracks whether the user wants to go to |
OHstin | 0:da2b8c7a1ec1 | 29 | //the previous screen or next screen |
OHstin | 0:da2b8c7a1ec1 | 30 | |
OHstin | 0:da2b8c7a1ec1 | 31 | void onScrollUp(); // user pressed the scroll up button |
OHstin | 0:da2b8c7a1ec1 | 32 | void onScrollDown(); // user pressed the scroll down button |
OHstin | 0:da2b8c7a1ec1 | 33 | void onEnter(); // user pressed the enter button |
OHstin | 0:da2b8c7a1ec1 | 34 | void onBack(); // user pressed the back button |
OHstin | 0:da2b8c7a1ec1 | 35 | |
OHstin | 0:da2b8c7a1ec1 | 36 | public: |
OHstin | 0:da2b8c7a1ec1 | 37 | /** |
OHstin | 0:da2b8c7a1ec1 | 38 | Creates an instance of the Temperature Screen |
OHstin | 0:da2b8c7a1ec1 | 39 | |
OHstin | 0:da2b8c7a1ec1 | 40 | */ |
OHstin | 0:da2b8c7a1ec1 | 41 | TemperatureScreen() |
OHstin | 0:da2b8c7a1ec1 | 42 | :ListController( "Temperature", // Title |
OHstin | 0:da2b8c7a1ec1 | 43 | "View Temp", // Option 1 |
OHstin | 0:da2b8c7a1ec1 | 44 | "Temp Plot", // Option 2 |
OHstin | 0:da2b8c7a1ec1 | 45 | "", // Option 3 |
OHstin | 0:da2b8c7a1ec1 | 46 | "", // Option 4 |
OHstin | 0:da2b8c7a1ec1 | 47 | 2) // Number of Options |
OHstin | 0:da2b8c7a1ec1 | 48 | {}; |
OHstin | 0:da2b8c7a1ec1 | 49 | /** |
OHstin | 0:da2b8c7a1ec1 | 50 | Manages the execution of the Temperature Screen |
OHstin | 0:da2b8c7a1ec1 | 51 | @returns |
OHstin | 0:da2b8c7a1ec1 | 52 | |
OHstin | 0:da2b8c7a1ec1 | 53 | -1 - Navigate to previous screen\n |
OHstin | 0:da2b8c7a1ec1 | 54 | 0 - User selected option 1\n |
OHstin | 0:da2b8c7a1ec1 | 55 | 1 - User selected option 2 |
OHstin | 0:da2b8c7a1ec1 | 56 | */ |
OHstin | 0:da2b8c7a1ec1 | 57 | int start(); |
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 | |
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 | int TemperatureScreen::start() |
OHstin | 0:da2b8c7a1ec1 | 74 | { |
OHstin | 0:da2b8c7a1ec1 | 75 | |
OHstin | 0:da2b8c7a1ec1 | 76 | // Activate PullDown Resistors |
OHstin | 0:da2b8c7a1ec1 | 77 | enterButton.mode(PullDown); |
OHstin | 0:da2b8c7a1ec1 | 78 | upButton.mode(PullDown); |
OHstin | 0:da2b8c7a1ec1 | 79 | downButton.mode(PullDown); |
OHstin | 0:da2b8c7a1ec1 | 80 | backButton.mode(PullDown); |
OHstin | 0:da2b8c7a1ec1 | 81 | |
OHstin | 0:da2b8c7a1ec1 | 82 | upButton.rise(this,&TemperatureScreen::onScrollUp); // call onScrollUp when the up button is pressed |
OHstin | 0:da2b8c7a1ec1 | 83 | downButton.rise(this,&TemperatureScreen::onScrollDown); // call onScrollDown when the down button is pressed |
OHstin | 0:da2b8c7a1ec1 | 84 | enterButton.rise(this,&TemperatureScreen::onEnter); // call onEnter when the enter button is pressed |
OHstin | 0:da2b8c7a1ec1 | 85 | backButton.rise(this,&TemperatureScreen::onBack); // call onBack when the back button is pressed |
OHstin | 0:da2b8c7a1ec1 | 86 | |
OHstin | 0:da2b8c7a1ec1 | 87 | // Launch the List Controller |
OHstin | 0:da2b8c7a1ec1 | 88 | ListController::showInfo(); |
OHstin | 0:da2b8c7a1ec1 | 89 | changeScreen = false; |
OHstin | 0:da2b8c7a1ec1 | 90 | |
OHstin | 0:da2b8c7a1ec1 | 91 | debounce.start(); // start the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 92 | |
OHstin | 0:da2b8c7a1ec1 | 93 | while(!changeScreen) { |
OHstin | 0:da2b8c7a1ec1 | 94 | |
OHstin | 0:da2b8c7a1ec1 | 95 | // mbed goes to sleep to save power |
OHstin | 0:da2b8c7a1ec1 | 96 | Sleep(); |
OHstin | 0:da2b8c7a1ec1 | 97 | } |
OHstin | 0:da2b8c7a1ec1 | 98 | |
OHstin | 0:da2b8c7a1ec1 | 99 | // detach all interrupts |
OHstin | 0:da2b8c7a1ec1 | 100 | upButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 101 | downButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 102 | enterButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 103 | backButton.rise(NULL); |
OHstin | 0:da2b8c7a1ec1 | 104 | |
OHstin | 0:da2b8c7a1ec1 | 105 | return nextScreen; |
OHstin | 0:da2b8c7a1ec1 | 106 | } |
OHstin | 0:da2b8c7a1ec1 | 107 | |
OHstin | 0:da2b8c7a1ec1 | 108 | void TemperatureScreen::onScrollUp() |
OHstin | 0:da2b8c7a1ec1 | 109 | { |
OHstin | 0:da2b8c7a1ec1 | 110 | if (debounceSuccess()) { // check if debouncing succeeded |
OHstin | 0:da2b8c7a1ec1 | 111 | |
OHstin | 0:da2b8c7a1ec1 | 112 | ListController::scrollUp(); // scroll up |
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 TemperatureScreen::onScrollDown() |
OHstin | 0:da2b8c7a1ec1 | 118 | { |
OHstin | 0:da2b8c7a1ec1 | 119 | if (debounceSuccess()) { // check if debouncing succeeded |
OHstin | 0:da2b8c7a1ec1 | 120 | |
OHstin | 0:da2b8c7a1ec1 | 121 | ListController::scrollDown(); // scroll down |
OHstin | 0:da2b8c7a1ec1 | 122 | debounce.reset(); // reset the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 123 | } |
OHstin | 0:da2b8c7a1ec1 | 124 | } |
OHstin | 0:da2b8c7a1ec1 | 125 | |
OHstin | 0:da2b8c7a1ec1 | 126 | void TemperatureScreen::onEnter() |
OHstin | 0:da2b8c7a1ec1 | 127 | { |
OHstin | 0:da2b8c7a1ec1 | 128 | if (debounceSuccess()) { // check if debouncing succeeded |
OHstin | 0:da2b8c7a1ec1 | 129 | playSound(); |
OHstin | 0:da2b8c7a1ec1 | 130 | nextScreen = ListController::getCurrentOption(); // get the option that user selected |
OHstin | 0:da2b8c7a1ec1 | 131 | changeScreen = true; // user wants to go to a different screen |
OHstin | 0:da2b8c7a1ec1 | 132 | debounce.reset(); // reset the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 133 | } |
OHstin | 0:da2b8c7a1ec1 | 134 | } |
OHstin | 0:da2b8c7a1ec1 | 135 | |
OHstin | 0:da2b8c7a1ec1 | 136 | void TemperatureScreen::onBack() |
OHstin | 0:da2b8c7a1ec1 | 137 | { |
OHstin | 0:da2b8c7a1ec1 | 138 | if(debounceSuccess()) { // if debouncing succeeded |
OHstin | 0:da2b8c7a1ec1 | 139 | playSound(); |
OHstin | 0:da2b8c7a1ec1 | 140 | nextScreen = -1; // go to previous screen |
OHstin | 0:da2b8c7a1ec1 | 141 | changeScreen = true; // user wants to go to a different screen |
OHstin | 0:da2b8c7a1ec1 | 142 | debounce.reset(); // reset the debounce timer |
OHstin | 0:da2b8c7a1ec1 | 143 | } |
OHstin | 0:da2b8c7a1ec1 | 144 | |
OHstin | 0:da2b8c7a1ec1 | 145 | } |
OHstin | 0:da2b8c7a1ec1 | 146 | |
OHstin | 0:da2b8c7a1ec1 | 147 | #endif |