41 lines
836 B
C++
41 lines
836 B
C++
#include "PressureMonitor.h"
|
|
#include <cmath>
|
|
|
|
PressureMonitor::PressureMonitor()
|
|
: m_stableTickCount(0)
|
|
{
|
|
}
|
|
|
|
bool PressureMonitor::tick(float realtimePressure, float calibratedPressure)
|
|
{
|
|
if (calibratedPressure <= 0.0f) {
|
|
m_stableTickCount = 0;
|
|
return false;
|
|
}
|
|
|
|
float upperBound = calibratedPressure + 10.0f;
|
|
float lowerBound = calibratedPressure - 10.0f;
|
|
|
|
if (realtimePressure >= lowerBound && realtimePressure <= upperBound) {
|
|
m_stableTickCount++;
|
|
} else {
|
|
m_stableTickCount = 0;
|
|
}
|
|
|
|
return m_stableTickCount >= REQUIRED_STABLE_TICKS;
|
|
}
|
|
|
|
void PressureMonitor::reset()
|
|
{
|
|
m_stableTickCount = 0;
|
|
}
|
|
|
|
bool PressureMonitor::isCurrentlyInRange() const
|
|
{
|
|
return m_stableTickCount > 0;
|
|
}
|
|
|
|
int PressureMonitor::stableTickCount() const
|
|
{
|
|
return m_stableTickCount;
|
|
} |