ESPHome 2025.5.0
Loading...
Searching...
No Matches
pulse_counter_sensor.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7#include <cinttypes>
8
9#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3)
10#include <driver/pcnt.h>
11#define HAS_PCNT
12#endif // defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3)
13
14namespace esphome {
15namespace pulse_counter {
16
22
23#ifdef HAS_PCNT
24using pulse_counter_t = int16_t;
25#else // HAS_PCNT
26using pulse_counter_t = int32_t;
27#endif // HAS_PCNT
28
39
51
52#ifdef HAS_PCNT
56
57 pcnt_unit_t pcnt_unit;
58 pcnt_channel_t pcnt_channel;
59};
60#endif // HAS_PCNT
61
62PulseCounterStorageBase *get_storage(bool hw_pcnt = false);
63
65 public:
66 explicit PulseCounterSensor(bool hw_pcnt = false) : storage_(*get_storage(hw_pcnt)) {}
67
68 void set_pin(InternalGPIOPin *pin) { pin_ = pin; }
71 void set_filter_us(uint32_t filter) { storage_.filter_us = filter; }
72 void set_total_sensor(sensor::Sensor *total_sensor) { total_sensor_ = total_sensor; }
73
74 void set_total_pulses(uint32_t pulses);
75
77 void setup() override;
78 void update() override;
79 float get_setup_priority() const override { return setup_priority::DATA; }
80 void dump_config() override;
81
82 protected:
85 uint32_t last_time_{0};
86 uint32_t current_total_{0};
88};
89
90} // namespace pulse_counter
91} // 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
This class simplifies creating components that periodically check a state.
Definition component.h:301
void setup() override
Unit of measurement is "pulses/min".
void set_total_sensor(sensor::Sensor *total_sensor)
void set_falling_edge_mode(PulseCounterCountMode mode)
void set_rising_edge_mode(PulseCounterCountMode mode)
Base-class for all sensors.
Definition sensor.h:57
PulseCounterStorageBase * get_storage(bool hw_pcnt)
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:19
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
bool pulse_counter_setup(InternalGPIOPin *pin) override
static void gpio_intr(BasicPulseCounterStorage *arg)
bool pulse_counter_setup(InternalGPIOPin *pin) override
virtual pulse_counter_t read_raw_value()=0
virtual bool pulse_counter_setup(InternalGPIOPin *pin)=0