3rd Repo, trying to figure this out.

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Branch:
feature/fakeSensor
Revision:
50:c07e968b9582
Child:
83:0d3572a8a851
diff -r 83bea7fb2728 -r c07e968b9582 FakeSensor/FakeBarometer.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FakeSensor/FakeBarometer.cpp	Thu Apr 06 18:52:01 2017 +0000
@@ -0,0 +1,34 @@
+#include "FakeSensor.h"
+#include "mbed.h"
+
+/*
+    Constructor
+    Takes in minimum and maximum values for fake pressure readings
+*/
+FakeBarometer::FakeBarometer(float pressMin, float pressMax)
+{
+    pressureMin = pressMin;
+    pressureMax = pressMax;
+}
+
+/*
+    Simply fakes a get call to the sensor by doing nothing
+*/
+void FakeBarometer::get() {}
+
+/*
+    Generates a random number for pressure using the range given in the constructor
+    Returns the random number generated
+*/
+float FakeBarometer::pressure()
+{
+    int rangeMax = 1000;
+    float targetRange = pressureMax - pressureMin;
+    srand(time(NULL));
+    int randNum = (rand()%rangeMax);
+    float perc = (float)randNum / rangeMax;
+    float percRange = perc * targetRange;
+    float actual = percRange + pressureMin;
+    return actual;
+}
+        
\ No newline at end of file