mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-06 04:48:27 +02:00
Pulse meter internal filter mode (#3082)
Co-authored-by: Paul Daumlechner <paul.daumlechner@live.de> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
@@ -10,8 +10,14 @@ namespace pulse_meter {
|
||||
|
||||
class PulseMeterSensor : public sensor::Sensor, public Component {
|
||||
public:
|
||||
enum InternalFilterMode {
|
||||
FILTER_EDGE = 0,
|
||||
FILTER_PULSE,
|
||||
};
|
||||
|
||||
void set_pin(InternalGPIOPin *pin) { this->pin_ = pin; }
|
||||
void set_filter_us(uint32_t filter) { this->filter_us_ = filter; }
|
||||
void set_filter_mode(InternalFilterMode mode) { this->filter_mode_ = mode; }
|
||||
void set_timeout_us(uint32_t timeout) { this->timeout_us_ = timeout; }
|
||||
void set_total_sensor(sensor::Sensor *sensor) { this->total_sensor_ = sensor; }
|
||||
|
||||
@@ -30,14 +36,17 @@ class PulseMeterSensor : public sensor::Sensor, public Component {
|
||||
uint32_t filter_us_ = 0;
|
||||
uint32_t timeout_us_ = 1000000UL * 60UL * 5UL;
|
||||
sensor::Sensor *total_sensor_ = nullptr;
|
||||
InternalFilterMode filter_mode_{FILTER_EDGE};
|
||||
|
||||
Deduplicator<uint32_t> pulse_width_dedupe_;
|
||||
Deduplicator<uint32_t> total_dedupe_;
|
||||
|
||||
volatile uint32_t last_detected_edge_us_ = 0;
|
||||
volatile uint32_t last_valid_edge_us_ = 0;
|
||||
volatile uint32_t last_valid_low_edge_us_ = 0;
|
||||
volatile uint32_t last_valid_high_edge_us_ = 0;
|
||||
volatile uint32_t pulse_width_us_ = 0;
|
||||
volatile uint32_t total_pulses_ = 0;
|
||||
volatile bool sensor_is_high_ = false;
|
||||
};
|
||||
|
||||
} // namespace pulse_meter
|
||||
|
||||
Reference in New Issue
Block a user