![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SOFT253 Coursework Weather Reader
Fork of Soft253-WeatherReader by
Diff: main.cpp
- Revision:
- 3:d17f07a0d08d
- Parent:
- 2:27b92722246b
- Child:
- 4:edef041d2094
--- a/main.cpp Sat Apr 22 09:27:18 2017 +0000 +++ b/main.cpp Fri Apr 28 12:03:17 2017 +0000 @@ -13,16 +13,20 @@ void readData(); void createDataThread(); void printData(); +void storeNewRecord(); //Prim.Variables float tempCelsius = 25.50; float humi = 55; float barometerPressure = 0; float barometerTemperature = 0; -float dataReadTime = 2.0; +float dataReadTime = 0.5; int humiMax = 100; char cmd=0; uint32_t seconds = 0, minutes=0, hours=0; +int headNode = 0; +int currentNode = 0; +const int maxNumRecords = 120; //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 @@ -31,6 +35,15 @@ // Test Data generator setup DataGenerator dataGen; +struct dataEntry{ + float airTemp; + float airPress; + float barTemp; + float barPress; + }tempEntry; + +dataEntry storedDataArray [maxNumRecords]; + int main(){ printf("SOFT253 simple Temperature Humidity and Pressure Sensor Monitor\n\r"); printf("Using the X-NUCLEO-IKS01A1 shield and MBED Libraries\n\r"); @@ -40,6 +53,7 @@ while(1) { if (isNewData == true){ + storeNewRecord(); printData(); } @@ -51,23 +65,40 @@ } } +void storeNewRecord(){ + + if(headNode>=120){ + headNode = 0; + } + + storedDataArray[headNode] = tempEntry; + currentNode = headNode; + headNode++; +} + /* Reads all the data in whenever the ticker interrupt is called */ void readData(){ //Check if old data has been printed if it hasn't don't do anything //As you have interrupted printdata section. if (isNewData == false){ + //Random data CHANGE ME dataGen.ReadTempHumi(&tempCelsius, &humi); barometerPressure = dataGen.pressure(); barometerTemperature = dataGen.temperature(); + tempEntry.airTemp = tempCelsius; + tempEntry.airPress = humi; + tempEntry.barTemp = barometerTemperature; + tempEntry.barPress = barometerPressure; + isNewData = true; } } /* Prints the data that was read */ void printData(){ - printf("%4.2fC %3.1f%%", tempCelsius, humi); - printf(" %6.1f %4.1f\r\n", barometerPressure, barometerTemperature); + printf("0%i %4.2fC %3.1f%%", headNode, tempEntry.airTemp, tempEntry.airPress); + printf(" %6.1f %4.1f\r\n", tempEntry.barPress, tempEntry.barTemp); isNewData = false; }