6 namespace pulse_meter {
8 static const char *
const TAG =
"pulse_meter";
35 const uint32_t now =
micros();
42 auto *temp = this->
set_;
54 now - this->get_->last_rising_edge_us_ >= this->filter_us_) {
77 float pulse_width_us = delta_us / float(this->
get_->
count_);
94 ESP_LOGD(TAG,
"No pulse detected for %" PRIu32
"s, assuming 0 pulses/min",
95 time_since_valid_edge_us / 1000000);
108 LOG_SENSOR(
"",
"Pulse Meter",
this);
109 LOG_PIN(
" Pin: ", this->
pin_);
111 ESP_LOGCONFIG(TAG,
" Filtering rising edges less than %" PRIu32
" µs apart", this->
filter_us_);
113 ESP_LOGCONFIG(TAG,
" Filtering pulses shorter than %" PRIu32
" µs", this->
filter_us_);
115 ESP_LOGCONFIG(TAG,
" Assuming 0 pulses/min after not receiving a pulse for %" PRIu32
"s",
122 const uint32_t now =
micros();
124 auto &
set = *sensor->
set_;
127 state.last_sent_edge_us_ = now;
128 set.last_detected_edge_us_ = now;
129 set.last_rising_edge_us_ = now;
137 const uint32_t now =
micros();
140 auto &
set = *sensor->
set_;
145 if (length &&
state.latched_ && !
state.last_pin_val_) {
146 state.latched_ =
false;
147 }
else if (length && !
state.latched_ &&
state.last_pin_val_) {
148 state.latched_ =
true;
149 set.last_detected_edge_us_ =
state.last_intr_;
156 set.last_rising_edge_us_ = !
state.latched_ && pin_val ? now :
set.last_detected_edge_us_;
158 state.last_intr_ = now;
159 state.last_pin_val_ = pin_val;
const float DATA
For components that import data from directly connected sensors like DHT.
static void edge_intr(PulseMeterSensor *sensor)
InternalFilterMode filter_mode_
sensor::Sensor * total_sensor_
uint32_t IRAM_ATTR HOT micros()
uint32_t last_detected_edge_us_
uint32_t last_processed_edge_us_
float state
This member variable stores the last state that has passed through all filters.
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
void set_total_pulses(uint32_t pulses)
static void pulse_intr(PulseMeterSensor *sensor)
uint32_t last_rising_edge_us_
virtual ISRInternalGPIOPin to_isr() const =0
Implementation of SPI Controller mode.
float get_setup_priority() const override
ISRInternalGPIOPin isr_pin_
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
esphome::sensor::Sensor * sensor