3rd Repo, trying to figure this out.

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

FakeSensor/FakeMeasurer.cpp

Committer:
Netaphous
Date:
2017-04-06
Branch:
feature/fakeSensor
Revision:
50:c07e968b9582
Child:
83:0d3572a8a851

File content as of revision 50:c07e968b9582:

#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;                
}