8static const char *
const TAG =
"pulse_meter";
67 const uint32_t now =
micros();
78 now -
state.last_rising_edge_us_ >= this->filter_us_) {
85 if (
state.count_ > 0) {
101 float pulse_width_us = delta_us / float(
state.count_);
102 ESP_LOGV(TAG,
"New pulse, delta: %" PRIu32
" µs, count: %" PRIu32
", width: %.5f µs", delta_us,
state.count_,
118 if (time_since_valid_edge_us > this->
timeout_us_) {
120 ESP_LOGD(TAG,
"No pulse detected for %" PRIu32
"s, assuming 0 pulses/min",
121 time_since_valid_edge_us / 1000000);
132 LOG_SENSOR(
"",
"Pulse Meter",
this);
133 LOG_PIN(
" Pin: ", this->
pin_);
135 ESP_LOGCONFIG(TAG,
" Filtering rising edges less than %" PRIu32
" µs apart", this->
filter_us_);
137 ESP_LOGCONFIG(TAG,
" Filtering pulses shorter than %" PRIu32
" µs", this->
filter_us_);
139 ESP_LOGCONFIG(TAG,
" Assuming 0 pulses/min after not receiving a pulse for %" PRIu32
"s",
146 const uint32_t now =
micros();
150 if ((now - edge_state.last_sent_edge_us_) >= sensor->
filter_us_) {
151 edge_state.last_sent_edge_us_ = now;
152 state.last_detected_edge_us_ = now;
153 state.last_rising_edge_us_ = now;
164 const uint32_t now =
micros();
173 pulse_state.latched_ =
false;
175 pulse_state.latched_ =
true;
176 state.last_detected_edge_us_ = pulse_state.last_intr_;
183 state.last_rising_edge_us_ = !pulse_state.latched_ && pin_val ? now :
state.last_detected_edge_us_;
185 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.
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_