![](/media/cache/profiles/ba5be68d3d541f2ca043d77fc54fe702.jpg.50x50_q85.jpg)
3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
FakeSensor/FakeMeasurer.cpp
- Committer:
- aburch1
- Date:
- 2017-05-11
- Revision:
- 83:0d3572a8a851
- Parent:
- 50:c07e968b9582
- Child:
- 85:422d0a1b95cf
File content as of revision 83:0d3572a8a851:
#include "FakeSensor.h" #include "mbed.h" /** Constructor Takes in minimum and maximum values for both temperature and humidity fake readings @param tempMin : Miniumum value for temperature. @param tempMax : Maxiumum value for temperature. @param humiMin : Miniumum value for humidity. @param humiMax : Maxiumum value for humidity. */ FakeMeasurer::FakeMeasurer(float tempMin, float tempMax, float humiMin, float humiMax) { temperatureMin = tempMin; temperatureMax = tempMax; humidityMin = humiMin; humidityMax = humiMax; } /** @return : True to fake successful initialisation of sensor. */ bool FakeMeasurer::init() { return true; } /** 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 and stores the random numbers in the variables passed in. @param temperature : Pointer to float where temperature reading is stored. @param humidity : Pointer to float where humidity reading is stored. */ 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; }