ESPHome  2022.6.2
pulse_meter_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 #include "esphome/core/helpers.h"
7 
8 namespace esphome {
9 namespace pulse_meter {
10 
11 class PulseMeterSensor : public sensor::Sensor, public Component {
12  public:
16  };
17 
18  void set_pin(InternalGPIOPin *pin) { this->pin_ = pin; }
19  void set_filter_us(uint32_t filter) { this->filter_us_ = filter; }
21  void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; }
22  void set_total_sensor(sensor::Sensor *sensor) { this->total_sensor_ = sensor; }
23 
24  void set_total_pulses(uint32_t pulses);
25 
26  void setup() override;
27  void loop() override;
28  float get_setup_priority() const override { return setup_priority::DATA; }
29  void dump_config() override;
30 
31  protected:
32  static void gpio_intr(PulseMeterSensor *sensor);
33 
34  InternalGPIOPin *pin_ = nullptr;
36  uint32_t filter_us_ = 0;
37  uint32_t timeout_us_ = 1000000UL * 60UL * 5UL;
40 
43 
44  volatile uint32_t last_detected_edge_us_ = 0;
45  volatile uint32_t last_valid_low_edge_us_ = 0;
46  volatile uint32_t last_valid_high_edge_us_ = 0;
47  volatile uint32_t pulse_width_us_ = 0;
48  volatile uint32_t total_pulses_ = 0;
49  volatile bool sensor_is_high_ = false;
50 };
51 
52 } // namespace pulse_meter
53 } // namespace esphome
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:18
BedjetMode mode
BedJet operating mode.
Definition: bedjet_base.h:102
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition: gpio.h:66
static void gpio_intr(PulseMeterSensor *sensor)
void set_filter_mode(InternalFilterMode mode)
Deduplicator< uint32_t > pulse_width_dedupe_
Definition: a4988.cpp:4
Base-class for all sensors.
Definition: sensor.h:47
void set_total_sensor(sensor::Sensor *sensor)