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 temperatureplot.h
OHstin 0:da2b8c7a1ec1 3 */
OHstin 0:da2b8c7a1ec1 4 #ifndef TEMPERATUREPLOT_H
OHstin 0:da2b8c7a1ec1 5 #define TEMPERATUREPLOT_H
OHstin 0:da2b8c7a1ec1 6
OHstin 0:da2b8c7a1ec1 7 /**
OHstin 0:da2b8c7a1ec1 8 @brief displays the temperature against time at various intervals
OHstin 0:da2b8c7a1ec1 9 @brief temperature is in degrees celsius
OHstin 0:da2b8c7a1ec1 10 @author Augustine K Kizito
OHstin 0:da2b8c7a1ec1 11 @data April 2015
OHstin 0:da2b8c7a1ec1 12 */
OHstin 0:da2b8c7a1ec1 13
OHstin 0:da2b8c7a1ec1 14
OHstin 0:da2b8c7a1ec1 15
OHstin 0:da2b8c7a1ec1 16
OHstin 0:da2b8c7a1ec1 17 class TemperaturePlot
OHstin 0:da2b8c7a1ec1 18 {
OHstin 0:da2b8c7a1ec1 19 private:
OHstin 0:da2b8c7a1ec1 20 bool changeScreen; // tracks if the user pressed a button that changes the screen
OHstin 0:da2b8c7a1ec1 21 int nextScreen; // tracks whether the user wants to go to
OHstin 0:da2b8c7a1ec1 22 //the previous screen or next screen
OHstin 0:da2b8c7a1ec1 23 int xCord; // tracks the x coordinate
OHstin 0:da2b8c7a1ec1 24 char tempString[32]; // temperature value as string
OHstin 0:da2b8c7a1ec1 25 bool pause; // tracks if the plotting has been paused
OHstin 0:da2b8c7a1ec1 26 int pInterval; // determines the intervals at which data is plotted
OHstin 0:da2b8c7a1ec1 27 Ticker timer; // plots data at particular intervals
OHstin 0:da2b8c7a1ec1 28
OHstin 0:da2b8c7a1ec1 29 void onBack(); // user pressed the back button
OHstin 0:da2b8c7a1ec1 30 void onEnter(); // user pressed the on enter button
OHstin 0:da2b8c7a1ec1 31 void plotData(); // plot temperature data
OHstin 0:da2b8c7a1ec1 32 void clearPlot(); // clear the plotted data
OHstin 0:da2b8c7a1ec1 33 void pausePlot(); // it pauses plotting of data so that the user can see it
OHstin 0:da2b8c7a1ec1 34
OHstin 0:da2b8c7a1ec1 35 public:
OHstin 0:da2b8c7a1ec1 36 /**
OHstin 0:da2b8c7a1ec1 37 Manages the execution of the Temperature Plot Screen
OHstin 0:da2b8c7a1ec1 38
OHstin 0:da2b8c7a1ec1 39 @param - integer interval, the intervals after which temperature is plotted against time on the LCD screen
OHstin 0:da2b8c7a1ec1 40 @returns
OHstin 0:da2b8c7a1ec1 41 -1 - navigate to previous screen
OHstin 0:da2b8c7a1ec1 42
OHstin 0:da2b8c7a1ec1 43 */
OHstin 0:da2b8c7a1ec1 44 int start(int interval);
OHstin 0:da2b8c7a1ec1 45
OHstin 0:da2b8c7a1ec1 46 };
OHstin 0:da2b8c7a1ec1 47
OHstin 0:da2b8c7a1ec1 48 int TemperaturePlot::start(int interval)
OHstin 0:da2b8c7a1ec1 49 {
OHstin 0:da2b8c7a1ec1 50 // Initialisations
OHstin 0:da2b8c7a1ec1 51 pInterval = interval;
OHstin 0:da2b8c7a1ec1 52 xCord = 0; // set the x cordinate to 0
OHstin 0:da2b8c7a1ec1 53 pause = false;
OHstin 0:da2b8c7a1ec1 54
OHstin 0:da2b8c7a1ec1 55 backButton.mode(PullDown); // activate pullDown Resistor
OHstin 0:da2b8c7a1ec1 56 enterButton.mode(PullDown); // activate pullDown Resistor
OHstin 0:da2b8c7a1ec1 57
OHstin 0:da2b8c7a1ec1 58 backButton.rise(this,&TemperaturePlot::onBack); // call onBack when the back button is pressed
OHstin 0:da2b8c7a1ec1 59 enterButton.rise(this,&TemperaturePlot::onEnter); // call onBack when the back button is pressed
OHstin 0:da2b8c7a1ec1 60
OHstin 0:da2b8c7a1ec1 61 plotData(); //plot data onto the screen
OHstin 0:da2b8c7a1ec1 62 lcd.printString("Deg Cel", 40,1);
OHstin 0:da2b8c7a1ec1 63
OHstin 0:da2b8c7a1ec1 64 // plot data on LCD screen depending on the interval previously selected by the user
OHstin 0:da2b8c7a1ec1 65 if ( interval == 0) {
OHstin 0:da2b8c7a1ec1 66 timer.attach(this, &TemperaturePlot::plotData,0.1); // call ISR every 1.0 second
OHstin 0:da2b8c7a1ec1 67 } else if ( interval == 1) {
OHstin 0:da2b8c7a1ec1 68 timer.attach(this, &TemperaturePlot::plotData,0.5); // call ISR every 5 seconds
OHstin 0:da2b8c7a1ec1 69 } else if ( interval == 2) {
OHstin 0:da2b8c7a1ec1 70 timer.attach(this, &TemperaturePlot::plotData,1); // call ISR every 10 seconds
OHstin 0:da2b8c7a1ec1 71 } else {
OHstin 0:da2b8c7a1ec1 72 timer.attach(this, &TemperaturePlot::plotData,5); // call ISR every 30 seconds
OHstin 0:da2b8c7a1ec1 73 }
OHstin 0:da2b8c7a1ec1 74
OHstin 0:da2b8c7a1ec1 75 changeScreen = false;
OHstin 0:da2b8c7a1ec1 76 debounce.start(); // start the debounce timer
OHstin 0:da2b8c7a1ec1 77
OHstin 0:da2b8c7a1ec1 78 while (!changeScreen) {
OHstin 0:da2b8c7a1ec1 79
OHstin 0:da2b8c7a1ec1 80 // mbed goes to sleep to save power
OHstin 0:da2b8c7a1ec1 81 Sleep();
OHstin 0:da2b8c7a1ec1 82
OHstin 0:da2b8c7a1ec1 83 }
OHstin 0:da2b8c7a1ec1 84
OHstin 0:da2b8c7a1ec1 85 // remove all interrupts
OHstin 0:da2b8c7a1ec1 86 backButton.rise(NULL);
OHstin 0:da2b8c7a1ec1 87 enterButton.rise(NULL);
OHstin 0:da2b8c7a1ec1 88 timer.detach();
OHstin 0:da2b8c7a1ec1 89 return nextScreen;
OHstin 0:da2b8c7a1ec1 90 }
OHstin 0:da2b8c7a1ec1 91
OHstin 0:da2b8c7a1ec1 92 void TemperaturePlot::plotData()
OHstin 0:da2b8c7a1ec1 93 {
OHstin 0:da2b8c7a1ec1 94 if (xCord > 83 ) {
OHstin 0:da2b8c7a1ec1 95
OHstin 0:da2b8c7a1ec1 96 xCord = 0; // reset the xCord back to zero
OHstin 0:da2b8c7a1ec1 97
OHstin 0:da2b8c7a1ec1 98 clearPlot(); // clear the plot region
OHstin 0:da2b8c7a1ec1 99
OHstin 0:da2b8c7a1ec1 100 }
OHstin 0:da2b8c7a1ec1 101
OHstin 0:da2b8c7a1ec1 102 float temperature = getTemperature(); // retreive temperature from the sensor
OHstin 0:da2b8c7a1ec1 103
OHstin 0:da2b8c7a1ec1 104 lcd.drawLine(xCord,(31*((50-temperature)/50)+16),xCord,47,1);
OHstin 0:da2b8c7a1ec1 105
OHstin 0:da2b8c7a1ec1 106 // print temperature onto the screen
OHstin 0:da2b8c7a1ec1 107 sprintf(tempString,"%0.2f",temperature);
OHstin 0:da2b8c7a1ec1 108 lcd.printString(tempString,0,1);
OHstin 0:da2b8c7a1ec1 109
OHstin 0:da2b8c7a1ec1 110 // increment the coordinate
OHstin 0:da2b8c7a1ec1 111 xCord++;
OHstin 0:da2b8c7a1ec1 112
OHstin 0:da2b8c7a1ec1 113
OHstin 0:da2b8c7a1ec1 114 }
OHstin 0:da2b8c7a1ec1 115
OHstin 0:da2b8c7a1ec1 116 void TemperaturePlot::onBack()
OHstin 0:da2b8c7a1ec1 117 {
OHstin 0:da2b8c7a1ec1 118 if(debounceSuccess()) { // debouncing successful
OHstin 0:da2b8c7a1ec1 119 // soundt the buzze
OHstin 0:da2b8c7a1ec1 120 playSound();
OHstin 0:da2b8c7a1ec1 121 nextScreen = -1;
OHstin 0:da2b8c7a1ec1 122 changeScreen = true; // user wants to go to a different screen
OHstin 0:da2b8c7a1ec1 123 // reset debounce timer
OHstin 0:da2b8c7a1ec1 124 debounce.reset();
OHstin 0:da2b8c7a1ec1 125 }
OHstin 0:da2b8c7a1ec1 126
OHstin 0:da2b8c7a1ec1 127 }
OHstin 0:da2b8c7a1ec1 128
OHstin 0:da2b8c7a1ec1 129 void TemperaturePlot::clearPlot()
OHstin 0:da2b8c7a1ec1 130 {
OHstin 0:da2b8c7a1ec1 131 // clears the plot area
OHstin 0:da2b8c7a1ec1 132
OHstin 0:da2b8c7a1ec1 133 for ( int x = 0; x < 84; x++) {
OHstin 0:da2b8c7a1ec1 134
OHstin 0:da2b8c7a1ec1 135 for ( int y = 16; y < 48; y++) {
OHstin 0:da2b8c7a1ec1 136
OHstin 0:da2b8c7a1ec1 137 lcd.clearPixel(x,y);
OHstin 0:da2b8c7a1ec1 138
OHstin 0:da2b8c7a1ec1 139 }
OHstin 0:da2b8c7a1ec1 140
OHstin 0:da2b8c7a1ec1 141 }
OHstin 0:da2b8c7a1ec1 142
OHstin 0:da2b8c7a1ec1 143 lcd.refresh();
OHstin 0:da2b8c7a1ec1 144
OHstin 0:da2b8c7a1ec1 145 }
OHstin 0:da2b8c7a1ec1 146
OHstin 0:da2b8c7a1ec1 147 void TemperaturePlot::onEnter()
OHstin 0:da2b8c7a1ec1 148 {
OHstin 0:da2b8c7a1ec1 149 if (debounceSuccess()) { // debouncing successful
OHstin 0:da2b8c7a1ec1 150
OHstin 0:da2b8c7a1ec1 151 playSound(); // play sound
OHstin 0:da2b8c7a1ec1 152 pausePlot(); // pause any plotting
OHstin 0:da2b8c7a1ec1 153 debounce.reset(); // reset debounce timer
OHstin 0:da2b8c7a1ec1 154 }
OHstin 0:da2b8c7a1ec1 155
OHstin 0:da2b8c7a1ec1 156 }
OHstin 0:da2b8c7a1ec1 157
OHstin 0:da2b8c7a1ec1 158 void TemperaturePlot::pausePlot()
OHstin 0:da2b8c7a1ec1 159 {
OHstin 0:da2b8c7a1ec1 160 pause = !pause;
OHstin 0:da2b8c7a1ec1 161
OHstin 0:da2b8c7a1ec1 162 if (pause) {
OHstin 0:da2b8c7a1ec1 163 timer.detach(); // detach timer and stop plotting data
OHstin 0:da2b8c7a1ec1 164 } else {
OHstin 0:da2b8c7a1ec1 165
OHstin 0:da2b8c7a1ec1 166 clearPlot(); // clear the plot area
OHstin 0:da2b8c7a1ec1 167 xCord = 0; // start plotting from extreme left
OHstin 0:da2b8c7a1ec1 168 plotData();
OHstin 0:da2b8c7a1ec1 169
OHstin 0:da2b8c7a1ec1 170 // start plotting data again
OHstin 0:da2b8c7a1ec1 171 if ( pInterval == 0) {
OHstin 0:da2b8c7a1ec1 172 timer.attach(this, &TemperaturePlot::plotData,0.1); // call ISR every 0.1 second
OHstin 0:da2b8c7a1ec1 173 } else if ( pInterval == 1) {
OHstin 0:da2b8c7a1ec1 174 timer.attach(this, &TemperaturePlot::plotData,0.5); // call ISR every 0.5 seconds
OHstin 0:da2b8c7a1ec1 175 } else if ( pInterval == 2) {
OHstin 0:da2b8c7a1ec1 176 timer.attach(this, &TemperaturePlot::plotData,1); // call ISR every 1 seconds
OHstin 0:da2b8c7a1ec1 177 } else {
OHstin 0:da2b8c7a1ec1 178 timer.attach(this, &TemperaturePlot::plotData,5); // call ISR every 5 seconds
OHstin 0:da2b8c7a1ec1 179 }
OHstin 0:da2b8c7a1ec1 180
OHstin 0:da2b8c7a1ec1 181
OHstin 0:da2b8c7a1ec1 182 }
OHstin 0:da2b8c7a1ec1 183 }
OHstin 0:da2b8c7a1ec1 184
OHstin 0:da2b8c7a1ec1 185 #endif