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 CurrentTemperatureScreen.h
OHstin 0:da2b8c7a1ec1 3
OHstin 0:da2b8c7a1ec1 4
OHstin 0:da2b8c7a1ec1 5
OHstin 0:da2b8c7a1ec1 6 */
OHstin 0:da2b8c7a1ec1 7 #ifndef CURRENTTEMPERATURESCREEN_H
OHstin 0:da2b8c7a1ec1 8 #define CURRENTTEMPERATURESCREEN_H
OHstin 0:da2b8c7a1ec1 9
OHstin 0:da2b8c7a1ec1 10 #include "ParameterController.h"
OHstin 0:da2b8c7a1ec1 11 #include "Inputs.h"
OHstin 0:da2b8c7a1ec1 12 #include "Sensors.h"
OHstin 0:da2b8c7a1ec1 13
OHstin 0:da2b8c7a1ec1 14 /**
OHstin 0:da2b8c7a1ec1 15 @brief Displays the current temperature along with it's sentiment on the LCD screen\n
OHstin 0:da2b8c7a1ec1 16 @brief It consists of a parameter controller\n
OHstin 0:da2b8c7a1ec1 17 @brief temperature is shown in deg cel by default but can be toggled to deg fahr\n
OHstin 0:da2b8c7a1ec1 18 @brief whent the enter button is pressed\n
OHstin 0:da2b8c7a1ec1 19 @author Augustine Kizito K\n
OHstin 0:da2b8c7a1ec1 20 @date April 2015
OHstin 0:da2b8c7a1ec1 21 */
OHstin 0:da2b8c7a1ec1 22
OHstin 0:da2b8c7a1ec1 23
OHstin 0:da2b8c7a1ec1 24
OHstin 0:da2b8c7a1ec1 25
OHstin 0:da2b8c7a1ec1 26 class CurrentTemperatureScreen : public ParameterController // inherit ParameterController Properties
OHstin 0:da2b8c7a1ec1 27 {
OHstin 0:da2b8c7a1ec1 28 private:
OHstin 0:da2b8c7a1ec1 29 void setTemperatureSentiment( float temperature); // get temperature sentiment
OHstin 0:da2b8c7a1ec1 30 void temperatureUpdate(); // update the temperature
OHstin 0:da2b8c7a1ec1 31 float getCurrentTemperature(); // get the current temperature
OHstin 0:da2b8c7a1ec1 32 void changeUnits(); // change units form celsius to fahrenheit
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 celsius; // tracks the current units of temperature
OHstin 0:da2b8c7a1ec1 40 Ticker tempTicker; // 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 temperature screen
OHstin 0:da2b8c7a1ec1 46
OHstin 0:da2b8c7a1ec1 47 @ returns
OHstin 0:da2b8c7a1ec1 48 -1 - navigate to previous screen
OHstin 0:da2b8c7a1ec1 49 */
OHstin 0:da2b8c7a1ec1 50 int start();
OHstin 0:da2b8c7a1ec1 51 /**
OHstin 0:da2b8c7a1ec1 52 This function creates an instance of the current temperature scren
OHstin 0:da2b8c7a1ec1 53
OHstin 0:da2b8c7a1ec1 54 */
OHstin 0:da2b8c7a1ec1 55 CurrentTemperatureScreen()
OHstin 0:da2b8c7a1ec1 56 :ParameterController( "Temperature", // Parameter
OHstin 0:da2b8c7a1ec1 57 "Deg Cel") // 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 CurrentTemperatureScreen::start()
OHstin 0:da2b8c7a1ec1 63 {
OHstin 0:da2b8c7a1ec1 64
OHstin 0:da2b8c7a1ec1 65 changeScreen = false;
OHstin 0:da2b8c7a1ec1 66 celsius = true; // units are in celsius
OHstin 0:da2b8c7a1ec1 67
OHstin 0:da2b8c7a1ec1 68 float currentTemperature = getCurrentTemperature(); // 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,&CurrentTemperatureScreen::onBack); // call onBack when the back button is pressed
OHstin 0:da2b8c7a1ec1 74 enterButton.rise(this,&CurrentTemperatureScreen::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 tempTicker.attach(this, &CurrentTemperatureScreen::temperatureUpdate, 10); // update parameter every 30 seconds
OHstin 0:da2b8c7a1ec1 79
OHstin 0:da2b8c7a1ec1 80 // initialise the ParameterController appropriately
OHstin 0:da2b8c7a1ec1 81 ParameterController::setValue(currentTemperature);
OHstin 0:da2b8c7a1ec1 82 setTemperatureSentiment(currentTemperature);
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 == false) { // shows the 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 tempTicker.detach();
OHstin 0:da2b8c7a1ec1 96
OHstin 0:da2b8c7a1ec1 97 return nextScreen;
OHstin 0:da2b8c7a1ec1 98 }
OHstin 0:da2b8c7a1ec1 99
OHstin 0:da2b8c7a1ec1 100 void CurrentTemperatureScreen::temperatureUpdate()
OHstin 0:da2b8c7a1ec1 101 {
OHstin 0:da2b8c7a1ec1 102
OHstin 0:da2b8c7a1ec1 103 float currentTemperature = getCurrentTemperature(); // get current temperature
OHstin 0:da2b8c7a1ec1 104 setTemperatureSentiment(currentTemperature); // update the temperature sentiment
OHstin 0:da2b8c7a1ec1 105
OHstin 0:da2b8c7a1ec1 106 if (!celsius) { // units are in celsius
OHstin 0:da2b8c7a1ec1 107 //convert to fahrenheit
OHstin 0:da2b8c7a1ec1 108 currentTemperature = (currentTemperature*9/5)+32;
OHstin 0:da2b8c7a1ec1 109 }
OHstin 0:da2b8c7a1ec1 110
OHstin 0:da2b8c7a1ec1 111 // initialise the ParameterController appropriately
OHstin 0:da2b8c7a1ec1 112 ParameterController::setValue(currentTemperature);
OHstin 0:da2b8c7a1ec1 113 ParameterController::updateInfo();
OHstin 0:da2b8c7a1ec1 114
OHstin 0:da2b8c7a1ec1 115 }
OHstin 0:da2b8c7a1ec1 116
OHstin 0:da2b8c7a1ec1 117
OHstin 0:da2b8c7a1ec1 118 void CurrentTemperatureScreen::setTemperatureSentiment(float temperature)
OHstin 0:da2b8c7a1ec1 119 {
OHstin 0:da2b8c7a1ec1 120
OHstin 0:da2b8c7a1ec1 121 if (temperature > 35) { // Blazing if temperature is greature than 35 Deg
OHstin 0:da2b8c7a1ec1 122 ParameterController::setSentiment("Blazing ");
OHstin 0:da2b8c7a1ec1 123 } else if ( temperature <= 35 && temperature > 25 ) {
OHstin 0:da2b8c7a1ec1 124 ParameterController::setSentiment("Hot "); // Hot if temperature is between 35 and 25 Deg Cel
OHstin 0:da2b8c7a1ec1 125 } else if ( temperature <= 25 && temperature > 20 ) {
OHstin 0:da2b8c7a1ec1 126 ParameterController::setSentiment("Warm "); // Warm if temperature is between 25 and 20 Deg Cel
OHstin 0:da2b8c7a1ec1 127 } else if ( temperature <= 20 && temperature > 15 ) {
OHstin 0:da2b8c7a1ec1 128 ParameterController::setSentiment("Cool "); // Cool if temperature is between 20 and 15 Deg Cel
OHstin 0:da2b8c7a1ec1 129 } else if ( temperature <= 15 && temperature >= 10 ) {
OHstin 0:da2b8c7a1ec1 130 ParameterController::setSentiment("Cold "); // Cold if temperature is between 15 and 10 Deg Cel
OHstin 0:da2b8c7a1ec1 131 } else {
OHstin 0:da2b8c7a1ec1 132 ParameterController::setSentiment("Frigid "); // Frigid if temperature is less than 10
OHstin 0:da2b8c7a1ec1 133 }
OHstin 0:da2b8c7a1ec1 134
OHstin 0:da2b8c7a1ec1 135 }
OHstin 0:da2b8c7a1ec1 136
OHstin 0:da2b8c7a1ec1 137 float CurrentTemperatureScreen::getCurrentTemperature()
OHstin 0:da2b8c7a1ec1 138 {
OHstin 0:da2b8c7a1ec1 139 float temperature = getTemperature(); // read temperature from BMP180 sensor
OHstin 0:da2b8c7a1ec1 140 return temperature;
OHstin 0:da2b8c7a1ec1 141 }
OHstin 0:da2b8c7a1ec1 142
OHstin 0:da2b8c7a1ec1 143 void CurrentTemperatureScreen::onBack()
OHstin 0:da2b8c7a1ec1 144 {
OHstin 0:da2b8c7a1ec1 145 if (debounceSuccess()) { // debugging successful
OHstin 0:da2b8c7a1ec1 146 playSound(); // play sound from buzzer
OHstin 0:da2b8c7a1ec1 147 nextScreen = -1;
OHstin 0:da2b8c7a1ec1 148 changeScreen = true; // user wants to view a different screen
OHstin 0:da2b8c7a1ec1 149 debounce.reset(); // reset the timer
OHstin 0:da2b8c7a1ec1 150 }
OHstin 0:da2b8c7a1ec1 151
OHstin 0:da2b8c7a1ec1 152
OHstin 0:da2b8c7a1ec1 153 }
OHstin 0:da2b8c7a1ec1 154
OHstin 0:da2b8c7a1ec1 155 void CurrentTemperatureScreen::onEnter()
OHstin 0:da2b8c7a1ec1 156 {
OHstin 0:da2b8c7a1ec1 157 if (debounceSuccess()) { // debugging successful
OHstin 0:da2b8c7a1ec1 158 playSound(); // sound the buzzer
OHstin 0:da2b8c7a1ec1 159 changeUnits(); // change the units
OHstin 0:da2b8c7a1ec1 160 debounce.reset(); // reset the timer
OHstin 0:da2b8c7a1ec1 161 }
OHstin 0:da2b8c7a1ec1 162
OHstin 0:da2b8c7a1ec1 163 }
OHstin 0:da2b8c7a1ec1 164
OHstin 0:da2b8c7a1ec1 165 void CurrentTemperatureScreen::changeUnits()
OHstin 0:da2b8c7a1ec1 166 {
OHstin 0:da2b8c7a1ec1 167 // toggle the units form Cel to Fahr and back
OHstin 0:da2b8c7a1ec1 168 celsius = !celsius;
OHstin 0:da2b8c7a1ec1 169
OHstin 0:da2b8c7a1ec1 170 float currentTemperature = getCurrentTemperature(); // get current temperature
OHstin 0:da2b8c7a1ec1 171 setTemperatureSentiment(currentTemperature);
OHstin 0:da2b8c7a1ec1 172
OHstin 0:da2b8c7a1ec1 173 if (celsius) { // Units are in celsius
OHstin 0:da2b8c7a1ec1 174 ParameterController::setUnit("Deg Cel ");
OHstin 0:da2b8c7a1ec1 175 } else { // Units are in Fahrenheit
OHstin 0:da2b8c7a1ec1 176 ParameterController::setUnit("Deg Fahr");
OHstin 0:da2b8c7a1ec1 177 //convert to fahrenheit
OHstin 0:da2b8c7a1ec1 178 currentTemperature = (currentTemperature*9/5)+32;
OHstin 0:da2b8c7a1ec1 179
OHstin 0:da2b8c7a1ec1 180 }
OHstin 0:da2b8c7a1ec1 181
OHstin 0:da2b8c7a1ec1 182 // update the ParameterController appropriately
OHstin 0:da2b8c7a1ec1 183 ParameterController::setValue(currentTemperature);
OHstin 0:da2b8c7a1ec1 184 ParameterController::updateInfo();
OHstin 0:da2b8c7a1ec1 185
OHstin 0:da2b8c7a1ec1 186 }
OHstin 0:da2b8c7a1ec1 187
OHstin 0:da2b8c7a1ec1 188
OHstin 0:da2b8c7a1ec1 189
OHstin 0:da2b8c7a1ec1 190 #endif