3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
FakeSensor/FakeMeasurer.cpp@85:422d0a1b95cf, 2017-05-13 (annotated)
- Committer:
- niallfrancis
- Date:
- Sat May 13 17:35:58 2017 +0000
- Revision:
- 85:422d0a1b95cf
- Parent:
- 83:0d3572a8a851
Finished commenting classes;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Netaphous | 50:c07e968b9582 | 1 | #include "FakeSensor.h" |
Netaphous | 50:c07e968b9582 | 2 | #include "mbed.h" |
Netaphous | 50:c07e968b9582 | 3 | |
niallfrancis | 85:422d0a1b95cf | 4 | /** |
niallfrancis | 85:422d0a1b95cf | 5 | @file : FakeMeasurer.cpp |
niallfrancis | 85:422d0a1b95cf | 6 | @authors : Radu Marcu, Jacob Williams, Niall Francis, Arron Burch |
niallfrancis | 85:422d0a1b95cf | 7 | |
niallfrancis | 85:422d0a1b95cf | 8 | @section DESCRIPTION |
niallfrancis | 85:422d0a1b95cf | 9 | |
niallfrancis | 85:422d0a1b95cf | 10 | This is the FakeMeasurer class. It is used to generate fake data readings, |
niallfrancis | 85:422d0a1b95cf | 11 | meant to simulate the results a real sensor would provide. It generates random |
niallfrancis | 85:422d0a1b95cf | 12 | values for humidity and temperature. |
niallfrancis | 85:422d0a1b95cf | 13 | */ |
niallfrancis | 85:422d0a1b95cf | 14 | |
niallfrancis | 85:422d0a1b95cf | 15 | |
niallfrancis | 85:422d0a1b95cf | 16 | |
aburch1 | 83:0d3572a8a851 | 17 | /** |
Netaphous | 50:c07e968b9582 | 18 | Constructor |
Netaphous | 50:c07e968b9582 | 19 | Takes in minimum and maximum values for both temperature and humidity fake readings |
aburch1 | 83:0d3572a8a851 | 20 | |
aburch1 | 83:0d3572a8a851 | 21 | @param tempMin : Miniumum value for temperature. |
aburch1 | 83:0d3572a8a851 | 22 | @param tempMax : Maxiumum value for temperature. |
aburch1 | 83:0d3572a8a851 | 23 | @param humiMin : Miniumum value for humidity. |
aburch1 | 83:0d3572a8a851 | 24 | @param humiMax : Maxiumum value for humidity. |
Netaphous | 50:c07e968b9582 | 25 | */ |
Netaphous | 50:c07e968b9582 | 26 | FakeMeasurer::FakeMeasurer(float tempMin, float tempMax, float humiMin, float humiMax) |
Netaphous | 50:c07e968b9582 | 27 | { |
Netaphous | 50:c07e968b9582 | 28 | temperatureMin = tempMin; |
Netaphous | 50:c07e968b9582 | 29 | temperatureMax = tempMax; |
Netaphous | 50:c07e968b9582 | 30 | humidityMin = humiMin; |
Netaphous | 50:c07e968b9582 | 31 | humidityMax = humiMax; |
aburch1 | 83:0d3572a8a851 | 32 | } |
aburch1 | 83:0d3572a8a851 | 33 | |
aburch1 | 83:0d3572a8a851 | 34 | /** |
aburch1 | 83:0d3572a8a851 | 35 | @return : True to fake successful initialisation of sensor. |
Netaphous | 50:c07e968b9582 | 36 | */ |
Netaphous | 50:c07e968b9582 | 37 | bool FakeMeasurer::init() |
Netaphous | 50:c07e968b9582 | 38 | { |
Netaphous | 50:c07e968b9582 | 39 | return true; |
Netaphous | 50:c07e968b9582 | 40 | } |
Netaphous | 50:c07e968b9582 | 41 | |
aburch1 | 83:0d3572a8a851 | 42 | /** |
aburch1 | 83:0d3572a8a851 | 43 | Fakes a calibration call to the sensor by doing nothing. |
Netaphous | 50:c07e968b9582 | 44 | */ |
Netaphous | 50:c07e968b9582 | 45 | void FakeMeasurer::calib() {} |
Netaphous | 50:c07e968b9582 | 46 | |
aburch1 | 83:0d3572a8a851 | 47 | /** |
Netaphous | 50:c07e968b9582 | 48 | Generates a random number for both temperature and humidity using the ranges |
aburch1 | 83:0d3572a8a851 | 49 | given in the constructor and stores the random numbers in the variables passed in. |
aburch1 | 83:0d3572a8a851 | 50 | |
aburch1 | 83:0d3572a8a851 | 51 | @param temperature : Pointer to float where temperature reading is stored. |
aburch1 | 83:0d3572a8a851 | 52 | @param humidity : Pointer to float where humidity reading is stored. |
Netaphous | 50:c07e968b9582 | 53 | */ |
Netaphous | 50:c07e968b9582 | 54 | void FakeMeasurer::ReadTempHumi(float *temperature, float *humidity) |
Netaphous | 50:c07e968b9582 | 55 | { |
Netaphous | 50:c07e968b9582 | 56 | int rangeMax = 1000; |
Netaphous | 50:c07e968b9582 | 57 | |
Netaphous | 50:c07e968b9582 | 58 | float targetRange = temperatureMax - temperatureMin; |
Netaphous | 50:c07e968b9582 | 59 | srand(time(NULL)); |
Netaphous | 50:c07e968b9582 | 60 | int randNum = (rand()%rangeMax); |
Netaphous | 50:c07e968b9582 | 61 | float perc = (float)randNum / rangeMax; |
Netaphous | 50:c07e968b9582 | 62 | float percRange = perc * targetRange; |
Netaphous | 50:c07e968b9582 | 63 | *temperature = percRange + temperatureMin; |
Netaphous | 50:c07e968b9582 | 64 | |
Netaphous | 50:c07e968b9582 | 65 | targetRange = humidityMax - humidityMin; |
Netaphous | 50:c07e968b9582 | 66 | srand(time(NULL)); |
Netaphous | 50:c07e968b9582 | 67 | randNum = (rand()%rangeMax); |
Netaphous | 50:c07e968b9582 | 68 | perc = (float)randNum / rangeMax; |
Netaphous | 50:c07e968b9582 | 69 | percRange = perc * targetRange; |
Netaphous | 50:c07e968b9582 | 70 | *humidity = percRange + humidityMin; |
Netaphous | 50:c07e968b9582 | 71 | } |