3rd Repo, trying to figure this out.

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Committer:
aburch1
Date:
Thu May 11 19:23:55 2017 +0000
Revision:
83:0d3572a8a851
Parent:
50:c07e968b9582
Child:
85:422d0a1b95cf
Comments cleaned and improved throughout classes. Main header class comment complete, other class comments still need to be written.

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
aburch1 83:0d3572a8a851 4 /**
Netaphous 50:c07e968b9582 5 Constructor
Netaphous 50:c07e968b9582 6 Takes in minimum and maximum values for both temperature and humidity fake readings
aburch1 83:0d3572a8a851 7
aburch1 83:0d3572a8a851 8 @param tempMin : Miniumum value for temperature.
aburch1 83:0d3572a8a851 9 @param tempMax : Maxiumum value for temperature.
aburch1 83:0d3572a8a851 10 @param humiMin : Miniumum value for humidity.
aburch1 83:0d3572a8a851 11 @param humiMax : Maxiumum value for humidity.
Netaphous 50:c07e968b9582 12 */
Netaphous 50:c07e968b9582 13 FakeMeasurer::FakeMeasurer(float tempMin, float tempMax, float humiMin, float humiMax)
Netaphous 50:c07e968b9582 14 {
Netaphous 50:c07e968b9582 15 temperatureMin = tempMin;
Netaphous 50:c07e968b9582 16 temperatureMax = tempMax;
Netaphous 50:c07e968b9582 17 humidityMin = humiMin;
Netaphous 50:c07e968b9582 18 humidityMax = humiMax;
aburch1 83:0d3572a8a851 19 }
aburch1 83:0d3572a8a851 20
aburch1 83:0d3572a8a851 21 /**
aburch1 83:0d3572a8a851 22 @return : True to fake successful initialisation of sensor.
Netaphous 50:c07e968b9582 23 */
Netaphous 50:c07e968b9582 24 bool FakeMeasurer::init()
Netaphous 50:c07e968b9582 25 {
Netaphous 50:c07e968b9582 26 return true;
Netaphous 50:c07e968b9582 27 }
Netaphous 50:c07e968b9582 28
aburch1 83:0d3572a8a851 29 /**
aburch1 83:0d3572a8a851 30 Fakes a calibration call to the sensor by doing nothing.
Netaphous 50:c07e968b9582 31 */
Netaphous 50:c07e968b9582 32 void FakeMeasurer::calib() {}
Netaphous 50:c07e968b9582 33
aburch1 83:0d3572a8a851 34 /**
Netaphous 50:c07e968b9582 35 Generates a random number for both temperature and humidity using the ranges
aburch1 83:0d3572a8a851 36 given in the constructor and stores the random numbers in the variables passed in.
aburch1 83:0d3572a8a851 37
aburch1 83:0d3572a8a851 38 @param temperature : Pointer to float where temperature reading is stored.
aburch1 83:0d3572a8a851 39 @param humidity : Pointer to float where humidity reading is stored.
Netaphous 50:c07e968b9582 40 */
Netaphous 50:c07e968b9582 41 void FakeMeasurer::ReadTempHumi(float *temperature, float *humidity)
Netaphous 50:c07e968b9582 42 {
Netaphous 50:c07e968b9582 43 int rangeMax = 1000;
Netaphous 50:c07e968b9582 44
Netaphous 50:c07e968b9582 45 float targetRange = temperatureMax - temperatureMin;
Netaphous 50:c07e968b9582 46 srand(time(NULL));
Netaphous 50:c07e968b9582 47 int randNum = (rand()%rangeMax);
Netaphous 50:c07e968b9582 48 float perc = (float)randNum / rangeMax;
Netaphous 50:c07e968b9582 49 float percRange = perc * targetRange;
Netaphous 50:c07e968b9582 50 *temperature = percRange + temperatureMin;
Netaphous 50:c07e968b9582 51
Netaphous 50:c07e968b9582 52 targetRange = humidityMax - humidityMin;
Netaphous 50:c07e968b9582 53 srand(time(NULL));
Netaphous 50:c07e968b9582 54 randNum = (rand()%rangeMax);
Netaphous 50:c07e968b9582 55 perc = (float)randNum / rangeMax;
Netaphous 50:c07e968b9582 56 percRange = perc * targetRange;
Netaphous 50:c07e968b9582 57 *humidity = percRange + humidityMin;
Netaphous 50:c07e968b9582 58 }