Fix broken PULSE_METER (#4199)

fixes https://github.com/esphome/issues/issues/3730
This commit is contained in:
cstaahl
2022-12-22 23:07:45 +01:00
committed by GitHub
parent 53b60ac817
commit 8237e13c44
2 changed files with 113 additions and 69 deletions
@@ -29,7 +29,11 @@ class PulseMeterSensor : public sensor::Sensor, public Component {
void dump_config() override;
protected:
enum StateChange { TO_LOW = 0, TO_HIGH, NONE };
static void gpio_intr(PulseMeterSensor *sensor);
void handle_state_change_(uint32_t now, uint32_t last_detected_edge_us, uint32_t last_valid_edge_us,
bool has_valid_edge);
InternalGPIOPin *pin_{nullptr};
ISRInternalGPIOPin isr_pin_;
@@ -42,14 +46,12 @@ class PulseMeterSensor : public sensor::Sensor, public Component {
Deduplicator<uint32_t> total_dedupe_;
volatile uint32_t last_detected_edge_us_ = 0;
volatile uint32_t last_valid_high_edge_us_ = 0;
volatile uint32_t last_valid_low_edge_us_ = 0;
volatile uint32_t last_valid_edge_us_ = 0;
volatile uint32_t pulse_width_us_ = 0;
volatile uint32_t total_pulses_ = 0;
volatile bool sensor_is_high_ = false;
volatile bool has_detected_edge_ = false;
volatile bool has_valid_high_edge_ = false;
volatile bool has_valid_low_edge_ = false;
volatile bool has_valid_edge_ = false;
volatile StateChange pending_state_change_{NONE};
};
} // namespace pulse_meter