![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SOFT253 Coursework Weather Reader
Fork of Soft253-WeatherReader by
Diff: main.cpp
- Revision:
- 5:ba160e9778d0
- Parent:
- 4:edef041d2094
- Child:
- 6:0cc980145515
--- a/main.cpp Fri Apr 28 13:47:23 2017 +0000 +++ b/main.cpp Tue May 02 09:36:46 2017 +0000 @@ -4,6 +4,7 @@ #include "LPS25H.h" #include "DataGenerator.h" #include <string> +#include <time.h> //Complex.Variables DigitalOut myled(LED1); @@ -28,7 +29,7 @@ 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; @@ -41,7 +42,7 @@ float airPress; float barTemp; float barPress; - string dt; + time_t dt; }tempEntry; dataEntry storedDataArray [maxNumRecords]; @@ -60,7 +61,6 @@ printData(); } - sec = time(NULL); /* Flicker the LED. */ myled = 1; // LED is ON @@ -76,7 +76,7 @@ headNode = 0; } - tempEntry.dt = ctime(&sec); + tempEntry.dt = time(0); storedDataArray[headNode] = tempEntry; currentNode = headNode; @@ -105,10 +105,11 @@ } /* Prints the data that was read */ void printData(){ - printf("%s %i: %4.2fC %3.1f%%", tempEntry.dt.c_str(), headNode, tempEntry.airTemp, tempEntry.airPress); + printf("%s", ctime(&tempEntry.dt)); + printf("%i: %4.2fC %3.1f%%", headNode, tempEntry.airTemp, tempEntry.airPress); printf(" %6.1f %4.1f\r\n", tempEntry.barPress, tempEntry.barTemp); isNewData = false; -} +}