7static const char *
const TAG =
"pulse_meter";
77 now -
state.last_rising_edge_us_ >= this->filter_us_) {
84 if (
state.count_ > 0) {
100 float pulse_width_us = delta_us / float(
state.count_);
101 ESP_LOGV(TAG,
"New pulse, delta: %" PRIu32
" µs, count: %" PRIu32
", width: %.5f µs", delta_us,
state.count_,
117 if (time_since_valid_edge_us > this->
timeout_us_) {
119 ESP_LOGD(TAG,
"No pulse detected for %" PRIu32
"s, assuming 0 pulses/min",
120 time_since_valid_edge_us / 1000000);
131 LOG_SENSOR(
"",
"Pulse Meter",
this);
132 LOG_PIN(
" Pin: ", this->
pin_);
134 ESP_LOGCONFIG(TAG,
" Filtering rising edges less than %" PRIu32
" µs apart", this->
filter_us_);
136 ESP_LOGCONFIG(TAG,
" Filtering pulses shorter than %" PRIu32
" µs", this->
filter_us_);
138 ESP_LOGCONFIG(TAG,
" Assuming 0 pulses/min after not receiving a pulse for %" PRIu32
"s",
149 if ((now - edge_state.last_sent_edge_us_) >= sensor->
filter_us_) {
150 edge_state.last_sent_edge_us_ = now;
151 state.last_detected_edge_us_ = now;
152 state.last_rising_edge_us_ = now;
172 pulse_state.latched_ =
false;
174 pulse_state.latched_ =
true;
175 state.last_detected_edge_us_ = pulse_state.last_intr_;
182 state.last_rising_edge_us_ = !pulse_state.latched_ && pin_val ? now :
state.last_detected_edge_us_;
184 pulse_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_
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.
uint32_t IRAM_ATTR HOT micros()
uint32_t last_detected_edge_us_
uint32_t last_rising_edge_us_