3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
Diff: FakeSensor/FakeMeasurer.cpp
- Branch:
- feature/fakeSensor
- Revision:
- 50:c07e968b9582
- Child:
- 83:0d3572a8a851
diff -r 83bea7fb2728 -r c07e968b9582 FakeSensor/FakeMeasurer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FakeSensor/FakeMeasurer.cpp Thu Apr 06 18:52:01 2017 +0000 @@ -0,0 +1,50 @@ +#include "FakeSensor.h" +#include "mbed.h" + +/* + Constructor + Takes in minimum and maximum values for both temperature and humidity fake readings +*/ +FakeMeasurer::FakeMeasurer(float tempMin, float tempMax, float humiMin, float humiMax) +{ + temperatureMin = tempMin; + temperatureMax = tempMax; + humidityMin = humiMin; + humidityMax = humiMax; +} +/* + Simply returns true to fake successful initialisation +*/ +bool FakeMeasurer::init() +{ + return true; +} + +/* + Simply fakes a calibration call to the sensor by doing nothing +*/ +void FakeMeasurer::calib() {} + +/* + Generates a random number for both temperature and humidity using the ranges + given in the constructor + Stores the random numbers in the variables given +*/ +void FakeMeasurer::ReadTempHumi(float *temperature, float *humidity) +{ + int rangeMax = 1000; + + float targetRange = temperatureMax - temperatureMin; + srand(time(NULL)); + int randNum = (rand()%rangeMax); + float perc = (float)randNum / rangeMax; + float percRange = perc * targetRange; + *temperature = percRange + temperatureMin; + + targetRange = humidityMax - humidityMin; + srand(time(NULL)); + randNum = (rand()%rangeMax); + perc = (float)randNum / rangeMax; + percRange = perc * targetRange; + *humidity = percRange + humidityMin; +} \ No newline at end of file