mirror of
https://github.com/esphome/esphome.git
synced 2024-12-23 16:47:57 +01:00
Update total_pulses_ at every detected pulse (#1875)
This commit is contained in:
parent
65c50e4f01
commit
635916737b
@ -23,7 +23,6 @@ void PulseMeterSensor::loop() {
|
||||
const uint32_t time_since_valid_edge_us = now - this->last_valid_edge_us_;
|
||||
if ((this->last_valid_edge_us_ != 0) && (time_since_valid_edge_us > this->timeout_us_)) {
|
||||
ESP_LOGD(TAG, "No pulse detected for %us, assuming 0 pulses/min", time_since_valid_edge_us / 1000000);
|
||||
this->last_detected_edge_us_ = 0;
|
||||
this->last_valid_edge_us_ = 0;
|
||||
this->pulse_width_us_ = 0;
|
||||
}
|
||||
@ -68,18 +67,15 @@ void ICACHE_RAM_ATTR PulseMeterSensor::gpio_intr(PulseMeterSensor *sensor) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore the first detected pulse (we need at least two pulses to measure the width)
|
||||
if (sensor->last_detected_edge_us_ != 0) {
|
||||
// Check to see if we should filter this edge out
|
||||
if ((now - sensor->last_detected_edge_us_) >= sensor->filter_us_) {
|
||||
// Don't measure the first valid pulse (we need at least two pulses to measure the width)
|
||||
if (sensor->last_valid_edge_us_ != 0) {
|
||||
sensor->pulse_width_us_ = (now - sensor->last_valid_edge_us_);
|
||||
}
|
||||
|
||||
sensor->total_pulses_++;
|
||||
sensor->last_valid_edge_us_ = now;
|
||||
// Check to see if we should filter this edge out
|
||||
if ((now - sensor->last_detected_edge_us_) >= sensor->filter_us_) {
|
||||
// Don't measure the first valid pulse (we need at least two pulses to measure the width)
|
||||
if (sensor->last_valid_edge_us_ != 0) {
|
||||
sensor->pulse_width_us_ = (now - sensor->last_valid_edge_us_);
|
||||
}
|
||||
|
||||
sensor->total_pulses_++;
|
||||
sensor->last_valid_edge_us_ = now;
|
||||
}
|
||||
|
||||
sensor->last_detected_edge_us_ = now;
|
||||
|
Loading…
Reference in New Issue
Block a user