Year Two Project ELEC 2645: Embedded Systems Project Portable Weather Station

Dependencies:   BMP180 ConfigFile N5110 PowerControl beep mbed

Committer:
OHstin
Date:
Mon May 11 15:25:52 2015 +0000
Revision:
0:da2b8c7a1ec1
Completed Weather Station

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OHstin 0:da2b8c7a1ec1 1 /**
OHstin 0:da2b8c7a1ec1 2 @file IntervalScreen.h
OHstin 0:da2b8c7a1ec1 3
OHstin 0:da2b8c7a1ec1 4 */
OHstin 0:da2b8c7a1ec1 5
OHstin 0:da2b8c7a1ec1 6 #ifndef INTERVALSCREEN_H
OHstin 0:da2b8c7a1ec1 7 #define INTERVALSCREEN_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 intervals overwhich they would like to plot\n
OHstin 0:da2b8c7a1ec1 14 @brief either temperature or pressure against time\n
OHstin 0:da2b8c7a1ec1 15 @brief Consists of a List controller with 4 selectable options:\n
OHstin 0:da2b8c7a1ec1 16 @brief 100ms, 500ms, 1 second, 5 seconds
OHstin 0:da2b8c7a1ec1 17 @author Augustine K Kizito
OHstin 0:da2b8c7a1ec1 18 @date April 2015
OHstin 0:da2b8c7a1ec1 19 */
OHstin 0:da2b8c7a1ec1 20
OHstin 0:da2b8c7a1ec1 21
OHstin 0:da2b8c7a1ec1 22 class IntervalScreen : public ListController // inherit the list Controller properties
OHstin 0:da2b8c7a1ec1 23 {
OHstin 0:da2b8c7a1ec1 24 private:
OHstin 0:da2b8c7a1ec1 25 bool changeScreen; // tracks if the user pressed a button that changes the screen
OHstin 0:da2b8c7a1ec1 26 int nextScreen; // tracks whether the user wants to go to
OHstin 0:da2b8c7a1ec1 27 //the previous screen or next screen
OHstin 0:da2b8c7a1ec1 28
OHstin 0:da2b8c7a1ec1 29 void onScrollUp(); // user pressed the scroll up button
OHstin 0:da2b8c7a1ec1 30 void onScrollDown(); // user pressed the scroll down button
OHstin 0:da2b8c7a1ec1 31 void onEnter(); // user pressed the enter button
OHstin 0:da2b8c7a1ec1 32 void onBack(); // user pressed the back button
OHstin 0:da2b8c7a1ec1 33
OHstin 0:da2b8c7a1ec1 34 public:
OHstin 0:da2b8c7a1ec1 35 /**
OHstin 0:da2b8c7a1ec1 36 Creates an instance of Interval Screen
OHstin 0:da2b8c7a1ec1 37
OHstin 0:da2b8c7a1ec1 38 */
OHstin 0:da2b8c7a1ec1 39 IntervalScreen()
OHstin 0:da2b8c7a1ec1 40 :ListController( "Interval", // Title
OHstin 0:da2b8c7a1ec1 41 "100ms", // Option 1
OHstin 0:da2b8c7a1ec1 42 "500ms", // Option 2
OHstin 0:da2b8c7a1ec1 43 "1 second", // Option 3
OHstin 0:da2b8c7a1ec1 44 "5 seconds", // Option 4
OHstin 0:da2b8c7a1ec1 45 4) // Number of Options
OHstin 0:da2b8c7a1ec1 46 {};
OHstin 0:da2b8c7a1ec1 47
OHstin 0:da2b8c7a1ec1 48 /**
OHstin 0:da2b8c7a1ec1 49 Manages the execution of the Interval Screen
OHstin 0:da2b8c7a1ec1 50
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\n
OHstin 0:da2b8c7a1ec1 56 2 - User selected option 3\n
OHstin 0:da2b8c7a1ec1 57 3 - User selected option 4\n
OHstin 0:da2b8c7a1ec1 58
OHstin 0:da2b8c7a1ec1 59 */
OHstin 0:da2b8c7a1ec1 60 int start();
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 int IntervalScreen::start()
OHstin 0:da2b8c7a1ec1 79 {
OHstin 0:da2b8c7a1ec1 80
OHstin 0:da2b8c7a1ec1 81 // Activate PullDown Resistors
OHstin 0:da2b8c7a1ec1 82 enterButton.mode(PullDown);
OHstin 0:da2b8c7a1ec1 83 upButton.mode(PullDown);
OHstin 0:da2b8c7a1ec1 84 downButton.mode(PullDown);
OHstin 0:da2b8c7a1ec1 85 backButton.mode(PullDown);
OHstin 0:da2b8c7a1ec1 86
OHstin 0:da2b8c7a1ec1 87 upButton.rise(this,&IntervalScreen::onScrollUp); // call onScrollUp when the up button is pressed
OHstin 0:da2b8c7a1ec1 88 downButton.rise(this,&IntervalScreen::onScrollDown); // call onScrollDown when the down button is pressed
OHstin 0:da2b8c7a1ec1 89 enterButton.rise(this,&IntervalScreen::onEnter); // call onEnter when the enter button is pressed
OHstin 0:da2b8c7a1ec1 90 backButton.rise(this,&IntervalScreen::onBack); // call onBack when the back button is pressed
OHstin 0:da2b8c7a1ec1 91
OHstin 0:da2b8c7a1ec1 92 ListController::showInfo(); // launch the List Controller
OHstin 0:da2b8c7a1ec1 93 changeScreen = false;
OHstin 0:da2b8c7a1ec1 94
OHstin 0:da2b8c7a1ec1 95 debounce.start(); // start the debounce timer
OHstin 0:da2b8c7a1ec1 96
OHstin 0:da2b8c7a1ec1 97 while(!changeScreen) {
OHstin 0:da2b8c7a1ec1 98
OHstin 0:da2b8c7a1ec1 99 // mbed goes to sleep to save power
OHstin 0:da2b8c7a1ec1 100 Sleep();
OHstin 0:da2b8c7a1ec1 101 }
OHstin 0:da2b8c7a1ec1 102
OHstin 0:da2b8c7a1ec1 103 // detach all interrupts
OHstin 0:da2b8c7a1ec1 104 upButton.rise(NULL);
OHstin 0:da2b8c7a1ec1 105 downButton.rise(NULL);
OHstin 0:da2b8c7a1ec1 106 enterButton.rise(NULL);
OHstin 0:da2b8c7a1ec1 107 backButton.rise(NULL);
OHstin 0:da2b8c7a1ec1 108
OHstin 0:da2b8c7a1ec1 109 return nextScreen;
OHstin 0:da2b8c7a1ec1 110 }
OHstin 0:da2b8c7a1ec1 111
OHstin 0:da2b8c7a1ec1 112 void IntervalScreen::onScrollUp()
OHstin 0:da2b8c7a1ec1 113 {
OHstin 0:da2b8c7a1ec1 114 if (debounceSuccess()) { // check if debouncing succeeded
OHstin 0:da2b8c7a1ec1 115
OHstin 0:da2b8c7a1ec1 116 ListController::scrollUp(); // scroll up
OHstin 0:da2b8c7a1ec1 117 debounce.reset(); // reset the debounce timer
OHstin 0:da2b8c7a1ec1 118 }
OHstin 0:da2b8c7a1ec1 119 }
OHstin 0:da2b8c7a1ec1 120
OHstin 0:da2b8c7a1ec1 121 void IntervalScreen::onScrollDown()
OHstin 0:da2b8c7a1ec1 122 {
OHstin 0:da2b8c7a1ec1 123 if (debounceSuccess()) { // check if debouncing succeeded
OHstin 0:da2b8c7a1ec1 124
OHstin 0:da2b8c7a1ec1 125 ListController::scrollDown(); // scroll down
OHstin 0:da2b8c7a1ec1 126 debounce.reset(); // reset the debounce timer
OHstin 0:da2b8c7a1ec1 127 }
OHstin 0:da2b8c7a1ec1 128 }
OHstin 0:da2b8c7a1ec1 129
OHstin 0:da2b8c7a1ec1 130 void IntervalScreen::onEnter()
OHstin 0:da2b8c7a1ec1 131 {
OHstin 0:da2b8c7a1ec1 132 if (debounceSuccess()) { // check if debouncing succeeded
OHstin 0:da2b8c7a1ec1 133 // sound the buzzer
OHstin 0:da2b8c7a1ec1 134 playSound();
OHstin 0:da2b8c7a1ec1 135 nextScreen = ListController::getCurrentOption(); // get the option that user selected
OHstin 0:da2b8c7a1ec1 136 changeScreen = true; // user wants to go to a different screen
OHstin 0:da2b8c7a1ec1 137 debounce.reset(); // reset the debounce timer
OHstin 0:da2b8c7a1ec1 138 }
OHstin 0:da2b8c7a1ec1 139 }
OHstin 0:da2b8c7a1ec1 140
OHstin 0:da2b8c7a1ec1 141 void IntervalScreen::onBack()
OHstin 0:da2b8c7a1ec1 142 {
OHstin 0:da2b8c7a1ec1 143 if(debounceSuccess()) {
OHstin 0:da2b8c7a1ec1 144 // sound the buzzer
OHstin 0:da2b8c7a1ec1 145 playSound();
OHstin 0:da2b8c7a1ec1 146 nextScreen = -1; // go to previous screen
OHstin 0:da2b8c7a1ec1 147 changeScreen = true; // user wants to go to a different screen
OHstin 0:da2b8c7a1ec1 148 debounce.reset(); // reset the debounce timer
OHstin 0:da2b8c7a1ec1 149 }
OHstin 0:da2b8c7a1ec1 150
OHstin 0:da2b8c7a1ec1 151 }
OHstin 0:da2b8c7a1ec1 152
OHstin 0:da2b8c7a1ec1 153 #endif