Files
VX5_KRO_GearPump/PressureMonitor.cpp
T

58 lines
1.2 KiB
C++

#include "PressureMonitor.h"
#include <cmath>
PressureMonitor::PressureMonitor()
: m_stableTickCount(0)
, m_totalTickCount(0)
, m_timeout(false)
{
}
bool PressureMonitor::tick(float realtimePressure, float calibratedPressure)
{
m_totalTickCount++;
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;
}
// 5分钟超时兜底:无论压力是否稳定,都触发结束
if (m_totalTickCount >= TIMEOUT_TICKS) {
m_timeout = true;
return true;
}
return m_stableTickCount >= REQUIRED_STABLE_TICKS;
}
void PressureMonitor::reset()
{
m_stableTickCount = 0;
m_totalTickCount = 0;
m_timeout = false;
}
bool PressureMonitor::isCurrentlyInRange() const
{
return m_stableTickCount > 0;
}
int PressureMonitor::stableTickCount() const
{
return m_stableTickCount;
}
bool PressureMonitor::wasTimeout() const
{
return m_timeout;
}