Skip to content

Commit 2bbbd6f

Browse files
Copilotdorkmo
andcommitted
Improve comments and single-pulse handling based on review feedback
Co-authored-by: dorkmo <[email protected]>
1 parent 7268b7e commit 2bbbd6f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

TankAlarm-112025-Client-BluesOpta/TankAlarm-112025-Client-BluesOpta.ino

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,7 @@ static float readTankSensor(uint8_t idx) {
19101910
const uint32_t MAX_ITERATIONS = RPM_SAMPLE_DURATION_MS * 2;
19111911
unsigned long firstPulseTime = 0;
19121912
unsigned long secondPulseTime = 0;
1913-
unsigned long localLastPulseTime = 0; // Local tracking for proper debounce
1913+
unsigned long cycleLastPulseTime = 0; // Track last pulse within this measurement cycle for debounce
19141914
uint32_t iterationCount = 0;
19151915
bool firstPulseDetected = false;
19161916
bool secondPulseDetected = false;
@@ -1942,9 +1942,9 @@ static float readTankSensor(uint8_t idx) {
19421942

19431943
if (edgeDetected) {
19441944
unsigned long now = millis();
1945-
// Debounce using local tracking within this measurement cycle
1946-
if (now - localLastPulseTime >= DEBOUNCE_MS) {
1947-
localLastPulseTime = now;
1945+
// Debounce using cycle-local tracking within this measurement
1946+
if (now - cycleLastPulseTime >= DEBOUNCE_MS) {
1947+
cycleLastPulseTime = now;
19481948
if (!firstPulseDetected) {
19491949
firstPulseTime = now;
19501950
firstPulseDetected = true;
@@ -1980,9 +1980,12 @@ static float readTankSensor(uint8_t idx) {
19801980
rpm = MS_PER_MINUTE / ((float)gRpmPulsePeriodMs[idx] * (float)pulsesPerRev);
19811981
} else if (firstPulseDetected && !secondPulseDetected) {
19821982
// Only one pulse detected - RPM is very low or stopped
1983-
// Use a conservative estimate based on the sample duration
1984-
// If we didn't get a second pulse in 3 seconds, RPM is < 20 (assuming 1 pulse/rev)
1985-
rpm = 0.0f;
1983+
// If we didn't get a second pulse within the sample duration,
1984+
// RPM is below: 60000ms / (RPM_SAMPLE_DURATION_MS * pulsesPerRev)
1985+
// For 3s sampling with 1 pulse/rev: < 20 RPM
1986+
// For 3s sampling with 4 pulses/rev: < 5 RPM
1987+
// Keep last reading to avoid false zero during temporary signal loss
1988+
rpm = gRpmLastReading[idx];
19861989
} else {
19871990
// No pulses detected, keep last reading
19881991
rpm = gRpmLastReading[idx];

0 commit comments

Comments
 (0)