SOFT253 Coursework Weather Reader
Fork of Soft253-WeatherReader by
Diff: main.cpp
- Revision:
- 4:edef041d2094
- Parent:
- 3:d17f07a0d08d
- Child:
- 5:ba160e9778d0
diff -r d17f07a0d08d -r edef041d2094 main.cpp --- a/main.cpp Fri Apr 28 12:03:17 2017 +0000 +++ b/main.cpp Fri Apr 28 13:47:23 2017 +0000 @@ -3,6 +3,7 @@ #include "hts221.h" #include "LPS25H.h" #include "DataGenerator.h" +#include <string> //Complex.Variables DigitalOut myled(LED1); @@ -20,14 +21,14 @@ float humi = 55; float barometerPressure = 0; float barometerTemperature = 0; -float dataReadTime = 0.5; +float dataReadTime = 2.0; int humiMax = 100; char cmd=0; uint32_t seconds = 0, minutes=0, hours=0; int headNode = 0; int currentNode = 0; const int maxNumRecords = 120; - +time_t sec; //Can't print data in a ticker method (not interrupt safe) //This is set once we have got new data, so it can be printed safely later bool isNewData=false; @@ -40,6 +41,7 @@ float airPress; float barTemp; float barPress; + string dt; }tempEntry; dataEntry storedDataArray [maxNumRecords]; @@ -50,6 +52,7 @@ dataTimer.attach(&readData, dataReadTime); //Attach timer to data reader. + while(1) { if (isNewData == true){ @@ -57,6 +60,8 @@ printData(); } + sec = time(NULL); + /* Flicker the LED. */ myled = 1; // LED is ON Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! @@ -71,6 +76,8 @@ headNode = 0; } + tempEntry.dt = ctime(&sec); + storedDataArray[headNode] = tempEntry; currentNode = headNode; headNode++; @@ -82,6 +89,7 @@ //As you have interrupted printdata section. if (isNewData == false){ //Random data CHANGE ME + dataGen.ReadTempHumi(&tempCelsius, &humi); barometerPressure = dataGen.pressure(); @@ -90,14 +98,14 @@ tempEntry.airTemp = tempCelsius; tempEntry.airPress = humi; tempEntry.barTemp = barometerTemperature; - tempEntry.barPress = barometerPressure; + tempEntry.barPress = barometerPressure; isNewData = true; } } /* Prints the data that was read */ void printData(){ - printf("0%i %4.2fC %3.1f%%", headNode, tempEntry.airTemp, tempEntry.airPress); + printf("%s %i: %4.2fC %3.1f%%", tempEntry.dt.c_str(), headNode, tempEntry.airTemp, tempEntry.airPress); printf(" %6.1f %4.1f\r\n", tempEntry.barPress, tempEntry.barTemp); isNewData = false; }