ESPHome 2025.5.0
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 {
11namespace pulse_meter {
12
14 public:
19
20 void set_pin(InternalGPIOPin *pin) { this->pin_ = pin; }
21 void set_filter_us(uint32_t filter) { this->filter_us_ = filter; }
22 void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; }
23 void set_total_sensor(sensor::Sensor *sensor) { this->total_sensor_ = sensor; }
25
26 void set_total_pulses(uint32_t pulses);
27
28 void setup() override;
29 void loop() override;
30 float get_setup_priority() const override;
31 void dump_config() override;
32
33 protected:
34 static void edge_intr(PulseMeterSensor *sensor);
35 static void pulse_intr(PulseMeterSensor *sensor);
36
38 uint32_t filter_us_ = 0;
39 uint32_t timeout_us_ = 1000000UL * 60UL * 5UL;
42
43 // Variables used in the loop
46 bool peeked_edge_ = false;
47 uint32_t total_pulses_ = 0;
49
50 // This struct (and the two pointers) are used to pass data between the ISR and loop.
51 // These two pointers are exchanged each loop.
52 // Use these to send data from the ISR to the loop not the other way around (except for resetting the values).
53 struct State {
56 uint32_t count_ = 0;
57 };
59 volatile State *set_ = state_;
60 volatile State *get_ = state_ + 1;
61
62 // Only use the following variables in the ISR or while guarded by an InterruptLock
64
66 bool last_pin_val_ = false;
67
69 struct EdgeState {
70 uint32_t last_sent_edge_us_ = 0;
71 };
73
75 struct PulseState {
76 uint32_t last_intr_ = 0;
77 bool latched_ = false;
78 };
80};
81
82} // namespace pulse_meter
83} // namespace esphome
BedjetMode mode
BedJet operating mode.
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio.h:73
bool last_pin_val_
The last pin value seen.
static void edge_intr(PulseMeterSensor *sensor)
void set_total_sensor(sensor::Sensor *sensor)
static void pulse_intr(PulseMeterSensor *sensor)
void set_filter_mode(InternalFilterMode mode)
Base-class for all sensors.
Definition sensor.h:57
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7