3rd Repo, trying to figure this out.

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

FakeSensor/FakeBarometer.cpp

Committer:
niallfrancis
Date:
2017-05-13
Revision:
85:422d0a1b95cf
Parent:
83:0d3572a8a851

File content as of revision 85:422d0a1b95cf:

#include "FakeSensor.h"
#include "mbed.h"

/**
    @file :     FakeBarometer.cpp
    @authors :   Radu Marcu, Jacob Williams, Niall Francis, Arron Burch
    
    @section DESCRIPTION
    
    This is the FakeBarometer class. It is used to generate fake data readings,
    meant to simulate the results a real sensor would provide. It generates random
    values for pressure.
*/




/**
    Constructor
    Takes in minimum and maximum values for fake pressure readings
    
    @param pressMin :   Minimum value for pressure.
    @param pressMax :   Maximum value for pressure.
*/
FakeBarometer::FakeBarometer(float pressMin, float pressMax)
{
    pressureMin = pressMin;
    pressureMax = pressMax;
}

/**
    Fakes a get call to the sensor by doing nothing.
*/
void FakeBarometer::get() {}

/**
    Generates a random number for pressure using the range given in the constructor
    
    @return actual :    The random number generated, simulating pressure.
*/
float FakeBarometer::pressure()
{
    int rangeMax = 1000;
    float targetRange = pressureMax - pressureMin;
    srand(time(NULL));
    int randNum = (rand()%rangeMax);
    float perc = (float)randNum / rangeMax;
    float percRange = perc * targetRange;
    float actual = percRange + pressureMin;
    return actual;
}