Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TirePressureMonitoring/Cpp Added Cpp porting from Emily racing kata repo
- Loading branch information
1 parent
82c60f0
commit 4abda94
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "sensor.hpp" | ||
|
||
using namespace std; | ||
|
||
class Alarm | ||
{ | ||
public: | ||
Alarm(); | ||
void check(); | ||
bool isAlarmOn(); | ||
|
||
protected: | ||
Sensor sensor; | ||
double lowPressureTreshold; | ||
double highPressureTreshold; | ||
bool alarmOn; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "alarm.hpp" | ||
#include "sensor.hpp" | ||
|
||
Alarm::Alarm() | ||
{ | ||
sensor = Sensor(); | ||
lowPressureTreshold = 17; | ||
highPressureTreshold = 21; | ||
alarmOn = false; | ||
} | ||
|
||
void Alarm::check() | ||
{ | ||
double psiPressureValue = sensor.popNextPressurePsiValue(); | ||
|
||
if (psiPressureValue < lowPressureTreshold || highPressureTreshold < psiPressureValue) | ||
{ | ||
alarmOn = true; | ||
} | ||
} | ||
|
||
bool Alarm::isAlarmOn() | ||
{ | ||
return alarmOn; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "sensor.hpp" | ||
|
||
#include <cstdlib> | ||
#include <time.h> | ||
|
||
using namespace std; | ||
|
||
Sensor::Sensor() | ||
{ | ||
srand((unsigned)time(0)); | ||
} | ||
|
||
double Sensor::popNextPressurePsiValue() | ||
{ | ||
// placeholder implementation that simulates a real sensor in a real tire | ||
double pressure = 16 + (float)rand()/((float)RAND_MAX/(6)); | ||
return pressure; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
using namespace std; | ||
|
||
class Sensor | ||
{ | ||
public: | ||
Sensor(); | ||
double popNextPressurePsiValue(); | ||
|
||
}; |