8static const char *
const TAG =
"pulse_meter";
65 const uint32_t now =
micros();
75 now - this->get_->last_rising_edge_us_ >= this->filter_us_) {
98 float pulse_width_us = delta_us / float(this->
get_->
count_);
99 ESP_LOGV(TAG,
"New pulse, delta: %" PRIu32
" µs, count: %" PRIu32
", width: %.5f µs", delta_us,
115 if (time_since_valid_edge_us > this->
timeout_us_) {
117 ESP_LOGD(TAG,
"No pulse detected for %" PRIu32
"s, assuming 0 pulses/min",
118 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",
145 const uint32_t now =
micros();
147 auto &set = *sensor->
set_;
150 state.last_sent_edge_us_ = now;
151 set.last_detected_edge_us_ = now;
152 set.last_rising_edge_us_ = now;
163 const uint32_t now =
micros();
166 auto &set = *sensor->
set_;
172 state.latched_ =
false;
174 state.latched_ =
true;
175 set.last_detected_edge_us_ =
state.last_intr_;
182 set.last_rising_edge_us_ = !
state.latched_ && pin_val ? now : set.last_detected_edge_us_;
184 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_