3rd Repo, trying to figure this out.

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Committer:
Netaphous
Date:
Thu Apr 06 18:52:01 2017 +0000
Branch:
feature/fakeSensor
Revision:
50:c07e968b9582
Child:
83:0d3572a8a851
Created fake barometer and measurer classes and implemented these into main, with lines currently commented out that force these calls

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Netaphous 50:c07e968b9582 1 #include "FakeSensor.h"
Netaphous 50:c07e968b9582 2 #include "mbed.h"
Netaphous 50:c07e968b9582 3
Netaphous 50:c07e968b9582 4 /*
Netaphous 50:c07e968b9582 5 Constructor
Netaphous 50:c07e968b9582 6 Takes in minimum and maximum values for fake pressure readings
Netaphous 50:c07e968b9582 7 */
Netaphous 50:c07e968b9582 8 FakeBarometer::FakeBarometer(float pressMin, float pressMax)
Netaphous 50:c07e968b9582 9 {
Netaphous 50:c07e968b9582 10 pressureMin = pressMin;
Netaphous 50:c07e968b9582 11 pressureMax = pressMax;
Netaphous 50:c07e968b9582 12 }
Netaphous 50:c07e968b9582 13
Netaphous 50:c07e968b9582 14 /*
Netaphous 50:c07e968b9582 15 Simply fakes a get call to the sensor by doing nothing
Netaphous 50:c07e968b9582 16 */
Netaphous 50:c07e968b9582 17 void FakeBarometer::get() {}
Netaphous 50:c07e968b9582 18
Netaphous 50:c07e968b9582 19 /*
Netaphous 50:c07e968b9582 20 Generates a random number for pressure using the range given in the constructor
Netaphous 50:c07e968b9582 21 Returns the random number generated
Netaphous 50:c07e968b9582 22 */
Netaphous 50:c07e968b9582 23 float FakeBarometer::pressure()
Netaphous 50:c07e968b9582 24 {
Netaphous 50:c07e968b9582 25 int rangeMax = 1000;
Netaphous 50:c07e968b9582 26 float targetRange = pressureMax - pressureMin;
Netaphous 50:c07e968b9582 27 srand(time(NULL));
Netaphous 50:c07e968b9582 28 int randNum = (rand()%rangeMax);
Netaphous 50:c07e968b9582 29 float perc = (float)randNum / rangeMax;
Netaphous 50:c07e968b9582 30 float percRange = perc * targetRange;
Netaphous 50:c07e968b9582 31 float actual = percRange + pressureMin;
Netaphous 50:c07e968b9582 32 return actual;
Netaphous 50:c07e968b9582 33 }
Netaphous 50:c07e968b9582 34