Code for a Portable Weather Station built on a PCB.

Dependencies:   BMP180 N5110 PowerControl mbed

Committer:
Volcano_498
Date:
Wed May 06 15:58:08 2015 +0000
Revision:
14:054e6faf0ca8
Parent:
12:1d4b5465ecc1
Revision 1.0.1 . Comments for semihost_powerdown and the block of code commented due to the fact that the function also prevents Flash Memory from being overwritten.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Volcano_498 0:b30f86a9a1c5 1 /**
Volcano_498 0:b30f86a9a1c5 2 @file main.cpp
Volcano_498 0:b30f86a9a1c5 3 @brief Code for a Portable Weather Station to be built on PCB.
Volcano_498 0:b30f86a9a1c5 4 @brief Design Specs: *A small, portable battery-powered data logger that records sensor data at regular intervals.
Volcano_498 0:b30f86a9a1c5 5 @brief -- Minimises mbed power consumption to the greatest extent possible.
Volcano_498 0:b30f86a9a1c5 6 @brief -- Displays the information to the user.
Volcano_498 0:b30f86a9a1c5 7 @brief -- Features a BMP180 pressure and temperature sensor. (TMP102 is unnecessary as BMP180 also takes temp. readings)
Volcano_498 3:70e14f1577f7 8 @brief -- Features a Nokia 5110 display to print the sensor readings over and display them to the user.
Volcano_498 0:b30f86a9a1c5 9 @brief -- Sensor information is recorded on Flash memory on the mbed.
Volcano_498 0:b30f86a9a1c5 10 @brief -- Graph to display data to the user.
Volcano_498 0:b30f86a9a1c5 11 @brief -- mbed is powered by a Buck regulator (5V output) that is in turn supplied by a 9V PP3 battery which powers the PCB.
Volcano_498 0:b30f86a9a1c5 12 @brief -- Audible and visual alert when a threshold reading is obtained.
Volcano_498 0:b30f86a9a1c5 13 @brief -- Celsius-to-Fahrenheit and Celsius-to-Kelvin conversions of temperature readings and displaying them.
Volcano_498 0:b30f86a9a1c5 14 @brief -- Adjusting the unit the pressure is displayed in: millibars(mb), Pascals(Pa) and Atmospheres (atm).
Volcano_498 0:b30f86a9a1c5 15 @brief -- Displaying a brief splash screen to show changes in the unit display settings.
Volcano_498 0:b30f86a9a1c5 16 @author Volkan Esendag (SID:200795870)
Volcano_498 14:054e6faf0ca8 17 @date 11 March 2015 (created) / 6 May 2015(last modified)
Volcano_498 0:b30f86a9a1c5 18 */
Volcano_498 0:b30f86a9a1c5 19
Volcano_498 12:1d4b5465ecc1 20
Volcano_498 0:b30f86a9a1c5 21 #include "mbed.h"
Volcano_498 0:b30f86a9a1c5 22 #include "N5110.h"
Volcano_498 0:b30f86a9a1c5 23 #include "BMP180.h"
Volcano_498 0:b30f86a9a1c5 24 //import the PowerControl/EthernetPowerControl header files from the Power Control library
Volcano_498 0:b30f86a9a1c5 25 //to enable the power down features for the microprocessor and the Ethernet feature.
Volcano_498 0:b30f86a9a1c5 26 #include "PowerControl/PowerControl.h"
Volcano_498 0:b30f86a9a1c5 27 #include "PowerControl/EthernetPowerControl.h"
Volcano_498 0:b30f86a9a1c5 28
Volcano_498 1:454dddb8adc2 29 #ifndef USR_POWERDOWN
Volcano_498 0:b30f86a9a1c5 30 #define USR_POWERDOWN (0x104) //defines USB interface powerdown.
Volcano_498 1:454dddb8adc2 31 #endif
Volcano_498 1:454dddb8adc2 32
Volcano_498 11:dc05458980b6 33 #ifndef PNought_DEFAULT
Volcano_498 11:dc05458980b6 34 #define PNought_DEFAULT 1013.25 //Po = 101325 Pa or 1 atm or 1013.25 mb.
Volcano_498 2:08f2469728d5 35 #endif
Volcano_498 2:08f2469728d5 36
Volcano_498 2:08f2469728d5 37 /**
Volcano_498 3:70e14f1577f7 38 Custom struct for logging intervals. Fetch state number and select recording interval via the use of a button.
Volcano_498 2:08f2469728d5 39 */
Volcano_498 2:08f2469728d5 40
Volcano_498 3:70e14f1577f7 41 struct RecState {
Volcano_498 2:08f2469728d5 42 int recordState;
Volcano_498 2:08f2469728d5 43 float time;
Volcano_498 2:08f2469728d5 44 };
Volcano_498 10:06b35733ca25 45
Volcano_498 3:70e14f1577f7 46 //once struct has been declared, define a pointer type with it.
Volcano_498 2:08f2469728d5 47 typedef const struct RecState RecS;
Volcano_498 2:08f2469728d5 48
Volcano_498 12:1d4b5465ecc1 49 /**
Volcano_498 12:1d4b5465ecc1 50 @namespace recInterval
Volcano_498 12:1d4b5465ecc1 51 @brief Structed RecS object type that holds information on different logging interval settings for a given state.
Volcano_498 12:1d4b5465ecc1 52 @brief Has an array size of 10 to accomodate 10 different logging settings.
Volcano_498 12:1d4b5465ecc1 53 */
Volcano_498 12:1d4b5465ecc1 54
Volcano_498 2:08f2469728d5 55 RecS recInterval[10] = {
Volcano_498 3:70e14f1577f7 56 {0,600.0}, //state 0, 10 minutes
Volcano_498 3:70e14f1577f7 57 {1,1200.0}, //state 1, 20 minutes
Volcano_498 3:70e14f1577f7 58 {2,1800.0}, //state 2, 30 minutes
Volcano_498 3:70e14f1577f7 59 {3,3600.0}, //state 3, 1 hour. Default State.
Volcano_498 3:70e14f1577f7 60 {4,7200.0}, //state 4, 2 hours
Volcano_498 3:70e14f1577f7 61 {5,10800.0}, //state 5, 3 hours
Volcano_498 3:70e14f1577f7 62 {6,14400.0}, //state 6, 4 hours
Volcano_498 3:70e14f1577f7 63 {7,21600.0}, //state 7, 6 hours
Volcano_498 3:70e14f1577f7 64 {8,28800.0}, //state 8, 8 hours
Volcano_498 3:70e14f1577f7 65 {9,43200.0} //state 9, 12 hours
Volcano_498 3:70e14f1577f7 66 };
Volcano_498 3:70e14f1577f7 67
Volcano_498 12:1d4b5465ecc1 68 /**
Volcano_498 12:1d4b5465ecc1 69 @namespace dispInterval
Volcano_498 12:1d4b5465ecc1 70 @brief Another RecS pointer type object that holds information on device readings update intervals.
Volcano_498 12:1d4b5465ecc1 71 @brief Has an array size of 6 to accomodate 6 different display interval settings.
Volcano_498 12:1d4b5465ecc1 72 */
Volcano_498 12:1d4b5465ecc1 73
Volcano_498 3:70e14f1577f7 74 RecS dispInterval [6] = {
Volcano_498 3:70e14f1577f7 75 {0,1.0}, //state 0, 1 second. Default state.
Volcano_498 3:70e14f1577f7 76 {1,2.0}, //state 1, 2 seconds
Volcano_498 3:70e14f1577f7 77 {2,3.0}, //state 2, 3 seconds
Volcano_498 3:70e14f1577f7 78 {3,4.0}, //state 3, 4 seconds
Volcano_498 3:70e14f1577f7 79 {4,5.0}, //state 4, 5 seconds
Volcano_498 3:70e14f1577f7 80 {5,0.5}, //state 5, 500 milliseconds
Volcano_498 3:70e14f1577f7 81 };
Volcano_498 3:70e14f1577f7 82
Volcano_498 12:1d4b5465ecc1 83 /*!<Struct to set the temperature threshold after which point the device gives off a warning.*/
Volcano_498 3:70e14f1577f7 84 struct TempThreshold {
Volcano_498 3:70e14f1577f7 85 int tempState;
Volcano_498 3:70e14f1577f7 86 float thresTemp;
Volcano_498 3:70e14f1577f7 87 };
Volcano_498 3:70e14f1577f7 88
Volcano_498 3:70e14f1577f7 89 //define the TempTyp pointer type using the TempThreshold struct.
Volcano_498 3:70e14f1577f7 90 typedef const struct TempThreshold TempTyp;
Volcano_498 3:70e14f1577f7 91
Volcano_498 12:1d4b5465ecc1 92 /**
Volcano_498 12:1d4b5465ecc1 93 @namespace tempThres
Volcano_498 12:1d4b5465ecc1 94 @brief Structed TempTyp pointer type object to hold information on threshold temperature settings for the device.
Volcano_498 12:1d4b5465ecc1 95 @brief Should the temperature reading exceed a set value, visual and audible feedback is generated.
Volcano_498 12:1d4b5465ecc1 96 @brief Has 5 different settings to accomodate 5 threshold temperature settings.
Volcano_498 12:1d4b5465ecc1 97 */
Volcano_498 12:1d4b5465ecc1 98
Volcano_498 3:70e14f1577f7 99 TempTyp tempThres[5] = {
Volcano_498 3:70e14f1577f7 100 {0,30.0}, //state 0, 30'C
Volcano_498 3:70e14f1577f7 101 {1,40.0}, //state 1, 40'C
Volcano_498 3:70e14f1577f7 102 {2,50.0}, //state 2, 50'C. Default threshold.
Volcano_498 3:70e14f1577f7 103 {3,60.0}, //state 3, 60'C
Volcano_498 3:70e14f1577f7 104 {4,70.0} //state 4, 70'C
Volcano_498 3:70e14f1577f7 105 };
Volcano_498 3:70e14f1577f7 106
Volcano_498 12:1d4b5465ecc1 107 /**
Volcano_498 12:1d4b5465ecc1 108 @namespace lowerTemp
Volcano_498 12:1d4b5465ecc1 109 @brief Structed TempTyp pointer type object to hold information on lower end temperature settings for the device.
Volcano_498 12:1d4b5465ecc1 110 @brief This is instead used for the Temperature Plotter Menu to set a bottom floor for the plot space.
Volcano_498 12:1d4b5465ecc1 111 @brief Has 5 different settings to accomodate 5 minimum display temperature settings.
Volcano_498 12:1d4b5465ecc1 112 */
Volcano_498 12:1d4b5465ecc1 113
Volcano_498 11:dc05458980b6 114 TempTyp lowerTemp[5] = {
Volcano_498 11:dc05458980b6 115 {0,-10.0}, //state 0, -10'C
Volcano_498 11:dc05458980b6 116 {1,-5.0}, //state 1, -5'C
Volcano_498 11:dc05458980b6 117 {2,0.0}, //state 2, 0'C. Default lower threshold.
Volcano_498 11:dc05458980b6 118 {3,10.0}, //state 3, 10'C
Volcano_498 11:dc05458980b6 119 {4,20.0} //state 4, 20'C
Volcano_498 11:dc05458980b6 120 };
Volcano_498 11:dc05458980b6 121
Volcano_498 12:1d4b5465ecc1 122 /**
Volcano_498 12:1d4b5465ecc1 123 An array of characters to represent temperature unit settings (C - Degrees Celsius F - Degrees Fahrenheit K - Kelvins R - Degrees Rankine).
Volcano_498 12:1d4b5465ecc1 124 */
Volcano_498 12:1d4b5465ecc1 125
Volcano_498 6:0aca5c17c988 126 char tempUnit [4] = {'C','F','K','R'}; //character that stores temperature unit type.
Volcano_498 6:0aca5c17c988 127
Volcano_498 12:1d4b5465ecc1 128 /**
Volcano_498 12:1d4b5465ecc1 129 An array of characters to represent pressure unit settings (M - millibars P - Pascals A - Atmospheres)
Volcano_498 12:1d4b5465ecc1 130 */
Volcano_498 12:1d4b5465ecc1 131
Volcano_498 6:0aca5c17c988 132 char pressUnit[3] = {'M','P','A'}; //character that stores pressure units. M - millibars P - Pascals A - atmospheres
Volcano_498 6:0aca5c17c988 133
Volcano_498 12:1d4b5465ecc1 134 /**
Volcano_498 12:1d4b5465ecc1 135 An array of characters to represent unit settings (m - metres f - feet y - yards) for altitude.
Volcano_498 12:1d4b5465ecc1 136 */
Volcano_498 12:1d4b5465ecc1 137
Volcano_498 6:0aca5c17c988 138 char AltUnit[3] = {'m','f','y'}; //character that stores altitude units. m - metres f - feet y - yards
Volcano_498 2:08f2469728d5 139
Volcano_498 12:1d4b5465ecc1 140 /**
Volcano_498 12:1d4b5465ecc1 141 An array of characters to represent the column chart and the dot graph mode of the Temperature Plotter.
Volcano_498 12:1d4b5465ecc1 142 */
Volcano_498 12:1d4b5465ecc1 143
Volcano_498 11:dc05458980b6 144 char tempGraphMode [2] = {'c','d'}; //column chart, dot graph
Volcano_498 11:dc05458980b6 145
Volcano_498 12:1d4b5465ecc1 146 /**
Volcano_498 12:1d4b5465ecc1 147 An array of characters to represent the column chart and the dot graph mode of the Pressure Plotter.
Volcano_498 12:1d4b5465ecc1 148 */
Volcano_498 11:dc05458980b6 149 char pressGraphMode [2] = {'c','d'}; //column chart, dot graph
Volcano_498 11:dc05458980b6 150
Volcano_498 12:1d4b5465ecc1 151 /**
Volcano_498 12:1d4b5465ecc1 152 An array of PNought values to be used to calibrate the device for different weather fronts for altitude compensation.
Volcano_498 12:1d4b5465ecc1 153 float could work as well, but it is better to use double as pow(double x,double y) may not accept *arrays* with float pointer type!
Volcano_498 12:1d4b5465ecc1 154 */
Volcano_498 11:dc05458980b6 155 double PNought [13] = {983.25,988.25,993.25,998.25,1003.25,1008.25,PNought_DEFAULT,1018.25,1023.25,1028.25,1033.25,1038.25,1043.25};
Volcano_498 11:dc05458980b6 156
Volcano_498 11:dc05458980b6 157
Volcano_498 1:454dddb8adc2 158 /**
Volcano_498 1:454dddb8adc2 159 @namespace bmp180
Volcano_498 11:dc05458980b6 160 @brief A special structed type of Inter-integrated Circuit object created for the BMP180. For more info, see the BMP180 library by Dr. Craig Evans.
Volcano_498 1:454dddb8adc2 161 @see http://developer.mbed.org/users/eencae/code/BMP180/
Volcano_498 1:454dddb8adc2 162 */
Volcano_498 1:454dddb8adc2 163 BMP180 bmp180(p28,p27);
Volcano_498 1:454dddb8adc2 164 //Pins are declared in the public domain and the sensor itself acts on private variables.
Volcano_498 0:b30f86a9a1c5 165
Volcano_498 1:454dddb8adc2 166 /**
Volcano_498 1:454dddb8adc2 167 @namespace buzzerPwm
Volcano_498 1:454dddb8adc2 168 @brief PwmOut object to apply a PWM signal with a duty ratio of 50% to the buzzer as an improvised square wave.
Volcano_498 1:454dddb8adc2 169 @brief Used for an audible feedback should the temperature reading exceed a certain value.
Volcano_498 1:454dddb8adc2 170 */
Volcano_498 1:454dddb8adc2 171 PwmOut buzzerPwm(p24);
Volcano_498 0:b30f86a9a1c5 172
Volcano_498 1:454dddb8adc2 173 /**
Volcano_498 1:454dddb8adc2 174 @namespace redLED
Volcano_498 1:454dddb8adc2 175 @brief PwmOut object to apply a PWM signal to the red visual feedback LED via pin 22.
Volcano_498 1:454dddb8adc2 176 @brief Used for visual feedback to tell the user a certain temperature threshold has been reached.
Volcano_498 1:454dddb8adc2 177 */
Volcano_498 1:454dddb8adc2 178 PwmOut redLED(p22);
Volcano_498 1:454dddb8adc2 179
Volcano_498 1:454dddb8adc2 180 /**
Volcano_498 1:454dddb8adc2 181 @namespace greenLED
Volcano_498 1:454dddb8adc2 182 @brief PwmOut object to apply a PWM signal to the green visual feedback LED via pin 23.
Volcano_498 1:454dddb8adc2 183 @brief Used to let the user know the device is operating normally.
Volcano_498 1:454dddb8adc2 184 */
Volcano_498 1:454dddb8adc2 185 PwmOut greenLED(p23);
Volcano_498 1:454dddb8adc2 186
Volcano_498 1:454dddb8adc2 187 /**
Volcano_498 1:454dddb8adc2 188 @namespace serial
Volcano_498 1:454dddb8adc2 189 @brief Serial object to print readings over a USB cable and display them on a terminal.
Volcano_498 1:454dddb8adc2 190 */
Volcano_498 0:b30f86a9a1c5 191 Serial serial(USBTX,USBRX); //serial object to print readings for debugging WHILE the USB cable is connected.
Volcano_498 0:b30f86a9a1c5 192
Volcano_498 1:454dddb8adc2 193 /**
Volcano_498 1:454dddb8adc2 194 @namespace menuButton
Volcano_498 1:454dddb8adc2 195 @brief Interrupt object to call ISR for the designated menu button when an input to p15 is applied.
Volcano_498 1:454dddb8adc2 196 @namespace buttonOne
Volcano_498 1:454dddb8adc2 197 @brief Interrupt object to call ISR for Button 1 when an input to p16 is applied.
Volcano_498 1:454dddb8adc2 198 @namespace buttonTwo
Volcano_498 1:454dddb8adc2 199 @brief Interrupt object to call ISR for Button 2 when an input to p17 is applied.
Volcano_498 1:454dddb8adc2 200 @namespace buttonThree
Volcano_498 1:454dddb8adc2 201 @brief Interrupt object to call ISR for Button 3 when an input to p18 is applied.
Volcano_498 1:454dddb8adc2 202 */
Volcano_498 0:b30f86a9a1c5 203
Volcano_498 1:454dddb8adc2 204 InterruptIn menuButton(p15); //Interrupt object for the designated menu button.
Volcano_498 1:454dddb8adc2 205 InterruptIn buttonOne(p16); //Interrupt objects for the other buttons.
Volcano_498 1:454dddb8adc2 206 InterruptIn buttonTwo(p17);
Volcano_498 1:454dddb8adc2 207 InterruptIn buttonThree(p18);
Volcano_498 0:b30f86a9a1c5 208
Volcano_498 1:454dddb8adc2 209 /**
Volcano_498 1:454dddb8adc2 210 @namespace potAin
Volcano_498 1:454dddb8adc2 211 @brief Analogue input from potentiometer whose Vout is connected to pin 20.
Volcano_498 1:454dddb8adc2 212 */
Volcano_498 1:454dddb8adc2 213
Volcano_498 1:454dddb8adc2 214 AnalogIn potAin(p20); //Potentiometer feedback pin to the mbed.
Volcano_498 1:454dddb8adc2 215
Volcano_498 1:454dddb8adc2 216 /**
Volcano_498 1:454dddb8adc2 217 @namespace logTimer
Volcano_498 3:70e14f1577f7 218 @brief Ticker object to record/log readings with a specified interval. Can be varied with Interrupt Service Routines.
Volcano_498 1:454dddb8adc2 219 */
Volcano_498 1:454dddb8adc2 220
Volcano_498 1:454dddb8adc2 221 Ticker logTimer; //Ticker object to call ISR for a specified period of time.
Volcano_498 1:454dddb8adc2 222
Volcano_498 3:70e14f1577f7 223 /**
Volcano_498 3:70e14f1577f7 224 @namespace displayTimer
Volcano_498 3:70e14f1577f7 225 @brief Ticker object to display readings on screen with a specified interval. Can be varied with Interrupt Service Routines.
Volcano_498 3:70e14f1577f7 226 */
Volcano_498 6:0aca5c17c988 227 Ticker displayTimer; //ticker object to display readings
Volcano_498 3:70e14f1577f7 228
Volcano_498 1:454dddb8adc2 229 /*
Volcano_498 1:454dddb8adc2 230 @namespace leds
Volcano_498 1:454dddb8adc2 231 @brief GPIO output for status LEDs - used to display error message or as a flash memory overwrite operation feedback.
Volcano_498 1:454dddb8adc2 232 */
Volcano_498 1:454dddb8adc2 233
Volcano_498 1:454dddb8adc2 234 BusOut leds(LED1,LED2,LED3,LED4); //BusOut object for error feedback LEDs.
Volcano_498 1:454dddb8adc2 235 //configure pins of the LCD display...
Volcano_498 1:454dddb8adc2 236
Volcano_498 1:454dddb8adc2 237 /**
Volcano_498 1:454dddb8adc2 238 @namespace splashFlip
Volcano_498 1:454dddb8adc2 239 @brief Calls an ISR only once when attached. Used to delay splash screen for a few seconds before commencing with the program flow.
Volcano_498 1:454dddb8adc2 240 */
Volcano_498 1:454dddb8adc2 241 Timeout splashFlip;
Volcano_498 1:454dddb8adc2 242
Volcano_498 1:454dddb8adc2 243 /**
Volcano_498 1:454dddb8adc2 244 @namespace lcd
Volcano_498 1:454dddb8adc2 245 @brief Object that belongs to the N5110 class. Set up pin outputs for the Nokia 5110 display. Defined in N5110.h.
Volcano_498 1:454dddb8adc2 246 @see https://developer.mbed.org/users/eencae/code/N5110/
Volcano_498 1:454dddb8adc2 247 */
Volcano_498 6:0aca5c17c988 248 void printReadings(); // declare function to print readings here, which is then defined after the main() function.
Volcano_498 6:0aca5c17c988 249 void clearCells(); //declare function to clear all cells should there be a need for it. Even though lcd.clear() also does the job this can be handy in case of failure.
Volcano_498 2:08f2469728d5 250
Volcano_498 12:1d4b5465ecc1 251 float temp = 0.0; /*!< declare the temp variable for temperature universally so that it can be shared across functions to represent temperature. */
Volcano_498 12:1d4b5465ecc1 252 float press = 0.0; /*!< do the same for pressure using press. */
Volcano_498 12:1d4b5465ecc1 253 float altitude = 0.0; /*!< and altitude using, well, altitude :P */
Volcano_498 2:08f2469728d5 254
Volcano_498 12:1d4b5465ecc1 255 int i = 0; /*!< represents the column number (horizontal pixel number) of the display. */
Volcano_498 12:1d4b5465ecc1 256 int j = 0; /*!< represents the row number of the display. */
Volcano_498 3:70e14f1577f7 257
Volcano_498 12:1d4b5465ecc1 258 int dispSetting = 0; /*!< set display setting to default. */
Volcano_498 12:1d4b5465ecc1 259 int recSetting = 3; /*!< set log setting to default. */
Volcano_498 12:1d4b5465ecc1 260 int tempSetting = 2; /*!< set temperature threshold to default. */
Volcano_498 5:6d85cafa1085 261
Volcano_498 12:1d4b5465ecc1 262 int tempUnitSetting = 0; /*!< set temperature unit setting to default. */
Volcano_498 12:1d4b5465ecc1 263 int pressUnitSetting = 0; /*!< set pressure unit setting to default. */
Volcano_498 12:1d4b5465ecc1 264 int altUnitSetting = 0; /*!< and do the same for altitude. */
Volcano_498 12:1d4b5465ecc1 265 int tempGraphSetting = 1; /*!< set the default to be dot chart. */
Volcano_498 12:1d4b5465ecc1 266 int pressGraphSetting = 1; /*!< set the default to be dot chart. */
Volcano_498 12:1d4b5465ecc1 267 int PNoughtSetting = 6; /*!< set the default PNought to be PNought_DEFAULT. */
Volcano_498 12:1d4b5465ecc1 268 int subMenuId = 0; /*!< int used to store sub-menu number. For instance pressing the menu button once and then Button One gives Sub-Menu 1. */
Volcano_498 6:0aca5c17c988 269
Volcano_498 12:1d4b5465ecc1 270 int logCounter = 0; /*!< int pointer used to store second count for logging. Initialised to 0.*/
Volcano_498 12:1d4b5465ecc1 271 int lowerTempSetting = 2; /*!< set lower temperature display to default.*/
Volcano_498 10:06b35733ca25 272
Volcano_498 1:454dddb8adc2 273 N5110 lcd(p7,p8,p9,p10,p11,p13,p21); //VCC,SCE,RST,DC,MOSI,SCLK,BACKLIGHT
Volcano_498 0:b30f86a9a1c5 274
Volcano_498 0:b30f86a9a1c5 275 ///////////The following pieces of code are to configure real-time clock for the data logger.*************
Volcano_498 0:b30f86a9a1c5 276
Volcano_498 12:1d4b5465ecc1 277 char rxString[16]; /*!< buffer to store received string. Each character is a byte long - hence the char pointer type. */
Volcano_498 1:454dddb8adc2 278
Volcano_498 1:454dddb8adc2 279 int setTimeFlag = 0; /*!< set time flag set in serial ISR */
Volcano_498 0:b30f86a9a1c5 280
Volcano_498 1:454dddb8adc2 281 /**
Volcano_498 1:454dddb8adc2 282 Reads string input via serial interrupt and converts it into real time
Volcano_498 1:454dddb8adc2 283 @param rxString - string received from serial
Volcano_498 1:454dddb8adc2 284 @param time - integer that represents time, converted from input string (rxString).
Volcano_498 0:b30f86a9a1c5 285
Volcano_498 1:454dddb8adc2 286 */
Volcano_498 0:b30f86a9a1c5 287 void setTime()
Volcano_498 0:b30f86a9a1c5 288 {
Volcano_498 0:b30f86a9a1c5 289 // print time for debugging
Volcano_498 0:b30f86a9a1c5 290 serial.printf("set_time - %s",rxString);
Volcano_498 0:b30f86a9a1c5 291 // atoi() converts a string to an integer
Volcano_498 0:b30f86a9a1c5 292 int time = atoi(rxString);
Volcano_498 0:b30f86a9a1c5 293 // update the time
Volcano_498 0:b30f86a9a1c5 294 set_time(time);
Volcano_498 0:b30f86a9a1c5 295 }
Volcano_498 0:b30f86a9a1c5 296
Volcano_498 12:1d4b5465ecc1 297 /**
Volcano_498 12:1d4b5465ecc1 298 Interrupt Service Routine performed by Serial Interrupts - by using a serial terminal program such as CoolTerm.
Volcano_498 12:1d4b5465ecc1 299 Sets time flag in order to set and overwrite the current time onto the mbed. This only needs to be done once.
Volcano_498 12:1d4b5465ecc1 300 */
Volcano_498 12:1d4b5465ecc1 301
Volcano_498 0:b30f86a9a1c5 302 void serialISR()
Volcano_498 0:b30f86a9a1c5 303 {
Volcano_498 0:b30f86a9a1c5 304 // when a serial interrupt occurs, read rx string into buffer. Holds 16 characters. gets implies fetching a string from serial port.
Volcano_498 1:454dddb8adc2 305 serial.gets(rxString,16);
Volcano_498 0:b30f86a9a1c5 306 // set flag
Volcano_498 0:b30f86a9a1c5 307 setTimeFlag = 1;
Volcano_498 0:b30f86a9a1c5 308 }
Volcano_498 0:b30f86a9a1c5 309
Volcano_498 1:454dddb8adc2 310 /**
Volcano_498 1:454dddb8adc2 311 Disables USB interface when the mbed's USB cable isn't attached.
Volcano_498 11:dc05458980b6 312 Acknowledgements to Michael Wei's PowerControl library.
Volcano_498 11:dc05458980b6 313 @param arg - argument function (pointer type unsigned int/uint32_t)
Volcano_498 1:454dddb8adc2 314 @returns __semihost(USR_POWERDOWN, &arg)
Volcano_498 11:dc05458980b6 315 @see https://developer.mbed.org/users/JST2011/code/PowerControl/
Volcano_498 1:454dddb8adc2 316 */
Volcano_498 1:454dddb8adc2 317
Volcano_498 3:70e14f1577f7 318 int semihost_powerdown()
Volcano_498 3:70e14f1577f7 319 {
Volcano_498 3:70e14f1577f7 320
Volcano_498 1:454dddb8adc2 321 uint32_t arg; //variable for return function
Volcano_498 1:454dddb8adc2 322 return __semihost(USR_POWERDOWN, &arg); //return semihost state...
Volcano_498 3:70e14f1577f7 323
Volcano_498 1:454dddb8adc2 324 } //...to power down the USB interface when the USB cable is detached.
Volcano_498 1:454dddb8adc2 325
Volcano_498 14:054e6faf0ca8 326
Volcano_498 1:454dddb8adc2 327 LocalFileSystem local("local"); // create local filesystem
Volcano_498 1:454dddb8adc2 328
Volcano_498 12:1d4b5465ecc1 329 /**
Volcano_498 12:1d4b5465ecc1 330 Pretty self-explanatory: Using the local file system created, overwrites the mbed's Flash Memory and saves data on it.
Volcano_498 12:1d4b5465ecc1 331 @param data - placeholder for temperature data to be overwritten.
Volcano_498 12:1d4b5465ecc1 332 @param dataTwo - placeholder for pressure data to be overwritten.
Volcano_498 12:1d4b5465ecc1 333 @param dataThree - placeholder for time string to be stored - hence has an array size of 30 and a data type of char.
Volcano_498 12:1d4b5465ecc1 334 */
Volcano_498 12:1d4b5465ecc1 335
Volcano_498 1:454dddb8adc2 336 void writeDataToFile(float data, float dataTwo, char dataThree[30])
Volcano_498 1:454dddb8adc2 337 {
Volcano_498 1:454dddb8adc2 338 time_t seconds = time(NULL); // get current time
Volcano_498 1:454dddb8adc2 339 strftime(dataThree, 30 , "%R %x", localtime(&seconds)); //convert it into a string, from an array size of 30.
Volcano_498 3:70e14f1577f7 340
Volcano_498 1:454dddb8adc2 341 leds = 15; // turn on LEDs for feedback
Volcano_498 1:454dddb8adc2 342 FILE *fp = fopen("/local/tempLog.csv", "a"); // open 'log.txt' for appending. Instance of class FILE.
Volcano_498 1:454dddb8adc2 343 // if the file doesn't exist it is created, if it exists, data is appended to the end
Volcano_498 3:70e14f1577f7 344 fprintf(fp,"%s, %.2f , %.2f \n",dataThree,dataTwo,data); // print string to file
Volcano_498 1:454dddb8adc2 345 fclose(fp); // close file
Volcano_498 1:454dddb8adc2 346 leds = 0; // turn off LEDs to signify file access has finished
Volcano_498 1:454dddb8adc2 347 }
Volcano_498 1:454dddb8adc2 348
Volcano_498 1:454dddb8adc2 349 int menuButtonFlag = 0; /*!< menu button flag set in ISR */
Volcano_498 1:454dddb8adc2 350
Volcano_498 1:454dddb8adc2 351 int buttonOneFlag = 0; /*!< Button One flag set in ISR */
Volcano_498 1:454dddb8adc2 352 int buttonOneAltFlag = 0; /*!< Button One Alternate flag set in ISR */
Volcano_498 1:454dddb8adc2 353
Volcano_498 12:1d4b5465ecc1 354 /**
Volcano_498 12:1d4b5465ecc1 355 Interrupt Service Routine to toggle buttonOneFlag/buttonOneAltFlag when not in a settings main menu and when in one respectively.
Volcano_498 12:1d4b5465ecc1 356 No parameters to be entered by, or values to be returned to, the user.
Volcano_498 12:1d4b5465ecc1 357 */
Volcano_498 12:1d4b5465ecc1 358
Volcano_498 3:70e14f1577f7 359 void buttonOnePressed()
Volcano_498 3:70e14f1577f7 360 {
Volcano_498 6:0aca5c17c988 361 if(menuButtonFlag > 0) { //if menu button has been pressed and main menu entered
Volcano_498 1:454dddb8adc2 362 buttonOneAltFlag = !buttonOneAltFlag; //set/reset-if-set alternate flag and proceed to next menu
Volcano_498 6:0aca5c17c988 363 }
Volcano_498 6:0aca5c17c988 364 else {
Volcano_498 1:454dddb8adc2 365 buttonOneFlag = !buttonOneFlag; //set/reset-if-set flag if not navigated to a menu
Volcano_498 1:454dddb8adc2 366 }
Volcano_498 1:454dddb8adc2 367 }
Volcano_498 1:454dddb8adc2 368
Volcano_498 1:454dddb8adc2 369 int buttonTwoFlag = 0; /*!< Button Two flag set in ISR */
Volcano_498 1:454dddb8adc2 370 int buttonTwoAltFlag = 0; /*!< Button Two Alternate flag set in ISR */
Volcano_498 1:454dddb8adc2 371
Volcano_498 12:1d4b5465ecc1 372 /**
Volcano_498 12:1d4b5465ecc1 373 Interrupt Service Routine to toggle buttonTwoFlag/buttonTwoAltFlag.
Volcano_498 12:1d4b5465ecc1 374 No parameters to be entered by, or values to be returned to, the user.
Volcano_498 12:1d4b5465ecc1 375 */
Volcano_498 12:1d4b5465ecc1 376
Volcano_498 3:70e14f1577f7 377 void buttonTwoPressed()
Volcano_498 3:70e14f1577f7 378 {
Volcano_498 6:0aca5c17c988 379 if(menuButtonFlag > 0) {
Volcano_498 3:70e14f1577f7 380 buttonTwoAltFlag = !buttonTwoAltFlag;
Volcano_498 6:0aca5c17c988 381 }
Volcano_498 6:0aca5c17c988 382 else {
Volcano_498 3:70e14f1577f7 383 buttonTwoFlag = !buttonTwoFlag;
Volcano_498 1:454dddb8adc2 384 }
Volcano_498 1:454dddb8adc2 385 }
Volcano_498 1:454dddb8adc2 386
Volcano_498 1:454dddb8adc2 387 int buttonThreeFlag = 0; /*!< Button Three flag set in ISR */
Volcano_498 1:454dddb8adc2 388 int buttonThreeAltFlag = 0; /*!< Button Three Alternate flag set in ISR */
Volcano_498 1:454dddb8adc2 389
Volcano_498 12:1d4b5465ecc1 390 /**
Volcano_498 12:1d4b5465ecc1 391 Interrupt Service Routine to toggle buttonThreeFlag/buttonThreeAltFlag.
Volcano_498 12:1d4b5465ecc1 392 No parameters to be entered by, or values to be returned to, the user.
Volcano_498 12:1d4b5465ecc1 393 */
Volcano_498 12:1d4b5465ecc1 394
Volcano_498 3:70e14f1577f7 395 void buttonThreePressed()
Volcano_498 3:70e14f1577f7 396 {
Volcano_498 5:6d85cafa1085 397 if(menuButtonFlag > 0) {
Volcano_498 3:70e14f1577f7 398 buttonThreeAltFlag = !buttonThreeAltFlag;
Volcano_498 6:0aca5c17c988 399 }
Volcano_498 6:0aca5c17c988 400 else
Volcano_498 1:454dddb8adc2 401 buttonThreeFlag = !buttonThreeFlag;
Volcano_498 1:454dddb8adc2 402 }
Volcano_498 1:454dddb8adc2 403
Volcano_498 12:1d4b5465ecc1 404 /**
Volcano_498 12:1d4b5465ecc1 405 Interrupt Service Routine to increment menuButtonFlag when Menu Button is pressed to navigate to settings menus.
Volcano_498 12:1d4b5465ecc1 406 No parameters to be entered by, or values to be returned to, the user.
Volcano_498 12:1d4b5465ecc1 407 */
Volcano_498 12:1d4b5465ecc1 408
Volcano_498 7:104ac8e707e6 409 void menuButtonPressed()
Volcano_498 7:104ac8e707e6 410 {
Volcano_498 11:dc05458980b6 411 if(buttonOneAltFlag == 0 && buttonTwoAltFlag == 0 && buttonThreeAltFlag == 0 || buttonOneFlag || buttonTwoFlag){ //if no flag is set and therefore no menu accessed (except buttonOneFlag and buttonTwoFlag which are set in the measurement menu)
Volcano_498 7:104ac8e707e6 412 menuButtonFlag++; //increment the flag to access different menu states.
Volcano_498 7:104ac8e707e6 413
Volcano_498 11:dc05458980b6 414 if(menuButtonFlag > 3) { //if menu button has been clicked three times
Volcano_498 7:104ac8e707e6 415 menuButtonFlag = 0; //go back to the measurements menu
Volcano_498 7:104ac8e707e6 416 }
Volcano_498 7:104ac8e707e6 417 }
Volcano_498 7:104ac8e707e6 418 }
Volcano_498 7:104ac8e707e6 419
Volcano_498 5:6d85cafa1085 420 int splashFlag = 1; /*!< Splash flag set to continue with program flow for the main function before proceeding with program flow */
Volcano_498 5:6d85cafa1085 421
Volcano_498 5:6d85cafa1085 422 /**
Volcano_498 5:6d85cafa1085 423 Interrupt Service Routine to reset splashFlag when Timeout has been performed.
Volcano_498 5:6d85cafa1085 424 No parameters to be entered by, or values to be returned to, the user.
Volcano_498 5:6d85cafa1085 425 */
Volcano_498 1:454dddb8adc2 426
Volcano_498 3:70e14f1577f7 427 void splashDelay()
Volcano_498 3:70e14f1577f7 428 {
Volcano_498 1:454dddb8adc2 429 splashFlag = 0;
Volcano_498 1:454dddb8adc2 430 }
Volcano_498 1:454dddb8adc2 431
Volcano_498 5:6d85cafa1085 432 int dispTimerFlag = 0; /*!< Display flag set to 0 initially. Used to update values on the display when the ISR is called.*/
Volcano_498 5:6d85cafa1085 433
Volcano_498 5:6d85cafa1085 434 /**
Volcano_498 5:6d85cafa1085 435 Interrupt Service Routine to set dispTimerFlag when Ticker duration has elapsed.
Volcano_498 5:6d85cafa1085 436 No parameters to be entered by, or values to be returned to, the user.
Volcano_498 5:6d85cafa1085 437 */
Volcano_498 5:6d85cafa1085 438 void timerExpiDisplay()
Volcano_498 5:6d85cafa1085 439 {
Volcano_498 5:6d85cafa1085 440 dispTimerFlag = 1;
Volcano_498 5:6d85cafa1085 441 }
Volcano_498 5:6d85cafa1085 442
Volcano_498 11:dc05458980b6 443 int logTimerFlag = 0; /*!< Log flag set to 0 initially. Used to overwrite the Flash Memory when the ISR is called, by using a log counter.*/
Volcano_498 5:6d85cafa1085 444
Volcano_498 5:6d85cafa1085 445 /**
Volcano_498 5:6d85cafa1085 446 Interrupt Service Routine to set logTimerFlag when Ticker duration has elapsed.
Volcano_498 5:6d85cafa1085 447 No parameters to be entered by, or values to be returned to, the user.
Volcano_498 5:6d85cafa1085 448 */
Volcano_498 5:6d85cafa1085 449 void timerExpiLog()
Volcano_498 5:6d85cafa1085 450 {
Volcano_498 6:0aca5c17c988 451 logTimerFlag = 1;
Volcano_498 5:6d85cafa1085 452 }
Volcano_498 5:6d85cafa1085 453
Volcano_498 12:1d4b5465ecc1 454 /**
Volcano_498 12:1d4b5465ecc1 455 Displays the initial splash screen when the Weather Station is turned on from rest.
Volcano_498 12:1d4b5465ecc1 456 */
Volcano_498 12:1d4b5465ecc1 457
Volcano_498 11:dc05458980b6 458 void displayInitSplash() //!display splash screen
Volcano_498 3:70e14f1577f7 459 {
Volcano_498 1:454dddb8adc2 460 lcd.printString("Welcome to",15,1);
Volcano_498 1:454dddb8adc2 461 lcd.printString("Portable Weat.",3,2);
Volcano_498 3:70e14f1577f7 462 lcd.printString("Station",20,3);
Volcano_498 1:454dddb8adc2 463 lcd.printString("by Volkan",20,4);
Volcano_498 1:454dddb8adc2 464 lcd.printString("Esendag",20,5);
Volcano_498 2:08f2469728d5 465 }
Volcano_498 2:08f2469728d5 466
Volcano_498 12:1d4b5465ecc1 467 /**
Volcano_498 12:1d4b5465ecc1 468 Displays the first settings main menu.
Volcano_498 12:1d4b5465ecc1 469 */
Volcano_498 12:1d4b5465ecc1 470
Volcano_498 11:dc05458980b6 471 void displayMenuOne(){ //!settings main menu 1!
Volcano_498 6:0aca5c17c988 472 lcd.printString("Settings Menu",0,0);
Volcano_498 6:0aca5c17c988 473 lcd.printString("One",0,1);
Volcano_498 6:0aca5c17c988 474 lcd.printString("Use Buttons",0,2);
Volcano_498 6:0aca5c17c988 475 lcd.printString("To change",0,3);
Volcano_498 6:0aca5c17c988 476 lcd.printString("Settings",0,4);
Volcano_498 6:0aca5c17c988 477 lcd.refresh();
Volcano_498 6:0aca5c17c988 478 }
Volcano_498 6:0aca5c17c988 479
Volcano_498 12:1d4b5465ecc1 480 /**
Volcano_498 12:1d4b5465ecc1 481 Displays the second settings main menu.
Volcano_498 12:1d4b5465ecc1 482 */
Volcano_498 12:1d4b5465ecc1 483
Volcano_498 12:1d4b5465ecc1 484 void displayMenuTwo(){
Volcano_498 6:0aca5c17c988 485 lcd.printString("Settings Menu",0,0);
Volcano_498 6:0aca5c17c988 486 lcd.printString("Two",0,1);
Volcano_498 6:0aca5c17c988 487 lcd.printString("Use menuButton",0,2);
Volcano_498 11:dc05458980b6 488 lcd.printString("To Advance To",0,3);
Volcano_498 11:dc05458980b6 489 lcd.printString("Next menu",0,4);
Volcano_498 11:dc05458980b6 490 lcd.refresh();
Volcano_498 11:dc05458980b6 491 }
Volcano_498 11:dc05458980b6 492
Volcano_498 12:1d4b5465ecc1 493 /**
Volcano_498 12:1d4b5465ecc1 494 Displays the third settings main menu.
Volcano_498 12:1d4b5465ecc1 495 */
Volcano_498 12:1d4b5465ecc1 496
Volcano_498 12:1d4b5465ecc1 497 void displayMenuThree(){
Volcano_498 11:dc05458980b6 498 lcd.printString("Settings Menu",0,0);
Volcano_498 11:dc05458980b6 499 lcd.printString("Three",0,1);
Volcano_498 11:dc05458980b6 500 lcd.printString("Use menuButton",0,2);
Volcano_498 6:0aca5c17c988 501 lcd.printString("To Go Back To",0,3);
Volcano_498 6:0aca5c17c988 502 lcd.printString("Display menu",0,4);
Volcano_498 6:0aca5c17c988 503 lcd.refresh();
Volcano_498 6:0aca5c17c988 504 }
Volcano_498 6:0aca5c17c988 505
Volcano_498 12:1d4b5465ecc1 506 /**
Volcano_498 12:1d4b5465ecc1 507 Displays the Temperature Unit Display Sub-Menu. In this menu one can determine whether the temperature will be displayed...
Volcano_498 12:1d4b5465ecc1 508 ...in degrees Celsius(default), degrees Fahrenheit, Kelvins or degrees Rankine.
Volcano_498 12:1d4b5465ecc1 509 */
Volcano_498 12:1d4b5465ecc1 510
Volcano_498 11:dc05458980b6 511 void displayTempUnit(){ //!temperature unit display sub-menu
Volcano_498 6:0aca5c17c988 512 lcd.printString("Use Button 2",0,0);
Volcano_498 6:0aca5c17c988 513 lcd.printString("To decrease",0,1);
Volcano_498 6:0aca5c17c988 514 lcd.printString("Temp. Setting;",0,2);
Volcano_498 6:0aca5c17c988 515 lcd.printString("Button 3",0,3);
Volcano_498 6:0aca5c17c988 516 lcd.printString("To increase.",0,4);
Volcano_498 6:0aca5c17c988 517
Volcano_498 6:0aca5c17c988 518 char bufferSt[14]; //buffer to store string
Volcano_498 6:0aca5c17c988 519 sprintf(bufferSt,"current:%c",tempUnit[tempUnitSetting]); //write the typed string and the current unit setting onto the buffer
Volcano_498 6:0aca5c17c988 520
Volcano_498 6:0aca5c17c988 521 lcd.printString(bufferSt,0,5); //print the buffer
Volcano_498 6:0aca5c17c988 522 lcd.refresh(); //needs to refresh to write the string buffers to the display
Volcano_498 6:0aca5c17c988 523 }
Volcano_498 6:0aca5c17c988 524
Volcano_498 12:1d4b5465ecc1 525 /**
Volcano_498 12:1d4b5465ecc1 526 Displays the Pressure Unit Display Sub-Menu. In this menu one can determine whether the pressure will be displayed...
Volcano_498 12:1d4b5465ecc1 527 ...in millibars(default), Pascals or Atmospheres.
Volcano_498 12:1d4b5465ecc1 528 */
Volcano_498 12:1d4b5465ecc1 529
Volcano_498 11:dc05458980b6 530 void displayPressUnit(){ //!pressure unit display sub menu
Volcano_498 6:0aca5c17c988 531 lcd.printString("Use Button 1",0,0);
Volcano_498 6:0aca5c17c988 532 lcd.printString("To decrease",0,1);
Volcano_498 6:0aca5c17c988 533 lcd.printString("Press Setting;",0,2);
Volcano_498 6:0aca5c17c988 534 lcd.printString("Button 3",0,3);
Volcano_498 6:0aca5c17c988 535 lcd.printString("To increase.",0,4);
Volcano_498 6:0aca5c17c988 536
Volcano_498 6:0aca5c17c988 537 char bufferSt[14]; //buffer to store string
Volcano_498 6:0aca5c17c988 538 sprintf(bufferSt,"current:%c",pressUnit[pressUnitSetting]);
Volcano_498 6:0aca5c17c988 539
Volcano_498 6:0aca5c17c988 540 lcd.printString(bufferSt,0,5);
Volcano_498 6:0aca5c17c988 541 lcd.refresh();
Volcano_498 6:0aca5c17c988 542 }
Volcano_498 6:0aca5c17c988 543
Volcano_498 12:1d4b5465ecc1 544 /**
Volcano_498 12:1d4b5465ecc1 545 Displays the Log Interval Menu for the Weather Station. In this menu one can determine how often the device will log...
Volcano_498 12:1d4b5465ecc1 546 ...or more correctly the number of counters it takes for the device to log data on and reset the counter.
Volcano_498 12:1d4b5465ecc1 547 */
Volcano_498 12:1d4b5465ecc1 548
Volcano_498 11:dc05458980b6 549 void displayLogMenu(){ //!displays the log interval change sub-menu.
Volcano_498 10:06b35733ca25 550 lcd.printString("Use Button 1",0,0);
Volcano_498 10:06b35733ca25 551 lcd.printString("To decrease",0,1);
Volcano_498 10:06b35733ca25 552 lcd.printString("Log Interval;",0,2);
Volcano_498 10:06b35733ca25 553 lcd.printString("Button 2",0,3);
Volcano_498 10:06b35733ca25 554 lcd.printString("To increase.",0,4);
Volcano_498 10:06b35733ca25 555
Volcano_498 10:06b35733ca25 556 char bufferSt[14]; //buffer to store string
Volcano_498 10:06b35733ca25 557 //just a universally applicable if-else if statement to create a string out of current time setting should more time settings be added...
Volcano_498 10:06b35733ca25 558 if(recInterval[recSetting].time >= 3600.0){ //if log interval is an hour (3600 seconds) or more
Volcano_498 10:06b35733ca25 559 float tempTime = recInterval[recSetting].time/3600.0; //convert time in seconds into hours
Volcano_498 10:06b35733ca25 560 sprintf(bufferSt,"set:%.1f hr",tempTime);
Volcano_498 10:06b35733ca25 561 }
Volcano_498 10:06b35733ca25 562 else if(recInterval[recSetting].time < 3600.0){ //if log interval is in minutes
Volcano_498 10:06b35733ca25 563 float tempTime = recInterval[recSetting].time/60.0; //convert time to minutes
Volcano_498 10:06b35733ca25 564 sprintf(bufferSt,"set:%.1f min",tempTime);
Volcano_498 10:06b35733ca25 565 }
Volcano_498 10:06b35733ca25 566 lcd.printString(bufferSt,0,5);
Volcano_498 10:06b35733ca25 567 lcd.refresh();
Volcano_498 10:06b35733ca25 568 }
Volcano_498 10:06b35733ca25 569
Volcano_498 12:1d4b5465ecc1 570 /**
Volcano_498 12:1d4b5465ecc1 571 Displays the Display Interval Sub-Menu. Intervals of a few seconds or 500 ms.
Volcano_498 12:1d4b5465ecc1 572 In other words, determines how often the device will update temperature/pressure/altitude readings.
Volcano_498 12:1d4b5465ecc1 573 */
Volcano_498 12:1d4b5465ecc1 574
Volcano_498 12:1d4b5465ecc1 575 void displayDispMenu(){
Volcano_498 6:0aca5c17c988 576 lcd.printString("Use Button 2",0,0);
Volcano_498 6:0aca5c17c988 577 lcd.printString("To decrease",0,1);
Volcano_498 6:0aca5c17c988 578 lcd.printString("Time Setting;",0,2);
Volcano_498 6:0aca5c17c988 579 lcd.printString("Button 3",0,3);
Volcano_498 6:0aca5c17c988 580 lcd.printString("To increase.",0,4);
Volcano_498 6:0aca5c17c988 581
Volcano_498 6:0aca5c17c988 582 char bufferSt[14]; //buffer to store string
Volcano_498 6:0aca5c17c988 583 //just a universally applicable if-else if statement to create a string out of current time setting should more time settings be added...
Volcano_498 6:0aca5c17c988 584 if(dispInterval[dispSetting].time >= 1.0){ //if time setting is a second or more
Volcano_498 6:0aca5c17c988 585 sprintf(bufferSt,"set:%.1f s",dispInterval[dispSetting].time);
Volcano_498 6:0aca5c17c988 586 }
Volcano_498 6:0aca5c17c988 587 else if(dispInterval[dispSetting].time < 1.0){ //if time setting is less than a second
Volcano_498 6:0aca5c17c988 588 float tempTime = dispInterval[dispSetting].time * 1000.0; //convert time to milliseconds
Volcano_498 6:0aca5c17c988 589 sprintf(bufferSt,"set:%.1f ms",tempTime);
Volcano_498 6:0aca5c17c988 590 }
Volcano_498 6:0aca5c17c988 591 lcd.printString(bufferSt,0,5);
Volcano_498 6:0aca5c17c988 592 lcd.refresh();
Volcano_498 6:0aca5c17c988 593 }
Volcano_498 6:0aca5c17c988 594
Volcano_498 12:1d4b5465ecc1 595 /**
Volcano_498 12:1d4b5465ecc1 596 Displays the Threshold Temperature Change menu. Above this threshold temperature set here a visual and audible alert will be generated.
Volcano_498 12:1d4b5465ecc1 597 This threshold temperature also determines the maximum value for the temperature graph menu.
Volcano_498 12:1d4b5465ecc1 598 */
Volcano_498 12:1d4b5465ecc1 599
Volcano_498 11:dc05458980b6 600 void displayThresholdTemp(){ //!displays the threshold temperature change sub-menu.
Volcano_498 6:0aca5c17c988 601 lcd.printString("Use Button 1",0,0);
Volcano_498 6:0aca5c17c988 602 lcd.printString("To decrease",0,1);
Volcano_498 6:0aca5c17c988 603 lcd.printString("Temp Thresh;",0,2);
Volcano_498 6:0aca5c17c988 604 lcd.printString("Button 3",0,3);
Volcano_498 6:0aca5c17c988 605 lcd.printString("To increase.",0,4);
Volcano_498 6:0aca5c17c988 606
Volcano_498 6:0aca5c17c988 607 char bufferSt[14]; //buffer to store string
Volcano_498 6:0aca5c17c988 608 sprintf(bufferSt,"current:%.1f",tempThres[tempSetting].thresTemp);
Volcano_498 6:0aca5c17c988 609
Volcano_498 6:0aca5c17c988 610 lcd.printString(bufferSt,0,5);
Volcano_498 6:0aca5c17c988 611 lcd.refresh();
Volcano_498 6:0aca5c17c988 612 }
Volcano_498 6:0aca5c17c988 613
Volcano_498 12:1d4b5465ecc1 614 /**
Volcano_498 12:1d4b5465ecc1 615 Displays the Altitude Change Sub-Menu for the Weather Station. Determines whether altitude data will be displayed in metres, feet or yards.
Volcano_498 12:1d4b5465ecc1 616 */
Volcano_498 12:1d4b5465ecc1 617
Volcano_498 11:dc05458980b6 618 void displayAltitudeUnit(){ //!displays the altitude unit change sub-menu.
Volcano_498 6:0aca5c17c988 619 lcd.printString("Use Button 1",0,0);
Volcano_498 6:0aca5c17c988 620 lcd.printString("To decrease",0,1);
Volcano_498 10:06b35733ca25 621 lcd.printString("Alti. Setting",0,2);
Volcano_498 6:0aca5c17c988 622 lcd.printString("Button 2",0,3);
Volcano_498 6:0aca5c17c988 623 lcd.printString("To increase.",0,4);
Volcano_498 6:0aca5c17c988 624
Volcano_498 6:0aca5c17c988 625 char bufferSt[14]; //buffer to store string
Volcano_498 6:0aca5c17c988 626 sprintf(bufferSt,"current:%c",AltUnit[altUnitSetting]);
Volcano_498 6:0aca5c17c988 627
Volcano_498 6:0aca5c17c988 628 lcd.printString(bufferSt,0,5);
Volcano_498 6:0aca5c17c988 629 lcd.refresh();
Volcano_498 6:0aca5c17c988 630 }
Volcano_498 6:0aca5c17c988 631
Volcano_498 12:1d4b5465ecc1 632 /**
Volcano_498 12:1d4b5465ecc1 633 Displays the Temperature Graph Sub-Menu for the Weather Station. This Sub-Menu determines whether the temperature value will be displayed as a...
Volcano_498 12:1d4b5465ecc1 634 ...column chart or a dot chart (just a mark at where the pressure would be located for a given point in time).
Volcano_498 12:1d4b5465ecc1 635 Also displays (and used to change) the lower end value for the temperature graph.
Volcano_498 12:1d4b5465ecc1 636 */
Volcano_498 12:1d4b5465ecc1 637
Volcano_498 11:dc05458980b6 638 void displayTempMode(){ //!temperature graph display mode
Volcano_498 11:dc05458980b6 639 lcd.printString("Graph mode",0,0);
Volcano_498 11:dc05458980b6 640 lcd.printString("for Temp.",0,1);
Volcano_498 11:dc05458980b6 641 lcd.printString("B2:change gr.",0,2);
Volcano_498 11:dc05458980b6 642
Volcano_498 11:dc05458980b6 643 char bufferSt[14]; //buffer to store string
Volcano_498 11:dc05458980b6 644 sprintf(bufferSt,"current:%c",tempGraphMode[tempGraphSetting]);
Volcano_498 11:dc05458980b6 645 lcd.printString(bufferSt,0,3);
Volcano_498 11:dc05458980b6 646
Volcano_498 11:dc05458980b6 647 lcd.printString("B3:LowThresho.",0,4);
Volcano_498 11:dc05458980b6 648 sprintf(bufferSt,"current:%.1f",lowerTemp[lowerTempSetting].thresTemp);
Volcano_498 11:dc05458980b6 649 lcd.printString(bufferSt,0,5);
Volcano_498 11:dc05458980b6 650 lcd.refresh();
Volcano_498 11:dc05458980b6 651 }
Volcano_498 11:dc05458980b6 652
Volcano_498 12:1d4b5465ecc1 653 /**
Volcano_498 12:1d4b5465ecc1 654 Displays the Pressure Graph Sub-Menu for the Weather Station. This Sub-Menu determines whether the pressure value will be displayed as a column chart or...
Volcano_498 12:1d4b5465ecc1 655 ...a dot chart (just a mark at where the pressure would be located for a given point in time)
Volcano_498 12:1d4b5465ecc1 656 */
Volcano_498 12:1d4b5465ecc1 657
Volcano_498 12:1d4b5465ecc1 658 void displayPressMode(){
Volcano_498 11:dc05458980b6 659 lcd.printString("Graph mode",0,0);
Volcano_498 11:dc05458980b6 660 lcd.printString("for Press.",0,1);
Volcano_498 11:dc05458980b6 661 lcd.printString("c: column ch",0,2);
Volcano_498 11:dc05458980b6 662 lcd.printString("d: dot chart",0,3);
Volcano_498 11:dc05458980b6 663
Volcano_498 11:dc05458980b6 664 char bufferSt[14]; //buffer to store string
Volcano_498 11:dc05458980b6 665 sprintf(bufferSt,"current:%c",pressGraphMode[pressGraphSetting]);
Volcano_498 11:dc05458980b6 666
Volcano_498 11:dc05458980b6 667 lcd.printString(bufferSt,0,5);
Volcano_498 11:dc05458980b6 668 lcd.refresh();
Volcano_498 11:dc05458980b6 669 }
Volcano_498 11:dc05458980b6 670
Volcano_498 12:1d4b5465ecc1 671 /**
Volcano_498 12:1d4b5465ecc1 672 Displays the PNought value setting sub-menu. PNought indicates pressure at sea level and changing it allows to compensate for altitude...
Volcano_498 12:1d4b5465ecc1 673 ...at a certain weather front.
Volcano_498 12:1d4b5465ecc1 674 */
Volcano_498 12:1d4b5465ecc1 675
Volcano_498 12:1d4b5465ecc1 676 void displayPNoughtMenu(){
Volcano_498 11:dc05458980b6 677 lcd.printString("Alter P0 val",0,0);
Volcano_498 11:dc05458980b6 678 lcd.printString("to compensate",0,1);
Volcano_498 11:dc05458980b6 679 lcd.printString("for altitude",0,2);
Volcano_498 11:dc05458980b6 680 lcd.printString("atWeatherfront",0,3);
Volcano_498 11:dc05458980b6 681 lcd.printString("CurrentValue:",0,4);
Volcano_498 11:dc05458980b6 682
Volcano_498 11:dc05458980b6 683 char bufferSt[14]; //buffer to store string
Volcano_498 12:1d4b5465ecc1 684 sprintf(bufferSt,"%.2f",PNought[PNoughtSetting]); //.2f works just as well for doubles as floats as doubles are essentially high-precision floats!
Volcano_498 11:dc05458980b6 685
Volcano_498 11:dc05458980b6 686 lcd.printString(bufferSt,0,5);
Volcano_498 11:dc05458980b6 687 lcd.refresh();
Volcano_498 11:dc05458980b6 688 }
Volcano_498 11:dc05458980b6 689
Volcano_498 12:1d4b5465ecc1 690 /**
Volcano_498 12:1d4b5465ecc1 691 Displays the "measurement title" which is just a collection of shapes to make the measurements menu look nicer...
Volcano_498 12:1d4b5465ecc1 692 */
Volcano_498 8:29ac7d274ae0 693 void displayMeasurementTitle(){
Volcano_498 8:29ac7d274ae0 694 // origin x,y,width,height,type
Volcano_498 8:29ac7d274ae0 695 lcd.drawRect(0,0,83,6,0); // transparent, just outline
Volcano_498 8:29ac7d274ae0 696 lcd.drawCircle(10,3,2,0); // x,y,radius,transparent with outline
Volcano_498 8:29ac7d274ae0 697 lcd.drawCircle(14,3,2,1); // x,y,radius,black fill
Volcano_498 8:29ac7d274ae0 698 lcd.drawCircle(18,3,2,0); // x,y,radius,transparent with outline
Volcano_498 8:29ac7d274ae0 699 lcd.drawCircle(22,3,2,1); // x,y,radius,black fill
Volcano_498 8:29ac7d274ae0 700 lcd.drawCircle(26,3,2,0); // x,y,radius,transparent with outline
Volcano_498 8:29ac7d274ae0 701 lcd.drawCircle(30,3,2,1); // x,y,radius,black fill
Volcano_498 8:29ac7d274ae0 702 lcd.drawCircle(34,3,2,0); // x,y,radius,transparent with outline
Volcano_498 8:29ac7d274ae0 703 lcd.drawCircle(38,3,2,1); // x,y,radius,black fill
Volcano_498 8:29ac7d274ae0 704 lcd.drawCircle(34,3,2,0); // x,y,radius,transparent with outline
Volcano_498 8:29ac7d274ae0 705 lcd.drawCircle(46,3,2,1); // x,y,radius,black fill
Volcano_498 8:29ac7d274ae0 706 lcd.drawCircle(50,3,2,0); // x,y,radius,transparent with outline
Volcano_498 8:29ac7d274ae0 707 lcd.drawCircle(54,3,2,1); // x,y,radius,black fill
Volcano_498 8:29ac7d274ae0 708 lcd.drawCircle(58,3,2,0); // x,y,radius,transparent with outline
Volcano_498 8:29ac7d274ae0 709 lcd.drawCircle(62,3,2,1); // x,y,radius,black fill
Volcano_498 8:29ac7d274ae0 710 lcd.drawCircle(66,3,2,0); // x,y,radius,transparent with outline
Volcano_498 8:29ac7d274ae0 711 lcd.drawCircle(70,3,2,1); // x,y,radius,black fill
Volcano_498 8:29ac7d274ae0 712 lcd.drawCircle(74,3,2,0); // x,y,radius,transparent with outline
Volcano_498 8:29ac7d274ae0 713
Volcano_498 8:29ac7d274ae0 714 // x0,y0,x1,y1,type 0-white,1-black,2-dotted
Volcano_498 8:29ac7d274ae0 715 lcd.drawLine(0,0,6,6,1);
Volcano_498 8:29ac7d274ae0 716 lcd.drawLine(0,6,6,0,1);
Volcano_498 8:29ac7d274ae0 717 /*
Volcano_498 8:29ac7d274ae0 718 * *
Volcano_498 8:29ac7d274ae0 719 * *
Volcano_498 8:29ac7d274ae0 720 * *
Volcano_498 8:29ac7d274ae0 721 * Black line with intercept; (3,3).
Volcano_498 8:29ac7d274ae0 722 * *
Volcano_498 8:29ac7d274ae0 723 * *
Volcano_498 8:29ac7d274ae0 724 * *
Volcano_498 8:29ac7d274ae0 725 */
Volcano_498 8:29ac7d274ae0 726 lcd.drawLine(77,0,83,6,1);
Volcano_498 8:29ac7d274ae0 727 lcd.drawLine(77,6,83,0,1);
Volcano_498 12:1d4b5465ecc1 728 }
Volcano_498 12:1d4b5465ecc1 729
Volcano_498 12:1d4b5465ecc1 730 /**
Volcano_498 12:1d4b5465ecc1 731 Prints current time on the screen whenever the measurements menu is updated. Time is first converted into strings to be held in buffers.
Volcano_498 12:1d4b5465ecc1 732 @param hourBuffer
Volcano_498 12:1d4b5465ecc1 733 @param dateBuffer
Volcano_498 12:1d4b5465ecc1 734 Displays time and date on two different lines.
Volcano_498 12:1d4b5465ecc1 735 */
Volcano_498 8:29ac7d274ae0 736
Volcano_498 10:06b35733ca25 737 void printCurrentTime(char hourBuffer[14], char dateBuffer[14]){
Volcano_498 10:06b35733ca25 738
Volcano_498 10:06b35733ca25 739 lcd.printString(hourBuffer,0,1); //print hour:minute:second on row 1, column 0.
Volcano_498 10:06b35733ca25 740 lcd.printString(dateBuffer,0,2); //print dd:mm:yyyy on row 2, column 0.
Volcano_498 10:06b35733ca25 741 }
Volcano_498 10:06b35733ca25 742
Volcano_498 2:08f2469728d5 743 //1 bar is 100000 Pa. An atm is 101325 Pa. Therefore an mb is 100 Pa.
Volcano_498 10:06b35733ca25 744 //http://www.cplusplus.com/reference/ctime/strftime/
Volcano_498 11:dc05458980b6 745 //has information on time string formatting.
Volcano_498 2:08f2469728d5 746
Volcano_498 3:70e14f1577f7 747 int main()
Volcano_498 3:70e14f1577f7 748 {
Volcano_498 3:70e14f1577f7 749
Volcano_498 10:06b35733ca25 750 splashFlip.attach(&splashDelay,3.0); //attach timer and wait for ISR to be called after 3 seconds.
Volcano_498 3:70e14f1577f7 751
Volcano_498 6:0aca5c17c988 752 displayTimer.attach(&timerExpiDisplay,dispInterval[dispSetting].time); //do the same for display dispInterval[dispSetting].time
Volcano_498 6:0aca5c17c988 753
Volcano_498 10:06b35733ca25 754 logTimer.attach(&timerExpiLog,1.0); //initiate log timer with an interval of a second.
Volcano_498 6:0aca5c17c988 755
Volcano_498 6:0aca5c17c988 756 menuButton.rise(&menuButtonPressed); //event generated on rising edge (a positive spike in voltage), indicated by .rise
Volcano_498 5:6d85cafa1085 757
Volcano_498 6:0aca5c17c988 758 buttonOne.rise(&buttonOnePressed);
Volcano_498 6:0aca5c17c988 759
Volcano_498 6:0aca5c17c988 760 buttonTwo.rise(&buttonTwoPressed);
Volcano_498 6:0aca5c17c988 761
Volcano_498 6:0aca5c17c988 762 buttonThree.rise(&buttonThreePressed);
Volcano_498 10:06b35733ca25 763
Volcano_498 12:1d4b5465ecc1 764 serial.attach(&serialISR); // attach serial ISR, which is to be used to set time.
Volcano_498 10:06b35733ca25 765
Volcano_498 10:06b35733ca25 766 char buffer[30]; // buffer used to store time string for logging.
Volcano_498 10:06b35733ca25 767 char bufferTwo[14]; //buffer used to store time string for hour/minute/second display.
Volcano_498 10:06b35733ca25 768 char bufferThree[14]; //buffer used to store time string for day/month/year display.
Volcano_498 11:dc05458980b6 769 char tempBuffer[14]; //buffer used to store temperature graph display chunks.
Volcano_498 11:dc05458980b6 770 char pressBuffer[14]; //buffer used to store pressure graph display chunks.
Volcano_498 5:6d85cafa1085 771
Volcano_498 1:454dddb8adc2 772 // first need to initialise display
Volcano_498 1:454dddb8adc2 773 lcd.init();
Volcano_498 3:70e14f1577f7 774
Volcano_498 1:454dddb8adc2 775 displayInitSplash();
Volcano_498 3:70e14f1577f7 776
Volcano_498 0:b30f86a9a1c5 777 //initialise barometer
Volcano_498 0:b30f86a9a1c5 778 bmp180.init();
Volcano_498 3:70e14f1577f7 779
Volcano_498 1:454dddb8adc2 780 PHY_PowerDown(); //powers down the Ethernet feature.
Volcano_498 14:054e6faf0ca8 781
Volcano_498 14:054e6faf0ca8 782 /*
Volcano_498 1:454dddb8adc2 783 int result = semihost_powerdown(); //as a result, power down the USB connection
Volcano_498 1:454dddb8adc2 784 //unless the cable is connected.
Volcano_498 14:054e6faf0ca8 785 //but this also prevents the flash memory from being overwritten when the cable is disconnected.
Volcano_498 14:054e6faf0ca8 786 //so one should uncomment this block of code only if the device is to be used with the cable attached.
Volcano_498 14:054e6faf0ca8 787 */
Volcano_498 1:454dddb8adc2 788 Measurement measurement; // object created for pressure & temperature using the structure declared in BMP180 class
Volcano_498 3:70e14f1577f7 789
Volcano_498 3:70e14f1577f7 790 while(1) {
Volcano_498 10:06b35733ca25 791 if(setTimeFlag){ //if serial interrupt is performed using a serial terminal program (e.g: CoolTerm) and serial interrupt performed (e.g: by pressing Enter)
Volcano_498 10:06b35733ca25 792 set_time(1430180280); // initialise time to 28th of April, 00:18:00 using this method.
Volcano_498 11:dc05458980b6 793 //if not used to initialise time, software will not be able to keep counting up in time, as it will reset every time the mbed is reset!
Volcano_498 10:06b35733ca25 794 //http://www.epochconverter.com/ is a site which converts real time into UNIX time.
Volcano_498 10:06b35733ca25 795 setTimeFlag = 0; //reset flag in order to prevent it from re-setting the time in an infinite loop once this happens!
Volcano_498 10:06b35733ca25 796 }
Volcano_498 10:06b35733ca25 797
Volcano_498 11:dc05458980b6 798 if(splashFlag == 0) { //if splash screen ISR has been called proceed with program flow
Volcano_498 3:70e14f1577f7 799 splashFlip.detach(); //detach Timeout object
Volcano_498 5:6d85cafa1085 800 lcd.clear();
Volcano_498 3:70e14f1577f7 801 clearCells();
Volcano_498 6:0aca5c17c988 802 lcd.refresh(); //need to refresh to write buffer on lcd
Volcano_498 11:dc05458980b6 803 lcd.normalMode(); //set the LCD's black-on-white standard colour layout. Especially in case it has been inverted before this can be handy.
Volcano_498 11:dc05458980b6 804
Volcano_498 11:dc05458980b6 805
Volcano_498 11:dc05458980b6 806 if(buttonThreeFlag){
Volcano_498 11:dc05458980b6 807 lcd.inverseMode(); //if buttonTwoFlag is set (just in the measurements menu, Button 2 has been pressed), invert colours.
Volcano_498 11:dc05458980b6 808 }
Volcano_498 3:70e14f1577f7 809
Volcano_498 5:6d85cafa1085 810 if(dispTimerFlag) {
Volcano_498 5:6d85cafa1085 811 //read values (T in degrees Celsius and P in mb).
Volcano_498 8:29ac7d274ae0 812 displayMeasurementTitle();
Volcano_498 5:6d85cafa1085 813 measurement = bmp180.readValues();
Volcano_498 5:6d85cafa1085 814 temp = measurement.temperature;
Volcano_498 5:6d85cafa1085 815 press = measurement.pressure;
Volcano_498 5:6d85cafa1085 816 /*formula for calculating altitude from sea level by using atmospheric pressure. Unit in metres.
Volcano_498 5:6d85cafa1085 817 Use pow(double a,double b) for indices, not the ^ sign. Just a reminder! Also check out this site:
Volcano_498 5:6d85cafa1085 818 http://www.mide.com/products/slamstick/air-pressure-altitude-calculator.php
Volcano_498 5:6d85cafa1085 819 */
Volcano_498 11:dc05458980b6 820 double PNoughtCurrent = PNought[PNoughtSetting];
Volcano_498 11:dc05458980b6 821 altitude = 44330.0*(1.0-(pow((press/PNoughtCurrent),(1.0/5.255)))); //pow(10,5) = 10^5
Volcano_498 6:0aca5c17c988 822 dispTimerFlag = 0;
Volcano_498 6:0aca5c17c988 823
Volcano_498 10:06b35733ca25 824 printCurrentTime(bufferTwo,bufferThree);
Volcano_498 10:06b35733ca25 825
Volcano_498 11:dc05458980b6 826 if(buttonOneFlag){ //if Button 1 has been pressed whilst in the measurements menu
Volcano_498 11:dc05458980b6 827 lcd.clear(); //clear lcd once
Volcano_498 11:dc05458980b6 828 lcd.printString("Temp Graph",0,0); //string, column #, row #
Volcano_498 11:dc05458980b6 829 sprintf(tempBuffer,"%.0f",tempThres[tempSetting].thresTemp);
Volcano_498 11:dc05458980b6 830 lcd.printString(tempBuffer,0,1); //display max. temperature value for graph. Keep in mind each string is 6 pixels wide and 8 pixels tall.
Volcano_498 11:dc05458980b6 831 sprintf(tempBuffer,"%.0f",lowerTemp[lowerTempSetting].thresTemp);
Volcano_498 11:dc05458980b6 832 lcd.printString(tempBuffer,0,5); //display min. temperature value for graph.
Volcano_498 11:dc05458980b6 833 int i = 18; //set the initial x-coordinate of the graph plotter.
Volcano_498 11:dc05458980b6 834 while(buttonOneFlag){ //then enter infinite buttonOneFlag loop
Volcano_498 11:dc05458980b6 835 if(dispTimerFlag){ //if this flag has been set for display setting (since the outer if statement will not be able to affect the while loop)
Volcano_498 11:dc05458980b6 836 dispTimerFlag = 0; //set flag to 0 and wait for it to be set again
Volcano_498 11:dc05458980b6 837 measurement = bmp180.readValues();
Volcano_498 11:dc05458980b6 838 temp = measurement.temperature;
Volcano_498 12:1d4b5465ecc1 839 int tempHeight = (temp/(tempThres[tempSetting].thresTemp + lowerTemp[lowerTempSetting].thresTemp))*40; //Set graph vertical point by dividing current temperature by (threshold temperature plus lower temperature). Which is the height of the plot space.
Volcano_498 11:dc05458980b6 840 if(tempGraphSetting == 0){ //column chart selected
Volcano_498 11:dc05458980b6 841 // x0,y0,x1,y1,type 0-white,1-black,2-dotted
Volcano_498 11:dc05458980b6 842 lcd.drawLine(i,47,i,(47-tempHeight),1);
Volcano_498 11:dc05458980b6 843 }
Volcano_498 11:dc05458980b6 844 else if(tempGraphSetting == 1){ //dot chart selected
Volcano_498 11:dc05458980b6 845 lcd.setPixel(i,(47-tempHeight)); //x, y. 47-tempHeight gives the y point as, 47 is the bottom of the display and nominally set to the lower threshold.
Volcano_498 11:dc05458980b6 846 }
Volcano_498 11:dc05458980b6 847 i++;
Volcano_498 11:dc05458980b6 848 if(i > 83){ //if the 84th pixel has been exceeded
Volcano_498 12:1d4b5465ecc1 849 i = 18; //set i back to 18.
Volcano_498 11:dc05458980b6 850 lcd.clear();
Volcano_498 11:dc05458980b6 851 lcd.printString("Temp Graph",0,0); //string, column #, row #
Volcano_498 11:dc05458980b6 852 sprintf(tempBuffer,"%.0f",tempThres[tempSetting].thresTemp);
Volcano_498 11:dc05458980b6 853 lcd.printString(tempBuffer,0,1); //display max. temperature value for graph. Keep in mind each string is 6 pixels wide and 8 pixels tall.
Volcano_498 11:dc05458980b6 854 sprintf(tempBuffer,"%.0f",lowerTemp[lowerTempSetting].thresTemp);
Volcano_498 11:dc05458980b6 855 lcd.printString(tempBuffer,0,5); //display min. temperature value for graph.
Volcano_498 11:dc05458980b6 856 }
Volcano_498 11:dc05458980b6 857 } //terminate dispTimerFlag
Volcano_498 11:dc05458980b6 858
Volcano_498 11:dc05458980b6 859 lcd.refresh();
Volcano_498 11:dc05458980b6 860 } //break while if button is pressed again
Volcano_498 11:dc05458980b6 861 } //terminate if
Volcano_498 11:dc05458980b6 862
Volcano_498 11:dc05458980b6 863 else if(buttonTwoFlag){ //if otherwise Button 2 has been pressed whilst in the measurements menu
Volcano_498 11:dc05458980b6 864 lcd.clear(); //clear lcd once
Volcano_498 11:dc05458980b6 865 lcd.printString("Press Graph",0,0); //string, column #, row #
Volcano_498 11:dc05458980b6 866 lcd.printString("1.5",0,1); //display max. pressure value (set for atm) for graph. Keep in mind each string is 6 pixels wide and 8 pixels tall.
Volcano_498 11:dc05458980b6 867 lcd.printString("0",0,5); //display min. pressure value for graph.
Volcano_498 11:dc05458980b6 868 int i = 18; //set the initial x-coordinate of the graph plotter.
Volcano_498 11:dc05458980b6 869 while(buttonTwoFlag){ //then enter infinite buttonOneFlag loop
Volcano_498 11:dc05458980b6 870 if(dispTimerFlag){ //if this flag has been set for display setting (since the outer if statement will not be able to affect the while loop)
Volcano_498 11:dc05458980b6 871 dispTimerFlag = 0; //set flag to 0 and wait for it to be set again
Volcano_498 11:dc05458980b6 872 measurement = bmp180.readValues();
Volcano_498 11:dc05458980b6 873 press = measurement.pressure; //1 atm is 1013.25 mb. 1519.875 mb equals 1.5 atm.
Volcano_498 12:1d4b5465ecc1 874 int pressHeight = (press/(1519.875))*40; //Set graph vertical point by dividing current pressure by the plot space height. Then multiply by 40 as it is the number of pixels for the plot space.
Volcano_498 11:dc05458980b6 875 if(pressGraphSetting == 0){ //column chart selected
Volcano_498 11:dc05458980b6 876 // x0,y0,x1,y1,type 0-white,1-black,2-dotted
Volcano_498 11:dc05458980b6 877 lcd.drawLine(i,47,i,(47-pressHeight),1);
Volcano_498 11:dc05458980b6 878 }
Volcano_498 11:dc05458980b6 879 else if(tempGraphSetting == 1){ //dot chart selected
Volcano_498 11:dc05458980b6 880 lcd.setPixel(i,(47-pressHeight)); //x, y. 47-tempHeight gives the y point as, 47 is the bottom of the display and nominally set to the lower threshold.
Volcano_498 11:dc05458980b6 881 }
Volcano_498 11:dc05458980b6 882 i++;
Volcano_498 11:dc05458980b6 883 if(i > 83){ //if the 84th pixel has been exceeded
Volcano_498 12:1d4b5465ecc1 884 i = 18; //set i back to 18.
Volcano_498 11:dc05458980b6 885 lcd.clear();
Volcano_498 11:dc05458980b6 886 lcd.printString("Temp Graph",0,0); //string, column #, row #
Volcano_498 11:dc05458980b6 887 lcd.printString("1.5",0,1); //display max. pressure value (set for atm) for graph. Keep in mind each string is 6 pixels wide and 8 pixels tall.
Volcano_498 11:dc05458980b6 888 lcd.printString("0",0,5); //display min. pressure value for graph.
Volcano_498 11:dc05458980b6 889 }
Volcano_498 11:dc05458980b6 890 } //terminate dispTimerFlag
Volcano_498 11:dc05458980b6 891
Volcano_498 11:dc05458980b6 892 lcd.refresh();
Volcano_498 11:dc05458980b6 893 } //break while if button is pressed again
Volcano_498 11:dc05458980b6 894 }
Volcano_498 11:dc05458980b6 895
Volcano_498 11:dc05458980b6 896 else{
Volcano_498 11:dc05458980b6 897 printReadings();
Volcano_498 11:dc05458980b6 898 }
Volcano_498 5:6d85cafa1085 899 lcd.refresh();
Volcano_498 10:06b35733ca25 900 //currentSessionArray[] = [temp,press];
Volcano_498 8:29ac7d274ae0 901
Volcano_498 9:693f69e0a175 902 if(temp > tempThres[tempSetting].thresTemp){ //if temperature exceeds set threshold
Volcano_498 9:693f69e0a175 903 redLED = 0.95; //apply a PWM signal and light up the red LED
Volcano_498 9:693f69e0a175 904 buzzerPwm = 0.5; //apply a PWM signal to buzzer with 50% duty ratio to imitate a square wave.
Volcano_498 9:693f69e0a175 905 buzzerPwm.period_us(500); //period of 500 us or 0.5 ms equals a frequency of 2000 Hz.
Volcano_498 9:693f69e0a175 906 greenLED = 0.0; //if green LED has been set, reset it.
Volcano_498 9:693f69e0a175 907 }
Volcano_498 9:693f69e0a175 908 else{ //if not, light up green LED to signify that the device is operating normally.
Volcano_498 9:693f69e0a175 909 greenLED = 1.0;
Volcano_498 9:693f69e0a175 910 buzzerPwm = 0.0; //if PWM signal is set and threshold exceeded once, stop the buzzer until threshold is reached again.
Volcano_498 9:693f69e0a175 911 redLED = 0.0; //if red LED has been lit up previously, turn it off.
Volcano_498 9:693f69e0a175 912 }
Volcano_498 10:06b35733ca25 913 } //terminate dispTimerFlag
Volcano_498 10:06b35733ca25 914
Volcano_498 10:06b35733ca25 915 if(logTimerFlag){ //if a second has elapsed and the flag set
Volcano_498 10:06b35733ca25 916 logTimerFlag = 0; //reset the flag
Volcano_498 10:06b35733ca25 917 logCounter++; //increment Log Counter
Volcano_498 10:06b35733ca25 918
Volcano_498 10:06b35733ca25 919 time_t seconds = time(NULL); // get current time
Volcano_498 10:06b35733ca25 920 // format time into a string (time and date)//
Volcano_498 10:06b35733ca25 921
Volcano_498 10:06b35733ca25 922
Volcano_498 10:06b35733ca25 923 strftime(buffer, 30 , "%R, %x", localtime(&seconds)); //%X --> Time representation in HH:MM:SS. %D --> %m/%d/%y
Volcano_498 10:06b35733ca25 924 //replace %X,%D by %c for date and time representation like "23 Aug 2001 14:55:02".
Volcano_498 10:06b35733ca25 925 //add %A to show day e.g: Thursday or lowercase for abbreviation (Thu).
Volcano_498 10:06b35733ca25 926 //%R, %x gives time format as 09:06 7/8/14, for easy logging.
Volcano_498 10:06b35733ca25 927
Volcano_498 10:06b35733ca25 928 strftime(bufferTwo, 14 , "%X", localtime(&seconds));
Volcano_498 10:06b35733ca25 929 strftime(bufferThree, 14 , "%x", localtime(&seconds));
Volcano_498 10:06b35733ca25 930
Volcano_498 10:06b35733ca25 931 printCurrentTime(bufferTwo,bufferThree);
Volcano_498 10:06b35733ca25 932 printReadings();
Volcano_498 10:06b35733ca25 933
Volcano_498 11:dc05458980b6 934 if(logCounter >= recInterval[recSetting].time){ //if counter reaches time setting or exceeds it
Volcano_498 10:06b35733ca25 935 writeDataToFile(temp,press,buffer); //write temperature, pressure and time setting on Flash Memory.
Volcano_498 10:06b35733ca25 936 logCounter = 0; //reset counter so the cycle starts again.
Volcano_498 10:06b35733ca25 937 }
Volcano_498 10:06b35733ca25 938 }
Volcano_498 6:0aca5c17c988 939
Volcano_498 6:0aca5c17c988 940 if(menuButtonFlag == 1){ //if menu button has been pressed once
Volcano_498 6:0aca5c17c988 941
Volcano_498 6:0aca5c17c988 942 lcd.clear(); //clear the lcd display
Volcano_498 6:0aca5c17c988 943 displayMenuOne(); //display the menu strings function
Volcano_498 7:104ac8e707e6 944 subMenuId = 0; //initially set subMenuId to zero in case it is not
Volcano_498 10:06b35733ca25 945 while(buttonOneAltFlag){ //while Button One is pressed AND the menu button is;
Volcano_498 10:06b35733ca25 946 //(because using if will affect other settings as well, even though we're only interested in this menu while this flag has been set.)
Volcano_498 7:104ac8e707e6 947 if(subMenuId == 0){ //if initially the UI wasn't in a sub-menu
Volcano_498 7:104ac8e707e6 948 lcd.clear(); //clear lcd
Volcano_498 7:104ac8e707e6 949 }
Volcano_498 6:0aca5c17c988 950 displayTempUnit(); //display unit change menu
Volcano_498 7:104ac8e707e6 951 lcd.refresh();
Volcano_498 7:104ac8e707e6 952 //this helps avoid vertical swipe blurs and re-overwrites on the display while in sub-menu.
Volcano_498 6:0aca5c17c988 953 subMenuId = 1; //set sub-menu number to avoid confusions for the processor as it might change other settings!
Volcano_498 10:06b35733ca25 954
Volcano_498 10:06b35733ca25 955 if(buttonTwoAltFlag && subMenuId == 1){ //if in addition to the above conditions button 2 is pressed
Volcano_498 6:0aca5c17c988 956 tempUnitSetting--; //decrease the unit setting
Volcano_498 6:0aca5c17c988 957 buttonTwoAltFlag = 0; //reset flag to avoid repeated unit changes on loop
Volcano_498 6:0aca5c17c988 958 if(tempUnitSetting < 0) //if it goes below 0
Volcano_498 6:0aca5c17c988 959 tempUnitSetting = 3; //go back to the highest value
Volcano_498 6:0aca5c17c988 960 }
Volcano_498 6:0aca5c17c988 961 if(buttonThreeAltFlag && subMenuId == 1){ //if otherwise button 3 has been pressed
Volcano_498 6:0aca5c17c988 962 tempUnitSetting++; //increase temp setting
Volcano_498 6:0aca5c17c988 963 buttonThreeAltFlag = 0;
Volcano_498 6:0aca5c17c988 964 if(tempUnitSetting > 3) //if the upper limit has been exceeded (3)
Volcano_498 6:0aca5c17c988 965 tempUnitSetting = 0; //reset it to zero
Volcano_498 6:0aca5c17c988 966 }
Volcano_498 6:0aca5c17c988 967 } //close button one alt
Volcano_498 10:06b35733ca25 968 buttonOneAltFlag = 0; //reset flag in case it is not after the while loop
Volcano_498 7:104ac8e707e6 969 lcd.clear();
Volcano_498 7:104ac8e707e6 970 displayMenuOne(); //display the menu strings function
Volcano_498 7:104ac8e707e6 971 subMenuId = 0; //reset sub-menu ID when loop has finished executing so it can be applied to other sub-menus.
Volcano_498 6:0aca5c17c988 972
Volcano_498 6:0aca5c17c988 973 while(buttonTwoAltFlag){ //if Button Two flag is set AND the menu button is;
Volcano_498 7:104ac8e707e6 974 if(subMenuId == 0){
Volcano_498 7:104ac8e707e6 975 lcd.clear(); //clear lcd
Volcano_498 7:104ac8e707e6 976 }
Volcano_498 6:0aca5c17c988 977 displayPressUnit(); //display unit change menu
Volcano_498 7:104ac8e707e6 978 lcd.refresh();
Volcano_498 6:0aca5c17c988 979 subMenuId = 2;
Volcano_498 6:0aca5c17c988 980
Volcano_498 10:06b35733ca25 981 if(buttonOneAltFlag && subMenuId == 2){ //if in to the above conditions button 1 is pressed
Volcano_498 6:0aca5c17c988 982 pressUnitSetting--; //decrease the unit setting
Volcano_498 6:0aca5c17c988 983 buttonOneAltFlag = 0; //reset flag to avoid repeated unit changes on loop
Volcano_498 6:0aca5c17c988 984 if(pressUnitSetting < 0) //if it goes below 0
Volcano_498 6:0aca5c17c988 985 pressUnitSetting = 2; //go back to the highest value
Volcano_498 6:0aca5c17c988 986 }
Volcano_498 6:0aca5c17c988 987 if(buttonThreeAltFlag && subMenuId == 2){ //if otherwise button 3 has been pressed
Volcano_498 6:0aca5c17c988 988 pressUnitSetting++; //increase pressure setting
Volcano_498 6:0aca5c17c988 989 buttonThreeAltFlag = 0;
Volcano_498 6:0aca5c17c988 990 if(pressUnitSetting > 2) //if the upper limit has been exceeded (2)
Volcano_498 6:0aca5c17c988 991 pressUnitSetting = 0; //reset it to zero
Volcano_498 10:06b35733ca25 992 }
Volcano_498 10:06b35733ca25 993 } //close button two alt
Volcano_498 10:06b35733ca25 994 buttonTwoAltFlag = 0;
Volcano_498 10:06b35733ca25 995 lcd.clear();
Volcano_498 10:06b35733ca25 996 displayMenuOne(); //display the menu strings function
Volcano_498 10:06b35733ca25 997 subMenuId = 0;
Volcano_498 10:06b35733ca25 998 while(buttonThreeAltFlag){ //while Button Three flag is set AND the menu button is;
Volcano_498 10:06b35733ca25 999 if(subMenuId == 0){
Volcano_498 10:06b35733ca25 1000 lcd.clear(); //clear lcd
Volcano_498 10:06b35733ca25 1001 }
Volcano_498 10:06b35733ca25 1002 displayLogMenu(); //display log interval change menu
Volcano_498 10:06b35733ca25 1003 lcd.refresh(); //refresh to write buffer on display.
Volcano_498 11:dc05458980b6 1004 subMenuId = 3;
Volcano_498 10:06b35733ca25 1005
Volcano_498 11:dc05458980b6 1006 if(buttonOneAltFlag && subMenuId == 3){ //if added to the above conditions button 1 is pressed
Volcano_498 10:06b35733ca25 1007 lcd.clear(); //clear lcd
Volcano_498 10:06b35733ca25 1008 recSetting--; //decrease the unit setting
Volcano_498 10:06b35733ca25 1009 buttonOneAltFlag = 0; //reset flag to avoid repeated unit changes on loop
Volcano_498 10:06b35733ca25 1010 if(recSetting < 0){ //if it goes below 0
Volcano_498 10:06b35733ca25 1011 recSetting = 9; //go back to the highest value
Volcano_498 10:06b35733ca25 1012 }
Volcano_498 10:06b35733ca25 1013 displayLogMenu(); //overwrite the display interval menu to avoid having "ms" and "s" on the same menu as ms might remain even if the setting has been altered!
Volcano_498 10:06b35733ca25 1014 }
Volcano_498 11:dc05458980b6 1015 if(buttonTwoAltFlag && subMenuId == 3){ //if otherwise button 3 has been pressed
Volcano_498 10:06b35733ca25 1016 lcd.clear(); //clear lcd
Volcano_498 10:06b35733ca25 1017 recSetting++; //increase pressure setting
Volcano_498 10:06b35733ca25 1018 buttonTwoAltFlag = 0;
Volcano_498 10:06b35733ca25 1019 if(recSetting > 9){ //if the upper limit has been exceeded (2)
Volcano_498 10:06b35733ca25 1020 recSetting = 0; //reset it to zero
Volcano_498 10:06b35733ca25 1021 }
Volcano_498 10:06b35733ca25 1022 displayLogMenu(); //overwrite the display interval menu to avoid having "ms" and "s" on the same menu as ms might remain even if the setting has been altered!
Volcano_498 6:0aca5c17c988 1023 }
Volcano_498 6:0aca5c17c988 1024 } //close button two alt
Volcano_498 10:06b35733ca25 1025 buttonThreeAltFlag = 0;
Volcano_498 7:104ac8e707e6 1026 lcd.clear();
Volcano_498 7:104ac8e707e6 1027 displayMenuOne(); //display the menu strings function
Volcano_498 7:104ac8e707e6 1028 subMenuId = 0;
Volcano_498 6:0aca5c17c988 1029 } //close menu button flag
Volcano_498 6:0aca5c17c988 1030
Volcano_498 7:104ac8e707e6 1031 subMenuId = 0; //reset sub-menu ID after going through first menu in case it is not already
Volcano_498 7:104ac8e707e6 1032 if(menuButtonFlag == 2){ //if menu button has been pressed twice
Volcano_498 6:0aca5c17c988 1033
Volcano_498 6:0aca5c17c988 1034 lcd.clear(); //clear the lcd display
Volcano_498 6:0aca5c17c988 1035 displayMenuTwo(); //display the menu strings function
Volcano_498 6:0aca5c17c988 1036 while(buttonOneAltFlag){ //if Button One is pressed AND the menu button is;
Volcano_498 7:104ac8e707e6 1037 if(subMenuId == 0){
Volcano_498 7:104ac8e707e6 1038 lcd.clear(); //clear lcd
Volcano_498 7:104ac8e707e6 1039 }
Volcano_498 6:0aca5c17c988 1040 displayDispMenu(); //display unit change menu
Volcano_498 7:104ac8e707e6 1041 lcd.refresh();
Volcano_498 6:0aca5c17c988 1042 subMenuId = 4;
Volcano_498 7:104ac8e707e6 1043 lcd.refresh();
Volcano_498 6:0aca5c17c988 1044 if(buttonTwoAltFlag && subMenuId == 4){ //if added to the above conditions button 2 is pressed
Volcano_498 10:06b35733ca25 1045 lcd.clear(); //clear lcd
Volcano_498 6:0aca5c17c988 1046 dispSetting--; //decrease setting
Volcano_498 6:0aca5c17c988 1047 buttonTwoAltFlag = 0; //reset flag to avoid repeated unit changes on loop
Volcano_498 10:06b35733ca25 1048 if(dispSetting < 0){ //if it goes below 0
Volcano_498 6:0aca5c17c988 1049 dispSetting = 5; //go back to the highest value
Volcano_498 10:06b35733ca25 1050 }
Volcano_498 10:06b35733ca25 1051 displayDispMenu(); //overwrite the display interval menu to avoid having "ms" and "s" on the same menu as ms might remain even if the setting has been altered!
Volcano_498 10:06b35733ca25 1052 displayTimer.detach(); //detach the timer to disable it to overwrite the new setting
Volcano_498 10:06b35733ca25 1053 displayTimer.attach(&timerExpiDisplay,dispInterval[dispSetting].time); //re-attach the timer.
Volcano_498 6:0aca5c17c988 1054 }
Volcano_498 6:0aca5c17c988 1055 if(buttonThreeAltFlag && subMenuId == 4){ //if otherwise button 3 has been pressed
Volcano_498 10:06b35733ca25 1056 lcd.clear(); //clear lcd
Volcano_498 6:0aca5c17c988 1057 dispSetting++; //increase setting
Volcano_498 6:0aca5c17c988 1058 buttonThreeAltFlag = 0;
Volcano_498 10:06b35733ca25 1059 if(dispSetting > 5){ //if the upper limit has been exceeded (3)
Volcano_498 6:0aca5c17c988 1060 dispSetting = 0; //reset it to zero
Volcano_498 10:06b35733ca25 1061 }
Volcano_498 10:06b35733ca25 1062 displayDispMenu(); //overwrite the display interval menu to avoid having "ms" and "s" on the same menu as ms might remain even if the setting has been altered!
Volcano_498 10:06b35733ca25 1063 displayTimer.detach(); //detach the timer to disable it to overwrite the new setting
Volcano_498 10:06b35733ca25 1064 displayTimer.attach(&timerExpiDisplay,dispInterval[dispSetting].time); //re-attach the timer.
Volcano_498 6:0aca5c17c988 1065 }
Volcano_498 6:0aca5c17c988 1066 } //close button one alt
Volcano_498 6:0aca5c17c988 1067 buttonOneAltFlag = 0;
Volcano_498 7:104ac8e707e6 1068 lcd.clear(); //clear the lcd display
Volcano_498 7:104ac8e707e6 1069 displayMenuTwo(); //display the menu strings function
Volcano_498 7:104ac8e707e6 1070 subMenuId = 0;
Volcano_498 6:0aca5c17c988 1071
Volcano_498 6:0aca5c17c988 1072 while(buttonTwoAltFlag){ //if Button Two flag is set AND the menu button is;
Volcano_498 7:104ac8e707e6 1073 if(subMenuId == 0){
Volcano_498 7:104ac8e707e6 1074 lcd.clear(); //clear lcd
Volcano_498 7:104ac8e707e6 1075 }
Volcano_498 6:0aca5c17c988 1076 displayThresholdTemp(); //display unit change menu
Volcano_498 7:104ac8e707e6 1077 lcd.refresh();
Volcano_498 6:0aca5c17c988 1078 subMenuId = 5;
Volcano_498 6:0aca5c17c988 1079 if(buttonOneAltFlag && subMenuId == 5){ //if added to the above conditions button 1 is pressed
Volcano_498 6:0aca5c17c988 1080 tempSetting--; //decrease setting
Volcano_498 6:0aca5c17c988 1081 buttonOneAltFlag = 0; //reset flag to avoid repeated unit changes on loop
Volcano_498 6:0aca5c17c988 1082 if(tempSetting < 0) //if it goes below 0
Volcano_498 6:0aca5c17c988 1083 tempSetting = 4; //go back to the highest value
Volcano_498 6:0aca5c17c988 1084 }
Volcano_498 6:0aca5c17c988 1085 if(buttonThreeAltFlag && subMenuId == 5){ //if otherwise button 3 has been pressed
Volcano_498 6:0aca5c17c988 1086 tempSetting++; //increase setting
Volcano_498 6:0aca5c17c988 1087 buttonThreeAltFlag = 0;
Volcano_498 6:0aca5c17c988 1088 if(tempSetting > 4) //if the upper limit has been exceeded (2)
Volcano_498 6:0aca5c17c988 1089 tempSetting = 0; //reset it to zero
Volcano_498 6:0aca5c17c988 1090 }
Volcano_498 6:0aca5c17c988 1091 } //close button two alt
Volcano_498 6:0aca5c17c988 1092 buttonTwoAltFlag = 0;
Volcano_498 7:104ac8e707e6 1093 lcd.clear(); //clear the lcd display
Volcano_498 7:104ac8e707e6 1094 displayMenuTwo(); //display the menu strings function
Volcano_498 7:104ac8e707e6 1095 subMenuId = 0;
Volcano_498 6:0aca5c17c988 1096
Volcano_498 6:0aca5c17c988 1097 while(buttonThreeAltFlag){ //if Button Three flag is set AND the menu button is;
Volcano_498 7:104ac8e707e6 1098 if(subMenuId == 0){
Volcano_498 7:104ac8e707e6 1099 lcd.clear(); //clear lcd
Volcano_498 7:104ac8e707e6 1100 }
Volcano_498 6:0aca5c17c988 1101 displayAltitudeUnit(); //display unit change menu
Volcano_498 7:104ac8e707e6 1102 lcd.refresh();
Volcano_498 6:0aca5c17c988 1103 subMenuId = 6;
Volcano_498 6:0aca5c17c988 1104 if(buttonOneAltFlag && subMenuId == 6){ //if added to the above conditions button 1 is pressed
Volcano_498 6:0aca5c17c988 1105 altUnitSetting--; //decrease the unit setting
Volcano_498 6:0aca5c17c988 1106 buttonOneAltFlag = 0; //reset flag to avoid repeated unit changes on loop
Volcano_498 6:0aca5c17c988 1107 if(altUnitSetting < 0) //if it goes below 0
Volcano_498 6:0aca5c17c988 1108 altUnitSetting = 2; //go back to the highest value
Volcano_498 6:0aca5c17c988 1109 }
Volcano_498 6:0aca5c17c988 1110 if(buttonTwoAltFlag && subMenuId == 6){ //if otherwise button 2 has been pressed
Volcano_498 6:0aca5c17c988 1111 altUnitSetting++; //increase pressure setting
Volcano_498 6:0aca5c17c988 1112 buttonTwoAltFlag = 0;
Volcano_498 6:0aca5c17c988 1113 if(altUnitSetting > 2) //if the upper limit has been exceeded (2)
Volcano_498 6:0aca5c17c988 1114 altUnitSetting = 0; //reset it to zero
Volcano_498 6:0aca5c17c988 1115 }
Volcano_498 6:0aca5c17c988 1116 } //close button three alt
Volcano_498 6:0aca5c17c988 1117 buttonThreeAltFlag = 0;
Volcano_498 7:104ac8e707e6 1118 lcd.clear(); //clear the lcd display
Volcano_498 7:104ac8e707e6 1119 displayMenuTwo(); //display the menu strings function
Volcano_498 7:104ac8e707e6 1120 subMenuId = 0;
Volcano_498 6:0aca5c17c988 1121 } //close menu button flag
Volcano_498 6:0aca5c17c988 1122
Volcano_498 11:dc05458980b6 1123 subMenuId = 0;
Volcano_498 11:dc05458980b6 1124 if(menuButtonFlag == 3){ //if menu button has been pressed twice
Volcano_498 11:dc05458980b6 1125
Volcano_498 11:dc05458980b6 1126 lcd.clear(); //clear the lcd display
Volcano_498 11:dc05458980b6 1127 displayMenuThree(); //display the menu strings function
Volcano_498 11:dc05458980b6 1128 while(buttonOneAltFlag){ //while Button One is pressed AND the menu button is;
Volcano_498 11:dc05458980b6 1129 if(subMenuId == 0){
Volcano_498 11:dc05458980b6 1130 lcd.clear(); //clear lcd
Volcano_498 11:dc05458980b6 1131 }
Volcano_498 11:dc05458980b6 1132 displayTempMode(); //display temperature graph model change menu
Volcano_498 11:dc05458980b6 1133 lcd.refresh();
Volcano_498 11:dc05458980b6 1134 subMenuId = 7;
Volcano_498 11:dc05458980b6 1135 if(buttonTwoAltFlag && subMenuId == 7){ //if added to the above conditions button 2 is pressed
Volcano_498 11:dc05458980b6 1136 lcd.clear(); //clear lcd
Volcano_498 11:dc05458980b6 1137 tempGraphSetting = !tempGraphSetting; //change setting to its opposite (if 1, reset; if 0, set to 1). Increasing doesn't help when the setting can only have two settings as it can pop up with unintended characters before the flag resets!
Volcano_498 11:dc05458980b6 1138 buttonTwoAltFlag = 0; //reset flag to avoid repeated unit changes on loop
Volcano_498 11:dc05458980b6 1139 displayTempMode(); //overwrite the temperature graph menu
Volcano_498 11:dc05458980b6 1140 }
Volcano_498 11:dc05458980b6 1141 if(buttonThreeAltFlag && subMenuId == 7){ //if otherwise button 3 has been pressed
Volcano_498 11:dc05458980b6 1142 lcd.clear(); //clear lcd
Volcano_498 11:dc05458980b6 1143 lowerTempSetting++; //increase setting
Volcano_498 11:dc05458980b6 1144 buttonThreeAltFlag = 0;
Volcano_498 11:dc05458980b6 1145 if(lowerTempSetting > 4){ //if the upper limit has been exceeded (3)
Volcano_498 11:dc05458980b6 1146 lowerTempSetting = 0; //reset it to zero
Volcano_498 11:dc05458980b6 1147 }
Volcano_498 11:dc05458980b6 1148 displayTempMode(); //overwrite the temperature graph menu
Volcano_498 11:dc05458980b6 1149 }
Volcano_498 11:dc05458980b6 1150 } //close button one alt
Volcano_498 11:dc05458980b6 1151 buttonOneAltFlag = 0;
Volcano_498 11:dc05458980b6 1152 lcd.clear(); //clear the lcd display
Volcano_498 11:dc05458980b6 1153 displayMenuThree(); //display the menu strings function
Volcano_498 11:dc05458980b6 1154 subMenuId = 0;
Volcano_498 11:dc05458980b6 1155
Volcano_498 11:dc05458980b6 1156 while(buttonTwoAltFlag){ //if Button Two flag is set AND the menu button is;
Volcano_498 11:dc05458980b6 1157 if(logTimerFlag){
Volcano_498 11:dc05458980b6 1158 lcd.clear(); //clear lcd
Volcano_498 11:dc05458980b6 1159 displayPressMode(); //display unit change menu
Volcano_498 11:dc05458980b6 1160 lcd.refresh();
Volcano_498 11:dc05458980b6 1161 logTimerFlag = 0;
Volcano_498 11:dc05458980b6 1162 }
Volcano_498 11:dc05458980b6 1163 subMenuId = 8;
Volcano_498 11:dc05458980b6 1164 if(buttonOneAltFlag && subMenuId == 8){ //if added to the above conditions button 1 is pressed
Volcano_498 11:dc05458980b6 1165 pressGraphSetting = !pressGraphSetting; //invert the setting so it becomes a 1 when it previously used to be a 0 and vice versa.
Volcano_498 11:dc05458980b6 1166 buttonOneAltFlag = 0; //reset flag to avoid repeated unit changes on loop
Volcano_498 11:dc05458980b6 1167 }
Volcano_498 11:dc05458980b6 1168 //no ButtonThree option here as it has no use... or is there not?
Volcano_498 11:dc05458980b6 1169 while(buttonThreeAltFlag && subMenuId == 8){ //if added to the above conditions button 1 is pressed
Volcano_498 11:dc05458980b6 1170 if(logTimerFlag){
Volcano_498 11:dc05458980b6 1171 lcd.clear();
Volcano_498 11:dc05458980b6 1172 lcd.printString("*Easter Egg*",0,0);
Volcano_498 11:dc05458980b6 1173 lcd.printString("No Age of",0,1);
Volcano_498 11:dc05458980b6 1174 lcd.printString("Empires puns",0,2);
Volcano_498 11:dc05458980b6 1175 lcd.printString("To be Found",0,3);
Volcano_498 11:dc05458980b6 1176 lcd.printString("Here!",0,4);
Volcano_498 11:dc05458980b6 1177 lcd.printString("B3 to go back",0,5);
Volcano_498 11:dc05458980b6 1178 lcd.refresh();
Volcano_498 11:dc05458980b6 1179 logTimerFlag = 0;
Volcano_498 11:dc05458980b6 1180 }
Volcano_498 11:dc05458980b6 1181 }
Volcano_498 11:dc05458980b6 1182 } //close button two alt
Volcano_498 11:dc05458980b6 1183 buttonTwoAltFlag = 0;
Volcano_498 11:dc05458980b6 1184 lcd.clear(); //clear the lcd display
Volcano_498 11:dc05458980b6 1185 displayMenuThree(); //display the menu strings function
Volcano_498 11:dc05458980b6 1186 subMenuId = 0;
Volcano_498 11:dc05458980b6 1187
Volcano_498 11:dc05458980b6 1188 while(buttonThreeAltFlag){ //if Button Three flag is set AND the menu button is;
Volcano_498 11:dc05458980b6 1189 if(subMenuId == 0){
Volcano_498 11:dc05458980b6 1190 lcd.clear(); //clear lcd
Volcano_498 11:dc05458980b6 1191 }
Volcano_498 11:dc05458980b6 1192 displayPNoughtMenu(); //display Altitude Compensation change menu
Volcano_498 11:dc05458980b6 1193 lcd.refresh();
Volcano_498 11:dc05458980b6 1194 subMenuId = 9;
Volcano_498 11:dc05458980b6 1195 if(buttonOneAltFlag && subMenuId == 9){ //if added to the above conditions button 1 is pressed
Volcano_498 11:dc05458980b6 1196 PNoughtSetting--; //decrease the unit setting
Volcano_498 11:dc05458980b6 1197 buttonOneAltFlag = 0; //reset flag to avoid repeated unit changes on loop
Volcano_498 11:dc05458980b6 1198 if(PNoughtSetting < 0) //if it goes below 0
Volcano_498 11:dc05458980b6 1199 PNoughtSetting = 12; //go back to the highest value
Volcano_498 11:dc05458980b6 1200 }
Volcano_498 11:dc05458980b6 1201 if(buttonTwoAltFlag && subMenuId == 9){ //if otherwise button 2 has been pressed
Volcano_498 11:dc05458980b6 1202 PNoughtSetting++; //increase pressure setting
Volcano_498 11:dc05458980b6 1203 buttonTwoAltFlag = 0;
Volcano_498 11:dc05458980b6 1204 if(PNoughtSetting > 12) //if the upper limit has been exceeded (12)
Volcano_498 11:dc05458980b6 1205 PNoughtSetting = 0; //reset it to zero
Volcano_498 11:dc05458980b6 1206 }
Volcano_498 11:dc05458980b6 1207 } //close button three alt
Volcano_498 11:dc05458980b6 1208 buttonThreeAltFlag = 0;
Volcano_498 11:dc05458980b6 1209 lcd.clear(); //clear the lcd display
Volcano_498 11:dc05458980b6 1210 displayMenuThree(); //display the menu strings function
Volcano_498 11:dc05458980b6 1211 subMenuId = 0;
Volcano_498 11:dc05458980b6 1212 } //close menu button flag
Volcano_498 5:6d85cafa1085 1213
Volcano_498 5:6d85cafa1085 1214
Volcano_498 5:6d85cafa1085 1215 Sleep(); //put the mbed to sleep once the program flow has been completed.
Volcano_498 11:dc05458980b6 1216 lcd.setBrightness(potAin.read()); //read potentiometer ratio and set display brightness according to it. Function inside a function...
Volcano_498 5:6d85cafa1085 1217
Volcano_498 3:70e14f1577f7 1218
Volcano_498 3:70e14f1577f7 1219 } //close if
Volcano_498 3:70e14f1577f7 1220 } //close while
Volcano_498 1:454dddb8adc2 1221 } //terminate main()
Volcano_498 2:08f2469728d5 1222
Volcano_498 5:6d85cafa1085 1223 /**
Volcano_498 11:dc05458980b6 1224 Fetches readings from the sensor via the main() function and prints them on the display.
Volcano_498 11:dc05458980b6 1225 Or converts them into their respective units depending on temperature/pressure unit settings.
Volcano_498 5:6d85cafa1085 1226 @param temp - temperature reading from the BMP180(˚C).
Volcano_498 5:6d85cafa1085 1227 @param press - pressure reading from the BMP180(mb).
Volcano_498 5:6d85cafa1085 1228 @param altitude - altitude calculated from the pressure reading (m).
Volcano_498 5:6d85cafa1085 1229 */
Volcano_498 5:6d85cafa1085 1230
Volcano_498 3:70e14f1577f7 1231 void printReadings()
Volcano_498 3:70e14f1577f7 1232 {
Volcano_498 2:08f2469728d5 1233 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
Volcano_498 3:70e14f1577f7 1234 // so can display a string of a maximum 14 characters in length
Volcano_498 3:70e14f1577f7 1235 // or create formatted strings - ensure they aren't more than 14 characters long
Volcano_498 7:104ac8e707e6 1236
Volcano_498 7:104ac8e707e6 1237 if(tempUnitSetting == 0){ //if Celsius has been selected as the temperature unit
Volcano_498 7:104ac8e707e6 1238 int length = sprintf(buffer,"T = %.2f 'C",temp); // print formatted data to buffer
Volcano_498 7:104ac8e707e6 1239 // it is important the format specifier ensures the length will fit in the buffer
Volcano_498 7:104ac8e707e6 1240 if (length <= 14) { // if string will fit on display
Volcano_498 10:06b35733ca25 1241 lcd.printString(buffer,0,3); // display on screen. Column 0, row 3.
Volcano_498 7:104ac8e707e6 1242 }
Volcano_498 7:104ac8e707e6 1243 } //close unit setting 0
Volcano_498 7:104ac8e707e6 1244 else if(tempUnitSetting == 1){ //Fahrenheit
Volcano_498 7:104ac8e707e6 1245 float tempTemp = (temp*1.8) + 32;
Volcano_498 11:dc05458980b6 1246 int length = sprintf(buffer,"T = %.2f 'F",tempTemp); // print formatted data to buffer
Volcano_498 7:104ac8e707e6 1247 // it is important the format specifier ensures the length will fit in the buffer
Volcano_498 7:104ac8e707e6 1248 if (length <= 14) { // if string will fit on display
Volcano_498 10:06b35733ca25 1249 lcd.printString(buffer,0,3); // display on screen. Column 0, row 3.
Volcano_498 7:104ac8e707e6 1250 }
Volcano_498 7:104ac8e707e6 1251 } //close unit setting 1
Volcano_498 7:104ac8e707e6 1252 else if(tempUnitSetting == 2){ //Kelvin
Volcano_498 7:104ac8e707e6 1253 float tempTemp = temp + 273.15;
Volcano_498 7:104ac8e707e6 1254 int length = sprintf(buffer,"T = %.1f K",tempTemp); // print formatted data to buffer
Volcano_498 7:104ac8e707e6 1255 // it is important the format specifier ensures the length will fit in the buffer
Volcano_498 7:104ac8e707e6 1256 if (length <= 14) { // if string will fit on display
Volcano_498 10:06b35733ca25 1257 lcd.printString(buffer,0,3); // display on screen. Column 0, row 3.
Volcano_498 7:104ac8e707e6 1258 }
Volcano_498 7:104ac8e707e6 1259 } //close unit setting 2
Volcano_498 7:104ac8e707e6 1260
Volcano_498 7:104ac8e707e6 1261 else if(tempUnitSetting == 3){ //Rankine
Volcano_498 7:104ac8e707e6 1262 float tempTemp = (temp + 273.15)*1.8;
Volcano_498 11:dc05458980b6 1263 int length = sprintf(buffer,"T = %.1f 'Ra",tempTemp); // print formatted data to buffer
Volcano_498 3:70e14f1577f7 1264 // it is important the format specifier ensures the length will fit in the buffer
Volcano_498 7:104ac8e707e6 1265 if (length <= 14) { // if string will fit on display
Volcano_498 10:06b35733ca25 1266 lcd.printString(buffer,0,3); // display on screen. Column 0, row 3.
Volcano_498 7:104ac8e707e6 1267 }
Volcano_498 7:104ac8e707e6 1268 } //close unit setting 3
Volcano_498 7:104ac8e707e6 1269
Volcano_498 7:104ac8e707e6 1270 if(pressUnitSetting == 0){ //if pressure is to be displayed in mb
Volcano_498 7:104ac8e707e6 1271 int length = sprintf(buffer,"P = %.2f mb",press); //use single letters to represent parameters or string may not fit in the banks!
Volcano_498 7:104ac8e707e6 1272 if (length <= 14) {
Volcano_498 10:06b35733ca25 1273 lcd.printString(buffer,0,4); // Column 0, row 4.
Volcano_498 7:104ac8e707e6 1274 }
Volcano_498 7:104ac8e707e6 1275 } //close unit setting 0
Volcano_498 7:104ac8e707e6 1276
Volcano_498 7:104ac8e707e6 1277 else if(pressUnitSetting == 1){ //Pa
Volcano_498 7:104ac8e707e6 1278 float tempPress = press*100; //convert from mb to Pa
Volcano_498 7:104ac8e707e6 1279 int length = sprintf(buffer,"P = %.0f Pa",tempPress); //use single letters to represent parameters or string may not fit in the banks!
Volcano_498 7:104ac8e707e6 1280 if (length <= 14) {
Volcano_498 10:06b35733ca25 1281 lcd.printString(buffer,0,4); // Column 0, row 4.
Volcano_498 7:104ac8e707e6 1282 }
Volcano_498 7:104ac8e707e6 1283 } //close unit setting 1
Volcano_498 7:104ac8e707e6 1284 else if(pressUnitSetting == 2){ //atm
Volcano_498 7:104ac8e707e6 1285 float tempPress = press/1013.25; //an atm is 1013.25 mb; therefore dividing press by that gives pressure in atm.
Volcano_498 11:dc05458980b6 1286 int length = sprintf(buffer,"P = %.4f atm",tempPress); //use single letters to represent parameters or string may not fit in the banks!
Volcano_498 7:104ac8e707e6 1287 if (length <= 14) {
Volcano_498 10:06b35733ca25 1288 lcd.printString(buffer,0,4); // Column 0, row 4.
Volcano_498 7:104ac8e707e6 1289 }
Volcano_498 7:104ac8e707e6 1290 } //close unit setting 2
Volcano_498 7:104ac8e707e6 1291
Volcano_498 7:104ac8e707e6 1292 //Now for the altitude display settings. Bear in mind that a metre is 3.2808399 feet; or 1.0936133 yards. Three feet equals a yard.
Volcano_498 7:104ac8e707e6 1293 if(altUnitSetting == 0){ //if metres have been selected
Volcano_498 7:104ac8e707e6 1294 int length = sprintf(buffer,"A = %.1f m",altitude);
Volcano_498 7:104ac8e707e6 1295 if (length <= 14) {
Volcano_498 10:06b35733ca25 1296 lcd.printString(buffer,0,5); //Column 0, row 3.
Volcano_498 7:104ac8e707e6 1297 }
Volcano_498 7:104ac8e707e6 1298 } // close unit setting 0
Volcano_498 7:104ac8e707e6 1299 else if(altUnitSetting == 1){ //feet
Volcano_498 7:104ac8e707e6 1300 float tempAlt = altitude*3.2808399; //convert to feet
Volcano_498 7:104ac8e707e6 1301 int length = sprintf(buffer,"A = %.1f ft",tempAlt);
Volcano_498 7:104ac8e707e6 1302 if (length <= 14) {
Volcano_498 10:06b35733ca25 1303 lcd.printString(buffer,0,5); //Column 0, row 5.
Volcano_498 7:104ac8e707e6 1304 }
Volcano_498 7:104ac8e707e6 1305 } //close unit setting 1
Volcano_498 7:104ac8e707e6 1306 else if(altUnitSetting == 2){ //yards
Volcano_498 7:104ac8e707e6 1307 float tempAlt = altitude*1.0936133; //convert to yards
Volcano_498 11:dc05458980b6 1308 int length = sprintf(buffer,"A = %.1f yd",tempAlt);
Volcano_498 7:104ac8e707e6 1309 if (length <= 14) {
Volcano_498 10:06b35733ca25 1310 lcd.printString(buffer,0,5); //Column 0, row 5.
Volcano_498 7:104ac8e707e6 1311 }
Volcano_498 7:104ac8e707e6 1312 } //close unit setting 2
Volcano_498 3:70e14f1577f7 1313 }
Volcano_498 3:70e14f1577f7 1314
Volcano_498 12:1d4b5465ecc1 1315 /**
Volcano_498 12:1d4b5465ecc1 1316 Function to "kill" all cells after looping through i-j coordinates. Used as a back-up to lcd.clear() should that fail.
Volcano_498 12:1d4b5465ecc1 1317 Void type, so it returns no values.
Volcano_498 12:1d4b5465ecc1 1318 */
Volcano_498 3:70e14f1577f7 1319 void clearCells()
Volcano_498 3:70e14f1577f7 1320 {
Volcano_498 3:70e14f1577f7 1321 //loop through cells, and clear them
Volcano_498 3:70e14f1577f7 1322 for (int i = 0; i < 83 ; i++) {
Volcano_498 3:70e14f1577f7 1323 for (int j = 0; j < 47; j++) {
Volcano_498 3:70e14f1577f7 1324 lcd.clearPixel(i,j); //function to "kill" all cells after looping through.
Volcano_498 2:08f2469728d5 1325 }
Volcano_498 3:70e14f1577f7 1326 }
Volcano_498 3:70e14f1577f7 1327 lcd.refresh(); //must refresh to write buffer to display
Volcano_498 12:1d4b5465ecc1 1328 }