3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
FakeSensor/FakeBarometer.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 | |
aburch1 | 83:0d3572a8a851 | 4 | /** |
niallfrancis | 85:422d0a1b95cf | 5 | @file : FakeBarometer.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 FakeBarometer 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 pressure. |
niallfrancis | 85:422d0a1b95cf | 13 | */ |
niallfrancis | 85:422d0a1b95cf | 14 | |
niallfrancis | 85:422d0a1b95cf | 15 | |
niallfrancis | 85:422d0a1b95cf | 16 | |
niallfrancis | 85:422d0a1b95cf | 17 | |
niallfrancis | 85:422d0a1b95cf | 18 | /** |
Netaphous | 50:c07e968b9582 | 19 | Constructor |
Netaphous | 50:c07e968b9582 | 20 | Takes in minimum and maximum values for fake pressure readings |
aburch1 | 83:0d3572a8a851 | 21 | |
aburch1 | 83:0d3572a8a851 | 22 | @param pressMin : Minimum value for pressure. |
aburch1 | 83:0d3572a8a851 | 23 | @param pressMax : Maximum value for pressure. |
Netaphous | 50:c07e968b9582 | 24 | */ |
Netaphous | 50:c07e968b9582 | 25 | FakeBarometer::FakeBarometer(float pressMin, float pressMax) |
Netaphous | 50:c07e968b9582 | 26 | { |
Netaphous | 50:c07e968b9582 | 27 | pressureMin = pressMin; |
Netaphous | 50:c07e968b9582 | 28 | pressureMax = pressMax; |
Netaphous | 50:c07e968b9582 | 29 | } |
Netaphous | 50:c07e968b9582 | 30 | |
aburch1 | 83:0d3572a8a851 | 31 | /** |
aburch1 | 83:0d3572a8a851 | 32 | Fakes a get call to the sensor by doing nothing. |
Netaphous | 50:c07e968b9582 | 33 | */ |
Netaphous | 50:c07e968b9582 | 34 | void FakeBarometer::get() {} |
Netaphous | 50:c07e968b9582 | 35 | |
aburch1 | 83:0d3572a8a851 | 36 | /** |
Netaphous | 50:c07e968b9582 | 37 | Generates a random number for pressure using the range given in the constructor |
aburch1 | 83:0d3572a8a851 | 38 | |
aburch1 | 83:0d3572a8a851 | 39 | @return actual : The random number generated, simulating pressure. |
Netaphous | 50:c07e968b9582 | 40 | */ |
Netaphous | 50:c07e968b9582 | 41 | float FakeBarometer::pressure() |
Netaphous | 50:c07e968b9582 | 42 | { |
Netaphous | 50:c07e968b9582 | 43 | int rangeMax = 1000; |
Netaphous | 50:c07e968b9582 | 44 | float targetRange = pressureMax - pressureMin; |
Netaphous | 50:c07e968b9582 | 45 | srand(time(NULL)); |
Netaphous | 50:c07e968b9582 | 46 | int randNum = (rand()%rangeMax); |
Netaphous | 50:c07e968b9582 | 47 | float perc = (float)randNum / rangeMax; |
Netaphous | 50:c07e968b9582 | 48 | float percRange = perc * targetRange; |
Netaphous | 50:c07e968b9582 | 49 | float actual = percRange + pressureMin; |
Netaphous | 50:c07e968b9582 | 50 | return actual; |
Netaphous | 50:c07e968b9582 | 51 | } |
Netaphous | 50:c07e968b9582 | 52 |