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 both temperature and humidity fake readings
Netaphous 50:c07e968b9582 7 */
Netaphous 50:c07e968b9582 8 FakeMeasurer::FakeMeasurer(float tempMin, float tempMax, float humiMin, float humiMax)
Netaphous 50:c07e968b9582 9 {
Netaphous 50:c07e968b9582 10 temperatureMin = tempMin;
Netaphous 50:c07e968b9582 11 temperatureMax = tempMax;
Netaphous 50:c07e968b9582 12 humidityMin = humiMin;
Netaphous 50:c07e968b9582 13 humidityMax = humiMax;
Netaphous 50:c07e968b9582 14 }
Netaphous 50:c07e968b9582 15 /*
Netaphous 50:c07e968b9582 16 Simply returns true to fake successful initialisation
Netaphous 50:c07e968b9582 17 */
Netaphous 50:c07e968b9582 18 bool FakeMeasurer::init()
Netaphous 50:c07e968b9582 19 {
Netaphous 50:c07e968b9582 20 return true;
Netaphous 50:c07e968b9582 21 }
Netaphous 50:c07e968b9582 22
Netaphous 50:c07e968b9582 23 /*
Netaphous 50:c07e968b9582 24 Simply fakes a calibration call to the sensor by doing nothing
Netaphous 50:c07e968b9582 25 */
Netaphous 50:c07e968b9582 26 void FakeMeasurer::calib() {}
Netaphous 50:c07e968b9582 27
Netaphous 50:c07e968b9582 28 /*
Netaphous 50:c07e968b9582 29 Generates a random number for both temperature and humidity using the ranges
Netaphous 50:c07e968b9582 30 given in the constructor
Netaphous 50:c07e968b9582 31 Stores the random numbers in the variables given
Netaphous 50:c07e968b9582 32 */
Netaphous 50:c07e968b9582 33 void FakeMeasurer::ReadTempHumi(float *temperature, float *humidity)
Netaphous 50:c07e968b9582 34 {
Netaphous 50:c07e968b9582 35 int rangeMax = 1000;
Netaphous 50:c07e968b9582 36
Netaphous 50:c07e968b9582 37 float targetRange = temperatureMax - temperatureMin;
Netaphous 50:c07e968b9582 38 srand(time(NULL));
Netaphous 50:c07e968b9582 39 int randNum = (rand()%rangeMax);
Netaphous 50:c07e968b9582 40 float perc = (float)randNum / rangeMax;
Netaphous 50:c07e968b9582 41 float percRange = perc * targetRange;
Netaphous 50:c07e968b9582 42 *temperature = percRange + temperatureMin;
Netaphous 50:c07e968b9582 43
Netaphous 50:c07e968b9582 44 targetRange = humidityMax - humidityMin;
Netaphous 50:c07e968b9582 45 srand(time(NULL));
Netaphous 50:c07e968b9582 46 randNum = (rand()%rangeMax);
Netaphous 50:c07e968b9582 47 perc = (float)randNum / rangeMax;
Netaphous 50:c07e968b9582 48 percRange = perc * targetRange;
Netaphous 50:c07e968b9582 49 *humidity = percRange + humidityMin;
Netaphous 50:c07e968b9582 50 }