Discard odd-position '1' bursts: filter wind-up spurious pulse

This commit is contained in:
2026-06-29 01:54:57 +02:00
parent 5ae2321f2d
commit a810456ef1
+17 -1
View File
@@ -23,7 +23,7 @@
// ---------------------------------------------------------------------------
#define DIAL_PIN 4 // GPIO connected to the pulse contact (to GND)
#define PULSE_DEBOUNCE_MS 15 // ignore edges faster than this
#define PULSE_DEBOUNCE_MS 100 // ignore edges faster than this
#define INTER_PULSE_MS 350 // silence longer than this = digit complete
#define INTER_DIGIT_MS 2500 // silence longer than this = number complete, publish
@@ -58,6 +58,7 @@ static volatile int dialPulses = 0;
static volatile unsigned long dialLastPulse = 0; // millis() of last counted pulse
static String dialNumber = "";
static unsigned long dialLastDigit = 0; // millis() of last completed digit
static int dialRawCount = 0; // raw digit count since last publish (odd positions = wind-up spurious)
static void IRAM_ATTR onDialPulse() {
unsigned long now = millis();
@@ -278,18 +279,33 @@ static void dialLoop() {
interrupts();
lastLoggedPulses = 0;
dialRawCount++;
// 10 pulses = digit '0'; 19 pulses = digits '1''9'
char digit = '0' + (pulses >= 10 ? 0 : pulses);
bool spurious = (dialRawCount % 2 == 1) && (digit == '1');
if (spurious) {
Serial.printf("[DIAL] burst end pulses=%d -> digit='%c' (wind-up spurious, discarded)\n", pulses, digit);
} else {
dialNumber += digit;
dialLastDigit = now;
Serial.printf("[DIAL] burst end pulses=%d -> digit='%c' number_so_far=%s\n", pulses, digit, dialNumber.c_str());
}
}
// Number complete when no further digits arrive within the timeout
if (dialNumber.length() > 0 && (now - dialLastDigit) >= INTER_DIGIT_MS) {
Serial.printf("[DIAL] number complete=%s\n", dialNumber.c_str());
mqttPublishDialed(dialNumber);
dialNumber = "";
dialRawCount = 0;
}
// If the sequence stalled with no accepted digit (e.g. user wound up then
// stopped), reset the count so the next wind-up is treated as position 1.
if (dialRawCount > 0 && dialNumber.length() == 0 && pulses == 0
&& (now - lastPulse) >= INTER_DIGIT_MS) {
Serial.println("[DIAL] idle reset");
dialRawCount = 0;
}
}