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