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 CurrentPressureScreen.h
OHstin 0:da2b8c7a1ec1 3
OHstin 0:da2b8c7a1ec1 4
OHstin 0:da2b8c7a1ec1 5 */
OHstin 0:da2b8c7a1ec1 6
OHstin 0:da2b8c7a1ec1 7
OHstin 0:da2b8c7a1ec1 8 #ifndef CURRENTPRESSURESCREEN_H
OHstin 0:da2b8c7a1ec1 9 #define CURRENTPRESSURESCREEN_H
OHstin 0:da2b8c7a1ec1 10
OHstin 0:da2b8c7a1ec1 11 #include "ParameterController.h"
OHstin 0:da2b8c7a1ec1 12 #include "Inputs.h"
OHstin 0:da2b8c7a1ec1 13 #include "Sensors.h"
OHstin 0:da2b8c7a1ec1 14
OHstin 0:da2b8c7a1ec1 15 /**
OHstin 0:da2b8c7a1ec1 16 @brief Displays the current pressure along with it's sentiment on the LCD screen\n
OHstin 0:da2b8c7a1ec1 17 @brief It consists of a parameter controller\n
OHstin 0:da2b8c7a1ec1 18 @brief pressure is shown in mbars by default but can be toggled to kPscl\n
OHstin 0:da2b8c7a1ec1 19 @brief when the enter button is pressed \n
OHstin 0:da2b8c7a1ec1 20 @author Augustine Kizito K \n
OHstin 0:da2b8c7a1ec1 21 @date April 2015 \n
OHstin 0:da2b8c7a1ec1 22
OHstin 0:da2b8c7a1ec1 23 */
OHstin 0:da2b8c7a1ec1 24
OHstin 0:da2b8c7a1ec1 25
OHstin 0:da2b8c7a1ec1 26 class CurrentPressureScreen : public ParameterController // inherit ParameterController Properties
OHstin 0:da2b8c7a1ec1 27 {
OHstin 0:da2b8c7a1ec1 28 private:
OHstin 0:da2b8c7a1ec1 29 void setPressureSentiment( float pressure); // get pressure sentiment
OHstin 0:da2b8c7a1ec1 30 void pressureUpdate(); // update the pressure
OHstin 0:da2b8c7a1ec1 31 float getCurrentPressure(); // get the current temperature
OHstin 0:da2b8c7a1ec1 32 void changeUnits(); // change units form mbar to Pa
OHstin 0:da2b8c7a1ec1 33 void onBack(); // user pressed the back button
OHstin 0:da2b8c7a1ec1 34 void onEnter(); // user pressed the enter button
OHstin 0:da2b8c7a1ec1 35
OHstin 0:da2b8c7a1ec1 36 bool changeScreen; // tracks if the user pressed a button that changes screen
OHstin 0:da2b8c7a1ec1 37 int nextScreen; // tracks whether the user wants to go to
OHstin 0:da2b8c7a1ec1 38 //the previous screen or next screen
OHstin 0:da2b8c7a1ec1 39 bool mbar; // tracks the current units of pressure
OHstin 0:da2b8c7a1ec1 40 Ticker prsTicker; // create ticker object
OHstin 0:da2b8c7a1ec1 41
OHstin 0:da2b8c7a1ec1 42
OHstin 0:da2b8c7a1ec1 43 public:
OHstin 0:da2b8c7a1ec1 44 /**
OHstin 0:da2b8c7a1ec1 45 This function manages the execution of the current pressure screen
OHstin 0:da2b8c7a1ec1 46
OHstin 0:da2b8c7a1ec1 47 */
OHstin 0:da2b8c7a1ec1 48 int start();
OHstin 0:da2b8c7a1ec1 49 /**
OHstin 0:da2b8c7a1ec1 50 Creates an instance of the Current Pressure Screen
OHstin 0:da2b8c7a1ec1 51
OHstin 0:da2b8c7a1ec1 52 returns
OHstin 0:da2b8c7a1ec1 53 -1 - navigate to previous screen
OHstin 0:da2b8c7a1ec1 54 */
OHstin 0:da2b8c7a1ec1 55 CurrentPressureScreen()
OHstin 0:da2b8c7a1ec1 56 :ParameterController( "Pressure", // Parameter
OHstin 0:da2b8c7a1ec1 57 "mbars") // Units
OHstin 0:da2b8c7a1ec1 58 {} // initialises parameter controller
OHstin 0:da2b8c7a1ec1 59
OHstin 0:da2b8c7a1ec1 60 };
OHstin 0:da2b8c7a1ec1 61
OHstin 0:da2b8c7a1ec1 62 int CurrentPressureScreen::start()
OHstin 0:da2b8c7a1ec1 63 {
OHstin 0:da2b8c7a1ec1 64
OHstin 0:da2b8c7a1ec1 65 changeScreen = false;
OHstin 0:da2b8c7a1ec1 66 mbar = true; // units are in millibars
OHstin 0:da2b8c7a1ec1 67
OHstin 0:da2b8c7a1ec1 68 float currentPressure = getCurrentPressure(); // get current temperature
OHstin 0:da2b8c7a1ec1 69
OHstin 0:da2b8c7a1ec1 70 backButton.mode(PullDown); // activate pullDown resistor
OHstin 0:da2b8c7a1ec1 71 enterButton.mode(PullDown); // activate pullDown resistor
OHstin 0:da2b8c7a1ec1 72
OHstin 0:da2b8c7a1ec1 73 backButton.rise(this,&CurrentPressureScreen::onBack); // call onBack when the back button is pressed
OHstin 0:da2b8c7a1ec1 74 enterButton.rise(this,&CurrentPressureScreen::onEnter); // call onBack when the back button is pressed
OHstin 0:da2b8c7a1ec1 75
OHstin 0:da2b8c7a1ec1 76 debounce.start(); // start the debouncing timer
OHstin 0:da2b8c7a1ec1 77
OHstin 0:da2b8c7a1ec1 78 prsTicker.attach(this, &CurrentPressureScreen::pressureUpdate, 10); // update parameter every 30 seconds
OHstin 0:da2b8c7a1ec1 79
OHstin 0:da2b8c7a1ec1 80 // initialise the ParameterController appropriately
OHstin 0:da2b8c7a1ec1 81 ParameterController::setValue(currentPressure);
OHstin 0:da2b8c7a1ec1 82 setPressureSentiment(currentPressure);
OHstin 0:da2b8c7a1ec1 83
OHstin 0:da2b8c7a1ec1 84 // Launch the Parameter Controller
OHstin 0:da2b8c7a1ec1 85 ParameterController::showInfo();
OHstin 0:da2b8c7a1ec1 86
OHstin 0:da2b8c7a1ec1 87 while(!changeScreen) { // shows the menu screen until the user presses the back button
OHstin 0:da2b8c7a1ec1 88 // mbed goes to sleep to save power
OHstin 0:da2b8c7a1ec1 89 Sleep();
OHstin 0:da2b8c7a1ec1 90 }
OHstin 0:da2b8c7a1ec1 91
OHstin 0:da2b8c7a1ec1 92 // detach interrupts
OHstin 0:da2b8c7a1ec1 93 backButton.rise(NULL);
OHstin 0:da2b8c7a1ec1 94 enterButton.rise(NULL);
OHstin 0:da2b8c7a1ec1 95 prsTicker.detach();
OHstin 0:da2b8c7a1ec1 96
OHstin 0:da2b8c7a1ec1 97 return nextScreen;
OHstin 0:da2b8c7a1ec1 98 }
OHstin 0:da2b8c7a1ec1 99
OHstin 0:da2b8c7a1ec1 100 void CurrentPressureScreen::pressureUpdate()
OHstin 0:da2b8c7a1ec1 101 {
OHstin 0:da2b8c7a1ec1 102
OHstin 0:da2b8c7a1ec1 103 float currentPressure = getCurrentPressure(); // get current temperature
OHstin 0:da2b8c7a1ec1 104 // update the pressure sentiment
OHstin 0:da2b8c7a1ec1 105 setPressureSentiment(currentPressure);
OHstin 0:da2b8c7a1ec1 106
OHstin 0:da2b8c7a1ec1 107 if (!mbar) { // units are currently is Pascals
OHstin 0:da2b8c7a1ec1 108 //convert to Pascal
OHstin 0:da2b8c7a1ec1 109 currentPressure = (currentPressure*9/5)+32;
OHstin 0:da2b8c7a1ec1 110 }
OHstin 0:da2b8c7a1ec1 111
OHstin 0:da2b8c7a1ec1 112 // initialise the ParameterController appropriately
OHstin 0:da2b8c7a1ec1 113 ParameterController::setValue(currentPressure);
OHstin 0:da2b8c7a1ec1 114 ParameterController::updateInfo();
OHstin 0:da2b8c7a1ec1 115
OHstin 0:da2b8c7a1ec1 116 }
OHstin 0:da2b8c7a1ec1 117
OHstin 0:da2b8c7a1ec1 118
OHstin 0:da2b8c7a1ec1 119 void CurrentPressureScreen::setPressureSentiment(float pressure)
OHstin 0:da2b8c7a1ec1 120 {
OHstin 0:da2b8c7a1ec1 121
OHstin 0:da2b8c7a1ec1 122 if (pressure >= 1000 ) { // Sunny if temperatuure is 1000mb or higher
OHstin 0:da2b8c7a1ec1 123 ParameterController::setSentiment("Sunny :-) ");
OHstin 0:da2b8c7a1ec1 124 } else if ( pressure < 1000 && pressure >= 980 ) {
OHstin 0:da2b8c7a1ec1 125 ParameterController::setSentiment("Sunny & Clouds"); // Sunny with clouds
OHstin 0:da2b8c7a1ec1 126 } else if ( pressure < 980 && pressure >= 960 ) {
OHstin 0:da2b8c7a1ec1 127 ParameterController::setSentiment("Cloudy "); // Cloudy
OHstin 0:da2b8c7a1ec1 128 } else if ( pressure < 960 && pressure >= 940 ) {
OHstin 0:da2b8c7a1ec1 129 ParameterController::setSentiment("Rainy "); // Rainy
OHstin 0:da2b8c7a1ec1 130 } else if ( pressure < 940 && pressure >= 920 ) {
OHstin 0:da2b8c7a1ec1 131 ParameterController::setSentiment("Stormy! "); // Stormy
OHstin 0:da2b8c7a1ec1 132 } else {
OHstin 0:da2b8c7a1ec1 133 ParameterController::setSentiment("Thunderstorm!!"); // Thunderstorm
OHstin 0:da2b8c7a1ec1 134 }
OHstin 0:da2b8c7a1ec1 135
OHstin 0:da2b8c7a1ec1 136 }
OHstin 0:da2b8c7a1ec1 137
OHstin 0:da2b8c7a1ec1 138 float CurrentPressureScreen::getCurrentPressure()
OHstin 0:da2b8c7a1ec1 139 {
OHstin 0:da2b8c7a1ec1 140 float pressure = getPressure(); // read temperature from BMP180 sensor
OHstin 0:da2b8c7a1ec1 141 return pressure;
OHstin 0:da2b8c7a1ec1 142 }
OHstin 0:da2b8c7a1ec1 143
OHstin 0:da2b8c7a1ec1 144 void CurrentPressureScreen::onBack()
OHstin 0:da2b8c7a1ec1 145 {
OHstin 0:da2b8c7a1ec1 146 if (debounceSuccess()) { // debouncing was successful
OHstin 0:da2b8c7a1ec1 147 playSound(); // play sound from buzzer
OHstin 0:da2b8c7a1ec1 148 nextScreen = -1;
OHstin 0:da2b8c7a1ec1 149 changeScreen = true; // user wants to view a different screen
OHstin 0:da2b8c7a1ec1 150 debounce.reset(); // reset the timer
OHstin 0:da2b8c7a1ec1 151 }
OHstin 0:da2b8c7a1ec1 152
OHstin 0:da2b8c7a1ec1 153
OHstin 0:da2b8c7a1ec1 154 }
OHstin 0:da2b8c7a1ec1 155
OHstin 0:da2b8c7a1ec1 156 void CurrentPressureScreen::onEnter()
OHstin 0:da2b8c7a1ec1 157 {
OHstin 0:da2b8c7a1ec1 158 if (debounceSuccess()) { // debouncing was successful
OHstin 0:da2b8c7a1ec1 159 //sound the buzzer
OHstin 0:da2b8c7a1ec1 160 playSound();
OHstin 0:da2b8c7a1ec1 161 changeUnits(); // change the units
OHstin 0:da2b8c7a1ec1 162 debounce.reset(); // reset the debounce timer
OHstin 0:da2b8c7a1ec1 163 }
OHstin 0:da2b8c7a1ec1 164
OHstin 0:da2b8c7a1ec1 165 }
OHstin 0:da2b8c7a1ec1 166
OHstin 0:da2b8c7a1ec1 167 void CurrentPressureScreen::changeUnits()
OHstin 0:da2b8c7a1ec1 168 {
OHstin 0:da2b8c7a1ec1 169 // toggle the units form Cel to Fahr and back
OHstin 0:da2b8c7a1ec1 170 mbar = !mbar;
OHstin 0:da2b8c7a1ec1 171
OHstin 0:da2b8c7a1ec1 172 float currentPressure = getCurrentPressure(); // get current temperature
OHstin 0:da2b8c7a1ec1 173 // update the pressure sentiment
OHstin 0:da2b8c7a1ec1 174 setPressureSentiment(currentPressure);
OHstin 0:da2b8c7a1ec1 175
OHstin 0:da2b8c7a1ec1 176 if (mbar) { // units are in milibars
OHstin 0:da2b8c7a1ec1 177 ParameterController::setUnit("mbars");
OHstin 0:da2b8c7a1ec1 178 } else { // units are in Pascals
OHstin 0:da2b8c7a1ec1 179 ParameterController::setUnit("kPscl");
OHstin 0:da2b8c7a1ec1 180 //convert to kilo Pascals
OHstin 0:da2b8c7a1ec1 181 currentPressure = currentPressure/10;
OHstin 0:da2b8c7a1ec1 182
OHstin 0:da2b8c7a1ec1 183 }
OHstin 0:da2b8c7a1ec1 184
OHstin 0:da2b8c7a1ec1 185 // update the ParameterController appropriately
OHstin 0:da2b8c7a1ec1 186 ParameterController::setValue(currentPressure);
OHstin 0:da2b8c7a1ec1 187 ParameterController::updateInfo();
OHstin 0:da2b8c7a1ec1 188
OHstin 0:da2b8c7a1ec1 189 }
OHstin 0:da2b8c7a1ec1 190
OHstin 0:da2b8c7a1ec1 191
OHstin 0:da2b8c7a1ec1 192
OHstin 0:da2b8c7a1ec1 193 #endif