mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Update total_pulses_ at every detected pulse (#1875)
This commit is contained in:
parent
65c50e4f01
commit
635916737b
1 changed files with 8 additions and 12 deletions
|
@ -23,7 +23,6 @@ void PulseMeterSensor::loop() {
|
||||||
const uint32_t time_since_valid_edge_us = now - this->last_valid_edge_us_;
|
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_)) {
|
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);
|
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->last_valid_edge_us_ = 0;
|
||||||
this->pulse_width_us_ = 0;
|
this->pulse_width_us_ = 0;
|
||||||
}
|
}
|
||||||
|
@ -68,18 +67,15 @@ void ICACHE_RAM_ATTR PulseMeterSensor::gpio_intr(PulseMeterSensor *sensor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore the first detected pulse (we need at least two pulses to measure the width)
|
// Check to see if we should filter this edge out
|
||||||
if (sensor->last_detected_edge_us_ != 0) {
|
if ((now - sensor->last_detected_edge_us_) >= sensor->filter_us_) {
|
||||||
// Check to see if we should filter this edge out
|
// Don't measure the first valid pulse (we need at least two pulses to measure the width)
|
||||||
if ((now - sensor->last_detected_edge_us_) >= sensor->filter_us_) {
|
if (sensor->last_valid_edge_us_ != 0) {
|
||||||
// Don't measure the first valid pulse (we need at least two pulses to measure the width)
|
sensor->pulse_width_us_ = (now - sensor->last_valid_edge_us_);
|
||||||
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->total_pulses_++;
|
||||||
|
sensor->last_valid_edge_us_ = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
sensor->last_detected_edge_us_ = now;
|
sensor->last_detected_edge_us_ = now;
|
||||||
|
|
Loading…
Reference in a new issue