压力监视等待初版

This commit is contained in:
2026-09-14 17:08:21 +08:00
parent 96c5fab758
commit 0bc587e989
5 changed files with 95 additions and 14 deletions
+41
View File
@@ -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;
}