8static const char *
const TAG =
"pulse_meter";
61 const uint32_t now =
micros();
71 now - this->get_->last_rising_edge_us_ >= this->filter_us_) {
94 float pulse_width_us = delta_us / float(this->
get_->
count_);
95 ESP_LOGV(TAG,
"New pulse, delta: %" PRIu32
" µs, count: %" PRIu32
", width: %.5f µs", delta_us,
111 if (time_since_valid_edge_us > this->
timeout_us_) {
113 ESP_LOGD(TAG,
"No pulse detected for %" PRIu32
"s, assuming 0 pulses/min",
114 time_since_valid_edge_us / 1000000);
127 LOG_SENSOR(
"",
"Pulse Meter",
this);
128 LOG_PIN(
" Pin: ", this->
pin_);
130 ESP_LOGCONFIG(TAG,
" Filtering rising edges less than %" PRIu32
" µs apart", this->
filter_us_);
132 ESP_LOGCONFIG(TAG,
" Filtering pulses shorter than %" PRIu32
" µs", this->
filter_us_);
134 ESP_LOGCONFIG(TAG,
" Assuming 0 pulses/min after not receiving a pulse for %" PRIu32
"s",
141 const uint32_t now =
micros();
143 auto &set = *sensor->
set_;
146 state.last_sent_edge_us_ = now;
147 set.last_detected_edge_us_ = now;
148 set.last_rising_edge_us_ = now;
159 const uint32_t now =
micros();
162 auto &set = *sensor->
set_;
168 state.latched_ =
false;
170 state.latched_ =
true;
171 set.last_detected_edge_us_ =
state.last_intr_;
178 set.last_rising_edge_us_ = !
state.latched_ && pin_val ? now : set.last_detected_edge_us_;
180 state.last_intr_ = now;
virtual bool digital_read()=0
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
virtual ISRInternalGPIOPin to_isr() const =0
Helper class to disable interrupts.
uint32_t last_processed_edge_us_
bool last_pin_val_
The last pin value seen.
sensor::Sensor * total_sensor_
static void edge_intr(PulseMeterSensor *sensor)
void dump_config() override
InternalFilterMode filter_mode_
static void pulse_intr(PulseMeterSensor *sensor)
ISRInternalGPIOPin isr_pin_
float get_setup_priority() const override
void set_total_pulses(uint32_t pulses)
void publish_state(float state)
Publish a new state to the front-end.
float state
This member variable stores the last state that has passed through all filters.
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT micros()
uint32_t last_detected_edge_us_
uint32_t last_rising_edge_us_