Temperature and Pressure logger.

Dependencies:   BMP180 N5110 PowerControl beep mbed

Committer:
takis94
Date:
Sat May 02 23:17:39 2015 +0000
Revision:
0:ec64ecaac130
Child:
1:d320c79324fe
finished

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takis94 0:ec64ecaac130 1 /**
takis94 0:ec64ecaac130 2 @file main.h
takis94 0:ec64ecaac130 3 @brief Header file containing functions prototypes, defines and global variables.
takis94 0:ec64ecaac130 4 @brief Doxygen documentation.
takis94 0:ec64ecaac130 5 @brief Wheather Station.
takis94 0:ec64ecaac130 6 @author Panayiotis Rodosthenous
takis94 0:ec64ecaac130 7 @date March 2015
takis94 0:ec64ecaac130 8 */
takis94 0:ec64ecaac130 9
takis94 0:ec64ecaac130 10 #ifndef MAIN_H
takis94 0:ec64ecaac130 11 #define MAIN_H
takis94 0:ec64ecaac130 12
takis94 0:ec64ecaac130 13 #define PI 3.14159265359
takis94 0:ec64ecaac130 14
takis94 0:ec64ecaac130 15 #include "mbed.h"
takis94 0:ec64ecaac130 16 #include "N5110.h"
takis94 0:ec64ecaac130 17 #include "BMP180.h"
takis94 0:ec64ecaac130 18 #include "PowerControl/PowerControl.h"
takis94 0:ec64ecaac130 19 #include "PowerControl/EthernetPowerControl.h"
takis94 0:ec64ecaac130 20 #include "beep.h"
takis94 0:ec64ecaac130 21
takis94 0:ec64ecaac130 22 /**
takis94 0:ec64ecaac130 23 @namespace bmp180
takis94 0:ec64ecaac130 24 @brief Assign sensor pins to the mbed
takis94 0:ec64ecaac130 25 */
takis94 0:ec64ecaac130 26 BMP180 bmp180(p28,p27); // SDA, SCL
takis94 0:ec64ecaac130 27
takis94 0:ec64ecaac130 28 /**
takis94 0:ec64ecaac130 29 @namespace serial
takis94 0:ec64ecaac130 30 @brief Serial connection for presenting data to pc
takis94 0:ec64ecaac130 31 */
takis94 0:ec64ecaac130 32 Serial serial(USBTX,USBRX); //tx,rx
takis94 0:ec64ecaac130 33
takis94 0:ec64ecaac130 34 /**
takis94 0:ec64ecaac130 35 @namespace pc
takis94 0:ec64ecaac130 36 @brief Serial connection for presenting data to serial
takis94 0:ec64ecaac130 37 */
takis94 0:ec64ecaac130 38 Serial pc(USBTX,USBRX); //tx,rx
takis94 0:ec64ecaac130 39
takis94 0:ec64ecaac130 40 /**
takis94 0:ec64ecaac130 41 @namespace lcd
takis94 0:ec64ecaac130 42 @brief Assign the LCD pins to the mbed
takis94 0:ec64ecaac130 43 */
takis94 0:ec64ecaac130 44 N5110 lcd(p7,p8,p9,p10,p11,p13,p26); ///VCC,SCE,RST,D/C,MOSI,SCLK,LED
takis94 0:ec64ecaac130 45
takis94 0:ec64ecaac130 46 /**
takis94 0:ec64ecaac130 47 @namespace local
takis94 0:ec64ecaac130 48 @brief Location to create a file for data logging
takis94 0:ec64ecaac130 49 */
takis94 0:ec64ecaac130 50 LocalFileSystem local("local");
takis94 0:ec64ecaac130 51
takis94 0:ec64ecaac130 52 /**
takis94 0:ec64ecaac130 53 @namespace buzzer
takis94 0:ec64ecaac130 54 @brief GPIO output for warning buzzer
takis94 0:ec64ecaac130 55 */
takis94 0:ec64ecaac130 56 Beep buzzer(p21);
takis94 0:ec64ecaac130 57
takis94 0:ec64ecaac130 58 /**
takis94 0:ec64ecaac130 59 @namespace button4
takis94 0:ec64ecaac130 60 @brief GPIO input for main screen button
takis94 0:ec64ecaac130 61 */
takis94 0:ec64ecaac130 62 DigitalIn button4(p19);
takis94 0:ec64ecaac130 63
takis94 0:ec64ecaac130 64 /**
takis94 0:ec64ecaac130 65 @namespace button
takis94 0:ec64ecaac130 66 @brief ISR input for temperature graph button
takis94 0:ec64ecaac130 67 */
takis94 0:ec64ecaac130 68 InterruptIn button(p18);
takis94 0:ec64ecaac130 69
takis94 0:ec64ecaac130 70 /**
takis94 0:ec64ecaac130 71 @namespace button2
takis94 0:ec64ecaac130 72 @brief ISR input for pressure graph button
takis94 0:ec64ecaac130 73 */
takis94 0:ec64ecaac130 74 InterruptIn button2(p17);
takis94 0:ec64ecaac130 75
takis94 0:ec64ecaac130 76 /**
takis94 0:ec64ecaac130 77 @namespace button3
takis94 0:ec64ecaac130 78 @brief ISR input for changing the units button
takis94 0:ec64ecaac130 79 */
takis94 0:ec64ecaac130 80 InterruptIn button3(p16);
takis94 0:ec64ecaac130 81
takis94 0:ec64ecaac130 82 /**
takis94 0:ec64ecaac130 83 @namespace switch_logging
takis94 0:ec64ecaac130 84 @brief GPIO input for data logging switch
takis94 0:ec64ecaac130 85 */
takis94 0:ec64ecaac130 86 DigitalIn switch_logging(p15);
takis94 0:ec64ecaac130 87
takis94 0:ec64ecaac130 88 /**
takis94 0:ec64ecaac130 89 @namespace ain
takis94 0:ec64ecaac130 90 @brief GPIO analogue input for brightness potentiometer
takis94 0:ec64ecaac130 91 */
takis94 0:ec64ecaac130 92 AnalogIn ain(p20);
takis94 0:ec64ecaac130 93
takis94 0:ec64ecaac130 94 /**
takis94 0:ec64ecaac130 95 @namespace green
takis94 0:ec64ecaac130 96 @brief GPIO output for status green LED
takis94 0:ec64ecaac130 97 */
takis94 0:ec64ecaac130 98 DigitalOut green(p25);
takis94 0:ec64ecaac130 99
takis94 0:ec64ecaac130 100 /**
takis94 0:ec64ecaac130 101 @namespace red
takis94 0:ec64ecaac130 102 @brief GPIO output for status red LED
takis94 0:ec64ecaac130 103 */
takis94 0:ec64ecaac130 104 DigitalOut red(p24);
takis94 0:ec64ecaac130 105
takis94 0:ec64ecaac130 106 /**
takis94 0:ec64ecaac130 107 @namespace leds
takis94 0:ec64ecaac130 108 @brief Bus output for status on-board LED
takis94 0:ec64ecaac130 109 */
takis94 0:ec64ecaac130 110 BusOut leds(LED4,LED3,LED2,LED1); //bus for on-board LEDs
takis94 0:ec64ecaac130 111
takis94 0:ec64ecaac130 112 /**
takis94 0:ec64ecaac130 113 @namespace timerReading
takis94 0:ec64ecaac130 114 @brief Ticker for reading the sensor
takis94 0:ec64ecaac130 115 */
takis94 0:ec64ecaac130 116 Ticker timerReading;
takis94 0:ec64ecaac130 117
takis94 0:ec64ecaac130 118 /**
takis94 0:ec64ecaac130 119 @namespace timer
takis94 0:ec64ecaac130 120 @brief Ticker for getting current time
takis94 0:ec64ecaac130 121 */
takis94 0:ec64ecaac130 122 Ticker timer;
takis94 0:ec64ecaac130 123
takis94 0:ec64ecaac130 124 /**
takis94 0:ec64ecaac130 125 @namespace timerFiles
takis94 0:ec64ecaac130 126 @brief Ticker for writing data to file
takis94 0:ec64ecaac130 127 */
takis94 0:ec64ecaac130 128 Ticker timerFiles;
takis94 0:ec64ecaac130 129
takis94 0:ec64ecaac130 130 /**
takis94 0:ec64ecaac130 131 @namespace timerClearScreen
takis94 0:ec64ecaac130 132 @brief Ticker for clearing the LCD
takis94 0:ec64ecaac130 133 */
takis94 0:ec64ecaac130 134 Ticker timerClearScreen;
takis94 0:ec64ecaac130 135
takis94 0:ec64ecaac130 136 int readingFlag = 0; /*!< reading flag set in ISR */
takis94 0:ec64ecaac130 137 int timerFlag = 0; /*!< timer flag set in ISR */
takis94 0:ec64ecaac130 138 int timerFilesFlag = 0; /*!< timerFiles flag set in ISR */
takis94 0:ec64ecaac130 139 int setTimeFlag = 0; /*!< setTime flag set in ISR */
takis94 0:ec64ecaac130 140 int graphTempFlag = 0; /*!< graphTemp flag set in ISR */
takis94 0:ec64ecaac130 141 int graphPresFlag = 0; /*!< graphPres flag set in ISR */
takis94 0:ec64ecaac130 142 int unitsFlag = 0; /*!< units flag set in ISR */
takis94 0:ec64ecaac130 143 int clearFlag = 0; /*!< celar flag set in ISR */
takis94 0:ec64ecaac130 144 int i = 0; /*!< variable i used as index in print() */
takis94 0:ec64ecaac130 145
takis94 0:ec64ecaac130 146 char rxString[16]; /*!< string used to transfer current time into the buffer */
takis94 0:ec64ecaac130 147 char bufferT[14]; /*!< buffer used to store current time */
takis94 0:ec64ecaac130 148 char bufferD[14]; /*!< buffer used to store current date */
takis94 0:ec64ecaac130 149
takis94 0:ec64ecaac130 150 float temperature; /*!< variable used to store current temperature */
takis94 0:ec64ecaac130 151 float pressure; /*!< variable used to store current pressure */
takis94 0:ec64ecaac130 152 float array[84]; /*!< array used to store temperature readings */
takis94 0:ec64ecaac130 153 float array2[84]; /*!< array used to store pressure readings */
takis94 0:ec64ecaac130 154
takis94 0:ec64ecaac130 155 /** Update
takis94 0:ec64ecaac130 156 *
takis94 0:ec64ecaac130 157 * Prints and updates the thermometer presented on the main screen.
takis94 0:ec64ecaac130 158 * For each specified range of temperatures adds or removes pixels from inside the thermometer.
takis94 0:ec64ecaac130 159 * Introduces a live update on the main screen.
takis94 0:ec64ecaac130 160 */
takis94 0:ec64ecaac130 161 void update();
takis94 0:ec64ecaac130 162
takis94 0:ec64ecaac130 163 /** Print
takis94 0:ec64ecaac130 164 *
takis94 0:ec64ecaac130 165 * Prints the different screens on the LCD.
takis94 0:ec64ecaac130 166 * According to the buttons status-flags, a different screen is presented. Buttons are used as interrupts.
takis94 0:ec64ecaac130 167 * Includes the update() function.
takis94 0:ec64ecaac130 168 * -Button 1: Print the temperature graph with the average temperature and weather prediction. Disables button 2.
takis94 0:ec64ecaac130 169 * -Button 2: Print the pressure graph with the average pressure and weather prediction. Disables button 1.
takis94 0:ec64ecaac130 170 * -Button 3: Converts the temperature and pressure units on the main screen. When one of buttons 1 or 2 is previously pressed, it removes the average and weather predictions from screen.
takis94 0:ec64ecaac130 171 * -No button pressed: Displays the main screen.
takis94 0:ec64ecaac130 172 */
takis94 0:ec64ecaac130 173 void print();
takis94 0:ec64ecaac130 174
takis94 0:ec64ecaac130 175 /** Write Data to File
takis94 0:ec64ecaac130 176 *
takis94 0:ec64ecaac130 177 * Logs the time, temperature and pressure on a .csv file on the mbed Flash memory.
takis94 0:ec64ecaac130 178 * It called when the logging switch is ON.
takis94 0:ec64ecaac130 179 * A ticker is used to call this function. Logs data every 10 sec.
takis94 0:ec64ecaac130 180 * @param time - the current time taken from setTime() function.
takis94 0:ec64ecaac130 181 * @param temperature - the current temperature read from sensor.
takis94 0:ec64ecaac130 182 * @param temperature - the current tpressure read from sensor.
takis94 0:ec64ecaac130 183 * @returns
takis94 0:ec64ecaac130 184 * log.csv - file with parameters in comma separated format stored on mbed.
takis94 0:ec64ecaac130 185 */
takis94 0:ec64ecaac130 186 void writeDataToFile(float tempereture,char* time,float pressure);
takis94 0:ec64ecaac130 187
takis94 0:ec64ecaac130 188 /** Serial ISR
takis94 0:ec64ecaac130 189 *
takis94 0:ec64ecaac130 190 * This is an ISR function, called when serial data is received.
takis94 0:ec64ecaac130 191 * Gets the time rxString.
takis94 0:ec64ecaac130 192 */
takis94 0:ec64ecaac130 193 void serialISR();
takis94 0:ec64ecaac130 194
takis94 0:ec64ecaac130 195 /** Set Time
takis94 0:ec64ecaac130 196 *
takis94 0:ec64ecaac130 197 * This function sets the UNIX time.
takis94 0:ec64ecaac130 198 * Updates the time, bu converting the time string into an integer value.
takis94 0:ec64ecaac130 199 */
takis94 0:ec64ecaac130 200 void setTime();
takis94 0:ec64ecaac130 201
takis94 0:ec64ecaac130 202 /** Timer Expired Reading
takis94 0:ec64ecaac130 203 *
takis94 0:ec64ecaac130 204 * This function sets the reading flag high when called.
takis94 0:ec64ecaac130 205 * Attached to the timerReading ticker.
takis94 0:ec64ecaac130 206 */
takis94 0:ec64ecaac130 207 void timerExpiredReading();
takis94 0:ec64ecaac130 208
takis94 0:ec64ecaac130 209 /** Timer Expired Time
takis94 0:ec64ecaac130 210 *
takis94 0:ec64ecaac130 211 * This function sets the timer flag high when called.
takis94 0:ec64ecaac130 212 * Attached to the timer ticker.
takis94 0:ec64ecaac130 213 */
takis94 0:ec64ecaac130 214 void timerExpiredTime();
takis94 0:ec64ecaac130 215
takis94 0:ec64ecaac130 216 /** Timer Expired Files
takis94 0:ec64ecaac130 217 *
takis94 0:ec64ecaac130 218 * This function sets the timerFiles flag high when called.
takis94 0:ec64ecaac130 219 * Attached to the timerFiles ticker.
takis94 0:ec64ecaac130 220 */
takis94 0:ec64ecaac130 221 void timeExpiredFiles();
takis94 0:ec64ecaac130 222
takis94 0:ec64ecaac130 223 /** Timer Expired Clear
takis94 0:ec64ecaac130 224 *
takis94 0:ec64ecaac130 225 * This function sets the clear flag high when called.
takis94 0:ec64ecaac130 226 * Attached to the clearScreen ticker.
takis94 0:ec64ecaac130 227 */
takis94 0:ec64ecaac130 228 void timerExpiredClear();
takis94 0:ec64ecaac130 229
takis94 0:ec64ecaac130 230 /** Button for Temperature Pressed
takis94 0:ec64ecaac130 231 *
takis94 0:ec64ecaac130 232 * This function toggles the graphTemp flag when button is pressed.
takis94 0:ec64ecaac130 233 * Attached to the button interrupt configuration.
takis94 0:ec64ecaac130 234 */
takis94 0:ec64ecaac130 235 void buttonTempPressed();
takis94 0:ec64ecaac130 236
takis94 0:ec64ecaac130 237 /** Button for Pressure Pressed
takis94 0:ec64ecaac130 238 *
takis94 0:ec64ecaac130 239 * This function toggles the graphPres flag when button2 is pressed.
takis94 0:ec64ecaac130 240 * Attached to the button2 interrupt configuration.
takis94 0:ec64ecaac130 241 */
takis94 0:ec64ecaac130 242 void buttonPresPressed();
takis94 0:ec64ecaac130 243
takis94 0:ec64ecaac130 244 /** Button for Units Pressed
takis94 0:ec64ecaac130 245 *
takis94 0:ec64ecaac130 246 * This function toggles the units flag when button3 is pressed.
takis94 0:ec64ecaac130 247 * Attached to the button3 interrupt configuration.
takis94 0:ec64ecaac130 248 */
takis94 0:ec64ecaac130 249 void buttonUnitsPressed();
takis94 0:ec64ecaac130 250
takis94 0:ec64ecaac130 251 #endif