A Weather station designed to read the values of temperature and pressure from the sensor (BMP180), data displayed via a nokia N5110 display.

Dependencies:   BMP180 N5110 PowerControl mbed

Committer:
amiraseman
Date:
Mon May 11 22:10:42 2015 +0000
Revision:
27:06fbad36c15e
Parent:
26:c0d8d2f68406
Final Commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
amiraseman 23:a0ce9fa869c2 1 /**
amiraseman 23:a0ce9fa869c2 2
amiraseman 23:a0ce9fa869c2 3 @file Barometer.h
amiraseman 23:a0ce9fa869c2 4 @brief Header file containing member functions and variables
amiraseman 23:a0ce9fa869c2 5 @author Amir M. Asemanpayeh
amiraseman 23:a0ce9fa869c2 6 @date May 2015
amiraseman 23:a0ce9fa869c2 7
amiraseman 23:a0ce9fa869c2 8 @brief Header file - Contains Global Variables, GPIO and Pins and Function prototypes
amiraseman 23:a0ce9fa869c2 9
amiraseman 23:a0ce9fa869c2 10 */
amiraseman 23:a0ce9fa869c2 11
amiraseman 23:a0ce9fa869c2 12
amiraseman 23:a0ce9fa869c2 13 #include "mbed.h"
amiraseman 23:a0ce9fa869c2 14 #include "N5110.h"
amiraseman 23:a0ce9fa869c2 15 #include "BMP180.h"
amiraseman 23:a0ce9fa869c2 16 #include "PowerControl/PowerControl.h"
amiraseman 23:a0ce9fa869c2 17 #include "PowerControl/EthernetPowerControl.h"
amiraseman 23:a0ce9fa869c2 18
amiraseman 23:a0ce9fa869c2 19 /**
amiraseman 23:a0ce9fa869c2 20 @namespace bmp180
amiraseman 23:a0ce9fa869c2 21 @brief A I2C instance to interact with the BMP sensor \n SDA, SCL
amiraseman 23:a0ce9fa869c2 22 */
amiraseman 23:a0ce9fa869c2 23 BMP180 bmp180(p28,p27);
amiraseman 23:a0ce9fa869c2 24
amiraseman 23:a0ce9fa869c2 25
amiraseman 23:a0ce9fa869c2 26 /**
amiraseman 23:a0ce9fa869c2 27 @namespace lcd
amiraseman 23:a0ce9fa869c2 28 @brief A serial data protocol to operate with a master/slave relationship to interact with the lcd \n VCC,SCE,RST,D/C,MOSI,SCLK,LED
amiraseman 23:a0ce9fa869c2 29 */
amiraseman 23:a0ce9fa869c2 30 N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
amiraseman 23:a0ce9fa869c2 31
amiraseman 23:a0ce9fa869c2 32
amiraseman 23:a0ce9fa869c2 33 /**
amiraseman 23:a0ce9fa869c2 34 @namespace leds
amiraseman 23:a0ce9fa869c2 35 @brief GPIO bus output for status LEDs
amiraseman 23:a0ce9fa869c2 36 */
amiraseman 23:a0ce9fa869c2 37 BusOut leds(LED4,LED3,LED2,LED1);
amiraseman 23:a0ce9fa869c2 38
amiraseman 23:a0ce9fa869c2 39
amiraseman 23:a0ce9fa869c2 40 /**
amiraseman 23:a0ce9fa869c2 41 @namespace serial
amiraseman 23:a0ce9fa869c2 42 @brief A USB Virtual Serial Port to print out messages to a host PC terminal
amiraseman 23:a0ce9fa869c2 43 */
amiraseman 23:a0ce9fa869c2 44 Serial serial(USBTX,USBRX);
amiraseman 23:a0ce9fa869c2 45
amiraseman 23:a0ce9fa869c2 46
amiraseman 23:a0ce9fa869c2 47 /**
amiraseman 23:a0ce9fa869c2 48 @namespace local
amiraseman 23:a0ce9fa869c2 49 @brief A local file system declared to store data files
amiraseman 23:a0ce9fa869c2 50 */
amiraseman 23:a0ce9fa869c2 51 LocalFileSystem local("local");
amiraseman 23:a0ce9fa869c2 52
amiraseman 23:a0ce9fa869c2 53
amiraseman 23:a0ce9fa869c2 54 /**
amiraseman 23:a0ce9fa869c2 55 @namespace button1
amiraseman 23:a0ce9fa869c2 56 @brief An Interrupt on digital pushbutton1 input p16
amiraseman 23:a0ce9fa869c2 57 */
amiraseman 23:a0ce9fa869c2 58 InterruptIn button1(p16);
amiraseman 23:a0ce9fa869c2 59
amiraseman 23:a0ce9fa869c2 60
amiraseman 23:a0ce9fa869c2 61 /**
amiraseman 23:a0ce9fa869c2 62 @namespace button2
amiraseman 23:a0ce9fa869c2 63 @brief An Interrupt on digital pushbutton2 input p17
amiraseman 23:a0ce9fa869c2 64 */
amiraseman 23:a0ce9fa869c2 65 InterruptIn button2(p17);
amiraseman 23:a0ce9fa869c2 66
amiraseman 23:a0ce9fa869c2 67
amiraseman 23:a0ce9fa869c2 68 /**
amiraseman 23:a0ce9fa869c2 69 @namespace button3
amiraseman 23:a0ce9fa869c2 70 @brief An Interrupt on digital pushbutton3 input p15
amiraseman 23:a0ce9fa869c2 71 */
amiraseman 23:a0ce9fa869c2 72 InterruptIn button3 (p15);
amiraseman 23:a0ce9fa869c2 73
amiraseman 23:a0ce9fa869c2 74
amiraseman 23:a0ce9fa869c2 75 /**
amiraseman 23:a0ce9fa869c2 76 @namespace button4
amiraseman 23:a0ce9fa869c2 77 @brief An Interrupt on digital pushbutton4 input p18
amiraseman 23:a0ce9fa869c2 78 */
amiraseman 23:a0ce9fa869c2 79 InterruptIn button4 (p18);
amiraseman 23:a0ce9fa869c2 80
amiraseman 23:a0ce9fa869c2 81
amiraseman 26:c0d8d2f68406 82
amiraseman 26:c0d8d2f68406 83
amiraseman 23:a0ce9fa869c2 84 /**
amiraseman 23:a0ce9fa869c2 85 @namespace redLED
amiraseman 23:a0ce9fa869c2 86 @brief A PwmOut interface is used to control the frequency and mark-space ratio of a led (The red LED)
amiraseman 23:a0ce9fa869c2 87 */
amiraseman 23:a0ce9fa869c2 88 PwmOut redLED(p24);//red
amiraseman 23:a0ce9fa869c2 89
amiraseman 23:a0ce9fa869c2 90
amiraseman 23:a0ce9fa869c2 91 /**
amiraseman 23:a0ce9fa869c2 92 @namespace yellowLED
amiraseman 23:a0ce9fa869c2 93 @brief A PwmOut interface is used to control the frequency and mark-space ratio of a led (The yellow LED)
amiraseman 23:a0ce9fa869c2 94 */
amiraseman 23:a0ce9fa869c2 95 PwmOut yellowLED(p23);//yellow
amiraseman 23:a0ce9fa869c2 96
amiraseman 23:a0ce9fa869c2 97
amiraseman 23:a0ce9fa869c2 98 /**
amiraseman 23:a0ce9fa869c2 99 @namespace greenLED
amiraseman 23:a0ce9fa869c2 100 @brief A PwmOut interface is used to control the frequency and mark-space ratio of a led (The green LED)
amiraseman 23:a0ce9fa869c2 101 */
amiraseman 23:a0ce9fa869c2 102 PwmOut greenLED(p22);
amiraseman 23:a0ce9fa869c2 103
amiraseman 23:a0ce9fa869c2 104
amiraseman 23:a0ce9fa869c2 105 /**
amiraseman 23:a0ce9fa869c2 106 @namespace buzzer
amiraseman 23:a0ce9fa869c2 107 @brief A PwmOut interface is used to control the frequency and mark-space ratio of a buzzer
amiraseman 23:a0ce9fa869c2 108 pulse train
amiraseman 23:a0ce9fa869c2 109 */
amiraseman 23:a0ce9fa869c2 110 PwmOut buzzer(p21);
amiraseman 23:a0ce9fa869c2 111
amiraseman 23:a0ce9fa869c2 112
amiraseman 23:a0ce9fa869c2 113 /**
amiraseman 23:a0ce9fa869c2 114 @namespace timer
amiraseman 23:a0ce9fa869c2 115 @brief Create ticker object for temperature and pressure readings
amiraseman 23:a0ce9fa869c2 116 */
amiraseman 23:a0ce9fa869c2 117 Ticker timer;
amiraseman 23:a0ce9fa869c2 118
amiraseman 23:a0ce9fa869c2 119
amiraseman 23:a0ce9fa869c2 120 /**
amiraseman 23:a0ce9fa869c2 121 @namespace dataLoggerTimer
amiraseman 23:a0ce9fa869c2 122 @brief a ticker object for the data logger functions
amiraseman 23:a0ce9fa869c2 123 */
amiraseman 23:a0ce9fa869c2 124 Ticker dataLoggerTimer ;
amiraseman 23:a0ce9fa869c2 125
amiraseman 23:a0ce9fa869c2 126
amiraseman 23:a0ce9fa869c2 127 /**
amiraseman 23:a0ce9fa869c2 128 @namespace powerSaverTimeout
amiraseman 23:a0ce9fa869c2 129 @brief create a timeout object for the poweerSaver function
amiraseman 23:a0ce9fa869c2 130 */
amiraseman 23:a0ce9fa869c2 131 Timeout powerSaverTimeout;
amiraseman 23:a0ce9fa869c2 132
amiraseman 23:a0ce9fa869c2 133 /**
amiraseman 23:a0ce9fa869c2 134 @namespace debounce
amiraseman 23:a0ce9fa869c2 135 @brief create a debounce timer object to implement a debounce counter to avoid multiple interrupts.
amiraseman 23:a0ce9fa869c2 136 */
amiraseman 23:a0ce9fa869c2 137 Timer debounce;
amiraseman 23:a0ce9fa869c2 138
amiraseman 23:a0ce9fa869c2 139
amiraseman 23:a0ce9fa869c2 140 int timerFlag = 1; /*!< Flag for tempesrature pressure reading ISR */
amiraseman 23:a0ce9fa869c2 141 int tickerFlag = 0 ; /*!<Flag to show the minutes passed */
amiraseman 23:a0ce9fa869c2 142 int button1Flag = 0; /*!< Flag set in button1Pressed ISR */
amiraseman 23:a0ce9fa869c2 143 int button2Flag = 0 ; /*!<Flag set in button2Pressed ISR */
amiraseman 23:a0ce9fa869c2 144 int button3Flag = 0 ; /*!< Flag set in button3Pressed ISR */
amiraseman 23:a0ce9fa869c2 145 int button4Flag = 0 ; /*!< Flag set in button4Pressed ISR */
amiraseman 23:a0ce9fa869c2 146 int unitFlag = 1 ; /*!< Flag set in the unitSettings function, indicates the units picked by user */
amiraseman 23:a0ce9fa869c2 147 int powerSaverFlag = 0 ; /*!<Flag set in the powerSettings function when the powerSaver is switched on */
amiraseman 23:a0ce9fa869c2 148 int lcdPowerFlag = 1 ; /*!< Flag set in the savePower function to indicate the status of the LCD (ON or OFF) */
amiraseman 23:a0ce9fa869c2 149 int dataLoggerFlag = 0 ; /*!< Flag set by user in the dataLoggerSetting function to turn on the logger */
amiraseman 23:a0ce9fa869c2 150 int runLoggerFlag = 0 ; /*!< Fag set when the logger is switched on, allows user to navigate to this option in the main menu */
amiraseman 23:a0ce9fa869c2 151 int alarmClockFlag = 0 ; /*!< Flag set in the AlarmClock function, indicates if the alarm clock has been turned on */
amiraseman 23:a0ce9fa869c2 152 int thresholdAlarmFlag = 0 ; /*!<Flag set in the thresholdAlarmmenu function,indicates if the thresholds are set */
amiraseman 23:a0ce9fa869c2 153
amiraseman 23:a0ce9fa869c2 154 int UNIXdate=0; /*!<An integer to store the value of UNIX time calculated by mktime function */
amiraseman 23:a0ce9fa869c2 155 int currentTime ;/*!<An integer to store the UNIX value of the current time */
amiraseman 23:a0ce9fa869c2 156 int powerSaverTime = 60; /*!<An integer to set the initial value of the power saver ticker */
amiraseman 23:a0ce9fa869c2 157 int dataLoggerTime = 60; /*!<An integer used to set the initial value of the data logger ticker */
amiraseman 23:a0ce9fa869c2 158
amiraseman 23:a0ce9fa869c2 159 float temperature; /*!<A float value to store the value of the temperature recieved from the sensor */
amiraseman 23:a0ce9fa869c2 160 float pressure; /*!<A float value to store the value of the pressure recieved from the sensor */
amiraseman 23:a0ce9fa869c2 161 float averageTemperature ; /*!<A float value to store the average value of temperature readingsn taken over a period of time */
amiraseman 23:a0ce9fa869c2 162 float averagePressure ; /*!<A float value to store the average value of pressure readings over a period of time */
amiraseman 23:a0ce9fa869c2 163 float minTemperature ; /*!<A float value to save the minimum value of temperature readings */
amiraseman 23:a0ce9fa869c2 164 float maxTemperature ; /*!<A float value to store the maximum value of temperature readings */
amiraseman 23:a0ce9fa869c2 165 float minPressure; /*!<A float value to store the minimum value of pressure readings */
amiraseman 23:a0ce9fa869c2 166 float maxPressure; /*!<A float value to store the maximum value of pressure readings */
amiraseman 23:a0ce9fa869c2 167
amiraseman 23:a0ce9fa869c2 168
amiraseman 23:a0ce9fa869c2 169
amiraseman 23:a0ce9fa869c2 170
amiraseman 23:a0ce9fa869c2 171 float arrayT[83] ; /*!<A A float array to store the values of temperature to calculate the average,minimum and maximum values*/
amiraseman 23:a0ce9fa869c2 172 float arrayP[83] ; /*!<A A float array to store the values of pressure to calculate the average,minimum and maximum values*/
amiraseman 23:a0ce9fa869c2 173 float arrayTG[83] ; /*!<A A float array to store the values of temperature to plot the related graph */
amiraseman 23:a0ce9fa869c2 174 float arrayPG[83] ;/*!<A A float array to store the values of pressure to plot the related graph */
amiraseman 23:a0ce9fa869c2 175
amiraseman 23:a0ce9fa869c2 176
amiraseman 23:a0ce9fa869c2 177 char bufferTime[14]; /*!<A A char array (buffer) to store time*/
amiraseman 23:a0ce9fa869c2 178 char bufferDate[14]; /*!<A A char array (buffer) to store date*/
amiraseman 23:a0ce9fa869c2 179 char bufferT[14];/*!<A A char array (buffer) to store the value of temperature in char*/
amiraseman 23:a0ce9fa869c2 180 char bufferP[14]; /*!<A A char array (buffer) to store the value of pressure in char */
amiraseman 23:a0ce9fa869c2 181 // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
amiraseman 23:a0ce9fa869c2 182 // so can display a string of a maximum 14 characters in length
amiraseman 23:a0ce9fa869c2 183 // or create formatted strings - ensure they aren't more than 14 characters long
amiraseman 23:a0ce9fa869c2 184
amiraseman 23:a0ce9fa869c2 185
amiraseman 23:a0ce9fa869c2 186
amiraseman 23:a0ce9fa869c2 187 char buffer0[14]; /*!<A A char array (buffer) used to display data on the LCD at (0,0)*/
amiraseman 23:a0ce9fa869c2 188 char buffer1[14]; /*!<A A char array (buffer) used to display data on the LCD at (0,1)*/
amiraseman 23:a0ce9fa869c2 189 char buffer2[14]; /*!<A A char array (buffer) used to display data on the LCD at (0,2)*/
amiraseman 23:a0ce9fa869c2 190 char buffer3[14]; /*!<A A char array (buffer) used to display data on the LCD at (0,3)*/
amiraseman 23:a0ce9fa869c2 191 char buffer4[14]; /*!<A A char array (buffer) used to display data on the LCD at (0,4)*/
amiraseman 23:a0ce9fa869c2 192 char buffer5[14]; /*!<A A char array (buffer) used to display data on the LCD at (0,5)*/
amiraseman 23:a0ce9fa869c2 193
amiraseman 23:a0ce9fa869c2 194
amiraseman 23:a0ce9fa869c2 195
amiraseman 23:a0ce9fa869c2 196 //arrays used to store data to the local file
amiraseman 23:a0ce9fa869c2 197 char timeSent[1000]; /*!<A A char array used to save time staps to the local file */
amiraseman 23:a0ce9fa869c2 198 char dateSent[1000]; /*!<A A char array used to save date stamps the local file */
amiraseman 23:a0ce9fa869c2 199 char temperatureSent[1000]; /*!<A A char array used to save the temperature readings to the local file */
amiraseman 23:a0ce9fa869c2 200 char pressureSent[1000]; /*!<A A char array used to save the pressure readings to the local file */
amiraseman 23:a0ce9fa869c2 201 char temperatureRecieved[1000]; /*!<A A char array used to retrive the saved temperature readings from the local file */
amiraseman 23:a0ce9fa869c2 202 char pressureRecieved[1000]; /*!<A A char array used to retrive the saved pressure readings from the local file */
amiraseman 23:a0ce9fa869c2 203 char timeRecieved[1000]; /*!<A A char array used to retrive the saved time stamps from the local file */
amiraseman 23:a0ce9fa869c2 204 char dateRecieved[1000]; /*!<A A char array used to retrive the saved date stamps from the local file */
amiraseman 23:a0ce9fa869c2 205
amiraseman 23:a0ce9fa869c2 206
amiraseman 23:a0ce9fa869c2 207
amiraseman 23:a0ce9fa869c2 208 char * pch; /*!<A A char array used to split the char arrays of temperature values retrived from the local file to the individual temperature strings */
amiraseman 23:a0ce9fa869c2 209 char * pch1; /*!<A A char array used to split the char arrays of pressure values retrived from the local file to the individual pressure strings*/
amiraseman 23:a0ce9fa869c2 210 char * pch2; /*!<A A char array used to split the char arrays of times retrived from the local file to the individual time strings*/
amiraseman 23:a0ce9fa869c2 211 char * pch3; /*!<A A char array used to split the char arrays of dates retrived from the local file to the individual date strings*/
amiraseman 23:a0ce9fa869c2 212
amiraseman 23:a0ce9fa869c2 213
amiraseman 23:a0ce9fa869c2 214 int state=0; /*!<A An integer used to navigate through the finite machines (indexes)*/
amiraseman 23:a0ce9fa869c2 215
amiraseman 23:a0ce9fa869c2 216 float frequency[]= {659,554,659,554,659,554,659,554,659,554,659,554}; /*!<A An array of floats with different frequencies for the buzzer*/
amiraseman 23:a0ce9fa869c2 217
amiraseman 23:a0ce9fa869c2 218
amiraseman 23:a0ce9fa869c2 219
amiraseman 27:06fbad36c15e 220 /**
amiraseman 27:06fbad36c15e 221 A structure, contains the output, titles and nextstate data
amiraseman 27:06fbad36c15e 222 @param output - integer value holds the output value of the members
amiraseman 27:06fbad36c15e 223 @param title - char array contains titles of the members
amiraseman 27:06fbad36c15e 224 @param nextState - int array contains the values for the next and previous states
amiraseman 27:06fbad36c15e 225 */
amiraseman 23:a0ce9fa869c2 226 struct State {
amiraseman 23:a0ce9fa869c2 227 int output;
amiraseman 23:a0ce9fa869c2 228 char title[14];
amiraseman 23:a0ce9fa869c2 229 int nextState[2];
amiraseman 23:a0ce9fa869c2 230 };
amiraseman 23:a0ce9fa869c2 231
amiraseman 27:06fbad36c15e 232
amiraseman 27:06fbad36c15e 233 /**
amiraseman 27:06fbad36c15e 234 Initialises a typedef struct, contains the output, titles and nextstate data for the start menu
amiraseman 27:06fbad36c15e 235 */
amiraseman 23:a0ce9fa869c2 236 typedef struct State STyp1; // for the start menu
amiraseman 23:a0ce9fa869c2 237 STyp1 fsmA[4] = {
amiraseman 23:a0ce9fa869c2 238 {0,"Live Data",{1,3}},
amiraseman 23:a0ce9fa869c2 239 {1,"Saved Data",{2,0}},
amiraseman 23:a0ce9fa869c2 240 {2,"Alarms",{3,1}},
amiraseman 23:a0ce9fa869c2 241 {3,"Settings",{0,2}},
amiraseman 23:a0ce9fa869c2 242 };
amiraseman 23:a0ce9fa869c2 243
amiraseman 27:06fbad36c15e 244
amiraseman 27:06fbad36c15e 245 /**
amiraseman 27:06fbad36c15e 246 Initialises a typedef struct, contains the output, titles and nextstate data for the settings menu
amiraseman 27:06fbad36c15e 247 */
amiraseman 23:a0ce9fa869c2 248 typedef struct State STyp2; // for the settings menu
amiraseman 23:a0ce9fa869c2 249 STyp2 fsmB[4] = {
amiraseman 23:a0ce9fa869c2 250 {0,"Date/Time",{1,3}},
amiraseman 23:a0ce9fa869c2 251 {1,"Units",{2,0}},
amiraseman 23:a0ce9fa869c2 252 {2,"Power Saver",{3,1}},
amiraseman 23:a0ce9fa869c2 253 {3,"Data Logger",{0,2}},
amiraseman 23:a0ce9fa869c2 254 };
amiraseman 23:a0ce9fa869c2 255
amiraseman 27:06fbad36c15e 256 /**
amiraseman 27:06fbad36c15e 257 Initialises a typedef struct, contains the output, titles and nextstate data for the time/date settings also the alarmclock function
amiraseman 27:06fbad36c15e 258 */
amiraseman 23:a0ce9fa869c2 259 typedef struct State STyp3; // for the time/date settings
amiraseman 23:a0ce9fa869c2 260 STyp3 fsmC[5] = {
amiraseman 23:a0ce9fa869c2 261 {12,"Hour:",{1,4}},
amiraseman 23:a0ce9fa869c2 262 {0,"Min:",{2,0}},
amiraseman 23:a0ce9fa869c2 263 {21,"Day:",{3,1}},
amiraseman 23:a0ce9fa869c2 264 {4,"Month:",{4,2}},
amiraseman 23:a0ce9fa869c2 265 {2015,"Year:",{0,3}},
amiraseman 23:a0ce9fa869c2 266 };
amiraseman 23:a0ce9fa869c2 267
amiraseman 23:a0ce9fa869c2 268
amiraseman 27:06fbad36c15e 269 /**
amiraseman 27:06fbad36c15e 270 Initialises a typedef struct, contains the output, titles and nextstate data for the unitsettings function
amiraseman 27:06fbad36c15e 271 */
amiraseman 23:a0ce9fa869c2 272 typedef struct State STyp4; // for the units settings
amiraseman 23:a0ce9fa869c2 273 STyp3 fsmD[4] = {
amiraseman 23:a0ce9fa869c2 274 {1,"C/mb",{1,3}},
amiraseman 23:a0ce9fa869c2 275 {2,"C/atm",{2,0}},
amiraseman 23:a0ce9fa869c2 276 {3,"F/mb",{3,1}},
amiraseman 23:a0ce9fa869c2 277 {4,"F/atm",{0,2}},
amiraseman 23:a0ce9fa869c2 278 };
amiraseman 23:a0ce9fa869c2 279
amiraseman 27:06fbad36c15e 280 /**
amiraseman 27:06fbad36c15e 281 Initialises a typedef struct, contains the output, titles and nextstate data for the powerSaverSetting
amiraseman 27:06fbad36c15e 282 */
amiraseman 23:a0ce9fa869c2 283 typedef struct State STyp5; // for the Power saver settings
amiraseman 23:a0ce9fa869c2 284 STyp5 fsmE[2] = {
amiraseman 23:a0ce9fa869c2 285 {0,"Off",{1,1}},
amiraseman 23:a0ce9fa869c2 286 {60,"On",{0,0}},
amiraseman 23:a0ce9fa869c2 287 };
amiraseman 23:a0ce9fa869c2 288
amiraseman 27:06fbad36c15e 289 /**
amiraseman 27:06fbad36c15e 290 Initialises a typedef struct, contains the output, titles and nextstate data for the alarms menu
amiraseman 27:06fbad36c15e 291 */
amiraseman 23:a0ce9fa869c2 292 typedef struct State Stype6; // for the alarms menu
amiraseman 23:a0ce9fa869c2 293 Stype6 fsmF[2] = {
amiraseman 23:a0ce9fa869c2 294 {0,"Thresholds",{1,1}},
amiraseman 23:a0ce9fa869c2 295 {1,"Alarm Clock", {0,0}},
amiraseman 23:a0ce9fa869c2 296 };
amiraseman 23:a0ce9fa869c2 297
amiraseman 27:06fbad36c15e 298 /**
amiraseman 27:06fbad36c15e 299 Initialises a typedef struct, contains the output, titles and nextstate data for the threshold and alarmclock functions
amiraseman 27:06fbad36c15e 300 */
amiraseman 23:a0ce9fa869c2 301 typedef struct State Stype7; // yes or no
amiraseman 23:a0ce9fa869c2 302 Stype7 fsmG[2] = {
amiraseman 23:a0ce9fa869c2 303 {1,"Yes",{1,1}},
amiraseman 23:a0ce9fa869c2 304 {0,"No", {0,0}},
amiraseman 23:a0ce9fa869c2 305 };
amiraseman 23:a0ce9fa869c2 306
amiraseman 27:06fbad36c15e 307 /**
amiraseman 27:06fbad36c15e 308 Initialises a typedef struct, contains the output, titles and nextstate data for the threshold menu
amiraseman 27:06fbad36c15e 309 */
amiraseman 23:a0ce9fa869c2 310 typedef struct State Stype8; // for the thresholds
amiraseman 23:a0ce9fa869c2 311 Stype8 fsmH[4] = {
amiraseman 23:a0ce9fa869c2 312 {20,"Min T:",{1,3}},
amiraseman 23:a0ce9fa869c2 313 {30,"Max T:",{2,0}},
amiraseman 23:a0ce9fa869c2 314 {1000,"Min P:",{3,1}},
amiraseman 23:a0ce9fa869c2 315 {1100,"Max P:",{0,2}},
amiraseman 23:a0ce9fa869c2 316 };
amiraseman 23:a0ce9fa869c2 317
amiraseman 23:a0ce9fa869c2 318
amiraseman 23:a0ce9fa869c2 319 /**
amiraseman 27:06fbad36c15e 320 ISR attached to the fisrt button interrupt
amiraseman 27:06fbad36c15e 321 @param button1Flag - integer to indicate if the interrupt has occured
amiraseman 23:a0ce9fa869c2 322 */
amiraseman 23:a0ce9fa869c2 323 void button1Pressed();
amiraseman 23:a0ce9fa869c2 324
amiraseman 23:a0ce9fa869c2 325 /**
amiraseman 27:06fbad36c15e 326 ISR attached to the second button interrupt
amiraseman 27:06fbad36c15e 327 @param button2Flag - integer to indicate if the interrupt has occured
amiraseman 23:a0ce9fa869c2 328 */
amiraseman 23:a0ce9fa869c2 329 void button2Pressed();
amiraseman 23:a0ce9fa869c2 330
amiraseman 23:a0ce9fa869c2 331 /**
amiraseman 27:06fbad36c15e 332 ISR attached to the third button interrupt
amiraseman 27:06fbad36c15e 333 @param button3Flag - integer to indicate if the interrupt has occured
amiraseman 23:a0ce9fa869c2 334 */
amiraseman 23:a0ce9fa869c2 335 void button3Pressed();
amiraseman 23:a0ce9fa869c2 336 /**
amiraseman 27:06fbad36c15e 337 ISR attached to the fourth button interrupt
amiraseman 27:06fbad36c15e 338 @param button4Flag - integer to indicate if the interrupt has occured
amiraseman 23:a0ce9fa869c2 339 */
amiraseman 23:a0ce9fa869c2 340 void button4Pressed();
amiraseman 23:a0ce9fa869c2 341
amiraseman 26:c0d8d2f68406 342
amiraseman 26:c0d8d2f68406 343
amiraseman 26:c0d8d2f68406 344
amiraseman 23:a0ce9fa869c2 345 /**
amiraseman 27:06fbad36c15e 346 ISR attached to the ticker timer
amiraseman 27:06fbad36c15e 347 @param timerFlag - integer to indicate the timer is expired
amiraseman 23:a0ce9fa869c2 348 */
amiraseman 23:a0ce9fa869c2 349 void timerExpired();
amiraseman 23:a0ce9fa869c2 350
amiraseman 23:a0ce9fa869c2 351 /**
amiraseman 27:06fbad36c15e 352 ISR attached to the ticker dataLoggerTimer
amiraseman 27:06fbad36c15e 353 @param dataLoggerFlag - integer to indicate the data logger timer is expired
amiraseman 23:a0ce9fa869c2 354 */
amiraseman 23:a0ce9fa869c2 355 void dataLoggerTimerExpired ();
amiraseman 23:a0ce9fa869c2 356
amiraseman 23:a0ce9fa869c2 357
amiraseman 23:a0ce9fa869c2 358 /**
amiraseman 27:06fbad36c15e 359 Opens the local folder, creates a csv file and stores the arrays.
amiraseman 27:06fbad36c15e 360 @param data - char array inserted in the local file
amiraseman 27:06fbad36c15e 361 @param data1 - char array inserted in the local file
amiraseman 27:06fbad36c15e 362 @param data2 - char array inserted in the local file
amiraseman 27:06fbad36c15e 363 @param data3 - char array inserted in the local file
amiraseman 23:a0ce9fa869c2 364 */
amiraseman 23:a0ce9fa869c2 365 void saveToFile(char *data,char *data1,char *data2,char *data3);
amiraseman 23:a0ce9fa869c2 366
amiraseman 27:06fbad36c15e 367
amiraseman 27:06fbad36c15e 368
amiraseman 27:06fbad36c15e 369
amiraseman 23:a0ce9fa869c2 370 /**
amiraseman 27:06fbad36c15e 371 Gets the local time from the RTC and stores them into two arrays
amiraseman 27:06fbad36c15e 372 @param currentTime - integer to store the current data epoch unix time stamp
amiraseman 27:06fbad36c15e 373 @param bufferTime - char array to store the time stamp
amiraseman 27:06fbad36c15e 374 @param bufferTime - char array to store the date stamp
amiraseman 23:a0ce9fa869c2 375 */
amiraseman 23:a0ce9fa869c2 376 void updateTime();
amiraseman 23:a0ce9fa869c2 377
amiraseman 27:06fbad36c15e 378
amiraseman 27:06fbad36c15e 379
amiraseman 23:a0ce9fa869c2 380 /**
amiraseman 27:06fbad36c15e 381 Displays the char arrays on the LCD
amiraseman 27:06fbad36c15e 382 @param buffer 0 - char array printed on (0,0)
amiraseman 27:06fbad36c15e 383 @param buffer 1 - char array printed on (0,1)
amiraseman 27:06fbad36c15e 384 @param buffer 2 - char array printed on (0,2)
amiraseman 27:06fbad36c15e 385 @param buffer 3 - char array printed on (0,3)
amiraseman 27:06fbad36c15e 386 @param buffer 4 - char array printed on (0,4)
amiraseman 27:06fbad36c15e 387 @param buffer 5 - char array printed on (0,5)
amiraseman 23:a0ce9fa869c2 388 */
amiraseman 23:a0ce9fa869c2 389 void display();
amiraseman 23:a0ce9fa869c2 390
amiraseman 23:a0ce9fa869c2 391 /**
amiraseman 27:06fbad36c15e 392 Reads the data from the sensor and stores them into arrays
amiraseman 27:06fbad36c15e 393 @param bufferT - char array to store temperature
amiraseman 27:06fbad36c15e 394 @param bufferP - char array to store pressure
amiraseman 27:06fbad36c15e 395 @param temperature - float to store the value of the temperature
amiraseman 27:06fbad36c15e 396 @param pressure - float to store the value of the pressure
amiraseman 23:a0ce9fa869c2 397 */
amiraseman 23:a0ce9fa869c2 398 void readData();
amiraseman 23:a0ce9fa869c2 399
amiraseman 23:a0ce9fa869c2 400
amiraseman 23:a0ce9fa869c2 401 /**
amiraseman 27:06fbad36c15e 402 ISR attached to power saver timeout to set the flag to 1
amiraseman 27:06fbad36c15e 403 @param powerSaverFlag - integer to indicate if the state of the power saver
amiraseman 23:a0ce9fa869c2 404 */
amiraseman 23:a0ce9fa869c2 405 void powerSaverExpired();
amiraseman 23:a0ce9fa869c2 406
amiraseman 27:06fbad36c15e 407
amiraseman 23:a0ce9fa869c2 408 /**
amiraseman 27:06fbad36c15e 409 Checks if the power saver option is set by the user, if yes puts the device in sleep mode and turns off the lcd.
amiraseman 27:06fbad36c15e 410 Also if the buttons are pressed it wakes up the device and attached the timeout
amiraseman 23:a0ce9fa869c2 411 */
amiraseman 23:a0ce9fa869c2 412 void powerSaverCheck();
amiraseman 23:a0ce9fa869c2 413
amiraseman 27:06fbad36c15e 414
amiraseman 27:06fbad36c15e 415
amiraseman 23:a0ce9fa869c2 416 /**
amiraseman 27:06fbad36c15e 417 Indicates the live data on the screen and updates the data once a second
amiraseman 27:06fbad36c15e 418 @param timerFlag - integer set when the timer ends
amiraseman 23:a0ce9fa869c2 419 */
amiraseman 23:a0ce9fa869c2 420 void liveData();
amiraseman 23:a0ce9fa869c2 421
amiraseman 23:a0ce9fa869c2 422 /**
amiraseman 27:06fbad36c15e 423 Recieves the data, puts them in arrays and saves them to the file. Saved arrays are restored and used to calculate the minimun maximum average values
amiraseman 27:06fbad36c15e 424 @param sumTemperature - integer to store the total value of temperature values
amiraseman 27:06fbad36c15e 425 @param sumPressure - integer to store the total value of pressure values
amiraseman 27:06fbad36c15e 426
amiraseman 27:06fbad36c15e 427 @param temperatureSent - char with the temperature values saved to the file
amiraseman 27:06fbad36c15e 428 @param pressureSent- char with the pressure values saved to the file
amiraseman 27:06fbad36c15e 429 @param timeSent- char with the time stamps saved to the file
amiraseman 27:06fbad36c15e 430 @param dateSent- char with the data stamps saved to the file
amiraseman 27:06fbad36c15e 431
amiraseman 27:06fbad36c15e 432 @param temperatureRecieved - char with the temperature values restored from the file
amiraseman 27:06fbad36c15e 433 @param pressureRecieved- char with the pressure values restored from the file
amiraseman 27:06fbad36c15e 434 @param timeRecieved- char with the time stamps restored from the file
amiraseman 27:06fbad36c15e 435 @param dateRecieved- char with the data stamps restored from the file
amiraseman 27:06fbad36c15e 436
amiraseman 27:06fbad36c15e 437 @param minTemperature - int to store the minimum value of temperature
amiraseman 27:06fbad36c15e 438 @param minPressure - int to store the minimum value of pressure
amiraseman 27:06fbad36c15e 439 @param maxTemperature - int to store the maximum value of temperature
amiraseman 27:06fbad36c15e 440 @param maxPressure - int to store the maximum value of pressure
amiraseman 27:06fbad36c15e 441 @param avgTemperature - int to store the average value of temperature
amiraseman 27:06fbad36c15e 442 @param avgPressure - int to store the average value of pressure
amiraseman 23:a0ce9fa869c2 443 */
amiraseman 23:a0ce9fa869c2 444 void loggerData();
amiraseman 23:a0ce9fa869c2 445
amiraseman 27:06fbad36c15e 446
amiraseman 23:a0ce9fa869c2 447 /**
amiraseman 27:06fbad36c15e 448 Uses the data from the loggerData function to indicate the calculated values and plot the graphs
amiraseman 23:a0ce9fa869c2 449 */
amiraseman 23:a0ce9fa869c2 450 void dataLogger();
amiraseman 23:a0ce9fa869c2 451
amiraseman 27:06fbad36c15e 452
amiraseman 23:a0ce9fa869c2 453
amiraseman 23:a0ce9fa869c2 454 /**
amiraseman 27:06fbad36c15e 455 Checks the current values of temperature and pressure and compares to the threshold values, triggers the alarm if match
amiraseman 23:a0ce9fa869c2 456 */
amiraseman 23:a0ce9fa869c2 457 void thresholdCheck();
amiraseman 23:a0ce9fa869c2 458
amiraseman 27:06fbad36c15e 459
amiraseman 23:a0ce9fa869c2 460 /**
amiraseman 27:06fbad36c15e 461 Alloes the user to set the values for the thresholds and also turn the alarm on or off
amiraseman 23:a0ce9fa869c2 462 */
amiraseman 23:a0ce9fa869c2 463 void threshold();
amiraseman 23:a0ce9fa869c2 464
amiraseman 23:a0ce9fa869c2 465 /**
amiraseman 27:06fbad36c15e 466 Compares the set time in the alarm clock section with the current time, triggers the alarm when they match
amiraseman 23:a0ce9fa869c2 467 */
amiraseman 23:a0ce9fa869c2 468 void alarmClockCheck();
amiraseman 23:a0ce9fa869c2 469
amiraseman 27:06fbad36c15e 470
amiraseman 27:06fbad36c15e 471
amiraseman 23:a0ce9fa869c2 472 /**
amiraseman 27:06fbad36c15e 473 Allows the user to set the min , hour, day, month and year values to set the alarm clock
amiraseman 23:a0ce9fa869c2 474 */
amiraseman 23:a0ce9fa869c2 475 void alarmClock ();
amiraseman 23:a0ce9fa869c2 476
amiraseman 23:a0ce9fa869c2 477 /**
amiraseman 27:06fbad36c15e 478 Alarm menu, includes two submenus : alarmclock and thresholds
amiraseman 23:a0ce9fa869c2 479 */
amiraseman 23:a0ce9fa869c2 480 void alarmsMenu ();
amiraseman 23:a0ce9fa869c2 481
amiraseman 23:a0ce9fa869c2 482 /**
amiraseman 27:06fbad36c15e 483 *Fourth option in the settings menu./n
amiraseman 27:06fbad36c15e 484 *Allows the user to turn on the data logger and set the value of time out /n
amiraseman 27:06fbad36c15e 485 *Attaches a timeout to set the dataloggerFlag /n
amiraseman 27:06fbad36c15e 486 @param dataLoggerFlag - integer used as a flag to indicate if the datalogger option is switched on or off
amiraseman 27:06fbad36c15e 487 @param state - integer used to navigate through fsm states
amiraseman 23:a0ce9fa869c2 488 */
amiraseman 23:a0ce9fa869c2 489 void dataLoggerSetting();
amiraseman 23:a0ce9fa869c2 490
amiraseman 23:a0ce9fa869c2 491 /**
amiraseman 23:a0ce9fa869c2 492 *Third option in the settings menu./n
amiraseman 23:a0ce9fa869c2 493 *Allows the user to turn on the power saving option and set the value of time out /n
amiraseman 23:a0ce9fa869c2 494 *Attaches a timeout to set the powerSaverFlag /n
amiraseman 23:a0ce9fa869c2 495 @param powerSaverFlag - integer used as a flag to indicate if the power saver option is switched on or off
amiraseman 23:a0ce9fa869c2 496 @param state - integer used to navigate through fsm states
amiraseman 23:a0ce9fa869c2 497 */
amiraseman 23:a0ce9fa869c2 498 void powerSaverSetting();
amiraseman 23:a0ce9fa869c2 499
amiraseman 23:a0ce9fa869c2 500 /**
amiraseman 23:a0ce9fa869c2 501 *Calculates the UNIX time value./n
amiraseman 23:a0ce9fa869c2 502 *Sets the integer values entered by user to the tm structure mebers /n
amiraseman 23:a0ce9fa869c2 503 *Converts the tm structure to time_t /n
amiraseman 23:a0ce9fa869c2 504 @param timeinfo - tm struct sent to mktime function
amiraseman 23:a0ce9fa869c2 505 @param rawtime - fundamental arithmetic type to represent the current time informations
amiraseman 23:a0ce9fa869c2 506 */
amiraseman 23:a0ce9fa869c2 507 void calculateUNIXTime();
amiraseman 23:a0ce9fa869c2 508
amiraseman 23:a0ce9fa869c2 509 /**
amiraseman 23:a0ce9fa869c2 510 *The second option in the settings menu./n
amiraseman 23:a0ce9fa869c2 511 *Allows the user to change the units /n
amiraseman 23:a0ce9fa869c2 512 @param unitFlag - integer used as a flag to indicate the units set
amiraseman 23:a0ce9fa869c2 513 @param state - integer used to navigate through fsm states
amiraseman 23:a0ce9fa869c2 514 */
amiraseman 23:a0ce9fa869c2 515 void unitsSetting();
amiraseman 23:a0ce9fa869c2 516
amiraseman 23:a0ce9fa869c2 517
amiraseman 23:a0ce9fa869c2 518 /**
amiraseman 23:a0ce9fa869c2 519 *The first option in the settings menu./n
amiraseman 23:a0ce9fa869c2 520 *Allows the user to enter time and date /n
amiraseman 23:a0ce9fa869c2 521 *Sends the recieved int arrays to the calculateUNIXtime function to calculate the unix time /n
amiraseman 23:a0ce9fa869c2 522 *sets the current time to the calculated unix time.
amiraseman 23:a0ce9fa869c2 523 @param state - integer used to navigate through fsm states
amiraseman 23:a0ce9fa869c2 524 */
amiraseman 23:a0ce9fa869c2 525 void timeDateSetting();
amiraseman 23:a0ce9fa869c2 526
amiraseman 23:a0ce9fa869c2 527
amiraseman 23:a0ce9fa869c2 528 /**
amiraseman 23:a0ce9fa869c2 529 *The setting menu displayed when the fourth state of fsmA is picked from the main menu /n
amiraseman 23:a0ce9fa869c2 530 *Depends on the state of the finite state machine used for this function, put the related title in the screen buffers /n
amiraseman 23:a0ce9fa869c2 531 *Also copy the bufferTime (buffer used to store time) on the first screen buffer (at the top) /n
amiraseman 23:a0ce9fa869c2 532 *Displays the screen buffers on the LCD/n
amiraseman 23:a0ce9fa869c2 533 *switch statement checks the current state of the fsm (fsmB),
amiraseman 23:a0ce9fa869c2 534 *The related function to each fsm state is executed as when a rising edge from the 4th button interrupts (button 4 is pressed)
amiraseman 23:a0ce9fa869c2 535
amiraseman 23:a0ce9fa869c2 536 */
amiraseman 23:a0ce9fa869c2 537 void settingsMenu();
amiraseman 23:a0ce9fa869c2 538
amiraseman 23:a0ce9fa869c2 539 /**
amiraseman 23:a0ce9fa869c2 540 *The main menu displayed at the start /n
amiraseman 23:a0ce9fa869c2 541 *Depends on the state of the finite state machine (fsmA) used for this function, put the related title in the screen buffers /n
amiraseman 23:a0ce9fa869c2 542 *Also copy the bufferTime (buffer used to store time) on the first screen buffer (at the top) /n
amiraseman 23:a0ce9fa869c2 543 *Displays the screen buffers on the LCD/n
amiraseman 23:a0ce9fa869c2 544 *switch statement checks the current state of the fsm (fsmA),
amiraseman 23:a0ce9fa869c2 545 *The related function to each fsm state is executed as when a rising edge from the 4th button interrupts (button 4 is pressed)
amiraseman 23:a0ce9fa869c2 546
amiraseman 23:a0ce9fa869c2 547 */
amiraseman 23:a0ce9fa869c2 548 void startMenu();
amiraseman 23:a0ce9fa869c2 549
amiraseman 23:a0ce9fa869c2 550
amiraseman 23:a0ce9fa869c2 551
amiraseman 23:a0ce9fa869c2 552
amiraseman 23:a0ce9fa869c2 553