ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
pulse_meter_sensor.h
Go to the documentation of this file.
1#pragma once
2
5#include "esphome/core/hal.h"
7
8#include <cinttypes>
9
10namespace esphome::pulse_meter {
11
12class PulseMeterSensor final : public sensor::Sensor, public Component {
13 SUB_SENSOR(total)
14
15 public:
16 enum InternalFilterMode {
17 FILTER_EDGE = 0,
18 FILTER_PULSE,
19 };
20
21 void set_pin(InternalGPIOPin *pin) { this->pin_ = pin; }
22 void set_filter_us(uint32_t filter) { this->filter_us_ = filter; }
23 void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; }
24 void set_filter_mode(InternalFilterMode mode) { this->filter_mode_ = mode; }
25
26 void set_total_pulses(uint32_t pulses);
27
28 void setup() override;
29 void loop() override;
30 void dump_config() override;
31
32 protected:
33 static void edge_intr(PulseMeterSensor *sensor);
34 static void pulse_intr(PulseMeterSensor *sensor);
35
38 uint32_t timeout_us_ = 1000000UL * 60UL * 5UL;
39 InternalFilterMode filter_mode_{FILTER_EDGE};
40
41 // Variables used in the loop
44 bool peeked_edge_ = false;
47
48 // This struct and variable are used to pass data between the ISR and loop.
49 // The data from state_ is read and then count_ in state_ is reset in each loop.
50 // This must be done while guarded by an InterruptLock. Use this variable to send data
51 // from the ISR to the loop not the other way around (except for resetting count_).
57 volatile State state_{};
58
59 // Only use the following variables in the ISR or while guarded by an InterruptLock
61
63 bool last_pin_val_ = false;
64
70
72 struct PulseState {
74 bool latched_ = false;
75 };
77};
78
79} // namespace esphome::pulse_meter
BedjetMode mode
BedJet operating mode.
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio_pin.h:98
bool last_pin_val_
The last pin value seen.
static void edge_intr(PulseMeterSensor *sensor)
static void pulse_intr(PulseMeterSensor *sensor)
Base-class for all sensors.
Definition sensor.h:48
static void uint32_t