Simple Weather Station. Data Logger and gives primitive weather predictions.

Dependencies:   BMP180 N5110 PowerControl beep mbed

Committer:
el13nsp
Date:
Mon May 11 14:01:38 2015 +0000
Revision:
7:b92507a1a1e5
Parent:
5:cae171557246
Final Version of Weather Station V 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el13nsp 5:cae171557246 1 /**
el13nsp 5:cae171557246 2 @file main.h
el13nsp 5:cae171557246 3 @brief Header file containing functions prototypes, defines and global variables.
el13nsp 5:cae171557246 4 @brief Revision 1.0.
el13nsp 5:cae171557246 5 @author Nikhil Suresh Pillai
el13nsp 5:cae171557246 6 @date May 2015
el13nsp 5:cae171557246 7 */
el13nsp 5:cae171557246 8
el13nsp 5:cae171557246 9 #ifndef MAIN_H
el13nsp 5:cae171557246 10 #define MAIN_H
el13nsp 5:cae171557246 11
el13nsp 5:cae171557246 12 #include "mbed.h"
el13nsp 5:cae171557246 13 #include "N5110.h"
el13nsp 5:cae171557246 14 #include "BMP180.h"
el13nsp 5:cae171557246 15 #include "beep.h"
el13nsp 5:cae171557246 16 #include "PowerControl/PowerControl.h"
el13nsp 5:cae171557246 17 #include "PowerControl/EthernetPowerControl.h"
el13nsp 5:cae171557246 18
el13nsp 5:cae171557246 19 #define celcius 0
el13nsp 5:cae171557246 20 #define fahrenheit 1
el13nsp 5:cae171557246 21
el13nsp 5:cae171557246 22 /**
el13nsp 5:cae171557246 23 @namespace bmp180
el13nsp 5:cae171557246 24 @brief I2C Bus for barometric pressure sensor chip's SDA and SCL
el13nsp 5:cae171557246 25 */
el13nsp 5:cae171557246 26 BMP180 bmp180(p28,p27);
el13nsp 5:cae171557246 27
el13nsp 5:cae171557246 28 /**
el13nsp 5:cae171557246 29 @namespace leds
el13nsp 5:cae171557246 30 @brief GPIO bus output for onboard status leds
el13nsp 5:cae171557246 31 */
el13nsp 5:cae171557246 32 BusOut leds(LED4,LED3,LED2,LED1);
el13nsp 5:cae171557246 33
el13nsp 5:cae171557246 34 /**
el13nsp 5:cae171557246 35 @namespace local
el13nsp 5:cae171557246 36 @brief Create local filesystem
el13nsp 5:cae171557246 37 */
el13nsp 5:cae171557246 38 LocalFileSystem local("local");
el13nsp 5:cae171557246 39
el13nsp 5:cae171557246 40 /**
el13nsp 5:cae171557246 41 @namespace POT1
el13nsp 5:cae171557246 42 @brief Analog GPIO for potentiometer
el13nsp 5:cae171557246 43 */
el13nsp 5:cae171557246 44 AnalogIn POT1(p20);
el13nsp 5:cae171557246 45
el13nsp 5:cae171557246 46 /**
el13nsp 5:cae171557246 47 @namespace logSwitch
el13nsp 5:cae171557246 48 @brief GPIO for logging switch
el13nsp 5:cae171557246 49 */
el13nsp 5:cae171557246 50 DigitalIn logSwitch(p21);
el13nsp 5:cae171557246 51
el13nsp 5:cae171557246 52 /**
el13nsp 5:cae171557246 53 @namespace redled
el13nsp 5:cae171557246 54 @brief GPIO for warning led
el13nsp 5:cae171557246 55 */
el13nsp 5:cae171557246 56 DigitalOut redled(p25);
el13nsp 5:cae171557246 57
el13nsp 5:cae171557246 58 /**
el13nsp 5:cae171557246 59 @namespace greenled
el13nsp 5:cae171557246 60 @brief GPIO for logging status led
el13nsp 5:cae171557246 61 */
el13nsp 5:cae171557246 62 DigitalOut greenled(p24);
el13nsp 5:cae171557246 63
el13nsp 5:cae171557246 64 /**
el13nsp 5:cae171557246 65 @namespace buzzer
el13nsp 5:cae171557246 66 @brief GPIO for warning buzzer
el13nsp 5:cae171557246 67 */
el13nsp 5:cae171557246 68 Beep buzzer(p22);
el13nsp 5:cae171557246 69
el13nsp 5:cae171557246 70 /**
el13nsp 5:cae171557246 71 @namespace buttonA
el13nsp 5:cae171557246 72 @brief GPIO for temperature graph button A
el13nsp 5:cae171557246 73 */
el13nsp 5:cae171557246 74 InterruptIn buttonA(p15);
el13nsp 5:cae171557246 75
el13nsp 5:cae171557246 76 /**
el13nsp 5:cae171557246 77 @namespace buttonB
el13nsp 5:cae171557246 78 @brief GPIO for pressure graph button B
el13nsp 5:cae171557246 79 */
el13nsp 5:cae171557246 80 InterruptIn buttonB(p18);
el13nsp 5:cae171557246 81
el13nsp 5:cae171557246 82 /**
el13nsp 5:cae171557246 83 @namespace buttonC
el13nsp 5:cae171557246 84 @brief GPIO for weather prediction button C
el13nsp 5:cae171557246 85 */
el13nsp 5:cae171557246 86 InterruptIn buttonC(p17);
el13nsp 5:cae171557246 87
el13nsp 5:cae171557246 88 /**
el13nsp 5:cae171557246 89 @namespace buttonD
el13nsp 5:cae171557246 90 @brief GPIO for unit change button D
el13nsp 5:cae171557246 91 */
el13nsp 5:cae171557246 92 InterruptIn buttonD(p16);
el13nsp 5:cae171557246 93
el13nsp 5:cae171557246 94 /**
el13nsp 5:cae171557246 95 @namespace lcd
el13nsp 5:cae171557246 96 @brief GPIO for LCD display
el13nsp 5:cae171557246 97 */
el13nsp 5:cae171557246 98 N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
el13nsp 5:cae171557246 99
el13nsp 5:cae171557246 100 /**
el13nsp 5:cae171557246 101 @namespace serial
el13nsp 5:cae171557246 102 @brief GPIO for serial reading and writing
el13nsp 5:cae171557246 103 */
el13nsp 5:cae171557246 104 Serial serial(USBTX,USBRX);
el13nsp 5:cae171557246 105
el13nsp 5:cae171557246 106 Ticker timer; /*!< timer Ticker initialised */
el13nsp 5:cae171557246 107 Ticker stateTimer; /*!< state timer Ticker initialised */
el13nsp 5:cae171557246 108 Ticker alarmTimer; /*!< alarm timer Ticker initialised */
el13nsp 5:cae171557246 109 Ticker writingTimer; /*!< writing timer Ticker initialised */
el13nsp 5:cae171557246 110 Ticker graphTimer; /*!< graph timer Ticker initialised */
el13nsp 5:cae171557246 111
el13nsp 5:cae171557246 112 int timerFlag=0; /*!< timer flag set in ISR */
el13nsp 5:cae171557246 113 int stateTimerFlag=0; /*!< state timer flag set in ISR */
el13nsp 5:cae171557246 114 int alarmTimerFlag=0; /*!< alarm timer flag set in ISR */
el13nsp 5:cae171557246 115 int writingTimerFlag=0; /*!< writing timer flag set in ISR */
el13nsp 5:cae171557246 116 int graphTimerFlag=0; /*!< graph timer flag set in ISR */
el13nsp 5:cae171557246 117 int setTimeFlag = 0; /*!< set time flag set in ISR */
el13nsp 5:cae171557246 118 int buttonAFlag = 0; /*!< button A flag set in ISR */
el13nsp 5:cae171557246 119 int buttonBFlag = 0; /*!< button B flag set in ISR */
el13nsp 5:cae171557246 120 int buttonCFlag = 0; /*!< button C flag set in ISR */
el13nsp 5:cae171557246 121 int initFlag = 0; /*!< init flag set in ISR */
el13nsp 5:cae171557246 122
el13nsp 5:cae171557246 123 int alarm = 0; /*!< alarm flag set in ISR */
el13nsp 5:cae171557246 124 int state = 0; /*!< state flag set in ISR */
el13nsp 5:cae171557246 125 int prediction = 0; /*!< prediction flag set in ISR */
el13nsp 5:cae171557246 126 int i = 0; /*!< Initialise increment variable i */
el13nsp 5:cae171557246 127 int j = 0; /*!< Initialise increment variable j*/
el13nsp 5:cae171557246 128 int unit = celcius; /*!< unit flag set in ISR */
el13nsp 5:cae171557246 129
el13nsp 5:cae171557246 130 char rxString[16]; /*!< buffer to store received string for time */
el13nsp 5:cae171557246 131
el13nsp 5:cae171557246 132 float temparray[84]; /*!< Array to hold temperature readings */
el13nsp 5:cae171557246 133 float pressarray[84]; /*!< Array to hold pressure readings */
el13nsp 5:cae171557246 134 float presscompare[12]; /*!< Array to hold pressure readings for prediction*/
el13nsp 5:cae171557246 135
el13nsp 5:cae171557246 136 /**
el13nsp 5:cae171557246 137 ISR that is called when serial data is received
el13nsp 5:cae171557246 138 */
el13nsp 5:cae171557246 139 void serialISR();
el13nsp 5:cae171557246 140
el13nsp 5:cae171557246 141 /**
el13nsp 5:cae171557246 142 Sets the UNIX time
el13nsp 5:cae171557246 143 */
el13nsp 5:cae171557246 144 void setTime();
el13nsp 5:cae171557246 145
el13nsp 5:cae171557246 146 /**
el13nsp 5:cae171557246 147 Checks the state for weather prediction
el13nsp 5:cae171557246 148 */
el13nsp 5:cae171557246 149 void setState();
el13nsp 5:cae171557246 150
el13nsp 5:cae171557246 151 /**
el13nsp 5:cae171557246 152 Logs data to csv file on the flash memory
el13nsp 5:cae171557246 153 @param temp - Temperature to log
el13nsp 5:cae171557246 154 @param press - Pressure to log
el13nsp 5:cae171557246 155 @param time - Time to log
el13nsp 5:cae171557246 156 */
el13nsp 5:cae171557246 157 void writeDataToFile(float temp,float press,char* time);
el13nsp 5:cae171557246 158
el13nsp 5:cae171557246 159 /**
el13nsp 5:cae171557246 160 Sets pixels to display sunny weather
el13nsp 5:cae171557246 161 */
el13nsp 5:cae171557246 162 void sunny();
el13nsp 5:cae171557246 163
el13nsp 5:cae171557246 164 /**
el13nsp 5:cae171557246 165 Sets pixels to display mild cloudy weather
el13nsp 5:cae171557246 166 */
el13nsp 5:cae171557246 167 void cloudySun();
el13nsp 5:cae171557246 168
el13nsp 5:cae171557246 169 /**
el13nsp 5:cae171557246 170 Sets pixels to display cloudy weather
el13nsp 5:cae171557246 171 */
el13nsp 5:cae171557246 172 void clouds();
el13nsp 5:cae171557246 173
el13nsp 5:cae171557246 174 /**
el13nsp 5:cae171557246 175 Sets pixels to display rainy weather
el13nsp 5:cae171557246 176 */
el13nsp 5:cae171557246 177 void rainy();
el13nsp 5:cae171557246 178
el13nsp 5:cae171557246 179 /**
el13nsp 5:cae171557246 180 Sets pixels to display stormy weather
el13nsp 5:cae171557246 181 */
el13nsp 5:cae171557246 182 void stormy();
el13nsp 5:cae171557246 183
el13nsp 5:cae171557246 184 #endif