压力监视等待初版
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user