5 namespace pulse_meter {
7 static const char *
const TAG =
"pulse_meter";
28 const uint32_t now =
micros();
32 const uint32_t time_since_valid_edge_us = now - last_valid_high_edge_us;
33 if ((has_valid_high_edge) && (time_since_valid_edge_us > this->
timeout_us_)) {
34 ESP_LOGD(TAG,
"No pulse detected for %us, assuming 0 pulses/min", time_since_valid_edge_us / 1000000);
48 if (pulse_width_ms == 0) {
69 LOG_SENSOR(
"",
"Pulse Meter",
this);
70 LOG_PIN(
" Pin: ", this->
pin_);
72 ESP_LOGCONFIG(TAG,
" Filtering rising edges less than %u µs apart", this->
filter_us_);
74 ESP_LOGCONFIG(TAG,
" Filtering pulses shorter than %u µs", this->
filter_us_);
76 ESP_LOGCONFIG(TAG,
" Assuming 0 pulses/min after not receiving a pulse for %us", this->
timeout_us_ / 1000000);
85 const uint32_t now =
micros();
volatile uint32_t pulse_width_us_
bool next(T value)
Feeds the next item in the series to the deduplicator and returns whether this is a duplicate...
InternalFilterMode filter_mode_
volatile uint32_t last_detected_edge_us_
volatile uint32_t last_valid_high_edge_us_
sensor::Sensor * total_sensor_
volatile bool has_valid_high_edge_
uint32_t IRAM_ATTR HOT micros()
volatile uint32_t last_valid_low_edge_us_
void dump_config() override
static void gpio_intr(PulseMeterSensor *sensor)
void publish_state(float state)
Publish a new state to the front-end.
void set_total_pulses(uint32_t pulses)
volatile bool sensor_is_high_
Deduplicator< uint32_t > total_dedupe_
virtual ISRInternalGPIOPin to_isr() const =0
Deduplicator< uint32_t > pulse_width_dedupe_
ISRInternalGPIOPin isr_pin_
volatile bool has_detected_edge_
volatile uint32_t total_pulses_
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
volatile bool has_valid_low_edge_