diff --git a/ESP32/src/vehicle-monitor.cpp b/ESP32/src/vehicle-monitor.cpp index 458ae58..b37c892 100644 --- a/ESP32/src/vehicle-monitor.cpp +++ b/ESP32/src/vehicle-monitor.cpp @@ -69,7 +69,11 @@ void IRAM_ATTR onSpeedSensorChange(bool newState) if(impulseDuration > 500) return; // impulse was too long, ignore it (maybe magnet stopped near the sensor) unsigned long timeSinceLastImpulse = utils::elapsed(speedSensorLastImpulseTime, now); - if(timeSinceLastImpulse < 30) + + // TODO: find a simple formula that works for any wheel diameter and number of magnets + unsigned long minInterval = speedSensorLastImpulseInterval == (unsigned long)-1 ? 200 : std::min((unsigned long)200, (unsigned long)30 + speedSensorLastImpulseInterval / 2); + + if(timeSinceLastImpulse < minInterval) { // too little time between impulses, probably some bouncing, ignore it }